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