| 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 | import io.swagger.v3.oas.annotations.Operation; | |
| 7 | import io.swagger.v3.oas.annotations.Parameter; | |
| 8 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 9 | import jakarta.validation.Valid; | |
| 10 | import java.time.LocalDateTime; | |
| 11 | import lombok.extern.slf4j.Slf4j; | |
| 12 | import org.springframework.beans.factory.annotation.Autowired; | |
| 13 | import org.springframework.format.annotation.DateTimeFormat; | |
| 14 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 15 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 16 | import org.springframework.web.bind.annotation.GetMapping; | |
| 17 | import org.springframework.web.bind.annotation.PostMapping; | |
| 18 | import org.springframework.web.bind.annotation.PutMapping; | |
| 19 | import org.springframework.web.bind.annotation.RequestBody; | |
| 20 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 21 | import org.springframework.web.bind.annotation.RequestParam; | |
| 22 | import org.springframework.web.bind.annotation.RestController; | |
| 23 | ||
| 24 | /** This is a REST controller for RecommendationRequests */ | |
| 25 | @Tag(name = "RecommendationRequest") | |
| 26 | @RequestMapping("/api/RecommendationRequest") | |
| 27 | @RestController | |
| 28 | @Slf4j | |
| 29 | public class RecommendationRequestController extends ApiController { | |
| 30 | ||
| 31 | @Autowired RecommendationRequestRepository recommendationRequestRepository; | |
| 32 | ||
| 33 | /** | |
| 34 | * List all recommendation requests | |
| 35 | * | |
| 36 | * @return an iterable of RecommendationRequest | |
| 37 | */ | |
| 38 | @Operation(summary = "List all recommendation requests") | |
| 39 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 40 | @GetMapping("/all") | |
| 41 | public Iterable<RecommendationRequest> allRecommendationRequests() { | |
| 42 | Iterable<RecommendationRequest> requests = recommendationRequestRepository.findAll(); | |
| 43 |
1
1. allRecommendationRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/RecommendationRequestController::allRecommendationRequests → KILLED |
return requests; |
| 44 | } | |
| 45 | ||
| 46 | /** | |
| 47 | * Get a single recommendation request by id | |
| 48 | * | |
| 49 | * @param id the id of the recommendation request | |
| 50 | * @return a RecommendationRequest | |
| 51 | */ | |
| 52 | @Operation( | |
| 53 | summary = "Get a single recommendation request", | |
| 54 | description = | |
| 55 | "Returns the recommendation request with the given id, or a 404 error if no recommendation request has that id") | |
| 56 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 57 | @GetMapping("") | |
| 58 | public RecommendationRequest getById( | |
| 59 | @Parameter(name = "id", description = "id of the recommendation request to get") @RequestParam | |
| 60 | Long id) { | |
| 61 | RecommendationRequest recommendationRequest = | |
| 62 | recommendationRequestRepository | |
| 63 | .findById(id) | |
| 64 |
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)); |
| 65 | ||
| 66 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::getById → KILLED |
return recommendationRequest; |
| 67 | } | |
| 68 | ||
| 69 | /** | |
| 70 | * Create a new recommendation request | |
| 71 | * | |
| 72 | * @param requesterEmail the email of the student requesting the recommendation | |
| 73 | * @param professorEmail the email of the professor being asked for the recommendation | |
| 74 | * @param explanation what the recommendation is for (e.g. the program being applied to) | |
| 75 | * @param dateRequested the date the recommendation was requested | |
| 76 | * @param dateNeeded the date by which the recommendation is needed | |
| 77 | * @param done whether the recommendation request has been fulfilled | |
| 78 | * @return the saved recommendation request | |
| 79 | */ | |
| 80 | @Operation(summary = "Create a new recommendation request") | |
| 81 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 82 | @PostMapping("/post") | |
| 83 | public RecommendationRequest postRecommendationRequest( | |
| 84 | @Parameter( | |
| 85 | name = "requesterEmail", | |
| 86 | description = "email of the student requesting the recommendation") | |
| 87 | @RequestParam | |
| 88 | String requesterEmail, | |
| 89 | @Parameter( | |
| 90 | name = "professorEmail", | |
| 91 | description = "email of the professor being asked for the recommendation") | |
| 92 | @RequestParam | |
| 93 | String professorEmail, | |
| 94 | @Parameter( | |
| 95 | name = "explanation", | |
| 96 | description = | |
| 97 | "what the recommendation is for (e.g. the program or position being applied to)") | |
| 98 | @RequestParam | |
| 99 | String explanation, | |
| 100 | @Parameter( | |
| 101 | name = "dateRequested", | |
| 102 | description = | |
| 103 | "date the recommendation was requested (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)") | |
| 104 | @RequestParam("dateRequested") | |
| 105 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 106 | LocalDateTime dateRequested, | |
| 107 | @Parameter( | |
| 108 | name = "dateNeeded", | |
| 109 | description = | |
| 110 | "date by which the recommendation is needed (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)") | |
| 111 | @RequestParam("dateNeeded") | |
| 112 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 113 | LocalDateTime dateNeeded, | |
| 114 | @Parameter( | |
| 115 | name = "done", | |
| 116 | description = "whether the recommendation request has been fulfilled") | |
| 117 | @RequestParam | |
| 118 | boolean done) { | |
| 119 | ||
| 120 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 121 | // See: https://www.baeldung.com/spring-date-parameters | |
| 122 | ||
| 123 | log.info("dateRequested={}, dateNeeded={}", dateRequested, dateNeeded); | |
| 124 | ||
| 125 | RecommendationRequest recommendationRequest = new RecommendationRequest(); | |
| 126 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
recommendationRequest.setRequesterEmail(requesterEmail); |
| 127 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
recommendationRequest.setProfessorEmail(professorEmail); |
| 128 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
recommendationRequest.setExplanation(explanation); |
| 129 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
recommendationRequest.setDateRequested(dateRequested); |
| 130 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
recommendationRequest.setDateNeeded(dateNeeded); |
| 131 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
recommendationRequest.setDone(done); |
| 132 | ||
| 133 | RecommendationRequest savedRecommendationRequest = | |
| 134 | recommendationRequestRepository.save(recommendationRequest); | |
| 135 | ||
| 136 |
1
1. postRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::postRecommendationRequest → KILLED |
return savedRecommendationRequest; |
| 137 | } | |
| 138 | ||
| 139 | /** | |
| 140 | * Delete a RecommendationRequest | |
| 141 | * | |
| 142 | * @param id the id of the recommendation request to delete | |
| 143 | * @return a message indicating the recommendation request was deleted | |
| 144 | */ | |
| 145 | @Operation( | |
| 146 | summary = "Delete a recommendation request", | |
| 147 | description = | |
| 148 | "Deletes the recommendation request with the given id and returns a message confirming it was deleted, or a 404 error if no recommendation request has that id") | |
| 149 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 150 | @DeleteMapping("") | |
| 151 | public Object deleteRecommendationRequest( | |
| 152 | @Parameter(name = "id", description = "id of the recommendation request to delete") | |
| 153 | @RequestParam | |
| 154 | Long id) { | |
| 155 | RecommendationRequest recommendationRequest = | |
| 156 | recommendationRequestRepository | |
| 157 | .findById(id) | |
| 158 |
1
1. lambda$deleteRecommendationRequest$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$deleteRecommendationRequest$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id)); |
| 159 | ||
| 160 |
1
1. deleteRecommendationRequest : removed call to edu/ucsb/cs156/example/repositories/RecommendationRequestRepository::delete → KILLED |
recommendationRequestRepository.delete(recommendationRequest); |
| 161 |
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)); |
| 162 | } | |
| 163 | ||
| 164 | /** | |
| 165 | * Update a single recommendation request | |
| 166 | * | |
| 167 | * @param id id of the recommendation request to update | |
| 168 | * @param incoming the new values for the recommendation request | |
| 169 | * @return the updated recommendation request | |
| 170 | */ | |
| 171 | @Operation( | |
| 172 | summary = "Update a single recommendation request", | |
| 173 | description = | |
| 174 | "Replaces requesterEmail, professorEmail, explanation, dateRequested, dateNeeded, and done of the recommendation request with the given id using the values in the JSON request body (any id in the body is ignored); dates are in iso format, e.g. YYYY-mm-ddTHH:MM:SS. Returns the updated recommendation request, or a 404 error if no recommendation request has that id") | |
| 175 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 176 | @PutMapping("") | |
| 177 | public RecommendationRequest updateRecommendationRequest( | |
| 178 | @Parameter(name = "id", description = "id of the recommendation request to update") | |
| 179 | @RequestParam | |
| 180 | Long id, | |
| 181 | @RequestBody @Valid RecommendationRequest incoming) { | |
| 182 | ||
| 183 | RecommendationRequest recommendationRequest = | |
| 184 | recommendationRequestRepository | |
| 185 | .findById(id) | |
| 186 |
1
1. lambda$updateRecommendationRequest$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$updateRecommendationRequest$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id)); |
| 187 | ||
| 188 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
recommendationRequest.setRequesterEmail(incoming.getRequesterEmail()); |
| 189 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
recommendationRequest.setProfessorEmail(incoming.getProfessorEmail()); |
| 190 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
recommendationRequest.setExplanation(incoming.getExplanation()); |
| 191 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
recommendationRequest.setDateRequested(incoming.getDateRequested()); |
| 192 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
recommendationRequest.setDateNeeded(incoming.getDateNeeded()); |
| 193 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
recommendationRequest.setDone(incoming.getDone()); |
| 194 | ||
| 195 | recommendationRequestRepository.save(recommendationRequest); | |
| 196 | ||
| 197 |
1
1. updateRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::updateRecommendationRequest → KILLED |
return recommendationRequest; |
| 198 | } | |
| 199 | } | |
Mutations | ||
| 43 |
1.1 |
|
| 64 |
1.1 |
|
| 66 |
1.1 |
|
| 126 |
1.1 |
|
| 127 |
1.1 |
|
| 128 |
1.1 |
|
| 129 |
1.1 |
|
| 130 |
1.1 |
|
| 131 |
1.1 |
|
| 136 |
1.1 |
|
| 158 |
1.1 |
|
| 160 |
1.1 |
|
| 161 |
1.1 |
|
| 186 |
1.1 |
|
| 188 |
1.1 |
|
| 189 |
1.1 |
|
| 190 |
1.1 |
|
| 191 |
1.1 |
|
| 192 |
1.1 |
|
| 193 |
1.1 |
|
| 197 |
1.1 |