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