| 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="pickupBuilding", description="String, Location the ride starts", example="Phelps Hall", required = true) | |
| 88 | @RequestParam String pickupBuilding, | |
| 89 | ||
| 90 | @Parameter(name="pickupRoom", description="String, Room number the pickupLocation", example="1431", required = true) | |
| 91 | @RequestParam String pickupRoom, | |
| 92 | ||
| 93 | @Parameter(name="dropoffBuilding", description="String, Location the ride ends", example="South Hall", required = true) | |
| 94 | @RequestParam String dropoffBuilding, | |
| 95 | ||
| 96 | @Parameter(name="dropoffRoom", description="String, Room number for the dropoffLocation", example="1431", required = true) | |
| 97 | @RequestParam String dropoffRoom, | |
| 98 | ||
| 99 | @Parameter(name="course", description="String, Course number for the class at the dropoffLocation", example="CMPSC 156", required = true) | |
| 100 | @RequestParam String course, | |
| 101 | ||
| 102 | @Parameter(name="notes", description="String, Extra information", example="We have two people riding", required = true) | |
| 103 | @RequestParam String notes | |
| 104 | ) | |
| 105 | { | |
| 106 | ||
| 107 | Ride ride = new Ride(); | |
| 108 | | |
| 109 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setRiderId → KILLED |
ride.setRiderId(getCurrentUser().getUser().getId()); |
| 110 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setStudent → KILLED |
ride.setStudent(getCurrentUser().getUser().getFullName()); |
| 111 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setDay → KILLED |
ride.setDay(day); |
| 112 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setStartTime → KILLED |
ride.setStartTime(startTime); |
| 113 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setEndTime → KILLED |
ride.setEndTime(endTime); |
| 114 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setPickupBuilding → KILLED |
ride.setPickupBuilding(pickupBuilding); |
| 115 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setPickupRoom → KILLED |
ride.setPickupRoom(pickupRoom); |
| 116 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setDropoffBuilding → KILLED |
ride.setDropoffBuilding(dropoffBuilding); |
| 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::setNotes → KILLED |
ride.setNotes(notes); |
| 120 | ||
| 121 | Ride savedRide = rideRepository.save(ride); | |
| 122 | ||
| 123 |
1
1. postRide : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideController::postRide → KILLED |
return savedRide; |
| 124 | } | |
| 125 | ||
| 126 | @Operation(summary = "Delete a ride, only user's if not admin/driver") | |
| 127 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER') || hasRole('ROLE_USER')") | |
| 128 | @DeleteMapping("") | |
| 129 | public Object deleteRide( | |
| 130 | @Parameter(name="id", description="long, Id of the Ride to be deleted", | |
| 131 | required = true) | |
| 132 | @RequestParam Long id) { | |
| 133 | ||
| 134 | Ride ride; | |
| 135 | ||
| 136 |
1
1. deleteRide : negated conditional → KILLED |
if (getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_ADMIN")) || |
| 137 |
1
1. deleteRide : negated conditional → KILLED |
getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_DRIVER"))) { |
| 138 | ride = rideRepository.findById(id) | |
| 139 |
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));; |
| 140 | } else { | |
| 141 | ride = rideRepository.findByIdAndRiderId(id, getCurrentUser().getUser().getId()) | |
| 142 |
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)); |
| 143 | } | |
| 144 | ||
| 145 |
1
1. deleteRide : removed call to edu/ucsb/cs156/gauchoride/repositories/RideRepository::delete → KILLED |
rideRepository.delete(ride); |
| 146 |
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)); |
| 147 | } | |
| 148 | ||
| 149 | ||
| 150 | @Operation(summary = "Update a single ride, only user's if not admin/driver") | |
| 151 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER') || hasRole('ROLE_USER')") | |
| 152 | @PutMapping("") | |
| 153 | public Ride updateRide( | |
| 154 | @Parameter(name="id", description="long, Id of the Ride to be edited", | |
| 155 | required = true) | |
| 156 | @RequestParam Long id, | |
| 157 | @RequestBody @Valid Ride incoming) { | |
| 158 | ||
| 159 | Ride ride; | |
| 160 | ||
| 161 |
1
1. updateRide : negated conditional → KILLED |
if (getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_ADMIN")) || |
| 162 |
1
1. updateRide : negated conditional → KILLED |
getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_DRIVER"))) { |
| 163 | ride = rideRepository.findById(id) | |
| 164 |
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));; |
| 165 | } else { | |
| 166 | ride = rideRepository.findByIdAndRiderId(id, getCurrentUser().getUser().getId()) | |
| 167 |
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)); |
| 168 | } | |
| 169 | ||
| 170 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setDay → KILLED |
ride.setDay(incoming.getDay()); |
| 171 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setStartTime → KILLED |
ride.setStartTime(incoming.getStartTime()); |
| 172 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setEndTime → KILLED |
ride.setEndTime(incoming.getEndTime()); |
| 173 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setPickupBuilding → KILLED |
ride.setPickupBuilding(incoming.getPickupBuilding()); |
| 174 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setPickupRoom → KILLED |
ride.setPickupRoom(incoming.getPickupRoom()); |
| 175 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setDropoffBuilding → KILLED |
ride.setDropoffBuilding(incoming.getDropoffBuilding()); |
| 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::setNotes → KILLED |
ride.setNotes(incoming.getNotes()); |
| 179 | ||
| 180 | rideRepository.save(ride); | |
| 181 | ||
| 182 |
1
1. updateRide : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideController::updateRide → KILLED |
return ride; |
| 183 | } | |
| 184 | } | |
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 |
|
| 109 |
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 |
|
| 123 |
1.1 |
|
| 136 |
1.1 |
|
| 137 |
1.1 |
|
| 139 |
1.1 |
|
| 142 |
1.1 |
|
| 145 |
1.1 |
|
| 146 |
1.1 |
|
| 161 |
1.1 |
|
| 162 |
1.1 |
|
| 164 |
1.1 |
|
| 167 |
1.1 |
|
| 170 |
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 |
|
| 182 |
1.1 |