HelpRequestController.java

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

Mutations

43

1.1
Location : allHelpRequest
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_helprequest()]
replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::allHelpRequest → 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::setRequestTime → 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::setExplanation → 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

74

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

83

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

85

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

94

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

96

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

97

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

108

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

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

114

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

115

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

120

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