| 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 | ||
| 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 | import org.apache.logging.log4j.message.ReusableMessage; | |
| 31 | ||
| 32 | /** | |
| 33 |  * This is a REST controller for RecommendationRequests | |
| 34 |  */ | |
| 35 | ||
| 36 | @Tag(name = "RecommendationRequests") | |
| 37 | @RequestMapping("/api/recommendationrequests") | |
| 38 | @RestController | |
| 39 | @Slf4j | |
| 40 | public class RecommendationRequestsController extends ApiController{ | |
| 41 | ||
| 42 |     @Autowired | |
| 43 |     RecommendationRequestRepository recommendationRequestRepository; | |
| 44 | ||
| 45 |     /** | |
| 46 |      * List all RecommendationRequests dates | |
| 47 |      *  | |
| 48 |      * @return an iterable of RecommendationRequest | |
| 49 |      */ | |
| 50 |     @Operation(summary= "List all recommendation request dates") | |
| 51 |     @PreAuthorize("hasRole('ROLE_USER')") | |
| 52 |     @GetMapping("/all") | |
| 53 |     public Iterable<RecommendationRequest> allRecommendationRequests() { | |
| 54 |         Iterable<RecommendationRequest> requests = recommendationRequestRepository.findAll(); | |
| 55 | 
1
1. allRecommendationRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::allRecommendationRequests → KILLED | 
        return requests; | 
| 56 |     } | |
| 57 | ||
| 58 |     /** | |
| 59 |      * Create a new date | |
| 60 |      *  | |
| 61 |      * @param requesterEmail  the email of the requester | |
| 62 |      * @param professorEmail  the email of the professor | |
| 63 |      * @param explanation     the explanation for the request | |
| 64 |      * @param dateRequested   the date of the request | |
| 65 |      * @param dateNeeded      the due date of the request | |
| 66 |      * @param done            whether the request is done or not | |
| 67 |      * @return the saved recommendation request | |
| 68 |      */ | |
| 69 |     @Operation(summary= "Create a new date") | |
| 70 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 71 |     @PostMapping("/post") | |
| 72 |     public RecommendationRequest postRecommendationRequest( | |
| 73 |             @Parameter(name="requesterEmail") @RequestParam String requesterEmail, | |
| 74 |             @Parameter(name="professorEmail") @RequestParam String professorEmail, | |
| 75 |             @Parameter(name="explanation") @RequestParam String explanation, | |
| 76 |             @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, | |
| 77 |             @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, | |
| 78 |             @Parameter(name="done") @RequestParam Boolean done) | |
| 79 |             throws JsonProcessingException { | |
| 80 | ||
| 81 |         // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 82 |         // See: https://www.baeldung.com/spring-date-parameters | |
| 83 | ||
| 84 |         log.info("recommendationRequestTime={}", dateRequested); | |
| 85 | ||
| 86 |         RecommendationRequest recommendationRequest = new RecommendationRequest(); | |
| 87 | 
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED | 
        recommendationRequest.setRequesterEmail(requesterEmail); | 
| 88 | 
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED | 
        recommendationRequest.setProfessorEmail(professorEmail); | 
| 89 | 
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED | 
        recommendationRequest.setExplanation(explanation); | 
| 90 | 
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED | 
        recommendationRequest.setDateRequested(dateRequested); | 
| 91 | 
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED | 
        recommendationRequest.setDateNeeded(dateNeeded); | 
| 92 | 
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED | 
        recommendationRequest.setDone(done); | 
| 93 | ||
| 94 |         RecommendationRequest savedRecommendationRequest = recommendationRequestRepository.save(recommendationRequest); | |
| 95 | ||
| 96 | 
1
1. postRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::postRecommendationRequest → KILLED | 
        return savedRecommendationRequest; | 
| 97 |     } | |
| 98 | ||
| 99 |     /** | |
| 100 |      * Get a single recommendation request by id | |
| 101 |      *  | |
| 102 |      * @param id the id of the recommendation request | |
| 103 |      * @return a RecommendationRequest | |
| 104 |      */ | |
| 105 |     @Operation(summary = "Get a single recommendation request") | |
| 106 |     @PreAuthorize("hasRole('ROLE_USER')") | |
| 107 |     @GetMapping | |
| 108 |     public RecommendationRequest getById( | |
| 109 |             @Parameter(name = "id") @RequestParam Long id) { | |
| 110 |         RecommendationRequest request = recommendationRequestRepository.findById(id) | |
| 111 | 
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::lambda$getById$0 → KILLED | 
                .orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id)); | 
