| 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 RecommendationRequest */ | |
| 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 |
1
1. allRecommendationRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/RecommendationRequestController::allRecommendationRequests → KILLED |
return recommendationRequestRepository.findAll(); |
| 43 | } | |
| 44 | ||
| 45 | /** | |
| 46 | * Get a single recommendation request by id | |
| 47 | * | |
| 48 | * @param id the database id of the recommendation request | |
| 49 | * @return the recommendation request with the given id | |
| 50 | */ | |
| 51 | @Operation( | |
| 52 | summary = "Get a single recommendation request", | |
| 53 | description = "Returns the recommendation request with the given id, or a 404 if none exists") | |
| 54 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 55 | @GetMapping("") | |
| 56 | public RecommendationRequest getById( | |
| 57 | @Parameter(name = "id", description = "Database id of the recommendation request, e.g. 7") | |
| 58 | @RequestParam | |
| 59 | Long id) { | |
| 60 | RecommendationRequest recommendationRequest = | |
| 61 | recommendationRequestRepository | |
| 62 | .findById(id) | |
| 63 |
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)); |
| 64 | ||
| 65 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::getById → KILLED |
return recommendationRequest; |
| 66 | } | |
| 67 | ||
| 68 | /** | |
| 69 | * Create a new recommendation request | |
| 70 | * | |
| 71 | * @param requesterEmail email of the student requesting the recommendation | |
| 72 | * @param professorEmail email of the professor being asked to write the recommendation | |
| 73 | * @param explanation what the recommendation is for | |
| 74 | * @param dateRequested when the request was made (ISO format) | |
| 75 | * @param dateNeeded when the recommendation is needed by (ISO format) | |
| 76 | * @param done whether the request has been completed | |
| 77 | * @return the saved recommendation request | |
| 78 | */ | |
| 79 | @Operation(summary = "Create a new recommendation request") | |
| 80 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 81 | @PostMapping("/post") | |
| 82 | public RecommendationRequest postRecommendationRequest( | |
| 83 | @Parameter( | |
| 84 | name = "requesterEmail", | |
| 85 | description = "Email of the student requesting the recommendation") | |
| 86 | @RequestParam | |
| 87 | String requesterEmail, | |
| 88 | @Parameter( | |
| 89 | name = "professorEmail", | |
| 90 | description = "Email of the professor asked to write the recommendation") | |
| 91 | @RequestParam | |
| 92 | String professorEmail, | |
| 93 | @Parameter( | |
| 94 | name = "explanation", | |
| 95 | description = "What the recommendation is for, e.g. grad school application") | |
| 96 | @RequestParam | |
| 97 | String explanation, | |
| 98 | @Parameter( | |
| 99 | name = "dateRequested", | |
| 100 | description = | |
| 101 | "Date the request was made (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)") | |
| 102 | @RequestParam("dateRequested") | |
| 103 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 104 | LocalDateTime dateRequested, | |
| 105 | @Parameter( | |
| 106 | name = "dateNeeded", | |
| 107 | description = | |
| 108 | "Date the recommendation is needed by (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)") | |
| 109 | @RequestParam("dateNeeded") | |
| 110 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 111 | LocalDateTime dateNeeded, | |
| 112 | @Parameter(name = "done", description = "true if the request has been completed") | |
| 113 | @RequestParam | |
| 114 | boolean done) { | |
| 115 | ||
| 116 | RecommendationRequest recommendationRequest = new RecommendationRequest(); | |
| 117 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
recommendationRequest.setRequesterEmail(requesterEmail); |
| 118 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
recommendationRequest.setProfessorEmail(professorEmail); |
| 119 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
recommendationRequest.setExplanation(explanation); |
| 120 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
recommendationRequest.setDateRequested(dateRequested); |
| 121 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
recommendationRequest.setDateNeeded(dateNeeded); |
| 122 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
recommendationRequest.setDone(done); |
| 123 | ||
| 124 |
1
1. postRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::postRecommendationRequest → KILLED |
return recommendationRequestRepository.save(recommendationRequest); |
| 125 | } | |
| 126 | ||
| 127 | @Operation( | |
| 128 | summary = "Update a single recommendation request", | |
| 129 | description = | |
| 130 | "Replaces every field except id of the recommendation request with the given id, using" | |
| 131 | + " the JSON body. Returns a 404 if no recommendation request has that id.") | |
| 132 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 133 | @PutMapping("") | |
| 134 | public RecommendationRequest updateRecommendationRequest( | |
| 135 | @Parameter(name = "id", description = "Database id of the recommendation request, e.g. 7") | |
| 136 | @RequestParam | |
| 137 | Long id, | |
| 138 | @RequestBody @Valid RecommendationRequest incoming) { | |
| 139 | ||
| 140 | RecommendationRequest recommendationRequest = | |
| 141 | recommendationRequestRepository | |
| 142 | .findById(id) | |
| 143 |
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)); |
| 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 | ||
| 157 | /** | |
| 158 | * Delete a recommendation request | |
| 159 | * | |
| 160 | * @param id the id of the recommendation request to delete | |
| 161 | * @return a message indicating the recommendation request was deleted | |
| 162 | */ | |
| 163 | @Operation( | |
| 164 | summary = "Delete a recommendation request", | |
| 165 | description = | |
| 166 | "Deletes the recommendation request with the given id, or returns a 404 if none exists") | |
| 167 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 168 | @DeleteMapping("") | |
| 169 | public Object deleteRecommendationRequest( | |
| 170 | @Parameter(name = "id", description = "Database id of the recommendation request, e.g. 7") | |
| 171 | @RequestParam | |
| 172 | Long id) { | |
| 173 | RecommendationRequest recommendationRequest = | |
| 174 | recommendationRequestRepository | |
| 175 | .findById(id) | |
| 176 |
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)); |
| 177 | ||
| 178 |
1
1. deleteRecommendationRequest : removed call to edu/ucsb/cs156/example/repositories/RecommendationRequestRepository::delete → KILLED |
recommendationRequestRepository.delete(recommendationRequest); |
| 179 |
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)); |
| 180 | } | |
| 181 | } | |
Mutations | ||
| 42 |
1.1 |
|
| 63 |
1.1 |
|
| 65 |
1.1 |
|
| 117 |
1.1 |
|
| 118 |
1.1 |
|
| 119 |
1.1 |
|
| 120 |
1.1 |
|
| 121 |
1.1 |
|
| 122 |
1.1 |
|
| 124 |
1.1 |
|
| 143 |
1.1 |
|
| 145 |
1.1 |
|
| 146 |
1.1 |
|
| 147 |
1.1 |
|
| 148 |
1.1 |
|
| 149 |
1.1 |
|
| 150 |
1.1 |
|
| 154 |
1.1 |
|
| 176 |
1.1 |
|
| 178 |
1.1 |
|
| 179 |
1.1 |