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