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 javax.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 = "Create a new ride") | |
74 | @PreAuthorize("hasRole('ROLE_USER')") | |
75 | @PostMapping("/post") | |
76 | public Ride postRide( | |
77 | @Parameter(name="day", description="String, Day of the week ride is requested (Monday - Sunday) and allows Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday", | |
78 | example="Tuesday", required = true) | |
79 | @RequestParam String day, | |
80 | ||
81 | @Parameter(name="startTime", description="String, Time the ride starts HH:MM(A/P)M", example="12:30AM", required = true) | |
82 | @RequestParam String startTime, | |
83 | ||
84 | @Parameter(name="endTime", description="String, Time the ride ends HH:MM(A/P)M", example="12:30AM", required = true) | |
85 | @RequestParam String endTime, | |
86 | ||
87 | @Parameter(name="pickupLocation", description="String, Location the ride starts", example="Phelps Hall", required = true) | |
88 | @RequestParam String pickupLocation, | |
89 | ||
90 | @Parameter(name="dropoffLocation", description="String, Location the ride ends", example="South Hall", required = true) | |
91 | @RequestParam String dropoffLocation, | |
92 | ||
93 | @Parameter(name="dropoffRoom", description="String, Room number for the dropoffLocation", example="1431", required = false) | |
94 | @RequestParam String dropoffRoom, | |
95 | ||
96 | @Parameter(name="course", description="String, Course number for the class at the dropoffLocation", example="CMPSC 156", required = true) | |
97 | @RequestParam String course, | |
98 | ||
99 | @Parameter(name="pickupRoom", description="String, Room number for the class at the pickupLocation", example="1940", required = false) | |
100 | @RequestParam String pickupRoom, | |
101 | ||
102 | @Parameter(name="notes", description="String, Notes for additional information", example="Library entrance by the arbor", required = false) | |
103 | @RequestParam String notes | |
104 | ||
105 | ||
106 | ) | |
107 | { | |
108 | ||
109 | Ride ride = new Ride(); | |
110 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setRiderId → KILLED |
ride.setRiderId(getCurrentUser().getUser().getId()); |
111 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setStudent → KILLED |
ride.setStudent(getCurrentUser().getUser().getFullName()); |
112 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setDay → KILLED |
ride.setDay(day); |
113 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setStartTime → KILLED |
ride.setStartTime(startTime); |
114 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setEndTime → KILLED |
ride.setEndTime(endTime); |
115 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setPickupLocation → KILLED |
ride.setPickupLocation(pickupLocation); |
116 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setDropoffLocation → KILLED |
ride.setDropoffLocation(dropoffLocation); |
117 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setDropoffRoom → KILLED |
ride.setDropoffRoom(dropoffRoom); |
118 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setCourse → KILLED |
ride.setCourse(course); |
119 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setPickupRoom → KILLED |
ride.setPickupRoom(pickupRoom); |
120 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setNotes → KILLED |
ride.setNotes(notes); |
121 | ||
122 | Ride savedRide = rideRepository.save(ride); | |
123 | ||
124 |
1
1. postRide : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideController::postRide → KILLED |
return savedRide; |
125 | } | |
126 | ||
127 | @Operation(summary = "Delete a ride, only user's if not admin/driver") | |
128 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER') || hasRole('ROLE_USER')") | |
129 | @DeleteMapping("") | |
130 | public Object deleteRide( | |
131 | @Parameter(name="id", description="long, Id of the Ride to be deleted", | |
132 | required = true) | |
133 | @RequestParam Long id) { | |
134 | ||
135 | Ride ride; | |
136 | ||
137 |
1
1. deleteRide : negated conditional → KILLED |
if (getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_ADMIN")) || |
138 |
1
1. deleteRide : negated conditional → KILLED |
getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_DRIVER"))) { |
139 | ride = rideRepository.findById(id) | |
140 |
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));; |
141 | } else { | |
142 | ride = rideRepository.findByIdAndRiderId(id, getCurrentUser().getUser().getId()) | |
143 |
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)); |
144 | } | |
145 | ||
146 |
1
1. deleteRide : removed call to edu/ucsb/cs156/gauchoride/repositories/RideRepository::delete → KILLED |
rideRepository.delete(ride); |
147 |
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)); |
148 | } | |
149 | ||
150 | ||
151 | @Operation(summary = "Update a single ride, only user's if not admin/driver") | |
152 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER') || hasRole('ROLE_USER')") | |
153 | @PutMapping("") | |
154 | public Ride updateRide( | |
155 | @Parameter(name="id", description="long, Id of the Ride to be edited", | |
156 | required = true) | |
157 | @RequestParam Long id, | |
158 | @RequestBody @Valid Ride incoming) { | |
159 | ||
160 | Ride ride; | |
161 | ||
162 |
1
1. updateRide : negated conditional → KILLED |
if (getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_ADMIN")) || |
163 |
1
1. updateRide : negated conditional → KILLED |
getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_DRIVER"))) { |
164 | ride = rideRepository.findById(id) | |
165 |
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));; |
166 | } else { | |
167 | ride = rideRepository.findByIdAndRiderId(id, getCurrentUser().getUser().getId()) | |
168 |
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)); |
169 | } | |
170 | ||
171 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setDay → KILLED |
ride.setDay(incoming.getDay()); |
172 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setStartTime → KILLED |
ride.setStartTime(incoming.getStartTime()); |
173 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setEndTime → KILLED |
ride.setEndTime(incoming.getEndTime()); |
174 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setPickupLocation → KILLED |
ride.setPickupLocation(incoming.getPickupLocation()); |
175 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setDropoffLocation → KILLED |
ride.setDropoffLocation(incoming.getDropoffLocation()); |
176 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setDropoffRoom → KILLED |
ride.setDropoffRoom(incoming.getDropoffRoom()); |
177 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setCourse → KILLED |
ride.setCourse(incoming.getCourse()); |
178 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setPickupRoom → KILLED |
ride.setPickupRoom(incoming.getPickupRoom()); |
179 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setNotes → KILLED |
ride.setNotes(incoming.getNotes()); |
180 | ||
181 | ||
182 | rideRepository.save(ride); | |
183 | ||
184 |
1
1. updateRide : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideController::updateRide → KILLED |
return ride; |
185 | } | |
186 | } | |
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 |
|
110 |
1.1 |
|
111 |
1.1 |
|
112 |
1.1 |
|
113 |
1.1 |
|
114 |
1.1 |
|
115 |
1.1 |
|
116 |
1.1 |
|
117 |
1.1 |
|
118 |
1.1 |
|
119 |
1.1 |
|
120 |
1.1 |
|
124 |
1.1 |
|
137 |
1.1 |
|
138 |
1.1 |
|
140 |
1.1 |
|
143 |
1.1 |
|
146 |
1.1 |
|
147 |
1.1 |
|
162 |
1.1 |
|
163 |
1.1 |
|
165 |
1.1 |
|
168 |
1.1 |
|
171 |
1.1 |
|
172 |
1.1 |
|
173 |
1.1 |
|
174 |
1.1 |
|
175 |
1.1 |
|
176 |
1.1 |
|
177 |
1.1 |
|
178 |
1.1 |
|
179 |
1.1 |
|
184 |
1.1 |