| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 4 | import edu.ucsb.cs156.example.entities.RecommendationRequest; | |
| 5 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 6 | import edu.ucsb.cs156.example.repositories.RecommendationRequestRepository; | |
| 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 jakarta.validation.Valid; | |
| 11 | import java.time.LocalDateTime; | |
| 12 | import lombok.extern.slf4j.Slf4j; | |
| 13 | import org.springframework.beans.factory.annotation.Autowired; | |
| 14 | import org.springframework.format.annotation.DateTimeFormat; | |
| 15 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 16 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 17 | import org.springframework.web.bind.annotation.GetMapping; | |
| 18 | import org.springframework.web.bind.annotation.PostMapping; | |
| 19 | import org.springframework.web.bind.annotation.PutMapping; | |
| 20 | import org.springframework.web.bind.annotation.RequestBody; | |
| 21 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 22 | import org.springframework.web.bind.annotation.RequestParam; | |
| 23 | import org.springframework.web.bind.annotation.RestController; | |
| 24 | ||
| 25 | /** REST controller for RecommendationRequest */ | |
| 26 | @Tag(name = "RecommendationRequest") | |
| 27 | @RequestMapping("/api/recommendationrequest") | |
| 28 | @RestController | |
| 29 | @Slf4j | |
| 30 | public class RecommendationRequestController extends ApiController { | |
| 31 | ||
| 32 | @Autowired private RecommendationRequestRepository recommendationRequestRepository; | |
| 33 | ||
| 34 | /** | |
| 35 | * Get all recommendation requests | |
| 36 | * | |
| 37 | * @return all RecommendationRequest entries as JSON | |
| 38 | */ | |
| 39 | @Operation(summary = "List all recommendation requests") | |
| 40 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 41 | @GetMapping("/all") | |
| 42 | public Iterable<RecommendationRequest> allRecommendationRequest() { | |
| 43 |
1
1. allRecommendationRequest : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/RecommendationRequestController::allRecommendationRequest → KILLED |
return recommendationRequestRepository.findAll(); |
| 44 | } | |
| 45 | ||
| 46 | /** Create a new recommendation request */ | |
| 47 | @Operation(summary = "Create a new recommendation request") | |
| 48 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 49 | @PostMapping("/post") | |
| 50 | public RecommendationRequest postRecommendationRequest( | |
| 51 | @Parameter(name = "requesterEmail") @RequestParam String requesterEmail, | |
| 52 | @Parameter(name = "professorEmail") @RequestParam String professorEmail, | |
| 53 | @Parameter(name = "explanation") @RequestParam String explanation, | |
| 54 | @Parameter(name = "dateRequested") | |
| 55 | @RequestParam("dateRequested") | |
| 56 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 57 | LocalDateTime dateRequested, | |
| 58 | @Parameter(name = "dateNeeded") | |
| 59 | @RequestParam("dateNeeded") | |
| 60 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 61 | LocalDateTime dateNeeded, | |
| 62 | @Parameter(name = "done") @RequestParam boolean done) | |
| 63 | throws JsonProcessingException { | |
| 64 | ||
| 65 | log.info("Creating RecommendationRequest for requesterEmail={}", requesterEmail); | |
| 66 | ||
| 67 | RecommendationRequest request = new RecommendationRequest(); | |
| 68 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
request.setRequesterEmail(requesterEmail); |
| 69 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
request.setProfessorEmail(professorEmail); |
| 70 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
request.setExplanation(explanation); |
| 71 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
request.setDateRequested(dateRequested); |
| 72 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
request.setDateNeeded(dateNeeded); |
| 73 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
request.setDone(done); |
| 74 | ||
| 75 |
1
1. postRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::postRecommendationRequest → KILLED |
return recommendationRequestRepository.save(request); |
| 76 | } | |
| 77 | ||
| 78 | /** Get a single recommendation request by id */ | |
| 79 | @Operation(summary = "Get a single recommendation request by id") | |
| 80 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 81 | @GetMapping("") | |
| 82 | public RecommendationRequest getRecommendationRequestById( | |
| 83 | @Parameter(name = "id") @RequestParam Long id) { | |
| 84 | ||
| 85 |
1
1. getRecommendationRequestById : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::getRecommendationRequestById → KILLED |
return recommendationRequestRepository |
| 86 | .findById(id) | |
| 87 |
1
1. lambda$getRecommendationRequestById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$getRecommendationRequestById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id)); |
| 88 | } | |
| 89 | ||
| 90 | /** Update a single recommendation request by id */ | |
| 91 | @Operation(summary = "Update a single recommendation request by id") | |
| 92 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 93 | @PutMapping("") | |
| 94 | public RecommendationRequest updateRecommendationRequest( | |
| 95 | @Parameter(name = "id") @RequestParam Long id, | |
| 96 | @RequestBody @Valid RecommendationRequest incoming) { | |
| 97 | ||
| 98 | RecommendationRequest request = | |
| 99 | recommendationRequestRepository | |
| 100 | .findById(id) | |
| 101 |
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)); |
| 102 | ||
| 103 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
request.setRequesterEmail(incoming.getRequesterEmail()); |
| 104 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
request.setProfessorEmail(incoming.getProfessorEmail()); |
| 105 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
request.setExplanation(incoming.getExplanation()); |
| 106 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
request.setDateRequested(incoming.getDateRequested()); |
| 107 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
request.setDateNeeded(incoming.getDateNeeded()); |
| 108 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
request.setDone(incoming.getDone()); |
| 109 | ||
| 110 | recommendationRequestRepository.save(request); | |
| 111 |
1
1. updateRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::updateRecommendationRequest → KILLED |
return request; |
| 112 | } | |
| 113 | ||
| 114 | /** Delete a RecommendationRequest */ | |
| 115 | @Operation(summary = "Delete a RecommendationRequest") | |
| 116 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 117 | @DeleteMapping("") | |
| 118 | public Object deleteRecommendationRequest(@Parameter(name = "id") @RequestParam Long id) { | |
| 119 | RecommendationRequest recommendationRequest = | |
| 120 | recommendationRequestRepository | |
| 121 | .findById(id) | |
| 122 |
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)); |
| 123 | ||
| 124 |
1
1. deleteRecommendationRequest : removed call to edu/ucsb/cs156/example/repositories/RecommendationRequestRepository::delete → KILLED |
recommendationRequestRepository.delete(recommendationRequest); |
| 125 |
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)); |
| 126 | } | |
| 127 | } | |
Mutations | ||
| 43 |
1.1 |
|
| 68 |
1.1 |
|
| 69 |
1.1 |
|
| 70 |
1.1 |
|
| 71 |
1.1 |
|
| 72 |
1.1 |
|
| 73 |
1.1 |
|
| 75 |
1.1 |
|
| 85 |
1.1 |
|
| 87 |
1.1 |
|
| 101 |
1.1 |
|
| 103 |
1.1 |
|
| 104 |
1.1 |
|
| 105 |
1.1 |
|
| 106 |
1.1 |
|
| 107 |
1.1 |
|
| 108 |
1.1 |
|
| 111 |
1.1 |
|
| 122 |
1.1 |
|
| 124 |
1.1 |
|
| 125 |
1.1 |