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