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