| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.example.entities.RecommendationRequest; | |
| 4 | import edu.ucsb.cs156.example.entities.UCSBDate; | |
| 5 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 6 | import edu.ucsb.cs156.example.repositories.RecommendationRequestRepository; | |
| 7 | import edu.ucsb.cs156.example.repositories.UCSBDateRepository; | |
| 8 | ||
| 9 | import io.swagger.v3.oas.annotations.Operation; | |
| 10 | import io.swagger.v3.oas.annotations.Parameter; | |
| 11 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 12 | import lombok.extern.slf4j.Slf4j; | |
| 13 | ||
| 14 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 15 | ||
| 16 | import org.springframework.beans.factory.annotation.Autowired; | |
| 17 | import org.springframework.format.annotation.DateTimeFormat; | |
| 18 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 19 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 20 | import org.springframework.web.bind.annotation.GetMapping; | |
| 21 | import org.springframework.web.bind.annotation.PostMapping; | |
| 22 | import org.springframework.web.bind.annotation.PutMapping; | |
| 23 | import org.springframework.web.bind.annotation.RequestBody; | |
| 24 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 25 | import org.springframework.web.bind.annotation.RequestParam; | |
| 26 | import org.springframework.web.bind.annotation.RestController; | |
| 27 | ||
| 28 | import jakarta.validation.Valid; | |
| 29 | ||
| 30 | import java.time.LocalDateTime; | |
| 31 | ||
| 32 | /** | |
| 33 | * This is a REST controller for RecommendationRequests | |
| 34 | */ | |
| 35 | ||
| 36 | @Tag(name = "RecommendationRequest") | |
| 37 | @RequestMapping("/api/RecommendationRequest") | |
| 38 | @RestController | |
| 39 | @Slf4j | |
| 40 | ||
| 41 | public class RecommendationRequestController extends ApiController { | |
| 42 | @Autowired | |
| 43 | RecommendationRequestRepository recommendationRequestRepository; | |
| 44 | ||
| 45 | /** | |
| 46 | * List all Recommendation Requests | |
| 47 | * | |
| 48 | * @return an iterable of RecommendationRequest | |
| 49 | */ | |
| 50 | @Operation(summary= "List all recommendation requests") | |
| 51 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 52 | @GetMapping("/all") | |
| 53 | public Iterable<RecommendationRequest> allRecommendationRequests() { | |
| 54 | Iterable<RecommendationRequest> recommendationRequests = recommendationRequestRepository.findAll(); | |
| 55 |
1
1. allRecommendationRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/RecommendationRequestController::allRecommendationRequests → KILLED |
return recommendationRequests; |
| 56 | } | |
| 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(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, | |
| 66 | @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, | |
| 67 | @Parameter(name="done") @RequestParam boolean done) | |
| 68 | throws JsonProcessingException { | |
| 69 | ||
| 70 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 71 | // See: https://www.baeldung.com/spring-date-parameters | |
| 72 | ||
| 73 | log.info("dateRequested={}", dateRequested); | |
| 74 | log.info("dateNeeded={}", dateNeeded); | |
| 75 | ||
| 76 | RecommendationRequest recommendationRequest = new RecommendationRequest(); | |
| 77 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
recommendationRequest.setRequesterEmail(requesterEmail); |
| 78 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
recommendationRequest.setProfessorEmail(professorEmail); |
| 79 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
recommendationRequest.setExplanation(explanation); |
| 80 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
recommendationRequest.setDateRequested(dateRequested); |
| 81 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
recommendationRequest.setDateNeeded(dateNeeded); |
| 82 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
recommendationRequest.setDone(done); |
| 83 | ||
| 84 | RecommendationRequest savedRecommendationRequest = recommendationRequestRepository.save(recommendationRequest); | |
| 85 | ||
| 86 |
1
1. postRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::postRecommendationRequest → KILLED |
return savedRecommendationRequest; |
| 87 | } | |
| 88 | ||
| 89 | /** | |
| 90 | * Get a single recommendation request by id | |
| 91 | * | |
| 92 | * @param id the id of the date | |
| 93 | * @return a RecommendationRequest | |
| 94 | */ | |
| 95 | @Operation(summary= "Get a single recommendation request") | |
| 96 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 97 | @GetMapping("") | |
| 98 | public RecommendationRequest getById( | |
| 99 | @Parameter(name="id") @RequestParam Long id) { | |
| 100 | RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id) | |
| 101 |
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)); |
| 102 | ||
| 103 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::getById → KILLED |
return recommendationRequest; |
| 104 | } | |
| 105 | ||
| 106 | /** | |
| 107 | * Update a single recommendation request | |
| 108 | * | |
| 109 | * @param id id of the recommendation request to update | |
| 110 | * @param incoming the new recommendation request | |
| 111 | * @return the updated recommendation request object | |
| 112 | */ | |
| 113 | @Operation(summary= "Update a single recommendation request") | |
| 114 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 115 | @PutMapping("") | |
| 116 | public RecommendationRequest updateRecommendationRequest( | |
| 117 | @Parameter(name="id") @RequestParam Long id, | |
| 118 | @RequestBody @Valid RecommendationRequest incoming) { | |
| 119 | ||
| 120 | RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id) | |
| 121 |
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)); |
| 122 | ||
| 123 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
recommendationRequest.setRequesterEmail(incoming.getRequesterEmail()); |
| 124 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
recommendationRequest.setProfessorEmail(incoming.getProfessorEmail()); |
| 125 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
recommendationRequest.setExplanation(incoming.getExplanation()); |
| 126 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
recommendationRequest.setDateRequested(incoming.getDateRequested()); |
| 127 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
recommendationRequest.setDateNeeded(incoming.getDateNeeded()); |
| 128 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
recommendationRequest.setDone(incoming.getDone()); |
| 129 | ||
| 130 | recommendationRequestRepository.save(recommendationRequest); | |
| 131 | ||
| 132 |
1
1. updateRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::updateRecommendationRequest → KILLED |
return recommendationRequest; |
| 133 | } | |
| 134 | ||
| 135 | /** | |
| 136 | * Delete a RecommendationRequest | |
| 137 | * | |
| 138 | * @param id the id of the recommendation request to delete | |
| 139 | * @return a message indicating the recommendation request was deleted | |
| 140 | */ | |
| 141 | @Operation(summary= "Delete a RecommendationRequest") | |
| 142 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 143 | @DeleteMapping("") | |
| 144 | public Object deleteRecommendationRequest( | |
| 145 | @Parameter(name="id") @RequestParam Long id) { | |
| 146 | RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id) | |
| 147 |
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)); |
| 148 | ||
| 149 |
1
1. deleteRecommendationRequest : removed call to edu/ucsb/cs156/example/repositories/RecommendationRequestRepository::delete → KILLED |
recommendationRequestRepository.delete(recommendationRequest); |
| 150 |
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)); |
| 151 | } | |
| 152 | } | |
Mutations | ||
| 55 |
1.1 |
|
| 77 |
1.1 |
|
| 78 |
1.1 |
|
| 79 |
1.1 |
|
| 80 |
1.1 |
|
| 81 |
1.1 |
|
| 82 |
1.1 |
|
| 86 |
1.1 |
|
| 101 |
1.1 |
|
| 103 |
1.1 |
|
| 121 |
1.1 |
|
| 123 |
1.1 |
|
| 124 |
1.1 |
|
| 125 |
1.1 |
|
| 126 |
1.1 |
|
| 127 |
1.1 |
|
| 128 |
1.1 |
|
| 132 |
1.1 |
|
| 147 |
1.1 |
|
| 149 |
1.1 |
|
| 150 |
1.1 |