HelpRequestController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.HelpRequest;
4
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.example.repositories.HelpRequestRepository;
6
7
import io.swagger.v3.oas.annotations.Operation;
8
import io.swagger.v3.oas.annotations.Parameter;
9
import io.swagger.v3.oas.annotations.tags.Tag;
10
import lombok.extern.slf4j.Slf4j;
11
12
import com.fasterxml.jackson.core.JsonProcessingException;
13
14
import org.springframework.beans.factory.annotation.Autowired;
15
import org.springframework.format.annotation.DateTimeFormat;
16
import org.springframework.security.access.prepost.PreAuthorize;
17
import org.springframework.web.bind.annotation.DeleteMapping;
18
import org.springframework.web.bind.annotation.GetMapping;
19
import org.springframework.web.bind.annotation.PostMapping;
20
import org.springframework.web.bind.annotation.PutMapping;
21
import org.springframework.web.bind.annotation.RequestBody;
22
import org.springframework.web.bind.annotation.RequestMapping;
23
import org.springframework.web.bind.annotation.RequestParam;
24
import org.springframework.web.bind.annotation.RestController;
25
26
import java.time.LocalDateTime;
27
28
import javax.validation.Valid;
29
30
@Tag(name = "HelpRequests")
31
@RequestMapping("/api/helprequests")
32
@RestController
33
@Slf4j
34
public class HelpRequestController extends ApiController{
35
    @Autowired
36
    HelpRequestRepository helpRequestRepository;
37
38
    @Operation(summary= "List all help requests")
39
    @PreAuthorize("hasRole('ROLE_USER')")
40
    @GetMapping("/all")
41
    public Iterable<HelpRequest> allHelpRequests() {
42
        Iterable<HelpRequest> requests = helpRequestRepository.findAll();
43 1 1. allHelpRequests : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::allHelpRequests → KILLED
        return requests;
44
    }
45
46
    @Operation(summary= "Create a new help request")
47
    @PreAuthorize("hasRole('ROLE_ADMIN')")
48
    @PostMapping("/post")
49
    public HelpRequest postHelpRequest(
50
            @Parameter(name="requesterEmail",description="Email of help requester",example="cgaucho@ucsb.edu") @RequestParam String requesterEmail,
51
            @Parameter(name="teamId",description="Team id",example="s22-5pm-3") @RequestParam String teamId,
52
            @Parameter(name="tableOrBreakoutRoom",description="Table or breakout room number",example="7") @RequestParam String tableOrBreakoutRoom,
53
            @Parameter(name="explanation",description="Description of help request",example="Need help with Swagger-ui") @RequestParam String explanation,
54
            @Parameter(name="solved",description="If request has been solved",example="false") @RequestParam boolean solved,
55
            @Parameter(name="requestTime", description="Time in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601",example="2022-04-20T17:35") @RequestParam("requestTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime requestTime)
56
            throws JsonProcessingException {
57
58
        // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
59
        // See: https://www.baeldung.com/spring-date-parameters
60
61
        log.info("requestTime={}", 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::setSolved → KILLED
        helpRequest.setSolved(solved);
69 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED
        helpRequest.setRequestTime(requestTime);
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
76
    @Operation(summary= "Get a single help request")
77
    @PreAuthorize("hasRole('ROLE_USER')")
78
    @GetMapping("")
79
    public HelpRequest getById(
80
            @Parameter(name="id") @RequestParam Long id) {
81
        HelpRequest helpRequest = helpRequestRepository.findById(id)
82 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));
83
84 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::getById → KILLED
        return helpRequest;
85
    }
86
    
87
    @Operation(summary= "Update a single help request")
88
    @PreAuthorize("hasRole('ROLE_ADMIN')")
89
    @PutMapping("")
90
    public HelpRequest updateHelpRequest(
91
        @Parameter(name="id") @RequestParam Long id,
92
        @RequestBody @Valid HelpRequest incoming) {
93
94
        HelpRequest helpRequest = helpRequestRepository.findById(id)
95 1 1. lambda$updateHelpRequest$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$updateHelpRequest$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id));
96
97 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED
        helpRequest.setRequesterEmail(incoming.getRequesterEmail());
98 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED
        helpRequest.setTeamId(incoming.getTeamId());
99 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED
        helpRequest.setTableOrBreakoutRoom(incoming.getTableOrBreakoutRoom());
100 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED
        helpRequest.setRequestTime(incoming.getRequestTime());
101 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED
        helpRequest.setExplanation(incoming.getExplanation());
102 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED
        helpRequest.setSolved(incoming.getSolved());
103
104
        helpRequestRepository.save(helpRequest);
105
106 1 1. updateHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::updateHelpRequest → KILLED
        return helpRequest;
107
    }
108
109
    @Operation(summary= "Delete a HelpRequest")
110
    @PreAuthorize("hasRole('ROLE_ADMIN')")
111
    @DeleteMapping("")
112
    public Object deleteHelpRequest(
113
            @Parameter(name="id") @RequestParam Long id) {
114
        HelpRequest helpRequest = helpRequestRepository.findById(id)
115 1 1. lambda$deleteHelpRequest$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$deleteHelpRequest$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id));
116
117 1 1. deleteHelpRequest : removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED
        helpRequestRepository.delete(helpRequest);
118 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));
119
    }
120
}

Mutations

43

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::setSolved → 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::setRequestTime → 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

82

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

84

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

95

1.1
Location : lambda$updateHelpRequest$1
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$1 → KILLED

97

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

98

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

99

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

100

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

101

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

102

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

106

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

115

1.1
Location : lambda$deleteHelpRequest$2
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$2 → KILLED

117

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_request()]
removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED

118

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_request()]
replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::deleteHelpRequest → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3