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