| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 4 | import edu.ucsb.cs156.example.entities.RecommendationRequest; | |
| 5 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 6 | import edu.ucsb.cs156.example.repositories.RecommendationRequestRepository; | |
| 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 jakarta.validation.Valid; | |
| 11 | import java.time.LocalDateTime; | |
| 12 | import lombok.extern.slf4j.Slf4j; | |
| 13 | import org.springframework.beans.factory.annotation.Autowired; | |
| 14 | import org.springframework.format.annotation.DateTimeFormat; | |
| 15 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 16 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 17 | import org.springframework.web.bind.annotation.GetMapping; | |
| 18 | import org.springframework.web.bind.annotation.PostMapping; | |
| 19 | import org.springframework.web.bind.annotation.PutMapping; | |
| 20 | import org.springframework.web.bind.annotation.RequestBody; | |
| 21 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 22 | import org.springframework.web.bind.annotation.RequestParam; | |
| 23 | import org.springframework.web.bind.annotation.RestController; | |
| 24 | ||
| 25 | /** This is a REST controller for RecommendationRequests */ | |
| 26 | @Tag(name = "RecommendationRequests") | |
| 27 | @RequestMapping("/api/recommendationrequests") | |
| 28 | @RestController | |
| 29 | @Slf4j | |
| 30 | public class RecommendationRequestsController extends ApiController { | |
| 31 | ||
| 32 | @Autowired RecommendationRequestRepository recommendationRequestRepository; | |
| 33 | ||
| 34 | /** | |
| 35 | * List all recommendation requests | |
| 36 | * | |
| 37 | * @return an iterable of recommendation requests | |
| 38 | */ | |
| 39 | @Operation(summary = "List all recommendation requests") | |
| 40 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 41 | @GetMapping("/all") | |
| 42 | public Iterable<RecommendationRequest> allRecommendationRequests() { | |
| 43 | Iterable<RecommendationRequest> recommendationRequests = | |
| 44 | recommendationRequestRepository.findAll(); | |
| 45 |
1
1. allRecommendationRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::allRecommendationRequests → KILLED |
return recommendationRequests; |
| 46 | } | |
| 47 | ||
| 48 | /** | |
| 49 | * Look up a single RecommendationRequest by id. | |
| 50 | * | |
| 51 | * @param id the id of the RecommendationRequest to retrieve | |
| 52 | * @return the matching RecommendationRequest as JSON | |
| 53 | * @throws edu.ucsb.cs156.example.errors.EntityNotFoundException if no record with that id exists | |
| 54 | */ | |
| 55 | @Operation(summary = "Get a single recommendationRequest") | |
| 56 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 57 | @GetMapping("") | |
| 58 | public RecommendationRequest getById(@Parameter(name = "id") @RequestParam Long id) { | |
| 59 | RecommendationRequest recommendationRequest = | |
| 60 | recommendationRequestRepository | |
| 61 | .findById(id) | |
| 62 |
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)); |
| 63 | ||
| 64 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::getById → KILLED |
return recommendationRequest; |
| 65 | } | |
| 66 | ||
| 67 | /** | |
| 68 | * Create a new recommendation request. | |
| 69 | * | |
| 70 | * @param code a short code or identifier for the request (e.g. course/letter type) | |
| 71 | * @param requesterEmail the student's email requesting the recommendation | |
| 72 | * @param professorEmail the professor's email who is being asked | |
| 73 | * @param explanation context/reason for the request | |
| 74 | * @param dateRequested when the request was made (ISO 8601, e.g. 2025-01-10T12:00:00) | |
| 75 | * @param dateNeeded when the letter/recommendation is needed by (ISO 8601) | |
| 76 | * @param done whether the recommendation has already been completed | |
| 77 | * @return the saved RecommendationRequest, including any generated id | |
| 78 | * @throws com.fasterxml.jackson.core.JsonProcessingException if there is an issue processing JSON | |
| 79 | */ | |
| 80 | @Operation(summary = "Create a new RecommendationRequest") | |
| 81 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 82 | @PostMapping("/post") | |
| 83 | public RecommendationRequest postRecommendationRequests( | |
| 84 | @Parameter(name = "code") @RequestParam String code, | |
| 85 | @Parameter(name = "requesterEmail") @RequestParam String requesterEmail, | |
| 86 | @Parameter(name = "professorEmail") @RequestParam String professorEmail, | |
| 87 | @Parameter(name = "explanation") @RequestParam String explanation, | |
| 88 | @Parameter(name = "dateRequested", description = "ISO datetime e.g. 2025-10-28T14:30:00") | |
| 89 | @RequestParam("dateRequested") | |
| 90 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 91 | LocalDateTime dateRequested, | |
| 92 | @Parameter(name = "dateNeeded", description = "ISO datetime e.g. 2025-11-15T23:59:00") | |
| 93 | @RequestParam("dateNeeded") | |
| 94 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 95 | LocalDateTime dateNeeded, | |
| 96 | @Parameter(name = "done") @RequestParam boolean done) | |
| 97 | throws JsonProcessingException { | |
| 98 | ||
| 99 | log.info("dateRequested={}", dateRequested); | |
| 100 | log.info("dateNeeded={}", dateNeeded); | |
| 101 | ||
| 102 | RecommendationRequest rr = new RecommendationRequest(); | |
| 103 |
1
1. postRecommendationRequests : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setCode → KILLED |
rr.setCode(code); |
| 104 |
1
1. postRecommendationRequests : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
rr.setRequesterEmail(requesterEmail); |
| 105 |
1
1. postRecommendationRequests : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
rr.setProfessorEmail(professorEmail); |
| 106 |
1
1. postRecommendationRequests : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
rr.setExplanation(explanation); |
| 107 |
1
1. postRecommendationRequests : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
rr.setDateRequested(dateRequested); |
| 108 |
1
1. postRecommendationRequests : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
rr.setDateNeeded(dateNeeded); |
| 109 |
1
1. postRecommendationRequests : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
rr.setDone(done); |
| 110 | ||
| 111 | RecommendationRequest saved = recommendationRequestRepository.save(rr); | |
| 112 | ||
| 113 |
1
1. postRecommendationRequests : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::postRecommendationRequests → KILLED |
return saved; |
| 114 | } | |
| 115 | ||
| 116 | /** | |
| 117 | * Delete a RecommendationRequest | |
| 118 | * | |
| 119 | * @param id the id of the request to delete | |
| 120 | * @return a message indicating the request was deleted | |
| 121 | */ | |
| 122 | @Operation(summary = "Delete a recommendation request") | |
| 123 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 124 | @DeleteMapping("") | |
| 125 | public Object deleteRecommendationRequest(@Parameter(name = "id") @RequestParam Long id) { | |
| 126 | ||
| 127 | RecommendationRequest rr = | |
| 128 | recommendationRequestRepository | |
| 129 | .findById(id) | |
| 130 |
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)); |
| 131 | ||
| 132 |
1
1. deleteRecommendationRequest : removed call to edu/ucsb/cs156/example/repositories/RecommendationRequestRepository::delete → KILLED |
recommendationRequestRepository.delete(rr); |
| 133 |
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)); |
| 134 | } | |
| 135 | ||
| 136 | /** | |
| 137 | * Update an existing RecommendationRequest identified by id. | |
| 138 | * | |
| 139 | * @param id the id of the RecommendationRequest to update | |
| 140 | * @param incoming the new field values for this RecommendationRequest (code, requesterEmail, | |
| 141 | * professorEmail, explanation, dateRequested, dateNeeded, done) | |
| 142 | * @return the updated RecommendationRequest, after saving | |
| 143 | * @throws edu.ucsb.cs156.example.errors.EntityNotFoundException if no RecommendationRequest with | |
| 144 | * that id exists | |
| 145 | */ | |
| 146 | @Operation(summary = "Update a single recommendation request") | |
| 147 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 148 | @PutMapping("") | |
| 149 | public RecommendationRequest updateRecommendationRequest( | |
| 150 | @Parameter(name = "id") @RequestParam Long id, | |
| 151 | @RequestBody @Valid RecommendationRequest incoming) { | |
| 152 | ||
| 153 | RecommendationRequest rr = | |
| 154 | recommendationRequestRepository | |
| 155 | .findById(id) | |
| 156 |
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)); |
| 157 | ||
| 158 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setCode → KILLED |
rr.setCode(incoming.getCode()); |
| 159 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
rr.setRequesterEmail(incoming.getRequesterEmail()); |
| 160 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
rr.setProfessorEmail(incoming.getProfessorEmail()); |
| 161 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
rr.setExplanation(incoming.getExplanation()); |
| 162 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
rr.setDateRequested(incoming.getDateRequested()); |
| 163 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
rr.setDateNeeded(incoming.getDateNeeded()); |
| 164 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
rr.setDone(incoming.getDone()); |
| 165 | ||
| 166 | recommendationRequestRepository.save(rr); | |
| 167 | ||
| 168 |
1
1. updateRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::updateRecommendationRequest → KILLED |
return rr; |
| 169 | } | |
| 170 | } | |
Mutations | ||
| 45 |
1.1 |
|
| 62 |
1.1 |
|
| 64 |
1.1 |
|
| 103 |
1.1 |
|
| 104 |
1.1 |
|
| 105 |
1.1 |
|
| 106 |
1.1 |
|
| 107 |
1.1 |
|
| 108 |
1.1 |
|
| 109 |
1.1 |
|
| 113 |
1.1 |
|
| 130 |
1.1 |
|
| 132 |
1.1 |
|
| 133 |
1.1 |
|
| 156 |
1.1 |
|
| 158 |
1.1 |
|
| 159 |
1.1 |
|
| 160 |
1.1 |
|
| 161 |
1.1 |
|
| 162 |
1.1 |
|
| 163 |
1.1 |
|
| 164 |
1.1 |
|
| 168 |
1.1 |