RecommendationRequestController.java

1
package edu.ucsb.cs156.example.controllers;
2
import edu.ucsb.cs156.example.entities.UCSBRecommendationRequest;
3
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
4
import edu.ucsb.cs156.example.repositories.UCSBRecommendationRequestRepository;
5
6
import java.time.LocalDate;
7
import java.time.format.DateTimeFormatter;
8
9
import io.swagger.v3.oas.annotations.Operation;
10
import io.swagger.v3.oas.annotations.Parameter;
11
import io.swagger.v3.oas.annotations.tags.Tag;
12
import lombok.extern.slf4j.Slf4j;
13
14
import com.fasterxml.jackson.core.JsonProcessingException;
15
16
import org.springframework.beans.factory.annotation.Autowired;
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
37
@Tag(name = "RecommendationRequest")
38
@RequestMapping("/api/recommendationRequest")
39
@RestController
40
@Slf4j
41
public class RecommendationRequestController extends ApiController {
42
43
    @Autowired
44
    UCSBRecommendationRequestRepository  ucsbRecommendationRequestRepository; 
45
46
        /**
47
     * List all UCSB dates
48
     * 
49
     * @return an iterable of UCSBDate
50
     */
51
    @Operation(summary= "List all ucsb recommendation requests")
52
    @PreAuthorize("hasRole('ROLE_ADMIN')")
53
    @GetMapping("/all")
54
    public Iterable<UCSBRecommendationRequest> allUCSBRecommendationRequestRepository() {
55
        Iterable<UCSBRecommendationRequest> requests = ucsbRecommendationRequestRepository.findAll();
56 1 1. allUCSBRecommendationRequestRepository : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/RecommendationRequestController::allUCSBRecommendationRequestRepository → KILLED
        return requests;   
57
    }
58
59
60
61
    /**
62
     * Create a new rec
63
     * 
64
     * 
65
     * @param requesterEmail the name of the requestor : string 
66
     * @param professorEmail the name of the professor : string 
67
     * @param explanation what the request details : string
68
     * @param dateRequested date requestor sent request : iso format, e.g. YYYY-mm-ddTHH:MM:SS
69
     * @param dateNeeded date requestor needs request finished by : iso format, e.g. YYYY-mm-ddTHH:MM:SS
70
     * @param done the truth value of it being finished or not : bool
71
     * @return the saved recommendation request
72
     */
73
    @Operation(summary= "Create a recommendation request")
74
    @PreAuthorize("hasRole('ROLE_USER')")
75
    @PostMapping("/post")
76
    public UCSBRecommendationRequest postRecommendationRequest
77
    (
78
            @Parameter(name="requesterEmail") @RequestParam String requesterEmail,
79
            @Parameter(name="professorEmail") @RequestParam String professorEmail,
80
            @Parameter(name="explanation") @RequestParam String explanation,
81
            @Parameter(name="done") @RequestParam Boolean done,
82
            @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,
83
            @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
84
    )
85
 
86
            throws JsonProcessingException {
87
88
        // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
89
        // See: https://www.baeldung.com/spring-date-parameters
90
91
        log.info("dateRequested={}", dateRequested);
92
        log.info("dateNeeded={}", dateNeeded);
93
94
        UCSBRecommendationRequest ucsbRecommendationRequest = new UCSBRecommendationRequest();
95 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setRequesterEmail → KILLED
        ucsbRecommendationRequest.setRequesterEmail(requesterEmail);
96 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setProfessorEmail → KILLED
        ucsbRecommendationRequest.setProfessorEmail(professorEmail);
97 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setExplanation → KILLED
        ucsbRecommendationRequest.setExplanation(explanation);
98 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setDateRequested → KILLED
        ucsbRecommendationRequest.setDateRequested(dateRequested);
99 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setDateNeeded → KILLED
        ucsbRecommendationRequest.setDateNeeded(dateNeeded);
100 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setDone → KILLED
        ucsbRecommendationRequest.setDone(done);
101
102
        UCSBRecommendationRequest saveducsbRecommendationRequest = ucsbRecommendationRequestRepository.save(ucsbRecommendationRequest);
103
104 1 1. postRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::postRecommendationRequest → KILLED
        return saveducsbRecommendationRequest;
105
    }
106
107
        /**
108
     * Get a single item on the menu by id
109
     * 
110
     * @param id the id of the menu item
111
     * @return a menu item
112
     */
113
    @Operation(summary= "Get a single recommendation by id")
114
    @PreAuthorize("hasRole('ROLE_USER')")
115
    @GetMapping("")
116
    public UCSBRecommendationRequest getById(
117
            @Parameter(name="id") @RequestParam Long id) {
118
                UCSBRecommendationRequest ucsbRecommendationRequest = ucsbRecommendationRequestRepository
119
                .findById(id)
120 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$getById$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBRecommendationRequest.class, id));
121
122 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::getById → KILLED
        return ucsbRecommendationRequest;
