| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.example.entities.RecommendationRequest; | |
| 4 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 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 lombok.extern.slf4j.Slf4j; | |
| 10 | ||
| 11 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 12 | ||
| 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 | import javax.validation.Valid; | |
| 26 | ||
| 27 | import java.time.LocalDateTime; | |
| 28 | ||
| 29 | @Tag(name = "RecommendationRequest") | |
| 30 | @RequestMapping("/api/RecommendationRequest") | |
| 31 | @RestController | |
| 32 | @Slf4j | |
| 33 | public class RecommendationRequestController extends ApiController{ | |
| 34 | @Autowired | |
| 35 | RecommendationRequestRepository recommendationRequestRepository; | |
| 36 | ||
| 37 | @Operation(summary= "List all recomendation requests") | |
| 38 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 39 | @GetMapping("/all") | |
| 40 | public Iterable<RecommendationRequest> allRecommendationRequests() { | |
| 41 | Iterable<RecommendationRequest> requests = recommendationRequestRepository.findAll(); | |
| 42 |
1
1. allRecommendationRequests : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::allRecommendationRequests → KILLED |
return requests; |
| 43 | } | |
| 44 | ||
| 45 | @Operation(summary= "Create a new recommendation request") | |
| 46 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 47 | @PostMapping("/post") | |
| 48 | public RecommendationRequest postRecommendationRequest( | |
| 49 | @Parameter(name="requesterEmail") @RequestParam String requesterEmail, | |
| 50 | @Parameter(name="professorEmail") @RequestParam String professorEmail, | |
| 51 | @Parameter(name="explanation") @RequestParam String explanation, | |
| 52 | @Parameter(name="dateRequested") @RequestParam("dateRequested") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dateRequested, | |
| 53 | @Parameter(name="dateNeeded") @RequestParam("dateNeeded") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dateNeeded, | |
| 54 | @Parameter(name="done") @RequestParam boolean done) | |
| 55 | throws JsonProcessingException { | |
| 56 | ||
| 57 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 58 | // See: https://www.baeldung.com/spring-date-parameters | |
| 59 | ||
| 60 | log.info("dateRequested={}", dateRequested); | |
| 61 | ||
| 62 | RecommendationRequest recommendationRequest = new RecommendationRequest(); | |
| 63 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
recommendationRequest.setRequesterEmail(requesterEmail); |
| 64 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
recommendationRequest.setProfessorEmail(professorEmail); |
| 65 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
recommendationRequest.setExplanation(explanation); |
| 66 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
recommendationRequest.setDateRequested(dateRequested); |
| 67 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
recommendationRequest.setDateNeeded(dateNeeded); |
| 68 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
recommendationRequest.setDone(done); |
| 69 | ||
| 70 | RecommendationRequest savedRecommendationRequest = 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 getById( | |
| 79 | @Parameter(name="id") @RequestParam Long id) { | |
| 80 | RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id) | |
| 81 |
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)); |
| 82 | ||
| 83 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::getById → KILLED |
return recommendationRequest; |
| 84 | } | |
| 85 | ||
| 86 | @Operation(summary= "Update a single recommendation request") | |
| 87 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 88 | @PutMapping("") | |
| 89 | public RecommendationRequest updateRecommendationRequest( | |
| 90 | @Parameter(name="id") @RequestParam Long id, | |
| 91 | @RequestBody @Valid RecommendationRequest incoming) { | |
| 92 | ||
| 93 | RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id) | |
| 94 |
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)); |
| 95 | ||
| 96 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
recommendationRequest.setProfessorEmail(incoming.getProfessorEmail()); |
| 97 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
recommendationRequest.setRequesterEmail(incoming.getRequesterEmail()); |
| 98 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
recommendationRequest.setExplanation(incoming.getExplanation()); |
| 99 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
recommendationRequest.setDateRequested(incoming.getDateRequested()); |
| 100 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
recommendationRequest.setDateNeeded(incoming.getDateNeeded()); |
| 101 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
recommendationRequest.setDone(incoming.getDone()); |
| 102 | ||
| 103 | recommendationRequestRepository.save(recommendationRequest); | |
| 104 | ||
| 105 |
1
1. updateRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::updateRecommendationRequest → KILLED |
return recommendationRequest; |
| 106 | } | |
| 107 | ||
| 108 | @Operation(summary= "Delete a RecomendationRequest") | |
| 109 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 110 | @DeleteMapping("") | |
| 111 | public Object deleteRecommendationRequest( | |
| 112 | @Parameter(name="id") @RequestParam Long id) { | |
| 113 | RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id) | |
| 114 |
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)); |
| 115 | ||
| 116 |
1
1. deleteRecommendationRequest : removed call to edu/ucsb/cs156/example/repositories/RecommendationRequestRepository::delete → KILLED |
recommendationRequestRepository.delete(recommendationRequest); |
| 117 |
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)); |
| 118 | } | |
| 119 | ||
| 120 | ||
| 121 | } | |
Mutations | ||
| 42 |
1.1 |
|
| 63 |
1.1 |
|
| 64 |
1.1 |
|
| 65 |
1.1 |
|
| 66 |
1.1 |
|
| 67 |
1.1 |
|
| 68 |
1.1 |
|
| 72 |
1.1 |
|
| 81 |
1.1 |
|
| 83 |
1.1 |
|
| 94 |
1.1 |
|
| 96 |
1.1 |
|
| 97 |
1.1 |
|
| 98 |
1.1 |
|
| 99 |
1.1 |
|
| 100 |
1.1 |
|
| 101 |
1.1 |
|
| 105 |
1.1 |
|
| 114 |
1.1 |
|
| 116 |
1.1 |
|
| 117 |
1.1 |