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 HeloRequests
32
 */
33
@Tag(name = "HelpRequests")
34
@RequestMapping("/api/helprequests")
35
@RestController
36
@Slf4j
37
public class HelpRequestsController extends ApiController {
38
39
    @Autowired
40
    HelpRequestRepository helpRequestRepository;
41
42
    /**
43
     * List all UCSB helprequests
44
     * 
45
     * @return an iterable of HelpRequest
46
     */
47
    @Operation(summary= "List all ucsb helprequests")
48
    @PreAuthorize("hasRole('ROLE_USER')")
49
    @GetMapping("/all")
50
    public Iterable<HelpRequest> allHelpRequests() {
51
        Iterable<HelpRequest> helprequests = helpRequestRepository.findAll();
52 1 1. allHelpRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/HelpRequestsController::allHelpRequests → KILLED
        return helprequests;
53
    }
54
55
     /**
56
     * Create a new helprequest
57
     * 
58
     * @param requesterEmail helprequest email
59
     * @param teamId         team id
60
     * @param tableOrBreakoutRoom     table
61
     * @param requestTime     time
62
     * @param explanation     explain
63
     * @param solved          solve
64
     * @return the saved helprequest
65
     */
66
    @Operation(summary= "Create a new helprequest")
67
    @PreAuthorize("hasRole('ROLE_ADMIN')")
68
    @PostMapping("/post")
69
    public HelpRequest postHelpRequest(
70
            @Parameter(name="requesterEmail") @RequestParam String requesterEmail,
71
            @Parameter(name="teamId") @RequestParam String teamId,
72
            @Parameter(name="tableOrBreakoutRoom") @RequestParam String tableOrBreakoutRoom,
73
            @Parameter(name="explanation") @RequestParam String explanation,
74
            @Parameter(name="solved") @RequestParam boolean solved,
75
            @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)
76
            throws JsonProcessingException {
77
78
        // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
79
        // See: https://www.baeldung.com/spring-date-parameters
80
81
        log.info("requestTime={}", requestTime);
82
83
        HelpRequest helprequest = new HelpRequest();
84 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED
        helprequest.setRequesterEmail(requesterEmail);
85 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED
        helprequest.setTeamId(teamId);
86 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED
        helprequest.setTableOrBreakoutRoom(tableOrBreakoutRoom);
87 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED
        helprequest.setRequestTime(requestTime);
88 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED
        helprequest.setExplanation(explanation);
89 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED
        helprequest.setSolved(solved);
90
91
        HelpRequest savedHelpRequest = helpRequestRepository.save(helprequest);
92
93 1 1. postHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::postHelpRequest → KILLED
        return savedHelpRequest;
94
    }
95
96
97
    /**
98
     * Get a single helprequest by id
99
     * 
100
     * @param id the id of the helprequest
101
     * @return a HelpRequest
102
     */
103
    @Operation(summary= "Get a single helprequest")
104
    @PreAuthorize("hasRole('ROLE_USER')")
105
    @GetMapping("")
106
    public HelpRequest getById(
107
            @Parameter(name="id") @RequestParam Long id) {
108
        HelpRequest helprequest = helpRequestRepository.findById(id)
109 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));
110
111 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::getById → KILLED
        return helprequest;
112
    }
113
114
115
    /**
116
     * Update a single helprequest
117
     * 
118
     * @param id       id of the helprequest to update
119
     * @param incoming the new helprequest
120
     * @return the updated helprequest object
121
     */
122
    @Operation(summary= "Update a single helprequest")
123
    @PreAuthorize("hasRole('ROLE_ADMIN')")
124
    @PutMapping("")
125
    public HelpRequest updateHelpRequest(
126
            @Parameter(name="id") @RequestParam Long id,
127
            @RequestBody @Valid HelpRequest incoming) {
128
129
        HelpRequest helprequest = helpRequestRepository.findById(id)
130 1 1. lambda$updateHelpRequest$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::lambda$updateHelpRequest$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id));
131
132
133 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED
        helprequest.setRequesterEmail(incoming.getRequesterEmail());
134 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED
        helprequest.setTeamId(incoming.getTeamId());
135 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED
        helprequest.setTableOrBreakoutRoom(incoming.getTableOrBreakoutRoom());
136 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED
        helprequest.setRequestTime(incoming.getRequestTime());
137 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED
        helprequest.setExplanation(incoming.getExplanation());
138 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED
        helprequest.setSolved(incoming.getSolved());
139
140
        
141
142
        helpRequestRepository.save(helprequest);
143
144 1 1. updateHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::updateHelpRequest → KILLED
        return helprequest;
145
    }
146
147
    /**
148
     * Delete a HelpRequest
149
     * 
150
     * @param id the id of the helprequest to delete
151
     * @return a message indicating the helprequest was deleted
152
     */
153
    @Operation(summary= "Delete a HelpRequest")
154
    @PreAuthorize("hasRole('ROLE_ADMIN')")
155
    @DeleteMapping("")
156
    public Object deleteHelpRequest(
157
            @Parameter(name="id") @RequestParam Long id) {
158
        HelpRequest helprequest = helpRequestRepository.findById(id)
159 1 1. lambda$deleteHelpRequest$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::lambda$deleteHelpRequest$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id));
160
161 1 1. deleteHelpRequest : removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED
        helpRequestRepository.delete(helprequest);
162 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));
163
    }
164
165
166
}

Mutations

52

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

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_helprequests()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → 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_helprequests()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → 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_helprequests()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → 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_helprequests()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED

88

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_helprequests()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED

89

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_helprequests()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED

93

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

109

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

111

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

130

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

133

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

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::setTeamId → 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::setTableOrBreakoutRoom → 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::setRequestTime → 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::setExplanation → 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::setSolved → KILLED

144

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

159

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

161

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

162

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

Active mutators

Tests examined


Report generated by PIT 1.17.0