RecommendationRequestController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.RecommendationRequest;
4
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.example.repositories.RecommendationRequestRepository;
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
32
33
34
@Tag(name = "RecommendationRequest")
35
@RequestMapping("/api/recommendationrequest")
36
@RestController
37
@Slf4j
38
public class RecommendationRequestController extends ApiController{
39
40
    @Autowired
41
    RecommendationRequestRepository recommendationRequestRepository;
42
43
    /**
44
     * List all Recommendation requests
45
     * 
46
     * @return an iterable of RecommendationRequest
47
     */
48
    @Operation(summary= "List all recommendation requests")
49
    @PreAuthorize("hasRole('ROLE_USER')")
50
    @GetMapping("/all")
51
    public Iterable<RecommendationRequest> allRecommendationRequests() {
52
        Iterable<RecommendationRequest> requests = recommendationRequestRepository.findAll();
53 1 1. allRecommendationRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/RecommendationRequestController::allRecommendationRequests → KILLED
        return requests;
54
    }
55
56
    /**
57
     * Get a single recommendation request by id
58
     * 
59
     * @param id the id of the recommendation request
60
     * @return a RecommendationRequest
61
     */
62
    @Operation(summary= "Get a single recommendation request")
63
    @PreAuthorize("hasRole('ROLE_USER')")
64
    @GetMapping("")
65
    public RecommendationRequest getById(
66
            @Parameter(name="id") @RequestParam Long id) {
67
        RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id)
68 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$getById$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id));
69
70 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::getById → KILLED
        return recommendationRequest;
71
    }
72
73
    /**
74
     * Create a new recommendation request
75
     * 
76
     * @param requesterEmail  the email of the person making the request
77
     * @param professorEmail  the email of the professor
78
     * @param explanation   explanation of the request
79
     * @param dateRequested the date of the request
80
     * @param dateNeeded    the date the request is needed
81
     * @param done          the status of the request   
82
     * @return the saved recommendation request
83
     */
84
    @Operation(summary= "Create a new recommendation request")
85
    @PreAuthorize("hasRole('ROLE_ADMIN')")
86
    @PostMapping("/post")
87
    public RecommendationRequest postRecommendationRequest(
88
            @Parameter(name="requesterEmail") @RequestParam String requesterEmail,
89
            @Parameter(name="professorEmail") @RequestParam String professorEmail,
90
            @Parameter(name="explanation") @RequestParam String explanation,
91
            @Parameter(name="dateRequested", description="date (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)") @RequestParam("dateRequested") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dateRequested,
92
            @Parameter(name="dateNeeded", description="date (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)") @RequestParam("dateNeeded") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dateNeeded,
93
            @Parameter(name="done") @RequestParam boolean done)
94
            throws JsonProcessingException {
95
96
        // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
97
        // See: https://www.baeldung.com/spring-date-parameters
98
99
        log.info("localDateTime={}", dateRequested);
100
101
        RecommendationRequest recommendationRequest = new RecommendationRequest();
102 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED
        recommendationRequest.setRequesterEmail(requesterEmail);
103 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED
        recommendationRequest.setProfessorEmail(professorEmail);
104 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED
        recommendationRequest.setExplanation(explanation);
105 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED
        recommendationRequest.setDateRequested(dateRequested);
106 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED
        recommendationRequest.setDateNeeded(dateNeeded);
107 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED
        recommendationRequest.setDone(done);
108
109
        RecommendationRequest savedRecommendationRequest = recommendationRequestRepository.save(recommendationRequest);
110
111 1 1. postRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::postRecommendationRequest → KILLED
        return savedRecommendationRequest;
112
    }
113
114
    /**
115
     * Delete a Recommendation Request
116
     * 
117
     * @param id the id of the request to delete
118
     * @return a message indicating the request was deleted
119
     */
120
    @Operation(summary= "Delete a recommendation request")
121
    @PreAuthorize("hasRole('ROLE_ADMIN')")
122
    @DeleteMapping("")
123
    public Object deleteRecommendationRequest(
124
            @Parameter(name="id") @RequestParam Long id) {
125
        RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id)
126 1 1. lambda$deleteRecommendationRequest$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$deleteRecommendationRequest$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id));
127
128 1 1. deleteRecommendationRequest : removed call to edu/ucsb/cs156/example/repositories/RecommendationRequestRepository::delete → KILLED
        recommendationRequestRepository.delete(recommendationRequest);
129 1 1. deleteRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::deleteRecommendationRequest → KILLED
        return genericMessage("Recommendation Request with id %s deleted".formatted(id));
130
    }
131
132
    /**
133
     * Update a single recommendation request
134
     * 
135
     * @param id       id of the request to update
136
     * @param incoming the new request
137
     * @return the updated recommendation request object
138
     */
139
    @Operation(summary= "Update a single recommendation request")
140
    @PreAuthorize("hasRole('ROLE_ADMIN')")
141
    @PutMapping("")
142
    public RecommendationRequest updateRecommendationRequest(
143
            @Parameter(name="id") @RequestParam Long id,
144
            @RequestBody @Valid RecommendationRequest incoming) {
145
146
        RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id)
147 1 1. lambda$updateRecommendationRequest$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$updateRecommendationRequest$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id));
148
149 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED
        recommendationRequest.setRequesterEmail(incoming.getRequesterEmail());
150 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED
        recommendationRequest.setProfessorEmail(incoming.getProfessorEmail());
151 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED
        recommendationRequest.setExplanation(incoming.getExplanation());
152 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED
        recommendationRequest.setDateRequested(incoming.getDateRequested());
153 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED
        recommendationRequest.setDateNeeded(incoming.getDateNeeded());
154 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED
        recommendationRequest.setDone(incoming.getDone());
155
156
        recommendationRequestRepository.save(recommendationRequest);
157
158 1 1. updateRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::updateRecommendationRequest → KILLED
        return recommendationRequest;
159
    }
160
}

Mutations

53

1.1
Location : allRecommendationRequests
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:logged_in_user_can_get_all_recommendationrequest()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/RecommendationRequestController::allRecommendationRequests → KILLED

68

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

70

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

102

1.1
Location : postRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:an_admin_user_can_post_a_new_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED

103

1.1
Location : postRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:an_admin_user_can_post_a_new_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED

104

1.1
Location : postRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:an_admin_user_can_post_a_new_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED

105

1.1
Location : postRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:an_admin_user_can_post_a_new_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED

106

1.1
Location : postRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:an_admin_user_can_post_a_new_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED

107

1.1
Location : postRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:an_admin_user_can_post_a_new_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED

111

1.1
Location : postRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:an_admin_user_can_post_a_new_recommendationrequest()]
replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::postRecommendationRequest → KILLED

126

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

128

1.1
Location : deleteRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:admin_can_delete_a_recommendationrequest()]
removed call to edu/ucsb/cs156/example/repositories/RecommendationRequestRepository::delete → KILLED

129

1.1
Location : deleteRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:admin_can_delete_a_recommendationrequest()]
replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::deleteRecommendationRequest → KILLED

147

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

149

1.1
Location : updateRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:admin_can_edit_an_existing_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED

150

1.1
Location : updateRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:admin_can_edit_an_existing_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED

151

1.1
Location : updateRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:admin_can_edit_an_existing_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED

152

1.1
Location : updateRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:admin_can_edit_an_existing_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED

153

1.1
Location : updateRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:admin_can_edit_an_existing_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED

154

1.1
Location : updateRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:admin_can_edit_an_existing_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED

158

1.1
Location : updateRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:admin_can_edit_an_existing_recommendationrequest()]
replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::updateRecommendationRequest → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0