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