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 | /** | |
32 | * This is a REST controller for RecommendationRequests | |
33 | */ | |
34 | @Tag(name = "RecommendationRequest") | |
35 | @RequestMapping("/api/recommendationrequests") | |
36 | @RestController | |
37 | @Slf4j | |
38 | ||
39 | public class RecommendationRequestController extends ApiController { | |
40 | ||
41 | @Autowired | |
42 | ||
43 | /** | |
44 | * List all recommendationRequests | |
45 | * | |
46 | * @return an iterable of recommendationRequest | |
47 | */ | |
48 | RecommendationRequestRepository recommendationRequestRepository; | |
49 | ||
50 | @Operation(summary= "List all recommendationRequests") | |
51 | @PreAuthorize("hasRole('ROLE_USER')") | |
52 | @GetMapping("/all") | |
53 | public Iterable<RecommendationRequest> allRecommendationRequests() { | |
54 | Iterable<RecommendationRequest> requests = recommendationRequestRepository.findAll(); | |
55 |
1
1. allRecommendationRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/RecommendationRequestController::allRecommendationRequests → KILLED |
return requests; |
56 | } | |
57 | ||
58 | /** | |
59 | * Get a single recommendationRequest by id | |
60 | * | |
61 | * @param id the id of the recommendationRequest | |
62 | * @return a RecommendationRequest | |
63 | */ | |
64 | @Operation(summary= "Get a single date") | |
65 | @PreAuthorize("hasRole('ROLE_USER')") | |
66 | @GetMapping("") | |
67 | public RecommendationRequest getById( | |
68 | @Parameter(name="id") @RequestParam Long id) { | |
69 | RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id) | |
70 |
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)); |
71 | ||
72 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::getById → KILLED |
return recommendationRequest; |
73 | } | |
74 | ||
75 | /** | |
76 | * Create a new recommendationRequest | |
77 | * | |
78 | * @param requesterEmail email of the requester | |
79 | * @param professorEmail email of the professor | |
80 | * @param explanation explanation | |
81 | * @param dateRequested date requested | |
82 | * @param dateNeeded date needed | |
83 | * @param done completed or no | |
84 | * @return the saved recommendationRequest | |
85 | */ | |
86 | @Operation(summary= "Create a new recommendationRequest") | |
87 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
88 | @PostMapping("/post") | |
89 | public RecommendationRequest postRecommendationRequest( | |
90 | @Parameter(name="requesterEmail") @RequestParam String requesterEmail, | |
91 | @Parameter(name="professorEmail") @RequestParam String professorEmail, | |
92 | @Parameter(name="explanation") @RequestParam String explanation, | |
93 | @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, | |
94 | @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, | |
95 | @Parameter(name="done") @RequestParam boolean done) | |
96 | | |
97 | throws JsonProcessingException { | |
98 | ||
99 | RecommendationRequest recommendationRequest = RecommendationRequest.builder() | |
100 | .requesterEmail(requesterEmail) | |
101 | .professorEmail(professorEmail) | |
102 | .explanation(explanation) | |
103 | .dateRequested(dateRequested) | |
104 | .dateNeeded(dateNeeded) | |
105 | .done(done) | |
106 | .build(); | |
107 | | |
108 | RecommendationRequest savedRecommendationRequest = recommendationRequestRepository.save(recommendationRequest); | |
109 | ||
110 |
1
1. postRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::postRecommendationRequest → KILLED |
return savedRecommendationRequest; |
111 | } | |
112 | ||
113 | /** | |
114 | * Delete a RecommendationRequest | |
115 | * | |
116 | * @param id the id of the request to delete | |
117 | * @return a message indicating the request was deleted | |
118 | */ | |
119 | @Operation(summary= "Delete a RecommendationRequest") | |
120 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
121 | @DeleteMapping("") | |
122 | public Object deleteRecommendationRequest( | |
123 | @Parameter(name="id") @RequestParam Long id) { | |
124 | RecommendationRequest request = recommendationRequestRepository.findById(id) | |
125 |
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)); |
126 | ||
127 |
1
1. deleteRecommendationRequest : removed call to edu/ucsb/cs156/example/repositories/RecommendationRequestRepository::delete → KILLED |
recommendationRequestRepository.delete(request); |
128 |
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)); |
129 | } | |
130 | ||
131 | /** | |
132 | * Update a single date | |
133 | * | |
134 | * @param id id of the request to update | |
135 | * @param incoming the request date | |
136 | * @return the updated request object | |
137 | */ | |
138 | ||
139 | @Operation(summary= "Update a single request") | |
140 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
141 | @PutMapping("") | |
142 | public RecommendationRequest updateRecommendationRequest( | |
143 | @Parameter(name="id") @RequestParam Long id, | |
144 | @RequestBody @Valid RecommendationRequest incoming) { | |
145 | ||
146 | RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id) | |
147 |
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)); |
148 | ||
149 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
recommendationRequest.setRequesterEmail(incoming.getRequesterEmail()); |
150 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
recommendationRequest.setProfessorEmail(incoming.getProfessorEmail()); |
151 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
recommendationRequest.setExplanation(incoming.getExplanation()); |
152 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
recommendationRequest.setDateRequested(incoming.getDateRequested()); |
153 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
recommendationRequest.setDateNeeded(incoming.getDateNeeded()); |
154 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
recommendationRequest.setDone(incoming.getDone()); |
155 | ||
156 | recommendationRequestRepository.save(recommendationRequest); | |
157 | ||
158 |
1
1. updateRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::updateRecommendationRequest → KILLED |
return recommendationRequest; |
159 | } | |
160 | } | |
161 | ||
162 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
163 | // See: https://www.baeldung.com/spring-date-parameter | |
Mutations | ||
55 |
1.1 |
|
70 |
1.1 |
|
72 |
1.1 |
|
110 |
1.1 |
|
125 |
1.1 |
|
127 |
1.1 |
|
128 |
1.1 |
|
147 |
1.1 |
|
149 |
1.1 |
|
150 |
1.1 |
|
151 |
1.1 |
|
152 |
1.1 |
|
153 |
1.1 |
|
154 |
1.1 |
|
158 |
1.1 |