| 112 | ||
| 113 | 
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::getById → KILLED | 
        return request; | 
| 114 |     } | |
| 115 | ||
| 116 |     /** | |
| 117 |      * Update a single recommendation request | |
| 118 |      *  | |
| 119 |      * @param id       id of the date to update | |
| 120 |      * @param incoming the new recommendation request | |
| 121 |      * @return the updated request object | |
| 122 |      */ | |
| 123 |     @Operation(summary= "Update a single recommendation request") | |
| 124 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 125 |     @PutMapping("") | |
| 126 |     public RecommendationRequest updateRecommendationRequest( | |
| 127 |             @Parameter(name="id") @RequestParam Long id, | |
| 128 |             @RequestBody @Valid RecommendationRequest incoming) { | |
| 129 | ||
| 130 |         RecommendationRequest request = recommendationRequestRepository.findById(id) | |
| 131 | 
1
1. lambda$updateRecommendationRequest$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::lambda$updateRecommendationRequest$1 → KILLED | 
                .orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id)); | 
| 132 | ||
| 133 | 
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED | 
        request.setRequesterEmail(incoming.getRequesterEmail()); | 
| 134 | 
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED | 
        request.setProfessorEmail(incoming.getProfessorEmail()); | 
| 135 | 
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED | 
        request.setExplanation(incoming.getExplanation()); | 
| 136 | 
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED | 
        request.setDateRequested(incoming.getDateRequested()); | 
| 137 | 
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED | 
        request.setDateNeeded(incoming.getDateNeeded()); | 
| 138 | 
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED | 
        request.setDone(incoming.getDone()); | 
| 139 | ||
| 140 |         recommendationRequestRepository.save(request); | |
| 141 | ||
| 142 | 
1
1. updateRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::updateRecommendationRequest → KILLED | 
        return request; | 
| 143 |     } | |
| 144 | ||
| 145 |     /** | |
| 146 |      * Delete a Recommendation Request | |
| 147 |      *  | |
| 148 |      * @param id the id of the recommmendation request to delete | |
| 149 |      * @return a message indicating the recommendation request was deleted | |
| 150 |      */ | |
| 151 |     @Operation(summary= "Delete a RecommendationRequest") | |
| 152 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 153 |     @DeleteMapping("") | |
| 154 |     public Object deleteRecommendationRequest( | |
| 155 |             @Parameter(name="id") @RequestParam Long id) { | |
| 156 |         RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id) | |
| 157 | 
1
1. lambda$deleteRecommendationRequest$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::lambda$deleteRecommendationRequest$2 → KILLED | 
                .orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id)); | 
| 158 | ||
| 159 | 
1
1. deleteRecommendationRequest : removed call to edu/ucsb/cs156/example/repositories/RecommendationRequestRepository::delete → KILLED | 
        recommendationRequestRepository.delete(recommendationRequest); | 
| 160 | 
1
1. deleteRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::deleteRecommendationRequest → KILLED | 
        return genericMessage("RecommendationRequest with id %s deleted".formatted(id)); | 
| 161 |     } | |
| 162 | } | |
Mutations | ||
| 55 | 
 
 1.1  | 
|
| 87 | 
 
 1.1  | 
|
| 88 | 
 
 1.1  | 
|
| 89 | 
 
 1.1  | 
|
| 90 | 
 
 1.1  | 
|
| 91 | 
 
 1.1  | 
|
| 92 | 
 
 1.1  | 
|
| 96 | 
 
 1.1  | 
|
| 111 | 
 
 1.1  | 
|
| 113 | 
 
 1.1  | 
|
| 131 | 
 
 1.1  | 
|
| 133 | 
 
 1.1  | 
|
| 134 | 
 
 1.1  | 
|
| 135 | 
 
 1.1  | 
|
| 136 | 
 
 1.1  | 
|
| 137 | 
 
 1.1  | 
|
| 138 | 
 
 1.1  | 
|
| 142 | 
 
 1.1  | 
|
| 157 | 
 
 1.1  | 
|
| 159 | 
 
 1.1  | 
|
| 160 | 
 
 1.1  |