RecommendationRequestsController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.Articles;
4
import edu.ucsb.cs156.example.entities.RecommendationRequest;
5
import edu.ucsb.cs156.example.entities.UCSBDate;
6
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
7
import edu.ucsb.cs156.example.repositories.RecommendationRequestRepository;
8
import edu.ucsb.cs156.example.repositories.UCSBDateRepository;
9
10
import io.swagger.v3.oas.annotations.Operation;
11
import io.swagger.v3.oas.annotations.Parameter;
12
import io.swagger.v3.oas.annotations.tags.Tag;
13
import lombok.extern.slf4j.Slf4j;
14
15
import com.fasterxml.jackson.core.JsonProcessingException;
16
17
import org.springframework.beans.factory.annotation.Autowired;
18
import org.springframework.format.annotation.DateTimeFormat;
19
import org.springframework.security.access.method.P;
20
import org.springframework.security.access.prepost.PreAuthorize;
21
import org.springframework.web.bind.annotation.DeleteMapping;
22
import org.springframework.web.bind.annotation.GetMapping;
23
import org.springframework.web.bind.annotation.PostMapping;
24
import org.springframework.web.bind.annotation.PutMapping;
25
import org.springframework.web.bind.annotation.RequestBody;
26
import org.springframework.web.bind.annotation.RequestMapping;
27
import org.springframework.web.bind.annotation.RequestParam;
28
import org.springframework.web.bind.annotation.RestController;
29
30
import jakarta.validation.Valid;
31
32
import java.time.LocalDateTime;
33
34
/**
35
 * This is a REST controller for RecommendationRequests
36
 */
37
38
@Tag(name = "RecommendationRequests")
39
@RequestMapping("/api/recommendationrequests")
40
@RestController
41
@Slf4j
42
public class RecommendationRequestsController extends ApiController{
43
    @Autowired
44
    RecommendationRequestRepository recommendationRequestRepository;
45
46
    /**
47
     * List all Recommendation requests
48
     * 
49
     * @return an iterable of RecommendationRequest
50
     */
51
    @Operation(summary= "List all recommendation requests")
52
    @PreAuthorize("hasRole('ROLE_USER')")
53
    @GetMapping("/all")
54
    public Iterable<RecommendationRequest> allRecommendationRequests() {
55
        Iterable<RecommendationRequest> recommendationRequests = recommendationRequestRepository.findAll();
56 1 1. allRecommendationRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::allRecommendationRequests → KILLED
        return recommendationRequests;
57
    }
58
59
    /**
60
     * Get a single recommendation request by id
61
     * 
62
     * @param id the id of the recommendation request
63
     * @return a recommendation request
64
     */
65
    @Operation(summary= "Get a single date")
66
    @PreAuthorize("hasRole('ROLE_USER')")
67
    @GetMapping("")
68
    public RecommendationRequest getById(
69
            @Parameter(name="id") @RequestParam Long id) {
70
        RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id)
71 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::lambda$getById$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id));
72
73 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::getById → KILLED
        return recommendationRequest;
74
    }
75
76
    /**
77
     * Create a new recommendation request
78
     * 
79
     * @param requesterEmail the email of the requester
80
     * @param professorEmail the email of the professor
81
     * @param explanation the explanation of the request
82
     * @param dateRequested the date the request was made
83
     * @param dateNeeded the date the request is needed
84
     * @param done whether the request is done
85
     * 
86
     * @return the saved rec request
87
     */
88
    @Operation(summary= "Create a new recommendation request")
89
    @PreAuthorize("hasRole('ROLE_ADMIN')")
90
    @PostMapping("/post")
91
    public RecommendationRequest postRecommendationRequest(
92
            @Parameter(name="requesterEmail") @RequestParam String requesterEmail,
93
            @Parameter(name="professorEmail") @RequestParam String professorEmail,
94
            @Parameter(name="explanation") @RequestParam String explanation,
95
            @Parameter(name="dateRequested") @RequestParam("dateRequested") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dateRequested,
96
            @Parameter(name="dateNeeded") @RequestParam("dateNeeded") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dateNeeded,
97
            @Parameter(name="done") @RequestParam boolean done)
