RecommendationRequestController.java

1
package edu.ucsb.cs156.rec.controllers;
2
3
import edu.ucsb.cs156.rec.entities.RecommendationRequest;
4
import edu.ucsb.cs156.rec.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.rec.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.checkerframework.checker.units.qual.g;
15
import org.springframework.beans.factory.annotation.Autowired;
16
import org.springframework.boot.context.properties.source.IterableConfigurationPropertySource;
17
import org.springframework.format.annotation.DateTimeFormat;
18
import org.springframework.security.access.prepost.PreAuthorize;
19
import org.springframework.web.bind.annotation.DeleteMapping;
20
import org.springframework.web.bind.annotation.GetMapping;
21
import org.springframework.web.bind.annotation.PostMapping;
22
import org.springframework.web.bind.annotation.PutMapping;
23
import org.springframework.web.bind.annotation.RequestBody;
24
import org.springframework.web.bind.annotation.RequestMapping;
25
import org.springframework.web.bind.annotation.RequestParam;
26
import org.springframework.web.bind.annotation.RestController;
27
28
import jakarta.validation.Valid;
29
30
import java.time.LocalDateTime;
31
32
/**
33
 * This is a REST controller for RecommendationRequest
34
 */
35
36
@Tag(name = "RecommendationRequest")
37
@RequestMapping("/api/recommendationrequest")
38
@RestController
39
@Slf4j
40
public class RecommendationRequestController extends ApiController{
41
    
42
    @Autowired
43
    RecommendationRequestRepository recommendationRequestRepository;
44
45
    /**
46
     * List all recommendation requests
47
     * 
48
     * @return an iterable of RecommendationRequest
49
     */
50
    @Operation(summary= "List all recommendation requests")
51
    @PreAuthorize("hasRole('ROLE_USER')")
52
    @GetMapping("/all")
53
    public Iterable<RecommendationRequest> allRecommendationRequests() {
54
        Iterable<RecommendationRequest> requests = recommendationRequestRepository.findAll();
55 1 1. allRecommendationRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/rec/controllers/RecommendationRequestController::allRecommendationRequests → KILLED
        return requests;
56
    }
57
58
    /**
59
     * Get a single recommendation request by id
60
     * 
61
     * @param id the id of the recommendation request
62
     * @return a recommendation request
63
     */
64
    @Operation(summary= "Get a single recommendation request")
65
    @PreAuthorize("hasRole('ROLE_USER')")
66
    @GetMapping("")
67
    public RecommendationRequest getById(
68
            @Parameter(name="id") @RequestParam Long id) {
69
        RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id)
70 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/rec/controllers/RecommendationRequestController::lambda$getById$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id));
71
72 1 1. getById : replaced return value with null for edu/ucsb/cs156/rec/controllers/RecommendationRequestController::getById → KILLED
        return recommendationRequest;
73
    }
74
75
    /**
76
     * Create a new recommendation request
77
     * 
78
     * @param requesterEmail the email of the requester
79
     * @param professorEmail the email of the professor
80
     * @param explanation the explanation of the request
81
     * @param dateRequested the date the request was made
82
     * @param dateNeeded the date the request is needed
83
     * @param done whether the request is done
84
     * @return the created RecommendationRequest
85
    */
86
    
87
    @Operation(summary= "Create a new recommendation request")
88
    @PreAuthorize("hasRole('ROLE_ADMIN')")
89
    @PostMapping("/post")
90
    public RecommendationRequest postRecommendationRequest(
91
        @Parameter(name="requesterEmail") @RequestParam String requesterEmail,
92
        @Parameter(name="professorEmail") @RequestParam String professorEmail,
93
        @Parameter(name="explanation") @RequestParam String explanation,
94
        @Parameter(name="dateRequested") @RequestParam("dateRequested") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dateRequested,
95
        @Parameter(name="dateNeeded") @RequestParam("dateNeeded") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dateNeeded,
96
        @Parameter(name="done") @RequestParam boolean done)
97
        throws JsonProcessingException {
98
99
            log.info("date_Requested{}", dateRequested);
100
101
            RecommendationRequest recommendationRequest = new RecommendationRequest();
102 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/rec/entities/RecommendationRequest::setRequesterEmail → KILLED
            recommendationRequest.setRequesterEmail(requesterEmail);
103 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/rec/entities/RecommendationRequest::setProfessorEmail → KILLED
            recommendationRequest.setProfessorEmail(professorEmail);
104 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/rec/entities/RecommendationRequest::setExplanation → KILLED
            recommendationRequest.setExplanation(explanation);
105 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/rec/entities/RecommendationRequest::setDateRequested → KILLED
            recommendationRequest.setDateRequested(dateRequested);
106 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/rec/entities/RecommendationRequest::setDateNeeded → KILLED
            recommendationRequest.setDateNeeded(dateNeeded);
107 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/rec/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/rec/controllers/RecommendationRequestController::postRecommendationRequest → KILLED
            return savedRecommendationRequest;
112
    }
113
114
    /**
115
     * Delete a recommendation request
116
     * 
117
     * @param id the id of the recommendation request to delete
118
     * @return a message indicating the recommedation 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/rec/controllers/RecommendationRequestController::lambda$deleteRecommendationRequest$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id));
127
128 1 1. deleteRecommendationRequest : removed call to edu/ucsb/cs156/rec/repositories/RecommendationRequestRepository::delete → KILLED
        recommendationRequestRepository.delete(recommendationRequest);
129 1 1. deleteRecommendationRequest : replaced return value with null for edu/ucsb/cs156/rec/controllers/RecommendationRequestController::deleteRecommendationRequest → KILLED
        return genericMessage("RecommendationRequest with id %s deleted".formatted(id));
130
    }
131
132
    /**
133
     * Update a single recommendation request
134
     * 
135
     * @param id       id of the recommendation request to update
136
     * @param incoming the new recommendation 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/rec/controllers/RecommendationRequestController::lambda$updateRecommendationRequest$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id));
148
149 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/rec/entities/RecommendationRequest::setRequesterEmail → KILLED
        recommendationRequest.setRequesterEmail(incoming.getRequesterEmail());
150 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/rec/entities/RecommendationRequest::setProfessorEmail → KILLED
        recommendationRequest.setProfessorEmail(incoming.getProfessorEmail());
151 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/rec/entities/RecommendationRequest::setExplanation → KILLED
        recommendationRequest.setExplanation(incoming.getExplanation());
152 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/rec/entities/RecommendationRequest::setDateRequested → KILLED
        recommendationRequest.setDateRequested(incoming.getDateRequested());
153 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/rec/entities/RecommendationRequest::setDateNeeded → KILLED
        recommendationRequest.setDateNeeded(incoming.getDateNeeded());
154 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/rec/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/rec/controllers/RecommendationRequestController::updateRecommendationRequest → KILLED
        return recommendationRequest;
159
    }
160
}

Mutations

55

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

70

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

72

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

102

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

103

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

104

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

105

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

106

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

107

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

111

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

126

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

128

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

129

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

147

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

149

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

150

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

151

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

152

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

153

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

154

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

158

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

Active mutators

Tests examined


Report generated by PIT 1.17.0