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