98
            throws JsonProcessingException {
99
100
        // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
101
        // See: https://www.baeldung.com/spring-date-parameters
102
103
        log.info("dateRequested={}", dateRequested);
104
        log.info("dateNeeded={}", dateNeeded);
105
106
        RecommendationRequest recommendationRequest = new RecommendationRequest();
107 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED
        recommendationRequest.setRequesterEmail(requesterEmail);
108 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED
        recommendationRequest.setProfessorEmail(professorEmail);
109 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED
        recommendationRequest.setExplanation(explanation);
110 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED
        recommendationRequest.setDateRequested(dateRequested);
111 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED
        recommendationRequest.setDateNeeded(dateNeeded);
112 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED
        recommendationRequest.setDone(done);
113
114
        RecommendationRequest savedRecommendationRequest = recommendationRequestRepository.save(recommendationRequest);
115
116 1 1. postRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::postRecommendationRequest → KILLED
        return savedRecommendationRequest;
117
    }
118
119
    /**
120
     * Delete a RecommendationRequest
121
     * 
122
     * @param id the id of the rec request to delete
123
     * @return a message indicating the rec request was deleted
124
     */
125
    @Operation(summary= "Delete a RecommendationRequest")
126
    @PreAuthorize("hasRole('ROLE_ADMIN')")
127
    @DeleteMapping("")
128
    public Object deleteRecommendationRequest(
129
            @Parameter(name="id") @RequestParam Long id) {
130
        RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id)
131 1 1. lambda$deleteRecommendationRequest$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::lambda$deleteRecommendationRequest$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id));
132
133 1 1. deleteRecommendationRequest : removed call to edu/ucsb/cs156/example/repositories/RecommendationRequestRepository::delete → KILLED
        recommendationRequestRepository.delete(recommendationRequest);
134 1 1. deleteRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::deleteRecommendationRequest → KILLED
        return genericMessage("RecommendationRequest with id %s deleted".formatted(id));
135
    }
136
137
138
     /**
139
     * Update a single date
140
     * 
141
     * @param id       id of the date to update
142
     * @param incoming the new date
143
     * @return the updated date object
144
     */
145
    @Operation(summary= "Update a single date")
146
    @PreAuthorize("hasRole('ROLE_ADMIN')")
147
    @PutMapping("")
148
    public RecommendationRequest updateRecommendationRequest(
149
            @Parameter(name="id") @RequestParam Long id,
150
            @RequestBody @Valid RecommendationRequest incoming) {
151
152
        RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id)
153 1 1. lambda$updateRecommendationRequest$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::lambda$updateRecommendationRequest$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id));
154
155 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED
        recommendationRequest.setDateNeeded(incoming.getDateNeeded());
156 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED
        recommendationRequest.setDateRequested(incoming.getDateRequested());
157 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED
        recommendationRequest.setExplanation(incoming.getExplanation());
158 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED
        recommendationRequest.setRequesterEmail(incoming.getRequesterEmail());
159 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED
        recommendationRequest.setProfessorEmail(incoming.getProfessorEmail());
160 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED
        recommendationRequest.setDone(incoming.getDone());
161
162
        recommendationRequestRepository.save(recommendationRequest);
163
164 1 1. updateRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::updateRecommendationRequest → KILLED
        return recommendationRequest;
165
    }
166
167
}

Mutations

56

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

71

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

73

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

107

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

108

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

109

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

110

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

111

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

112

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

116

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

131

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

133

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

134

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

153

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

155

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

156

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

157

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

158

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

159

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

160

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

164

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

Active mutators

Tests examined


Report generated by PIT 1.17.0