HelpRequestController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.HelpRequest;
4
import edu.ucsb.cs156.example.entities.UCSBDate;
5
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
6
import edu.ucsb.cs156.example.repositories.HelpRequestRepository;
7
8
import io.swagger.v3.oas.annotations.Operation;
9
import io.swagger.v3.oas.annotations.Parameter;
10
import io.swagger.v3.oas.annotations.tags.Tag;
11
import lombok.extern.slf4j.Slf4j;
12
13
import com.fasterxml.jackson.core.JsonProcessingException;
14
15
import org.springframework.beans.factory.annotation.Autowired;
16
import org.springframework.format.annotation.DateTimeFormat;
17
import org.springframework.security.access.prepost.PreAuthorize;
18
import org.springframework.web.bind.annotation.DeleteMapping;
19
import org.springframework.web.bind.annotation.GetMapping;
20
import org.springframework.web.bind.annotation.PostMapping;
21
import org.springframework.web.bind.annotation.PutMapping;
22
import org.springframework.web.bind.annotation.RequestBody;
23
import org.springframework.web.bind.annotation.RequestMapping;
24
import org.springframework.web.bind.annotation.RequestParam;
25
import org.springframework.web.bind.annotation.RestController;
26
27
import javax.validation.Valid;
28
29
import java.time.LocalDateTime;
30
31
@Tag(name = "HelpRequests")
32
@RequestMapping("/api/helprequests")
33
@RestController
34
@Slf4j
35
public class HelpRequestController extends ApiController {
36
    
37
    @Autowired
38
    HelpRequestRepository helpRequestRepository;
39
40
    @Operation(summary= "List all help requests")
41
    @PreAuthorize("hasRole('ROLE_USER')")
42
    @GetMapping("/all")
43
    public Iterable<HelpRequest> allHelpRequests() {
44
        Iterable<HelpRequest> helpRequests = helpRequestRepository.findAll();
45 1 1. allHelpRequests : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::allHelpRequests → KILLED
        return helpRequests;
46
    }
47
48
    @Operation(summary= "Create a new help request")
49
    @PreAuthorize("hasRole('ROLE_ADMIN')")
50
    @PostMapping("/post")
51
    public HelpRequest postHelpRequest(
52
            @Parameter(name="requesterEmail") @RequestParam String requesterEmail,
53
            @Parameter(name="teamId") @RequestParam String teamId,
54
            @Parameter(name="tableOrBreakoutRoom") @RequestParam String tableOrBreakoutRoom,
55
            @Parameter(name="explanation") @RequestParam String explanation,
56
            @Parameter(name="requestTime") @RequestParam("requestTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime requestTime,
57
            @Parameter(name="solved") @RequestParam boolean solved)
58
            throws JsonProcessingException {
59
60
61
        log.info("localDateTime={}", requestTime);
62
63
        HelpRequest helpRequest = new HelpRequest();
64 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED
        helpRequest.setRequesterEmail(requesterEmail);
65 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED
        helpRequest.setTeamId(teamId);
66 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED
        helpRequest.setTableOrBreakoutRoom(tableOrBreakoutRoom);
67 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED
        helpRequest.setExplanation(explanation);
68 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED
        helpRequest.setRequestTime(requestTime);
69 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED
        helpRequest.setSolved(solved);
70
71
        HelpRequest savedHelpRequest = helpRequestRepository.save(helpRequest);
72
73 1 1. postHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::postHelpRequest → KILLED
        return savedHelpRequest;
74
    }
75
    @Operation(summary= "Get a single help request")
76
    @PreAuthorize("hasRole('ROLE_USER')")
77
    @GetMapping("")
78
    public HelpRequest getById(
79
        @Parameter(name="id") @RequestParam Long id) {
80
        HelpRequest helpRequest = helpRequestRepository.findById(id)
81 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$getById$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id));
82
83 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::getById → KILLED
        return helpRequest;
84
    }
85
86
    @Operation(summary= "Delete a HelpRequest")
87
    @PreAuthorize("hasRole('ROLE_ADMIN')")
88
    @DeleteMapping("")
