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