| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.example.entities.RecommendationRequest; | |
| 4 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; // Added this import | |
| 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 java.time.LocalDateTime; | |
| 10 | import lombok.extern.slf4j.Slf4j; | |
| 11 | import org.springframework.beans.factory.annotation.Autowired; | |
| 12 | import org.springframework.format.annotation.DateTimeFormat; | |
| 13 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 14 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 15 | import org.springframework.web.bind.annotation.GetMapping; | |
| 16 | import org.springframework.web.bind.annotation.PostMapping; | |
| 17 | import org.springframework.web.bind.annotation.PutMapping; | |
| 18 | import org.springframework.web.bind.annotation.RequestBody; | |
| 19 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 20 | import org.springframework.web.bind.annotation.RequestParam; | |
| 21 | import org.springframework.web.bind.annotation.RestController; | |
| 22 | ||
| 23 | @Tag(name = "RecommendationRequest") | |
| 24 | @RequestMapping("/api/recommendationrequest") | |
| 25 | @RestController | |
| 26 | @Slf4j | |
| 27 | public class RecommendationRequestController extends ApiController { | |
| 28 | ||
| 29 | @Autowired RecommendationRequestRepository recommendationRequestRepository; | |
| 30 | ||
| 31 | @Operation(summary = "List all recommendation requests") | |
| 32 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 33 | @GetMapping("/all") | |
| 34 | public Iterable<RecommendationRequest> allRecommendationRequests() { | |
| 35 | Iterable<RecommendationRequest> requests = recommendationRequestRepository.findAll(); | |
| 36 |
1
1. allRecommendationRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/RecommendationRequestController::allRecommendationRequests → KILLED |
return requests; |
| 37 | } | |
| 38 | ||
| 39 | @Operation(summary = "Create a new recommendation request") | |
| 40 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 41 | @PostMapping("/post") | |
| 42 | public RecommendationRequest postRecommendationRequest( | |
| 43 | @Parameter(name = "requesterEmail") @RequestParam String requesterEmail, | |
| 44 | @Parameter(name = "professorEmail") @RequestParam String professorEmail, | |
| 45 | @Parameter(name = "explanation") @RequestParam String explanation, | |
| 46 | @Parameter( | |
| 47 | name = "dateRequested", | |
| 48 | description = | |
| 49 | "date (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)") | |
| 50 | @RequestParam("dateRequested") | |
| 51 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 52 | LocalDateTime dateRequested, | |
| 53 | @Parameter( | |
| 54 | name = "dateNeeded", | |
| 55 | description = | |
| 56 | "date (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)") | |
| 57 | @RequestParam("dateNeeded") | |
| 58 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 59 | LocalDateTime dateNeeded, | |
| 60 | @Parameter(name = "done") @RequestParam boolean done) { | |
| 61 | ||
| 62 | log.info( | |
| 63 | "postRecommendationRequest: requesterEmail={}, professorEmail={}, done={}", | |
| 64 | requesterEmail, | |
| 65 | professorEmail, | |
| 66 | done); | |
| 67 | ||
| 68 | RecommendationRequest request = new RecommendationRequest(); | |
| 69 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
request.setRequesterEmail(requesterEmail); |
| 70 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
request.setProfessorEmail(professorEmail); |
| 71 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
request.setExplanation(explanation); |
| 72 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
request.setDateRequested(dateRequested); |
| 73 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
request.setDateNeeded(dateNeeded); |
| 74 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
request.setDone(done); |
| 75 | ||
| 76 | RecommendationRequest savedRequest = recommendationRequestRepository.save(request); | |
| 77 | ||
| 78 |
1
1. postRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::postRecommendationRequest → KILLED |
return savedRequest; |
| 79 | } | |
| 80 | ||
| 81 | @Operation(summary = "Get a single recommendation request") | |
| 82 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 83 | @GetMapping("") | |
| 84 | public RecommendationRequest getById(@Parameter(name = "id") @RequestParam Long id) { | |
| 85 | ||
| 86 | RecommendationRequest recommendationRequest = | |
| 87 | recommendationRequestRepository | |
| 88 | .findById(id) | |
| 89 |
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)); |
| 90 | ||
| 91 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::getById → KILLED |
return recommendationRequest; |
| 92 | } | |
| 93 | ||
| 94 | @Operation(summary = "Update a single recommendation request") | |
| 95 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 96 | @PutMapping("") | |
| 97 | public RecommendationRequest updateRecommendationRequest( | |
| 98 | @Parameter(name = "id") @RequestParam Long id, @RequestBody RecommendationRequest incoming) { | |
| 99 | ||
| 100 | RecommendationRequest recommendationRequest = | |
| 101 | recommendationRequestRepository | |
| 102 | .findById(id) | |
| 103 |
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)); |
| 104 | ||
| 105 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
recommendationRequest.setRequesterEmail(incoming.getRequesterEmail()); |
| 106 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
recommendationRequest.setProfessorEmail(incoming.getProfessorEmail()); |
| 107 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
recommendationRequest.setExplanation(incoming.getExplanation()); |
| 108 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
recommendationRequest.setDateRequested(incoming.getDateRequested()); |
| 109 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
recommendationRequest.setDateNeeded(incoming.getDateNeeded()); |
| 110 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
recommendationRequest.setDone(incoming.getDone()); |
| 111 | ||
| 112 | recommendationRequestRepository.save(recommendationRequest); | |
| 113 | ||
| 114 |
1
1. updateRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::updateRecommendationRequest → KILLED |
return recommendationRequest; |
| 115 | } | |
| 116 | ||
| 117 | @Operation(summary = "Delete a recommendation request") | |
| 118 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 119 | @DeleteMapping("") | |
| 120 | public Object deleteRecommendationRequest(@Parameter(name = "id") @RequestParam Long id) { | |
| 121 | RecommendationRequest recommendationRequest = | |
| 122 | recommendationRequestRepository | |
| 123 | .findById(id) | |
| 124 |
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)); |
| 125 | ||
| 126 |
1
1. deleteRecommendationRequest : removed call to edu/ucsb/cs156/example/repositories/RecommendationRequestRepository::delete → KILLED |
recommendationRequestRepository.delete(recommendationRequest); |
| 127 |
1
1. deleteRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::deleteRecommendationRequest → KILLED |
return genericMessage("RecommendationRequest with id %d deleted".formatted(id)); |
| 128 | } | |
| 129 | } | |
Mutations | ||
| 36 |
1.1 |
|
| 69 |
1.1 |
|
| 70 |
1.1 |
|
| 71 |
1.1 |
|
| 72 |
1.1 |
|
| 73 |
1.1 |
|
| 74 |
1.1 |
|
| 78 |
1.1 |
|
| 89 |
1.1 |
|
| 91 |
1.1 |
|
| 103 |
1.1 |
|
| 105 |
1.1 |
|
| 106 |
1.1 |
|
| 107 |
1.1 |
|
| 108 |
1.1 |
|
| 109 |
1.1 |
|
| 110 |
1.1 |
|
| 114 |
1.1 |
|
| 124 |
1.1 |
|
| 126 |
1.1 |
|
| 127 |
1.1 |