1 | package edu.ucsb.cs156.example.controllers; | |
2 | ||
3 | ||
4 | import edu.ucsb.cs156.example.entities.RecommendationRequest; | |
5 | import edu.ucsb.cs156.example.entities.UCSBDate; | |
6 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
7 | import edu.ucsb.cs156.example.repositories.RecommendationRequestRepository; | |
8 | import edu.ucsb.cs156.example.repositories.UCSBDateRepository; | |
9 | ||
10 | import io.swagger.v3.oas.annotations.Operation; | |
11 | import io.swagger.v3.oas.annotations.Parameter; | |
12 | import io.swagger.v3.oas.annotations.tags.Tag; | |
13 | import lombok.extern.slf4j.Slf4j; | |
14 | ||
15 | import com.fasterxml.jackson.core.JsonProcessingException; | |
16 | ||
17 | import org.springframework.beans.factory.annotation.Autowired; | |
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 | ||
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 ucsb recommendation request") | |
53 | @PreAuthorize("hasRole('ROLE_USER')") | |
54 | @GetMapping("/all") | |
55 | public Iterable<RecommendationRequest> allRecommendationRequests() { | |
56 | Iterable<RecommendationRequest> recommendationRequests = recommendationRequestRepository.findAll(); | |
57 |
1
1. allRecommendationRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/RecommendationRequestController::allRecommendationRequests → KILLED |
return recommendationRequests; |
58 | } | |
59 | ||
60 | /** | |
61 | * Create a new recommendation request | |
62 | * | |
63 | * @param requestorEmail email of the requestor | |
64 | * @param professorEmail email of the professor | |
65 | * @param explanation explanation of the request | |
66 | * @param dateRequested date the date was requested | |
67 | * @param dateNeeded date the date is needed | |
68 | * @param done whether the request is done or not | |
69 | * @return the saved recommendation request | |
70 | */ | |
71 | @Operation(summary= "Create a new recommendation request") | |
72 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
73 | @PostMapping("/post") | |
74 | public RecommendationRequest postRecommendationRequest( | |
75 | @Parameter(name="requestorEmail") @RequestParam String requestorEmail, | |
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:SS; 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:SS; 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 | | |
90 | RecommendationRequest recommendationRequest = new RecommendationRequest(); | |
91 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequestorEmail → KILLED |
recommendationRequest.setRequestorEmail(requestorEmail); |
92 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
recommendationRequest.setProfessorEmail(professorEmail); |
93 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
recommendationRequest.setExplanation(explanation); |
94 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
recommendationRequest.setDateRequested(dateRequested); |
95 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
recommendationRequest.setDateNeeded(dateNeeded); |
96 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
recommendationRequest.setDone(done); |
97 | ||
98 | RecommendationRequest savedRecommendationRequest = recommendationRequestRepository.save(recommendationRequest); | |
99 | ||
100 |
1
1. postRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::postRecommendationRequest → KILLED |
return savedRecommendationRequest; |
101 | } | |
102 | ||
103 | /** | |
104 | * Get a single recommendation request by id | |
105 | * | |
106 | * @param id the id of the recommendation request | |
107 | * @return a RecommendationRequest | |
108 | */ | |
109 | @Operation(summary= "Get a single recommendation request") | |
110 | @PreAuthorize("hasRole('ROLE_USER')") | |
111 | @GetMapping("") | |
112 | public RecommendationRequest getById( | |
113 | @Parameter(name="id") @RequestParam Long id) { | |
114 | RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id) | |
115 |
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)); |
116 | ||
117 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::getById → KILLED |
return recommendationRequest; |
118 | } | |
119 | ||
120 | /** | |
121 | * Update a single recommmendation request | |
122 | * | |
123 | * @param id id of the recommendation request to update | |
124 | * @param incoming the new recommendation request | |
125 | * @return the updated recommendation request object | |
126 | */ | |
127 | @Operation(summary= "Update a single recommendation request") | |
128 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
129 | @PutMapping("") | |
130 | public RecommendationRequest updateRecommendationRequest( | |
131 | @Parameter(name="id") @RequestParam Long id, | |
132 | @RequestBody @Valid RecommendationRequest incoming) { | |
133 | ||
134 | RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id) | |
135 |
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)); |
136 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequestorEmail → KILLED |
recommendationRequest.setRequestorEmail(incoming.getRequestorEmail()); |
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::setDateNeeded → KILLED |
recommendationRequest.setDateNeeded(incoming.getDateNeeded()); |
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::setDone → KILLED |
recommendationRequest.setDone(incoming.getDone()); |
141 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
recommendationRequest.setExplanation(incoming.getExplanation()); |
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 RecommendationRequest | |
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 RecommendationRequest") | |
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 | ||
166 | ||
167 | ||
168 | ||
169 | | |
170 | } | |
Mutations | ||
57 |
1.1 |
|
91 |
1.1 |
|
92 |
1.1 |
|
93 |
1.1 |
|
94 |
1.1 |
|
95 |
1.1 |
|
96 |
1.1 |
|
100 |
1.1 |
|
115 |
1.1 |
|
117 |
1.1 |
|
135 |
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 |