| 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.repositories.RecommendationRequestRepository; | |
| 6 | import io.swagger.v3.oas.annotations.Operation; | |
| 7 | import io.swagger.v3.oas.annotations.Parameter; | |
| 8 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 9 | import java.time.LocalDateTime; | |
| 10 | import lombok.extern.slf4j.Slf4j; | |
| 11 | import org.springframework.beans.factory.annotation.Autowired; | |
| 12 | import org.springframework.format.annotation.DateTimeFormat; | |
| 13 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 14 | import org.springframework.web.bind.annotation.GetMapping; | |
| 15 | import org.springframework.web.bind.annotation.PostMapping; | |
| 16 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 17 | import org.springframework.web.bind.annotation.RequestParam; | |
| 18 | import org.springframework.web.bind.annotation.RestController; | |
| 19 | ||
| 20 | /** This is a REST controller for RecommendationRequests */ | |
| 21 | @Tag(name = "RecommendationRequests") | |
| 22 | @RequestMapping("/api/RecommendationRequest") | |
| 23 | @RestController | |
| 24 | @Slf4j | |
| 25 | public class RecommendationRequestController extends ApiController { | |
| 26 | ||
| 27 | @Autowired RecommendationRequestRepository recommendationRequestRepository; | |
| 28 | ||
| 29 | /** | |
| 30 | * List all RecommendationRequests | |
| 31 | * | |
| 32 | * @return an iterable of RecommendationRequest | |
| 33 | */ | |
| 34 | @Operation(summary = "List all recommendation requests") | |
| 35 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 36 | @GetMapping("/all") | |
| 37 | public Iterable<RecommendationRequest> allRecommendationRequests() { | |
| 38 | Iterable<RecommendationRequest> recommendationRequests = | |
| 39 | recommendationRequestRepository.findAll(); | |
| 40 |
1
1. allRecommendationRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/RecommendationRequestController::allRecommendationRequests → KILLED |
return recommendationRequests; |
| 41 | } | |
| 42 | ||
| 43 | /** | |
| 44 | * Create a new RecommendationRequest | |
| 45 | * | |
| 46 | * @param requesterEmail the email of the person requesting the recommendation | |
| 47 | * @param professorEmail the email of the professor receiving the request | |
| 48 | * @param explanation explanation of what the recommendation is for | |
| 49 | * @param dateRequested the date and time the recommendation was requested | |
| 50 | * @param dateNeeded the date and time by which the recommendation is needed | |
| 51 | * @param done whether the recommendation request has been completed | |
| 52 | * @return the saved RecommendationRequest | |
| 53 | */ | |
| 54 | @Operation(summary = "Create a new recommendation request") | |
| 55 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 56 | @PostMapping("/post") | |
| 57 | public RecommendationRequest postRecommendationRequest( | |
| 58 | @Parameter(name = "requesterEmail", description = "Email address of the requester") | |
| 59 | @RequestParam | |
| 60 | String requesterEmail, | |
| 61 | @Parameter(name = "professorEmail", description = "Email address of the professor") | |
| 62 | @RequestParam | |
| 63 | String professorEmail, | |
| 64 | @Parameter(name = "explanation", description = "Explanation of the recommendation request") | |
| 65 | @RequestParam | |
| 66 | String explanation, | |
| 67 | @Parameter( | |
| 68 | name = "dateRequested", | |
| 69 | description = "Date and time requested in ISO format, e.g. 2022-05-20T00:00:00") | |
| 70 | @RequestParam("dateRequested") | |
| 71 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 72 | LocalDateTime dateRequested, | |
| 73 | @Parameter( | |
| 74 | name = "dateNeeded", | |
| 75 | description = "Date and time needed in ISO format, e.g. 2022-11-15T00:00:00") | |
| 76 | @RequestParam("dateNeeded") | |
| 77 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 78 | LocalDateTime dateNeeded, | |
| 79 | @Parameter(name = "done", description = "Whether the recommendation request is completed") | |
| 80 | @RequestParam | |
| 81 | boolean done) | |
| 82 | throws JsonProcessingException { | |
| 83 | ||
| 84 | RecommendationRequest recommendationRequest = new RecommendationRequest(); | |
| 85 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
recommendationRequest.setRequesterEmail(requesterEmail); |
| 86 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
recommendationRequest.setProfessorEmail(professorEmail); |
| 87 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
recommendationRequest.setExplanation(explanation); |
| 88 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
recommendationRequest.setDateRequested(dateRequested); |
| 89 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
recommendationRequest.setDateNeeded(dateNeeded); |
| 90 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
recommendationRequest.setDone(done); |
| 91 | ||
| 92 | RecommendationRequest savedRecommendationRequest = | |
| 93 | recommendationRequestRepository.save(recommendationRequest); | |
| 94 | ||
| 95 |
1
1. postRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::postRecommendationRequest → KILLED |
return savedRecommendationRequest; |
| 96 | } | |
| 97 | } | |
Mutations | ||
| 40 |
1.1 |
|
| 85 |
1.1 |
|
| 86 |
1.1 |
|
| 87 |
1.1 |
|
| 88 |
1.1 |
|
| 89 |
1.1 |
|
| 90 |
1.1 |
|
| 95 |
1.1 |