| 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 | @Tag(name = "RecommendationRequest") | |
| 26 | @RequestMapping("/api/recommendationrequests") | |
| 27 | @RestController | |
| 28 | @Slf4j | |
| 29 | public class RecommendationRequestController extends ApiController { | |
| 30 | ||
| 31 | @Autowired RecommendationRequestRepository recommendationRequestRepository; | |
| 32 | ||
| 33 | @Operation(summary = "List all recommendation requests") | |
| 34 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 35 | @GetMapping("/all") | |
| 36 | public Iterable<RecommendationRequest> allRecommendationRequests() { | |
| 37 | Iterable<RecommendationRequest> requests = recommendationRequestRepository.findAll(); | |
| 38 |
1
1. allRecommendationRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/RecommendationRequestController::allRecommendationRequests → KILLED |
return requests; |
| 39 | } | |
| 40 | ||
| 41 | @Operation(summary = "Create a new recommendation request") | |
| 42 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 43 | @PostMapping("/post") | |
| 44 | public RecommendationRequest postRecommendationRequest( | |
| 45 | @Parameter(name = "requesterEmail") @RequestParam String requesterEmail, | |
| 46 | @Parameter(name = "professorEmail") @RequestParam String professorEmail, | |
| 47 | @Parameter(name = "explanation") @RequestParam String explanation, | |
| 48 | @Parameter(name = "dateRequested", description = "in iso format, e.g. YYYY-mm-ddTHH:MM:SS") | |
| 49 | @RequestParam("dateRequested") | |
| 50 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 51 | LocalDateTime dateRequested, | |
| 52 | @Parameter(name = "dateNeeded", description = "in iso format, e.g. YYYY-mm-ddTHH:MM:SS") | |
| 53 | @RequestParam("dateNeeded") | |
| 54 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 55 | LocalDateTime dateNeeded, | |
| 56 | @Parameter(name = "done") @RequestParam boolean done) | |
| 57 | throws JsonProcessingException { | |
| 58 | ||
| 59 | log.info("dateRequested={}, dateNeeded={}", dateRequested, dateNeeded); | |
| 60 | ||
| 61 | RecommendationRequest recommendationRequest = new RecommendationRequest(); | |
| 62 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
recommendationRequest.setRequesterEmail(requesterEmail); |
| 63 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
recommendationRequest.setProfessorEmail(professorEmail); |
| 64 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
recommendationRequest.setExplanation(explanation); |
| 65 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
recommendationRequest.setDateRequested(dateRequested); |
| 66 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
recommendationRequest.setDateNeeded(dateNeeded); |
| 67 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
recommendationRequest.setDone(done); |
| 68 | ||
| 69 | RecommendationRequest savedRecommendationRequest = | |
| 70 | recommendationRequestRepository.save(recommendationRequest); | |
| 71 | ||
| 72 |
1
1. postRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::postRecommendationRequest → KILLED |
return savedRecommendationRequest; |
| 73 | } | |
| 74 | ||
| 75 | @Operation(summary = "Get a single recommendation request") | |
| 76 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 77 | @GetMapping("") | |
| 78 | public RecommendationRequest getRecommendationRequestById( | |
| 79 | @Parameter(name = "id") @RequestParam Long id) { | |
| 80 | RecommendationRequest recommendationRequest = | |
| 81 | recommendationRequestRepository | |
| 82 | .findById(id) | |
| 83 |
1
1. lambda$getRecommendationRequestById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$getRecommendationRequestById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id)); |
| 84 | ||
| 85 |
1
1. getRecommendationRequestById : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::getRecommendationRequestById → KILLED |
return recommendationRequest; |
| 86 | } | |
| 87 | ||
| 88 | @Operation(summary = "Update a single recommendation request") | |
| 89 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 90 | @PutMapping("") | |
| 91 | public RecommendationRequest updateRecommendationRequest( | |
| 92 | @Parameter(name = "id") @RequestParam Long id, | |
| 93 | @RequestBody @Valid RecommendationRequest incoming) { | |
| 94 | ||
| 95 | RecommendationRequest recommendationRequest = | |
| 96 | recommendationRequestRepository | |
| 97 | .findById(id) | |
| 98 |
1
1. lambda$updateRecommendationRequest$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$updateRecommendationRequest$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id)); |
| 99 | ||
| 100 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
recommendationRequest.setRequesterEmail(incoming.getRequesterEmail()); |
| 101 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
recommendationRequest.setProfessorEmail(incoming.getProfessorEmail()); |
| 102 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
recommendationRequest.setExplanation(incoming.getExplanation()); |
| 103 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
recommendationRequest.setDateRequested(incoming.getDateRequested()); |
| 104 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
recommendationRequest.setDateNeeded(incoming.getDateNeeded()); |
| 105 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
recommendationRequest.setDone(incoming.getDone()); |
| 106 | ||
| 107 | recommendationRequestRepository.save(recommendationRequest); | |
| 108 | ||
| 109 |
1
1. updateRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::updateRecommendationRequest → KILLED |
return recommendationRequest; |
| 110 | } | |
| 111 | ||
| 112 | @Operation(summary = "Delete a recommendation request") | |
| 113 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 114 | @DeleteMapping("") | |
| 115 | public Object deleteRecommendationRequest(@Parameter(name = "id") @RequestParam Long id) { | |
| 116 | RecommendationRequest recommendationRequest = | |
| 117 | recommendationRequestRepository | |
| 118 | .findById(id) | |
| 119 |
1
1. lambda$deleteRecommendationRequest$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$deleteRecommendationRequest$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id)); |
| 120 | ||
| 121 |
1
1. deleteRecommendationRequest : removed call to edu/ucsb/cs156/example/repositories/RecommendationRequestRepository::delete → KILLED |
recommendationRequestRepository.delete(recommendationRequest); |
| 122 |
1
1. deleteRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::deleteRecommendationRequest → KILLED |
return genericMessage("record %s deleted".formatted(id)); |
| 123 | } | |
| 124 | } | |
Mutations | ||
| 38 |
1.1 |
|
| 62 |
1.1 |
|
| 63 |
1.1 |
|
| 64 |
1.1 |
|
| 65 |
1.1 |
|
| 66 |
1.1 |
|
| 67 |
1.1 |
|
| 72 |
1.1 |
|
| 83 |
1.1 |
|
| 85 |
1.1 |
|
| 98 |
1.1 |
|
| 100 |
1.1 |
|
| 101 |
1.1 |
|
| 102 |
1.1 |
|
| 103 |
1.1 |
|
| 104 |
1.1 |
|
| 105 |
1.1 |
|
| 109 |
1.1 |
|
| 119 |
1.1 |
|
| 121 |
1.1 |
|
| 122 |
1.1 |