| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | import edu.ucsb.cs156.example.entities.UCSBRecommendationRequest; | |
| 3 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 4 | import edu.ucsb.cs156.example.repositories.UCSBRecommendationRequestRepository; | |
| 5 | ||
| 6 | import java.time.LocalDate; | |
| 7 | import java.time.format.DateTimeFormatter; | |
| 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 RecommendationRequest | |
| 34 |  */ | |
| 35 | ||
| 36 | ||
| 37 | @Tag(name = "RecommendationRequest") | |
| 38 | @RequestMapping("/api/recommendationRequest") | |
| 39 | @RestController | |
| 40 | @Slf4j | |
| 41 | public class RecommendationRequestController extends ApiController { | |
| 42 | ||
| 43 |     @Autowired | |
| 44 |     UCSBRecommendationRequestRepository  ucsbRecommendationRequestRepository;  | |
| 45 | ||
| 46 |         /** | |
| 47 |      * List all UCSB dates | |
| 48 |      *  | |
| 49 |      * @return an iterable of UCSBDate | |
| 50 |      */ | |
| 51 |     @Operation(summary= "List all ucsb recommendation requests") | |
| 52 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 53 |     @GetMapping("/all") | |
| 54 |     public Iterable<UCSBRecommendationRequest> allUCSBRecommendationRequestRepository() { | |
| 55 |         Iterable<UCSBRecommendationRequest> requests = ucsbRecommendationRequestRepository.findAll(); | |
| 56 | 
1
1. allUCSBRecommendationRequestRepository : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/RecommendationRequestController::allUCSBRecommendationRequestRepository → KILLED | 
        return requests;    | 
| 57 |     } | |
| 58 | ||
| 59 | ||
| 60 | ||
| 61 |     /** | |
| 62 |      * Create a new rec | |
| 63 |      *  | |
| 64 |      *  | |
| 65 |      * @param requesterEmail the name of the requestor : string  | |
| 66 |      * @param professorEmail the name of the professor : string  | |
| 67 |      * @param explanation what the request details : string | |
| 68 |      * @param dateRequested date requestor sent request : iso format, e.g. YYYY-mm-ddTHH:MM:SS | |
| 69 |      * @param dateNeeded date requestor needs request finished by : iso format, e.g. YYYY-mm-ddTHH:MM:SS | |
| 70 |      * @param done the truth value of it being finished or not : bool | |
| 71 |      * @return the saved recommendation request | |
| 72 |      */ | |
| 73 |     @Operation(summary= "Create a recommendation request") | |
| 74 |     @PreAuthorize("hasRole('ROLE_USER')") | |
| 75 |     @PostMapping("/post") | |
| 76 |     public UCSBRecommendationRequest postRecommendationRequest | |
| 77 |     ( | |
| 78 |             @Parameter(name="requesterEmail") @RequestParam String requesterEmail, | |
| 79 |             @Parameter(name="professorEmail") @RequestParam String professorEmail, | |
| 80 |             @Parameter(name="explanation") @RequestParam String explanation, | |
| 81 |             @Parameter(name="done") @RequestParam Boolean done, | |
| 82 |             @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, | |
| 83 |             @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 | |
| 84 |     ) | |
| 85 |   | |
| 86 |             throws JsonProcessingException { | |
| 87 | ||
| 88 |         // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 89 |         // See: https://www.baeldung.com/spring-date-parameters | |
| 90 | ||
| 91 |         log.info("dateRequested={}", dateRequested); | |
| 92 |         log.info("dateNeeded={}", dateNeeded); | |
| 93 | ||
| 94 |         UCSBRecommendationRequest ucsbRecommendationRequest = new UCSBRecommendationRequest(); | |
| 95 | 
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setRequesterEmail → KILLED | 
        ucsbRecommendationRequest.setRequesterEmail(requesterEmail); | 
| 96 | 
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setProfessorEmail → KILLED | 
        ucsbRecommendationRequest.setProfessorEmail(professorEmail); | 
| 97 | 
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setExplanation → KILLED | 
        ucsbRecommendationRequest.setExplanation(explanation); | 
| 98 | 
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setDateRequested → KILLED | 
        ucsbRecommendationRequest.setDateRequested(dateRequested); | 
| 99 | 
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setDateNeeded → KILLED | 
        ucsbRecommendationRequest.setDateNeeded(dateNeeded); | 
| 100 | 
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setDone → KILLED | 
        ucsbRecommendationRequest.setDone(done); | 
| 101 | ||
| 102 |         UCSBRecommendationRequest saveducsbRecommendationRequest = ucsbRecommendationRequestRepository.save(ucsbRecommendationRequest); | |
| 103 | ||
| 104 | 
1
1. postRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::postRecommendationRequest → KILLED | 
        return saveducsbRecommendationRequest; | 
| 105 |     } | |
| 106 | ||
| 107 |         /** | |
| 108 |      * Get a single item on the menu by id | |
| 109 |      *  | |
| 110 |      * @param id the id of the menu item | |
| 111 |      * @return a menu item | |
| 112 |      */ | |
| 113 |     @Operation(summary= "Get a single recommendation by id") | |
| 114 |     @PreAuthorize("hasRole('ROLE_USER')") | |
| 115 |     @GetMapping("") | |
| 116 |     public UCSBRecommendationRequest getById( | |
| 117 |             @Parameter(name="id") @RequestParam Long id) { | |
| 118 |                 UCSBRecommendationRequest ucsbRecommendationRequest = ucsbRecommendationRequestRepository | |
| 119 |                 .findById(id) | |
| 120 | 
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$getById$0 → KILLED | 
                .orElseThrow(() -> new EntityNotFoundException(UCSBRecommendationRequest.class, id)); | 
| 121 | ||
| 122 | 
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::getById → KILLED | 
        return ucsbRecommendationRequest; | 
| 123 |     } | |
| 124 | ||
| 125 | ||
| 126 |         /** | |
| 127 |      * Update a single recommendation request | |
| 128 |      *  | |
| 129 |      * @param id       id of the date to update | |
| 130 |      * @param incoming the recommendation request | |
| 131 |      * @return the updated recommendation request object | |
| 132 |      */ | |
| 133 |     @Operation(summary= "Update a recommendation request") | |
| 134 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 135 |     @PutMapping("") | |
| 136 |     public UCSBRecommendationRequest updateRecommendationRequest( | |
| 137 |             @Parameter(name="id") @RequestParam Long id, | |
| 138 |             @RequestBody @Valid UCSBRecommendationRequest incoming) { | |
| 139 | ||
| 140 |         UCSBRecommendationRequest ucsbRecommendationRequest = ucsbRecommendationRequestRepository.findById(id) | |
| 141 | 
1
1. lambda$updateRecommendationRequest$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$updateRecommendationRequest$1 → KILLED | 
                .orElseThrow(() -> new EntityNotFoundException(UCSBRecommendationRequest.class, id)); | 
| 142 | ||
| 143 | 
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setDateNeeded → KILLED | 
        ucsbRecommendationRequest.setDateNeeded(incoming.getDateNeeded()); | 
| 144 | 
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setDateRequested → KILLED | 
        ucsbRecommendationRequest.setDateRequested(incoming.getDateRequested()); | 
| 145 | 
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setDone → KILLED | 
        ucsbRecommendationRequest.setDone(incoming.getDone()); | 
| 146 | 
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setExplanation → KILLED | 
        ucsbRecommendationRequest.setExplanation(incoming.getExplanation()); | 
| 147 | 
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setId → KILLED | 
        ucsbRecommendationRequest.setId(id); | 
| 148 | 
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setProfessorEmail → KILLED | 
        ucsbRecommendationRequest.setProfessorEmail(incoming.getProfessorEmail()); | 
| 149 | 
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/UCSBRecommendationRequest::setRequesterEmail → KILLED | 
        ucsbRecommendationRequest.setRequesterEmail(incoming.getRequesterEmail()); | 
| 150 |         ucsbRecommendationRequestRepository.save(ucsbRecommendationRequest); | |
| 151 | ||
| 152 | 
1
1. updateRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::updateRecommendationRequest → KILLED | 
        return ucsbRecommendationRequest; | 
| 153 |     } | |
| 154 | ||
| 155 |         /** | |
| 156 |      * Delete a UCSBRecommendationRequest  | |
| 157 |      *  | |
| 158 |      * @param id the id of the recommendationRequest to delete | |
| 159 |      * @return a message indicating the recommendationRequest was deleted | |
| 160 |      */ | |
| 161 |     @Operation(summary= "Delete a UCSBRecommendationRequest") | |
| 162 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 163 |     @DeleteMapping("") | |
| 164 |     public Object deleteUCSBDate( | |
| 165 |             @Parameter(name="id") @RequestParam Long id) { | |
| 166 |             UCSBRecommendationRequest ucsbRecommendationRequest = ucsbRecommendationRequestRepository.findById(id) | |
| 167 | 
1
1. lambda$deleteUCSBDate$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$deleteUCSBDate$2 → KILLED | 
                .orElseThrow(() -> new EntityNotFoundException(UCSBRecommendationRequest.class, id)); | 
| 168 | ||
| 169 | 
1
1. deleteUCSBDate : removed call to edu/ucsb/cs156/example/repositories/UCSBRecommendationRequestRepository::delete → KILLED | 
        ucsbRecommendationRequestRepository.delete(ucsbRecommendationRequest); | 
| 170 | 
1
1. deleteUCSBDate : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::deleteUCSBDate → KILLED | 
        return genericMessage("UCSBRecommendationRequest with id %s deleted".formatted(id)); | 
| 171 |     } | |
| 172 | ||
| 173 | ||
| 174 |      | |
| 175 | } | |
Mutations | ||
| 56 | 
 
 1.1  | 
|
| 95 | 
 
 1.1  | 
|
| 96 | 
 
 1.1  | 
|
| 97 | 
 
 1.1  | 
|
| 98 | 
 
 1.1  | 
|
| 99 | 
 
 1.1  | 
|
| 100 | 
 
 1.1  | 
|
| 104 | 
 
 1.1  | 
|
| 120 | 
 
 1.1  | 
|
| 122 | 
 
 1.1  | 
|
| 141 | 
 
 1.1  | 
|
| 143 | 
 
 1.1  | 
|
| 144 | 
 
 1.1  | 
|
| 145 | 
 
 1.1  | 
|
| 146 | 
 
 1.1  | 
|
| 147 | 
 
 1.1  | 
|
| 148 | 
 
 1.1  | 
|
| 149 | 
 
 1.1  | 
|
| 152 | 
 
 1.1  | 
|
| 167 | 
 
 1.1  | 
|
| 169 | 
 
 1.1  | 
|
| 170 | 
 
 1.1  |