89
    public Object deleteHelpRequest(
90
            @Parameter(name="id") @RequestParam Long id) {
91
        HelpRequest helpRequest = helpRequestRepository.findById(id)
92 1 1. lambda$deleteHelpRequest$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$deleteHelpRequest$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id));
93
94 1 1. deleteHelpRequest : removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED
        helpRequestRepository.delete(helpRequest);
95 1 1. deleteHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::deleteHelpRequest → KILLED
        return genericMessage("HelpRequest with id %s deleted".formatted(id));
96
    }
97
98
    @Operation(summary= "Update a single help request")
99
    @PreAuthorize("hasRole('ROLE_ADMIN')")
100
    @PutMapping("")
101
    public HelpRequest updateHelpRequest(
102
            @Parameter(name="id") @RequestParam Long id,
103
            @RequestBody @Valid HelpRequest incoming) {
104
105
        HelpRequest helpRequest = helpRequestRepository.findById(id)
106 1 1. lambda$updateHelpRequest$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$updateHelpRequest$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id));
107
108 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED
        helpRequest.setRequesterEmail(incoming.getRequesterEmail());
109 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED
        helpRequest.setTeamId(incoming.getTeamId());
110 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED
        helpRequest.setTableOrBreakoutRoom(incoming.getTableOrBreakoutRoom());
111 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED
        helpRequest.setExplanation(incoming.getExplanation());
112 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED
        helpRequest.setRequestTime(incoming.getRequestTime());
113 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED
        helpRequest.setSolved(incoming.getSolved());
114
115
        helpRequestRepository.save(helpRequest);
116
117 1 1. updateHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::updateHelpRequest → KILLED
        return helpRequest;
118
    }
119
}
120
121
// Empty Comment

Mutations

45

1.1
Location : allHelpRequests
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:logged_in_user_can_get_all_helprequests()]
replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::allHelpRequests → KILLED

64

1.1
Location : postHelpRequest
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:an_admin_user_can_post_a_new_helprequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED

65

1.1
Location : postHelpRequest
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:an_admin_user_can_post_a_new_helprequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED

66

1.1
Location : postHelpRequest
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:an_admin_user_can_post_a_new_helprequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED

67

1.1
Location : postHelpRequest
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:an_admin_user_can_post_a_new_helprequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED

68

1.1
Location : postHelpRequest
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:an_admin_user_can_post_a_new_helprequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED

69

1.1
Location : postHelpRequest
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:an_admin_user_can_post_a_new_helprequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED

73

1.1
Location : postHelpRequest
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:an_admin_user_can_post_a_new_helprequest()]
replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::postHelpRequest → KILLED

81

1.1
Location : lambda$getById$0
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:test_that_logged_in_user_can_get_by_id_when_the_id_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$getById$0 → KILLED

83

1.1
Location : getById
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:test_that_logged_in_user_can_get_by_id_when_the_id_exists()]
replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::getById → KILLED

92

1.1
Location : lambda$deleteHelpRequest$1
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:admin_tries_to_delete_non_existant_helprequest_and_gets_right_error_message()]
replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$deleteHelpRequest$1 → KILLED

94

1.1
Location : deleteHelpRequest
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:admin_can_delete_a_date()]
removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED

95

1.1
Location : deleteHelpRequest
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:admin_can_delete_a_date()]
replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::deleteHelpRequest → KILLED

106

1.1
Location : lambda$updateHelpRequest$2
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:admin_cannot_edit_helprequest_that_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$updateHelpRequest$2 → KILLED

108

1.1
Location : updateHelpRequest
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:admin_can_edit_an_existing_helprequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED

109

1.1
Location : updateHelpRequest
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:admin_can_edit_an_existing_helprequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED

110

1.1
Location : updateHelpRequest
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:admin_can_edit_an_existing_helprequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED

111

1.1
Location : updateHelpRequest
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:admin_can_edit_an_existing_helprequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED

112

1.1
Location : updateHelpRequest
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:admin_can_edit_an_existing_helprequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED

113

1.1
Location : updateHelpRequest
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:admin_can_edit_an_existing_helprequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED

117

1.1
Location : updateHelpRequest
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:admin_can_edit_an_existing_helprequest()]
replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::updateHelpRequest → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3