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

Mutations

48

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_recommendationrequests()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/RecommendationRequestController::allRecommendationRequests → KILLED

81

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

82

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

83

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

84

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

85

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

86

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

90

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

105

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

107

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

122

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

124

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

125

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

143

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

145

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

146

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

147

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

148

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

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::setDateNeeded → 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::setDone → 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()]
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