| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.example.entities.RecommendationRequest; | |
| 4 | import edu.ucsb.cs156.example.repositories.RecommendationRequestRepository; | |
| 5 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 6 | ||
| 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 lombok.extern.slf4j.Slf4j; | |
| 11 | ||
| 12 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 13 | ||
| 14 | import org.springframework.beans.factory.annotation.Autowired; | |
| 15 | import org.springframework.format.annotation.DateTimeFormat; | |
| 16 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 17 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 18 | import org.springframework.web.bind.annotation.GetMapping; | |
| 19 | import org.springframework.web.bind.annotation.PostMapping; | |
| 20 | import org.springframework.web.bind.annotation.PutMapping; | |
| 21 | import org.springframework.web.bind.annotation.RequestBody; | |
| 22 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 23 | import org.springframework.web.bind.annotation.RequestParam; | |
| 24 | import org.springframework.web.bind.annotation.RestController; | |
| 25 | ||
| 26 | import jakarta.validation.Valid; | |
| 27 | ||
| 28 | import java.time.LocalDateTime; | |
| 29 | ||
| 30 | /** | |
| 31 | * This is a REST controller for Recommendation Requests | |
| 32 | */ | |
| 33 | ||
| 34 | @Tag(name = "Recommendation Requests") | |
| 35 | @RequestMapping("/api/recommendation-requests") | |
| 36 | @RestController | |
| 37 | @Slf4j | |
| 38 | ||
| 39 | public class RecommendationRequestController extends ApiController { | |
| 40 | ||
| 41 | @Autowired | |
| 42 | RecommendationRequestRepository recommendationRequestRepository; | |
| 43 | ||
| 44 | ||
| 45 | @Operation(summary = "Get all recommendation requests") | |
| 46 | @GetMapping("/all") // get all records in the table and return as a JSON array | |
| 47 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 48 | public Iterable<RecommendationRequest> allRecommendationRequests() { | |
| 49 | Iterable<RecommendationRequest> requests = recommendationRequestRepository.findAll(); | |
| 50 |
1
1. allRecommendationRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/RecommendationRequestController::allRecommendationRequests → KILLED |
return requests; |
| 51 | } | |
| 52 | ||
| 53 | ||
| 54 | @Operation(summary = "Create a new recommendation request") | |
| 55 | @PostMapping("/post") // Use the data in the input parameters to create a new row in the table and return the data as JSON | |
| 56 | public RecommendationRequest postRecommendationRequest( | |
| 57 | @Parameter(name="requesterEmail") @RequestParam String requesterEmail, | |
| 58 | @Parameter(name="professorEmail") @RequestParam String professorEmail, | |
| 59 | @Parameter(name="explanation") @RequestParam String explanation, | |
| 60 | @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, | |
| 61 | @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, | |
| 62 | @Parameter(name="done") @RequestParam Boolean done) | |
| 63 | throws JsonProcessingException { | |
| 64 | ||
| 65 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 66 | // See: https://www.baeldung.com/spring-date-parameters | |
| 67 | ||
| 68 | log.info("dateRequested={}", dateRequested); | |
| 69 | log.info("dateNeeded={}", dateNeeded); | |
| 70 | ||
| 71 | RecommendationRequest recommendationRequest = new RecommendationRequest(); | |
| 72 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
recommendationRequest.setRequesterEmail(requesterEmail); |
| 73 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
recommendationRequest.setProfessorEmail(professorEmail); |
| 74 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
recommendationRequest.setExplanation(explanation); |
| 75 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
recommendationRequest.setDateRequested(dateRequested); |
| 76 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
recommendationRequest.setDateNeeded(dateNeeded); |
| 77 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
recommendationRequest.setDone(done); |
| 78 | ||
| 79 | RecommendationRequest savedRecommendationRequest = recommendationRequestRepository.save(recommendationRequest); | |
| 80 | ||
| 81 |
1
1. postRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::postRecommendationRequest → KILLED |
return savedRecommendationRequest; |
| 82 | } | |
| 83 | | |
| 84 | | |
| 85 | @Operation(summary = "Get a single RecommendationRequest by id") | |
| 86 | @Parameter(name = "id", description = "The id of the RecommendationRequest to retrieve", required = true) | |
| 87 | @GetMapping("") | |
| 88 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 89 | public RecommendationRequest getById(@RequestParam Long id) { | |
| 90 | RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id) | |
| 91 |
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)); |
| 92 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::getById → KILLED |
return recommendationRequest; |
| 93 | } | |
| 94 | ||
| 95 | ||
| 96 | @Operation(summary= "Delete a Recommendation Request") | |
| 97 | @Parameter(name="id", description="the id of the recommendation request to delete", required = true) | |
| 98 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 99 | @DeleteMapping("") | |
| 100 | public Object deleteRecommendationRequest( | |
| 101 | @Parameter(name="id") @RequestParam Long id) { | |
| 102 | RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id) | |
| 103 |
1
1. lambda$deleteRecommendationRequest$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$deleteRecommendationRequest$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id)); |
| 104 | ||
| 105 |
1
1. deleteRecommendationRequest : removed call to edu/ucsb/cs156/example/repositories/RecommendationRequestRepository::delete → KILLED |
recommendationRequestRepository.delete(recommendationRequest); |
| 106 |
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)); |
| 107 | } | |
| 108 | | |
| 109 | ||
| 110 | @Operation(summary = "Update a single recommendation request") | |
| 111 | @Parameter(name="id", description="the id of the recommendation request to update", required = true) | |
| 112 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 113 | @PutMapping("") | |
| 114 | public RecommendationRequest updateRecommendationRequest( | |
| 115 | @Parameter(name="id") @RequestParam Long id, | |
| 116 | @RequestBody @Valid RecommendationRequest incoming) { | |
| 117 | ||
| 118 | RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id) | |
| 119 |
1
1. lambda$updateRecommendationRequest$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$updateRecommendationRequest$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id)); |
| 120 | ||
| 121 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
recommendationRequest.setRequesterEmail(incoming.getRequesterEmail()); |
| 122 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
recommendationRequest.setProfessorEmail(incoming.getProfessorEmail()); |
| 123 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
recommendationRequest.setExplanation(incoming.getExplanation()); |
| 124 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
recommendationRequest.setDateRequested(incoming.getDateRequested()); |
| 125 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
recommendationRequest.setDateNeeded(incoming.getDateNeeded()); |
| 126 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
recommendationRequest.setDone(incoming.getDone()); |
| 127 | ||
| 128 | recommendationRequestRepository.save(recommendationRequest); | |
| 129 | ||
| 130 |
1
1. updateRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::updateRecommendationRequest → KILLED |
return recommendationRequest; |
| 131 | } | |
| 132 | ||
| 133 | } | |
Mutations | ||
| 50 |
1.1 |
|
| 72 |
1.1 |
|
| 73 |
1.1 |
|
| 74 |
1.1 |
|
| 75 |
1.1 |
|
| 76 |
1.1 |
|
| 77 |
1.1 |
|
| 81 |
1.1 |
|
| 91 |
1.1 |
|
| 92 |
1.1 |
|
| 103 |
1.1 |
|
| 105 |
1.1 |
|
| 106 |
1.1 |
|
| 119 |
1.1 |
|
| 121 |
1.1 |
|
| 122 |
1.1 |
|
| 123 |
1.1 |
|
| 124 |
1.1 |
|
| 125 |
1.1 |
|
| 126 |
1.1 |
|
| 130 |
1.1 |