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