1 | package edu.ucsb.cs156.gauchoride.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.gauchoride.entities.Ride; | |
4 | import edu.ucsb.cs156.gauchoride.errors.EntityNotFoundException; | |
5 | import edu.ucsb.cs156.gauchoride.repositories.RideRepository; | |
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.security.access.prepost.PreAuthorize; | |
13 | import org.springframework.security.core.authority.SimpleGrantedAuthority; | |
14 | import org.springframework.security.oauth2.jwt.NimbusReactiveJwtDecoder.SecretKeyReactiveJwtDecoderBuilder; | |
15 | import org.springframework.web.bind.annotation.DeleteMapping; | |
16 | import org.springframework.web.bind.annotation.GetMapping; | |
17 | import org.springframework.web.bind.annotation.PostMapping; | |
18 | import org.springframework.web.bind.annotation.PutMapping; | |
19 | import org.springframework.web.bind.annotation.RequestBody; | |
20 | import org.springframework.web.bind.annotation.RequestMapping; | |
21 | import org.springframework.web.bind.annotation.RequestParam; | |
22 | import org.springframework.web.bind.annotation.RestController; | |
23 | ||
24 | import jakarta.validation.Valid; | |
25 | ||
26 | ||
27 | @Tag(name = "Ride Request") | |
28 | @RequestMapping("/api/ride_request") | |
29 | @RestController | |
30 | ||
31 | public class RideController extends ApiController { | |
32 | ||
33 | @Autowired | |
34 | RideRepository rideRepository; | |
35 | ||
36 | @Operation(summary = "List all rides, only user's if not admin/driver") | |
37 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER') || hasRole('ROLE_USER')") | |
38 | @GetMapping("/all") | |
39 | public Iterable<Ride> allRides() { | |
40 | Iterable<Ride> rides; | |
41 | ||
42 |
1
1. allRides : negated conditional → KILLED |
if (getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_ADMIN")) || |
43 |
1
1. allRides : negated conditional → KILLED |
getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_DRIVER"))) { |
44 | rides = rideRepository.findAll(); | |
45 | } else { | |
46 | rides = rideRepository.findAllByRiderId(getCurrentUser().getUser().getId()); | |
47 | } | |
48 | ||
49 |
1
1. allRides : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideController::allRides → KILLED |
return rides; |
50 | } | |
51 | ||
52 | @Operation(summary = "Get a single ride by id, only user's if not admin/driver") | |
53 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER') || hasRole('ROLE_USER')") | |
54 | @GetMapping("") | |
55 | public Ride getById( | |
56 | @Parameter(name="id", description = "long, Id of the Ride to get", | |
57 | required = true) | |
58 | @RequestParam Long id) { | |
59 | Ride ride; | |
60 | | |
61 |
1
1. getById : negated conditional → KILLED |
if (getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_ADMIN")) || |
62 |
1
1. getById : negated conditional → KILLED |
getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_DRIVER"))) { |
63 | ride = rideRepository.findById(id) | |
64 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Ride.class, id));; |
65 | } else { | |
66 | ride = rideRepository.findByIdAndRiderId(id, getCurrentUser().getUser().getId()) | |
67 |
1
1. lambda$getById$1 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideController::lambda$getById$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Ride.class, id)); |
68 | } | |
69 | ||
70 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideController::getById → KILLED |
return ride; |
71 | } | |
72 | ||
73 | @Operation(summary = "Get all rides by shiftId") | |
74 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER')") | |
75 | @GetMapping("/shiftId") | |
76 | public Iterable<Ride> allRidesByShiftId( | |
77 | @Parameter(name="shiftId", description = "long, shiftId of the Ride to get", | |
78 | required = true) | |
79 | @RequestParam Long shiftId) { | |
80 | Iterable<Ride> rides; | |
81 | ||
82 | rides = rideRepository.findAllByShiftId(shiftId); | |
83 | ||
84 |
1
1. allRidesByShiftId : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideController::allRidesByShiftId → KILLED |
return rides; |
85 | } | |
86 | ||
87 | @Operation(summary = "Create a new ride") | |
88 | @PreAuthorize("hasRole('ROLE_USER')") | |
89 | @PostMapping("/post") | |
90 | public Ride postRide( | |
91 | @Parameter(name="day", description="String, Day of the week ride is requested (Monday - Sunday) and allows Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday", | |
92 | example="Tuesday", required = true) | |
93 | @RequestParam String day, | |
94 | ||
95 | @Parameter(name="startTime", description="String, Time the ride starts HH:MM(A/P)M", example="12:30AM", required = true) | |
96 | @RequestParam String startTime, | |
97 | ||
98 | @Parameter(name="endTime", description="String, Time the ride ends HH:MM(A/P)M", example="12:30AM", required = true) | |
99 | @RequestParam String endTime, | |
100 | ||
101 | @Parameter(name="pickupBuilding", description="String, Location the ride starts", example="Phelps Hall", required = true) | |
102 | @RequestParam String pickupBuilding, | |
103 | ||
104 | @Parameter(name="pickupRoom", description="String, Room number the pickupLocation", example="1431", required = true) | |
105 | @RequestParam String pickupRoom, | |
106 | ||
107 | @Parameter(name="dropoffBuilding", description="String, Location the ride ends", example="South Hall", required = true) | |
108 | @RequestParam String dropoffBuilding, | |
109 | ||
110 | @Parameter(name="dropoffRoom", description="String, Room number for the dropoffLocation", example="1431", required = true) | |
111 | @RequestParam String dropoffRoom, | |
112 | ||
113 | @Parameter(name="course", description="String, Course number for the class at the dropoffLocation", example="CMPSC 156", required = true) | |
114 | @RequestParam String course, | |
115 | ||
116 | @Parameter(name="notes", description="String, Extra information", example="We have two people riding", required = true) | |
117 | @RequestParam String notes | |
118 | ) | |
119 | { | |
120 | ||
121 | Ride ride = new Ride(); | |
122 | | |
123 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setRiderId → KILLED |
ride.setRiderId(getCurrentUser().getUser().getId()); |
124 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setStudent → KILLED |
ride.setStudent(getCurrentUser().getUser().getFullName()); |
125 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setDay → KILLED |
ride.setDay(day); |
126 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setStartTime → KILLED |
ride.setStartTime(startTime); |
127 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setEndTime → KILLED |
ride.setEndTime(endTime); |
128 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setPickupBuilding → KILLED |
ride.setPickupBuilding(pickupBuilding); |
129 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setPickupRoom → KILLED |
ride.setPickupRoom(pickupRoom); |
130 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setDropoffBuilding → KILLED |
ride.setDropoffBuilding(dropoffBuilding); |
131 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setDropoffRoom → KILLED |
ride.setDropoffRoom(dropoffRoom); |
132 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setCourse → KILLED |
ride.setCourse(course); |
133 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setNotes → KILLED |
ride.setNotes(notes); |
134 | ||
135 | Ride savedRide = rideRepository.save(ride); | |
136 | ||
137 |
1
1. postRide : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideController::postRide → KILLED |
return savedRide; |
138 | } | |
139 | ||
140 | @Operation(summary = "Delete a ride, only user's if not admin/driver") | |
141 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER') || hasRole('ROLE_USER')") | |
142 | @DeleteMapping("") | |
143 | public Object deleteRide( | |
144 | @Parameter(name="id", description="long, Id of the Ride to be deleted", | |
145 | required = true) | |
146 | @RequestParam Long id) { | |
147 | ||
148 | Ride ride; | |
149 | ||
150 |
1
1. deleteRide : negated conditional → KILLED |
if (getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_ADMIN")) || |
151 |
1
1. deleteRide : negated conditional → KILLED |
getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_DRIVER"))) { |
152 | ride = rideRepository.findById(id) | |
153 |
1
1. lambda$deleteRide$2 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideController::lambda$deleteRide$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Ride.class, id));; |
154 | } else { | |
155 | ride = rideRepository.findByIdAndRiderId(id, getCurrentUser().getUser().getId()) | |
156 |
1
1. lambda$deleteRide$3 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideController::lambda$deleteRide$3 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Ride.class, id)); |
157 | } | |
158 | ||
159 |
1
1. deleteRide : removed call to edu/ucsb/cs156/gauchoride/repositories/RideRepository::delete → KILLED |
rideRepository.delete(ride); |
160 |
1
1. deleteRide : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideController::deleteRide → KILLED |
return genericMessage("Ride with id %s deleted".formatted(id)); |
161 | } | |
162 | ||
163 | ||
164 | @Operation(summary = "Update a single ride, only user's if not admin/driver") | |
165 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER') || hasRole('ROLE_USER')") | |
166 | @PutMapping("") | |
167 | public Ride updateRide( | |
168 | @Parameter(name="id", description="long, Id of the Ride to be edited", | |
169 | required = true) | |
170 | @RequestParam Long id, | |
171 | @RequestBody @Valid Ride incoming) { | |
172 | ||
173 | Ride ride; | |
174 | ||
175 |
1
1. updateRide : negated conditional → KILLED |
if (getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_ADMIN")) || |
176 |
1
1. updateRide : negated conditional → KILLED |
getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_DRIVER"))) { |
177 | ride = rideRepository.findById(id) | |
178 |
1
1. lambda$updateRide$4 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideController::lambda$updateRide$4 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Ride.class, id));; |
179 | } else { | |
180 | ride = rideRepository.findByIdAndRiderId(id, getCurrentUser().getUser().getId()) | |
181 |
1
1. lambda$updateRide$5 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideController::lambda$updateRide$5 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Ride.class, id)); |
182 | } | |
183 | ||
184 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setDay → KILLED |
ride.setDay(incoming.getDay()); |
185 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setStartTime → KILLED |
ride.setStartTime(incoming.getStartTime()); |
186 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setEndTime → KILLED |
ride.setEndTime(incoming.getEndTime()); |
187 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setPickupBuilding → KILLED |
ride.setPickupBuilding(incoming.getPickupBuilding()); |
188 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setPickupRoom → KILLED |
ride.setPickupRoom(incoming.getPickupRoom()); |
189 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setDropoffBuilding → KILLED |
ride.setDropoffBuilding(incoming.getDropoffBuilding()); |
190 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setDropoffRoom → KILLED |
ride.setDropoffRoom(incoming.getDropoffRoom()); |
191 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setCourse → KILLED |
ride.setCourse(incoming.getCourse()); |
192 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setNotes → KILLED |
ride.setNotes(incoming.getNotes()); |
193 | ||
194 | rideRepository.save(ride); | |
195 | ||
196 |
1
1. updateRide : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideController::updateRide → KILLED |
return ride; |
197 | } | |
198 | ||
199 | @Operation(summary = "Admins can assign a driver to a ride") | |
200 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
201 | @PutMapping("/assigndriver") | |
202 | public Ride assigndriverRide( | |
203 | @Parameter(name="id", description="long, Id of the Ride to be edited", | |
204 | required = true) | |
205 | @RequestParam Long id, | |
206 | @RequestBody @Valid Ride incoming) { | |
207 | ||
208 | Ride ride; | |
209 | ||
210 | ride = rideRepository.findById(id) | |
211 |
1
1. lambda$assigndriverRide$6 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideController::lambda$assigndriverRide$6 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Ride.class, id)); |
212 | ||
213 |
1
1. assigndriverRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setShiftId → KILLED |
ride.setShiftId(incoming.getShiftId()); |
214 |
1
1. assigndriverRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setStatus → KILLED |
ride.setStatus("Assigned"); |
215 | ||
216 | rideRepository.save(ride); | |
217 | ||
218 |
1
1. assigndriverRide : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideController::assigndriverRide → KILLED |
return ride; |
219 | } | |
220 | } | |
Mutations | ||
42 |
1.1 |
|
43 |
1.1 |
|
49 |
1.1 |
|
61 |
1.1 |
|
62 |
1.1 |
|
64 |
1.1 |
|
67 |
1.1 |
|
70 |
1.1 |
|
84 |
1.1 |
|
123 |
1.1 |
|
124 |
1.1 |
|
125 |
1.1 |
|
126 |
1.1 |
|
127 |
1.1 |
|
128 |
1.1 |
|
129 |
1.1 |
|
130 |
1.1 |
|
131 |
1.1 |
|
132 |
1.1 |
|
133 |
1.1 |
|
137 |
1.1 |
|
150 |
1.1 |
|
151 |
1.1 |
|
153 |
1.1 |
|
156 |
1.1 |
|
159 |
1.1 |
|
160 |
1.1 |
|
175 |
1.1 |
|
176 |
1.1 |
|
178 |
1.1 |
|
181 |
1.1 |
|
184 |
1.1 |
|
185 |
1.1 |
|
186 |
1.1 |
|
187 |
1.1 |
|
188 |
1.1 |
|
189 |
1.1 |
|
190 |
1.1 |
|
191 |
1.1 |
|
192 |
1.1 |
|
196 |
1.1 |
|
211 |
1.1 |
|
213 |
1.1 |
|
214 |
1.1 |
|
218 |
1.1 |