1 | package edu.ucsb.cs156.gauchoride.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.gauchoride.entities.RiderApplication; | |
4 | import edu.ucsb.cs156.gauchoride.errors.EntityNotFoundException; | |
5 | import edu.ucsb.cs156.gauchoride.repositories.RiderApplicationRepository; | |
6 | ||
7 | import io.swagger.v3.oas.annotations.tags.Tag; | |
8 | import io.swagger.v3.oas.annotations.Operation; | |
9 | import io.swagger.v3.oas.annotations.Parameter; | |
10 | ||
11 | import org.springframework.beans.factory.annotation.Autowired; | |
12 | import org.springframework.http.ResponseEntity; | |
13 | import org.springframework.security.access.prepost.PreAuthorize; | |
14 | import org.springframework.security.core.authority.SimpleGrantedAuthority; | |
15 | import org.springframework.security.oauth2.jwt.NimbusReactiveJwtDecoder.SecretKeyReactiveJwtDecoderBuilder; | |
16 | import org.springframework.web.bind.annotation.DeleteMapping; | |
17 | import org.springframework.web.bind.annotation.GetMapping; | |
18 | import org.springframework.web.bind.annotation.PostMapping; | |
19 | import org.springframework.web.bind.annotation.PutMapping; | |
20 | import org.springframework.web.bind.annotation.RequestBody; | |
21 | import org.springframework.web.bind.annotation.RequestMapping; | |
22 | import org.springframework.web.bind.annotation.RequestParam; | |
23 | import org.springframework.web.bind.annotation.RestController; | |
24 | ||
25 | import jakarta.validation.Valid; | |
26 | ||
27 | import java.sql.Date; | |
28 | import java.time.LocalDate; | |
29 | import java.util.ArrayList; | |
30 | import java.util.List; | |
31 | ||
32 | ||
33 | @Tag(name = "Rider Application") | |
34 | @RequestMapping("/api") | |
35 | @RestController | |
36 | ||
37 | public class RiderApplicationController extends ApiController { | |
38 | ||
39 | @Autowired | |
40 | RiderApplicationRepository riderApplicationRepository; | |
41 | | |
42 | ||
43 | // // Endpoints for ROLE_MEMBER | |
44 | ||
45 | //Endpoints for members | |
46 | @Operation(summary = "Create a new rider application with the current user as the requester") | |
47 | @PreAuthorize("hasRole('ROLE_MEMBER')") | |
48 | @PostMapping("/riderApplication/new") | |
49 | public RiderApplication postRiderApplication( | |
50 | @Parameter(name="perm_number", description="String, Perm number consisting of 7 characters", example = "1234567", required = true) | |
51 | @RequestParam String perm_number, | |
52 | @Parameter(name="description", description="String, Please describe the mobility limitations that cause you to need to use the Gauchoride service. ", example = "My legs are broken", required = true) | |
53 | @RequestParam String description | |
54 | ) | |
55 | { | |
56 | RiderApplication riderApplication = new RiderApplication(); | |
57 | // Get the current date | |
58 | LocalDate localDate = LocalDate.now(); | |
59 | Date currentDate = Date.valueOf(localDate); | |
60 | ||
61 |
1
1. postRiderApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setStatus → KILLED |
riderApplication.setStatus("pending"); |
62 |
1
1. postRiderApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setUserId → KILLED |
riderApplication.setUserId(getCurrentUser().getUser().getId()); |
63 |
1
1. postRiderApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setPerm_number → KILLED |
riderApplication.setPerm_number(perm_number); |
64 |
1
1. postRiderApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setCreated_date → KILLED |
riderApplication.setCreated_date(currentDate); |
65 |
1
1. postRiderApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setUpdated_date → KILLED |
riderApplication.setUpdated_date(currentDate); |
66 |
1
1. postRiderApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setDescription → KILLED |
riderApplication.setDescription(description); |
67 |
1
1. postRiderApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setNotes → KILLED |
riderApplication.setNotes(""); |
68 |
1
1. postRiderApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setEmail → KILLED |
riderApplication.setEmail(getCurrentUser().getUser().getEmail()); |
69 | ||
70 | RiderApplication savedApplication = riderApplicationRepository.save(riderApplication); | |
71 |
1
1. postRiderApplication : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::postRiderApplication → KILLED |
return savedApplication; |
72 | }; | |
73 | ||
74 | @Operation(summary = "Get all rider requests owned by the current user") | |
75 | @PreAuthorize("hasRole('ROLE_MEMBER')") | |
76 | @GetMapping("/rider") | |
77 | public Iterable<RiderApplication> allApplications() | |
78 | { | |
79 | Iterable<RiderApplication> applications; | |
80 | applications = riderApplicationRepository.findAllByUserId(getCurrentUser().getUser().getId()); | |
81 |
1
1. allApplications : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::allApplications → KILLED |
return applications; |
82 | }; | |
83 | ||
84 | @Operation(summary = "Get a single rider application but only if owned by the current user") | |
85 | @PreAuthorize("hasRole('ROLE_MEMBER')") | |
86 | @GetMapping("/riderApplication") | |
87 | public RiderApplication getById( | |
88 | @Parameter(name="id", description = "Long, Id of the RiderApplication to get", | |
89 | required = true) | |
90 | @RequestParam Long id) | |
91 | { | |
92 | RiderApplication application; | |
93 | application = riderApplicationRepository.findByIdAndUserId(id, getCurrentUser().getUser().getId()) | |
94 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RiderApplication.class, id)); |
95 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::getById → KILLED |
return application; |
96 | }; | |
97 | ||
98 | @Operation(summary = "Edit an existing rider application but only if it is owned by the current user and the application is in the correct status") | |
99 | @PreAuthorize("hasRole('ROLE_MEMBER')") | |
100 | @PutMapping("/riderApplication") | |
101 | public ResponseEntity<Object> updateApplication( | |
102 | @Parameter(name="id", description="long, Id of the Application to be edited", | |
103 | required = true) | |
104 | @RequestParam Long id, | |
105 | @RequestBody @Valid RiderApplication incoming) | |
106 | { | |
107 | RiderApplication application; | |
108 | ||
109 | application = riderApplicationRepository.findByIdAndUserId(id, getCurrentUser().getUser().getId()) | |
110 |
1
1. lambda$updateApplication$1 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::lambda$updateApplication$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RiderApplication.class, id)); |
111 | ||
112 |
1
1. updateApplication : negated conditional → KILLED |
if ("pending".equals(application.getStatus())) |
113 | { | |
114 | // Get the current date | |
115 | LocalDate localDate = LocalDate.now(); | |
116 | Date currentDate = Date.valueOf(localDate); | |
117 | ||
118 |
1
1. updateApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setPerm_number → KILLED |
application.setPerm_number(incoming.getPerm_number()); |
119 |
1
1. updateApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setUpdated_date → KILLED |
application.setUpdated_date(currentDate); |
120 |
1
1. updateApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setDescription → KILLED |
application.setDescription(incoming.getDescription()); |
121 |
1
1. updateApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setNotes → KILLED |
application.setNotes(incoming.getNotes()); |
122 |
1
1. updateApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setStatus → KILLED |
application.setStatus(incoming.getStatus()); |
123 | riderApplicationRepository.save(application); | |
124 |
1
1. updateApplication : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::updateApplication → KILLED |
return ResponseEntity.ok(application); |
125 | } | |
126 |
1
1. updateApplication : negated conditional → KILLED |
else if ("accepted".equals(application.getStatus())) |
127 | { | |
128 | // Get the current date | |
129 | LocalDate localDate = LocalDate.now(); | |
130 | Date currentDate = Date.valueOf(localDate); | |
131 | ||
132 |
1
1. updateApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setPerm_number → KILLED |
application.setPerm_number(incoming.getPerm_number()); |
133 |
1
1. updateApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setUpdated_date → KILLED |
application.setUpdated_date(currentDate); |
134 |
1
1. updateApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setDescription → KILLED |
application.setDescription(incoming.getDescription()); |
135 |
1
1. updateApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setNotes → KILLED |
application.setNotes(incoming.getNotes()); |
136 |
1
1. updateApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setStatus → KILLED |
application.setStatus(incoming.getStatus()); |
137 | riderApplicationRepository.save(application); | |
138 |
1
1. updateApplication : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::updateApplication → KILLED |
return ResponseEntity.ok(application); |
139 | } | |
140 | else | |
141 | { | |
142 | String errorMessage = "RiderApplication with \"" + application.getStatus() + "\" status cannot be updated"; | |
143 |
1
1. updateApplication : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::updateApplication → KILLED |
return ResponseEntity.badRequest().body(errorMessage); |
144 | } | |
145 | }; | |
146 | ||
147 | @Operation(summary = "Cancel an existing rider application but only if it is owned by the current user and the application is in the correct status") | |
148 | @PreAuthorize("hasRole('ROLE_MEMBER')") | |
149 | @PutMapping("/riderApplication/cancel") | |
150 | public Object cancelApplication( | |
151 | @Parameter(name="id", description="long, Id of the Application to be edited", | |
152 | required = true) | |
153 | @RequestParam Long id) | |
154 | | |
155 | { | |
156 | RiderApplication application; | |
157 | ||
158 | application = riderApplicationRepository.findByIdAndUserId(id, getCurrentUser().getUser().getId()) | |
159 |
1
1. lambda$cancelApplication$2 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::lambda$cancelApplication$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RiderApplication.class, id)); |
160 | | |
161 |
1
1. cancelApplication : negated conditional → KILLED |
if ("pending".equals(application.getStatus())) |
162 | { | |
163 | // Get the current date | |
164 | LocalDate localDate = LocalDate.now(); | |
165 | Date currentDate = Date.valueOf(localDate); | |
166 | ||
167 |
1
1. cancelApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setStatus → KILLED |
application.setStatus("cancelled"); |
168 |
1
1. cancelApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setUpdated_date → KILLED |
application.setUpdated_date(currentDate); |
169 |
1
1. cancelApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setCancelled_date → KILLED |
application.setCancelled_date(currentDate); |
170 | riderApplicationRepository.save(application); | |
171 | ||
172 |
1
1. cancelApplication : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::cancelApplication → KILLED |
return genericMessage("Application with id %s is cancelled".formatted(id)); |
173 | } | |
174 | else | |
175 | { | |
176 |
1
1. cancelApplication : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::cancelApplication → KILLED |
return genericMessage("Application with \"%s\" status cannot be cancelled".formatted(application.getStatus())); |
177 | } | |
178 | }; | |
179 | ||
180 | ||
181 | // // Endpoints for ROLE_ADMIN | |
182 | ||
183 | @Operation(summary = "Get all rider applications") | |
184 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
185 | @GetMapping("/rider/admin/all") | |
186 | public Iterable<RiderApplication> allApplicationsAdmin() | |
187 | { | |
188 | Iterable<RiderApplication> applications; | |
189 | applications = riderApplicationRepository.findAll(); | |
190 |
1
1. allApplicationsAdmin : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::allApplicationsAdmin → KILLED |
return applications; |
191 | }; | |
192 | ||
193 | @Operation(summary = "Get all pending rider applications") | |
194 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
195 | @GetMapping("/rider/admin/pending") | |
196 | public Iterable<RiderApplication> allPendingApplications() | |
197 | { | |
198 | Iterable<RiderApplication> pendingApplications; | |
199 | pendingApplications = riderApplicationRepository.findAllByStatus("pending"); | |
200 | ||
201 |
1
1. allPendingApplications : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::allPendingApplications → KILLED |
return pendingApplications; |
202 | }; | |
203 | ||
204 | @Operation(summary = "Get a specific rider application") | |
205 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
206 | @GetMapping("/rider/admin") | |
207 | public RiderApplication specificApplication( | |
208 | @Parameter(name="id", description="long, Id of the Application to find", | |
209 | required = true) | |
210 | @RequestParam Long id) | |
211 | { | |
212 | RiderApplication application; | |
213 | application = riderApplicationRepository.findById(id) | |
214 |
1
1. lambda$specificApplication$3 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::lambda$specificApplication$3 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RiderApplication.class, id)); |
215 |
1
1. specificApplication : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::specificApplication → KILLED |
return application; |
216 | }; | |
217 | ||
218 | @Operation(summary = "Update the status/notes field of an application") | |
219 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
220 | @PutMapping("/rider/admin") | |
221 | public RiderApplication updateApplicationAdmin( | |
222 | @Parameter(name="id", description="long, Id of the Application to be updated", | |
223 | required = true) | |
224 | @RequestParam Long id, | |
225 | ||
226 | @Parameter(name="status", description="String, New Status of the Application", | |
227 | required = false) | |
228 | @RequestParam String status, | |
229 | ||
230 | @Parameter(name="notes", description="String, Notes to notify the Applicant", | |
231 | required = false) | |
232 | @RequestParam String notes) | |
233 | { | |
234 | RiderApplication application; | |
235 | application = riderApplicationRepository.findById(id) | |
236 |
1
1. lambda$updateApplicationAdmin$4 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::lambda$updateApplicationAdmin$4 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RiderApplication.class, id)); |
237 | ||
238 |
1
1. updateApplicationAdmin : negated conditional → KILLED |
if (!status.isEmpty()) |
239 | { | |
240 |
1
1. updateApplicationAdmin : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setStatus → KILLED |
application.setStatus(status); |
241 | } | |
242 | ||
243 |
1
1. updateApplicationAdmin : negated conditional → KILLED |
if (!notes.isEmpty()) |
244 | { | |
245 |
1
1. updateApplicationAdmin : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setNotes → KILLED |
application.setNotes(notes); |
246 | } | |
247 | | |
248 | riderApplicationRepository.save(application); | |
249 |
1
1. updateApplicationAdmin : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::updateApplicationAdmin → KILLED |
return application; |
250 | }; | |
251 | ||
252 | } | |
Mutations | ||
61 |
1.1 |
|
62 |
1.1 |
|
63 |
1.1 |
|
64 |
1.1 |
|
65 |
1.1 |
|
66 |
1.1 |
|
67 |
1.1 |
|
68 |
1.1 |
|
71 |
1.1 |
|
81 |
1.1 |
|
94 |
1.1 |
|
95 |
1.1 |
|
110 |
1.1 |
|
112 |
1.1 |
|
118 |
1.1 |
|
119 |
1.1 |
|
120 |
1.1 |
|
121 |
1.1 |
|
122 |
1.1 |
|
124 |
1.1 |
|
126 |
1.1 |
|
132 |
1.1 |
|
133 |
1.1 |
|
134 |
1.1 |
|
135 |
1.1 |
|
136 |
1.1 |
|
138 |
1.1 |
|
143 |
1.1 |
|
159 |
1.1 |
|
161 |
1.1 |
|
167 |
1.1 |
|
168 |
1.1 |
|
169 |
1.1 |
|
172 |
1.1 |
|
176 |
1.1 |
|
190 |
1.1 |
|
201 |
1.1 |
|
214 |
1.1 |
|
215 |
1.1 |
|
236 |
1.1 |
|
238 |
1.1 |
|
240 |
1.1 |
|
243 |
1.1 |
|
245 |
1.1 |
|
249 |
1.1 |