123
    }
124
125
126
        /**
127
     * Update a single recommendation request
128
     * 
129
     * @param id       id of the date to update
130
     * @param incoming the recommendation request
131
     * @return the updated recommendation request object
132
     */
133
    @Operation(summary= "Update a recommendation request")
134
    @PreAuthorize("hasRole('ROLE_ADMIN')")
135
    @PutMapping("")
136
    public UCSBRecommendationRequest updateRecommendationRequest(
137
            @Parameter(name="id") @RequestParam Long id,
138
            @RequestBody @Valid UCSBRecommendationRequest incoming) {
139
140
        UCSBRecommendationRequest ucsbRecommendationRequest = ucsbRecommendationRequestRepository.findById(id)
141 1 1. lambda$updateRecommendationRequest$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$updateRecommendationRequest$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBRecommendationRequest.class, id));
142
143 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setDateNeeded → KILLED
        ucsbRecommendationRequest.setDateNeeded(incoming.getDateNeeded());
144 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setDateRequested → KILLED
        ucsbRecommendationRequest.setDateRequested(incoming.getDateRequested());
145 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setDone → KILLED
        ucsbRecommendationRequest.setDone(incoming.getDone());
146 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setExplanation → KILLED
        ucsbRecommendationRequest.setExplanation(incoming.getExplanation());
147 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setId → KILLED
        ucsbRecommendationRequest.setId(id);
148 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setProfessorEmail → KILLED
        ucsbRecommendationRequest.setProfessorEmail(incoming.getProfessorEmail());
149 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setRequesterEmail → KILLED
        ucsbRecommendationRequest.setRequesterEmail(incoming.getRequesterEmail());
150
        ucsbRecommendationRequestRepository.save(ucsbRecommendationRequest);
151
152 1 1. updateRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::updateRecommendationRequest → KILLED
        return ucsbRecommendationRequest;
153
    }
154
155
        /**
156
     * Delete a UCSBRecommendationRequest 
157
     * 
158
     * @param id the id of the recommendationRequest to delete
159
     * @return a message indicating the recommendationRequest was deleted
160
     */
161
    @Operation(summary= "Delete a UCSBRecommendationRequest")
162
    @PreAuthorize("hasRole('ROLE_ADMIN')")
163
    @DeleteMapping("")
164
    public Object deleteUCSBDate(
165
            @Parameter(name="id") @RequestParam Long id) {
166
            UCSBRecommendationRequest ucsbRecommendationRequest = ucsbRecommendationRequestRepository.findById(id)
167 1 1. lambda$deleteUCSBDate$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$deleteUCSBDate$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBRecommendationRequest.class, id));
168
169 1 1. deleteUCSBDate : removed call to edu/ucsb/cs156/example/repositories/UCSBRecommendationRequestRepository::delete → KILLED
        ucsbRecommendationRequestRepository.delete(ucsbRecommendationRequest);
170 1 1. deleteUCSBDate : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::deleteUCSBDate → KILLED
        return genericMessage("UCSBRecommendationRequest with id %s deleted".formatted(id));
171
    }
172
173
174
    
175
}

Mutations

56

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

95

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

96

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

97

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

98

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

99

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

100

1.1
Location : postRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:admin_can_post_new_recommendation_request()]
removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setDone → 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:admin_can_post_new_recommendation_request()]
replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::postRecommendationRequest → KILLED

120

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

122

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

141

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

143

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_ucsbdate()]
removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setDateNeeded → KILLED

144

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_ucsbdate()]
removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setDateRequested → 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_ucsbdate()]
removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setDone → 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_ucsbdate()]
removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setExplanation → 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_ucsbdate()]
removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setId → 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_ucsbdate()]
removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setProfessorEmail → 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_ucsbdate()]
removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setRequesterEmail → 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_ucsbdate()]
replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::updateRecommendationRequest → KILLED

167

1.1
Location : lambda$deleteUCSBDate$2
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_ucsbdate_and_gets_right_error_message()]
replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$deleteUCSBDate$2 → KILLED

169

1.1
Location : deleteUCSBDate
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/UCSBRecommendationRequestRepository::delete → KILLED

170

1.1
Location : deleteUCSBDate
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::deleteUCSBDate → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0