| 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 RecommendationRequests | |
| 36 | * | |
| 37 | * @return an iterable of RecommendationRequests | |
| 38 | */ | |
| 39 | @Operation(summary = "List all recommendation requests") | |
| 40 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 41 | @GetMapping("/all") | |
| 42 | public Iterable<RecommendationRequest> allRecommendationRequests() { | |
| 43 | Iterable<RecommendationRequest> requests = recommendationRequestRepository.findAll(); | |
| 44 |
1
1. allRecommendationRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::allRecommendationRequests → KILLED |
return requests; |
| 45 | } | |
| 46 | ||
| 47 | /** | |
| 48 | * Create a new request | |
| 49 | * | |
| 50 | * @param requesterEmail the email of the requester | |
| 51 | * @param professorEmail the email of the giver (professor) | |
| 52 | * @param explanation the reason for requesting the recommendation | |
| 53 | * @param dateRequested the date it was requested | |
| 54 | * @param dateNeeded the date it is needed by | |
| 55 | * @param done if it is completed | |
| 56 | * @return the created RecommendationRequest | |
| 57 | */ | |
| 58 | @Operation(summary = "Create a new recommendation request") | |
| 59 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 60 | @PostMapping("/post") | |
| 61 | public RecommendationRequest postRecommendationRequest( | |
| 62 | @Parameter(name = "requesterEmail") @RequestParam String requesterEmail, | |
| 63 | @Parameter(name = "professorEmail") @RequestParam String professorEmail, | |
| 64 | @Parameter(name = "explanation") @RequestParam String explanation, | |
| 65 | @Parameter( | |
| 66 | name = "dateRequested", | |
| 67 | description = | |
| 68 | "date (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)") | |
| 69 | @RequestParam("dateRequested") | |
| 70 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 71 | LocalDateTime dateRequested, | |
| 72 | @Parameter( | |
| 73 | name = "dateNeeded", | |
| 74 | description = | |
| 75 | "date (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)") | |
| 76 | @RequestParam("dateNeeded") | |
| 77 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 78 | LocalDateTime dateNeeded, | |
| 79 | @Parameter(name = "done") @RequestParam Boolean done) | |
| 80 | throws JsonProcessingException { | |
| 81 | ||
| 82 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 83 | // See: https://www.baeldung.com/spring-date-parameters | |
| 84 | ||
| 85 | log.info( | |
| 86 | "Creating recommendation request for requesterEmail={} and professorEmail={}", | |
| 87 | requesterEmail, | |
| 88 | professorEmail); | |
| 89 | ||
| 90 | RecommendationRequest recommendationRequest = new RecommendationRequest(); | |
| 91 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
recommendationRequest.setRequesterEmail(requesterEmail); |
| 92 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
recommendationRequest.setProfessorEmail(professorEmail); |
| 93 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
recommendationRequest.setExplanation(explanation); |
| 94 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
recommendationRequest.setDateRequested(dateRequested); |
| 95 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
recommendationRequest.setDateNeeded(dateNeeded); |
| 96 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
recommendationRequest.setDone(done); |
| 97 | ||
| 98 | RecommendationRequest savedRecommendationRequest = | |
| 99 | recommendationRequestRepository.save(recommendationRequest); | |
| 100 | ||
| 101 |
1
1. postRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::postRecommendationRequest → KILLED |
return savedRecommendationRequest; |
| 102 | } | |
| 103 | ||
| 104 | /** | |
| 105 | * Get a single recommendation request by id | |
| 106 | * | |
| 107 | * @param id the id of the recommendation request | |
| 108 | * @return a RecommendationRequest | |
| 109 | */ | |
| 110 | @Operation(summary = "Get a single recommendation request") | |
| 111 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 112 | @GetMapping("") | |
| 113 | public RecommendationRequest getById(@Parameter(name = "id") @RequestParam Long id) { | |
| 114 | RecommendationRequest recommendationRequest = | |
| 115 | recommendationRequestRepository | |
| 116 | .findById(id) | |
| 117 |
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)); |
| 118 | ||
| 119 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::getById → KILLED |
return recommendationRequest; |
| 120 | } | |
| 121 | ||
| 122 | /** | |
| 123 | * Update a single request | |
| 124 | * | |
| 125 | * @param id id of the request to update | |
| 126 | * @param incoming the new request | |
| 127 | * @return the updated request object | |
| 128 | */ | |
| 129 | @Operation(summary = "Update a single request") | |
| 130 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 131 | @PutMapping("") | |
| 132 | public RecommendationRequest updateRecommendationRequest( | |
| 133 | @Parameter(name = "id") @RequestParam Long id, | |
| 134 | @RequestBody @Valid RecommendationRequest incoming) { | |
| 135 | ||
| 136 | RecommendationRequest recommendationRequest = | |
| 137 | recommendationRequestRepository | |
| 138 | .findById(id) | |
| 139 |
1
1. lambda$updateRecommendationRequest$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::lambda$updateRecommendationRequest$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id)); |
| 140 | ||
| 141 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
recommendationRequest.setRequesterEmail(incoming.getRequesterEmail()); |
| 142 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
recommendationRequest.setProfessorEmail(incoming.getProfessorEmail()); |
| 143 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
recommendationRequest.setExplanation(incoming.getExplanation()); |
| 144 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
recommendationRequest.setDateRequested(incoming.getDateRequested()); |
| 145 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
recommendationRequest.setDateNeeded(incoming.getDateNeeded()); |
| 146 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
recommendationRequest.setDone(incoming.getDone()); |
| 147 | ||
| 148 | recommendationRequestRepository.save(recommendationRequest); | |
| 149 | ||
| 150 |
1
1. updateRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::updateRecommendationRequest → KILLED |
return recommendationRequest; |
| 151 | } | |
| 152 | ||
| 153 | /** | |
| 154 | * Delete a RecommendationRequest | |
| 155 | * | |
| 156 | * @param id the id of the request to delete | |
| 157 | * @return a message indicating the request was deleted | |
| 158 | */ | |
| 159 | @Operation(summary = "Delete a RecommendationRequest") | |
| 160 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 161 | @DeleteMapping("") | |
| 162 | public Object deleteUCSBDate(@Parameter(name = "id") @RequestParam Long id) { | |
| 163 | RecommendationRequest recommendationRequest = | |
| 164 | recommendationRequestRepository | |
| 165 | .findById(id) | |
| 166 |
1
1. lambda$deleteUCSBDate$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::lambda$deleteUCSBDate$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id)); |
| 167 | ||
| 168 |
1
1. deleteUCSBDate : removed call to edu/ucsb/cs156/example/repositories/RecommendationRequestRepository::delete → KILLED |
recommendationRequestRepository.delete(recommendationRequest); |
| 169 |
1
1. deleteUCSBDate : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::deleteUCSBDate → KILLED |
return genericMessage("RecommendationRequest with id %s deleted".formatted(id)); |
| 170 | } | |
| 171 | } | |
Mutations | ||
| 44 |
1.1 |
|
| 91 |
1.1 |
|
| 92 |
1.1 |
|
| 93 |
1.1 |
|
| 94 |
1.1 |
|
| 95 |
1.1 |
|
| 96 |
1.1 |
|
| 101 |
1.1 |
|
| 117 |
1.1 |
|
| 119 |
1.1 |
|
| 139 |
1.1 |
|
| 141 |
1.1 |
|
| 142 |
1.1 |
|
| 143 |
1.1 |
|
| 144 |
1.1 |
|
| 145 |
1.1 |
|
| 146 |
1.1 |
|
| 150 |
1.1 |
|
| 166 |
1.1 |
|
| 168 |
1.1 |
|
| 169 |
1.1 |