HelpRequestsController.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 jakarta.validation.Valid;
27
28
import java.time.LocalDateTime;
29
30
/**
31
 * This is a REST controller for HelpRequests
32
 */
33
34
@Tag(name = "HelpRequests")
35
@RequestMapping("/api/helprequests")
36
@RestController
37
@Slf4j
38
39
public class HelpRequestsController extends ApiController {
40
41
    @Autowired
42
    HelpRequestRepository helpRequestRepository;
43
44
    @Operation(summary= "List all help requests")
45
    @PreAuthorize("hasRole('ROLE_USER')")
46
    @GetMapping("/all")
47
    public Iterable<HelpRequest> allHelpRequests() {
48
        Iterable<HelpRequest> requests = helpRequestRepository.findAll();
49 1 1. allHelpRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/HelpRequestsController::allHelpRequests → KILLED
        return requests;
50
    }
51
52
    @Operation(summary= "Get a help request")
53
    @PreAuthorize("hasRole('ROLE_USER')")
54
    @GetMapping("")
55
    public HelpRequest getById(
56
            @Parameter(name="id") @RequestParam Long id) {
57
        HelpRequest helpRequest = helpRequestRepository.findById(id)
58 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::lambda$getById$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id));
59
60 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::getById → KILLED
        return helpRequest;
61
    }
62
63
    @Operation(summary= "Create a new help request")
64
    @PreAuthorize("hasRole('ROLE_ADMIN')")
65
    @PostMapping("/post")
66
    public HelpRequest postHelpRequest(
67
            @Parameter(name="requesterEmail") @RequestParam String requesterEmail,
68
            @Parameter(name="teamId") @RequestParam String teamId,
69
            @Parameter(name="tableOrBreakoutRoom") @RequestParam String tableOrBreakoutRoom,
70
            @Parameter(name="requestTime", description="date (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)") @RequestParam("requestTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime requestTime,
71
            @Parameter(name="explanation") @RequestParam String explanation,
72
            @Parameter(name="solved") @RequestParam boolean solved
73
            )
74
            throws JsonProcessingException {
75
76
        // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
77
        // See: https://www.baeldung.com/spring-date-parameters
78
79
        log.info("requestTime={}", requestTime);
80
81
        HelpRequest helpRequest = new HelpRequest();
82 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED
        helpRequest.setRequesterEmail(requesterEmail);
83 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED
        helpRequest.setTeamId(teamId);
84 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED
        helpRequest.setTableOrBreakoutRoom(tableOrBreakoutRoom);
85 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED
        helpRequest.setRequestTime(requestTime);
86 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED
        helpRequest.setExplanation(explanation);
87 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED
        helpRequest.setSolved(solved);
88
89
        HelpRequest savedhelpRequest = helpRequestRepository.save(helpRequest);
90
91 1 1. postHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::postHelpRequest → KILLED
        return savedhelpRequest;
92
    }
93
94
95
    /**
96
     * Delete a HelpRequest
97
     * 
98
     * @param id the id of the request to delete
99
     * @return a message indicating the request was deleted
100
     */
101
    @Operation(summary= "Delete a HelpRequest")
102
    @PreAuthorize("hasRole('ROLE_ADMIN')")
103
    @DeleteMapping("")
104
    public Object deleteHelpRequest(
105
            @Parameter(name="id") @RequestParam Long id) {
106
        HelpRequest helpRequest = helpRequestRepository.findById(id)
107 1 1. lambda$deleteHelpRequest$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::lambda$deleteHelpRequest$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id));
108
109 1 1. deleteHelpRequest : removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED
        helpRequestRepository.delete(helpRequest);
110 1 1. deleteHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::deleteHelpRequest → KILLED
        return genericMessage("HelpRequest with id %s deleted".formatted(id));
111
    }
112
113
    /**
114
     * Update a single request
115
     * 
116
     * @param id       id of the request to update
117
     * @param incoming the new request
118
     * @return the updated request object
119
     */
120
    @Operation(summary= "Update a single request")
121
    @PreAuthorize("hasRole('ROLE_ADMIN')")
122
    @PutMapping("")
123
    public HelpRequest updateHelpRequest(
124
            @Parameter(name="id") @RequestParam Long id,
125
            @RequestBody @Valid HelpRequest incoming) {
126
127
        HelpRequest helpRequest = helpRequestRepository.findById(id)
128 1 1. lambda$updateHelpRequest$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::lambda$updateHelpRequest$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id));
129
130
        // helpRequest.setQuarterYYYYQ(incoming.getQuarterYYYYQ());
131
        // helpRequest.setName(incoming.getName());
132
        // helpRequest.setLocalDateTime(incoming.getLocalDateTime());
133
134 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED
        helpRequest.setRequesterEmail(incoming.getRequesterEmail());
135 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED
        helpRequest.setTeamId(incoming.getTeamId());
136 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED
        helpRequest.setTableOrBreakoutRoom(incoming.getTableOrBreakoutRoom());
137 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED
        helpRequest.setRequestTime(incoming.getRequestTime());
138 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED
        helpRequest.setExplanation(incoming.getExplanation());
139 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED
        helpRequest.setSolved(incoming.getSolved());
140
141
        helpRequestRepository.save(helpRequest);
142
143 1 1. updateHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::updateHelpRequest → KILLED
        return helpRequest;
144
    }
145
146
147
}

Mutations

49

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

58

1.1
Location : lambda$getById$0
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestsControllerTests]/[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/HelpRequestsController::lambda$getById$0 → KILLED

60

1.1
Location : getById
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestsControllerTests]/[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/HelpRequestsController::getById → KILLED

82

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

83

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

84

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

85

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

86

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

87

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

91

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

107

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

109

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

110

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

128

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

134

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

135

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

136

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

137

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

138

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

139

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

143

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

Active mutators

Tests examined


Report generated by PIT 1.17.0