| 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 | import io.swagger.annotations.Api; | |
| 7 | import io.swagger.annotations.ApiOperation; | |
| 8 | import io.swagger.annotations.ApiParam; | |
| 9 | ||
| 10 | import org.springframework.beans.factory.annotation.Autowired; | |
| 11 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 12 | import org.springframework.security.core.authority.SimpleGrantedAuthority; | |
| 13 | import org.springframework.security.oauth2.jwt.NimbusReactiveJwtDecoder.SecretKeyReactiveJwtDecoderBuilder; | |
| 14 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 15 | import org.springframework.web.bind.annotation.GetMapping; | |
| 16 | import org.springframework.web.bind.annotation.PostMapping; | |
| 17 | import org.springframework.web.bind.annotation.PutMapping; | |
| 18 | import org.springframework.web.bind.annotation.RequestBody; | |
| 19 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 20 | import org.springframework.web.bind.annotation.RequestParam; | |
| 21 | import org.springframework.web.bind.annotation.RestController; | |
| 22 | ||
| 23 | import javax.validation.Valid; | |
| 24 | ||
| 25 | ||
| 26 | @Api(description = "Ride Request") | |
| 27 | @RequestMapping("/api/ride_request") | |
| 28 | @RestController | |
| 29 | ||
| 30 | public class RideController extends ApiController { | |
| 31 | ||
| 32 | @Autowired | |
| 33 | RideRepository rideRepository; | |
| 34 | ||
| 35 | @ApiOperation(value = "List all rides, only user's if not admin/driver") | |
| 36 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER') || hasRole('ROLE_USER')") | |
| 37 | @GetMapping("/all") | |
| 38 | public Iterable<Ride> allRides() { | |
| 39 | Iterable<Ride> rides; | |
| 40 | ||
| 41 |
1
1. allRides : negated conditional → KILLED |
if (getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_ADMIN")) || |
| 42 |
1
1. allRides : negated conditional → KILLED |
getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_DRIVER"))) { |
| 43 | rides = rideRepository.findAll(); | |
| 44 | } else { | |
| 45 | rides = rideRepository.findAllByRiderId(getCurrentUser().getUser().getId()); | |
| 46 | } | |
| 47 | ||
| 48 |
1
1. allRides : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideController::allRides → KILLED |
return rides; |
| 49 | } | |
| 50 | ||
| 51 | @ApiOperation(value = "Get a single ride by id, only user's if not admin/driver") | |
| 52 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER') || hasRole('ROLE_USER')") | |
| 53 | @GetMapping("") | |
| 54 | public Ride getById( | |
| 55 | @ApiParam(name="id", type="long", value = "Id of the Ride to get", | |
| 56 | required = true) | |
| 57 | @RequestParam Long id) { | |
| 58 | Ride ride; | |
| 59 | | |
| 60 |
1
1. getById : negated conditional → KILLED |
if (getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_ADMIN")) || |
| 61 |
1
1. getById : negated conditional → KILLED |
getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_DRIVER"))) { |
| 62 | ride = rideRepository.findById(id) | |
| 63 |
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));; |
| 64 | } else { | |
| 65 | ride = rideRepository.findByIdAndRiderId(id, getCurrentUser().getUser().getId()) | |
| 66 |
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)); |
| 67 | } | |
| 68 | ||
| 69 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideController::getById → KILLED |
return ride; |
| 70 | } | |
| 71 | ||
| 72 | @ApiOperation(value = "Create a new ride") | |
| 73 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 74 | @PostMapping("/post") | |
| 75 | public Ride postRide( | |
| 76 | @ApiParam(name="day", type="String", value = "Day of the week ride is requested (Monday - Sunday)", example="Tuesday", | |
| 77 | required = true, allowableValues = "Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday") | |
| 78 | @RequestParam String day, | |
| 79 | ||
| 80 | @ApiParam(name="startTime", type="String", value = "Time the ride starts HH:MM(A/P)M", example="12:30AM", required = true) | |
| 81 | @RequestParam String startTime, | |
| 82 | ||
| 83 | @ApiParam(name="endTime", type="String", value = "Time the ride ends HH:MM(A/P)M", example="12:30AM", required = true) | |
| 84 | @RequestParam String endTime, | |
| 85 | ||
| 86 | @ApiParam(name="pickupLocation", type="String", value = "Location the ride starts", example="Phelps Hall", required = true) | |
| 87 | @RequestParam String pickupLocation, | |
| 88 | ||
| 89 | @ApiParam(name="dropoffLocation", type="String", value = "Location the ride ends", example="South Hall", required = true) | |
| 90 | @RequestParam String dropoffLocation, | |
| 91 | ||
| 92 | @ApiParam(name="room", type="String", value = "Room number for the dropoffLocation", example="1431", required = true) | |
| 93 | @RequestParam String room, | |
| 94 | ||
| 95 | @ApiParam(name="course", type="String", value = "Course number for the class at the dropoffLocation", example="CMPSC 156", required = true) | |
| 96 | @RequestParam String course | |
| 97 | ) | |
| 98 | { | |
| 99 | ||
| 100 | Ride ride = new Ride(); | |
| 101 | | |
| 102 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setRiderId → KILLED |
ride.setRiderId(getCurrentUser().getUser().getId()); |
| 103 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setStudent → KILLED |
ride.setStudent(getCurrentUser().getUser().getFullName()); |
| 104 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setDay → KILLED |
ride.setDay(day); |
| 105 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setStartTime → KILLED |
ride.setStartTime(startTime); |
| 106 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setEndTime → KILLED |
ride.setEndTime(endTime); |
| 107 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setPickupLocation → KILLED |
ride.setPickupLocation(pickupLocation); |
| 108 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setDropoffLocation → KILLED |
ride.setDropoffLocation(dropoffLocation); |
| 109 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setRoom → KILLED |
ride.setRoom(room); |
| 110 |
1
1. postRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setCourse → KILLED |
ride.setCourse(course); |
| 111 | ||
| 112 | Ride savedRide = rideRepository.save(ride); | |
| 113 | ||
| 114 |
1
1. postRide : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideController::postRide → KILLED |
return savedRide; |
| 115 | } | |
| 116 | ||
| 117 | @ApiOperation(value = "Delete a ride, only user's if not admin/driver") | |
| 118 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER') || hasRole('ROLE_USER')") | |
| 119 | @DeleteMapping("") | |
| 120 | public Object deleteRide( | |
| 121 | @ApiParam(name="id", type="long", value = "Id of the Ride to be deleted", | |
| 122 | required = true) | |
| 123 | @RequestParam Long id) { | |
| 124 | ||
| 125 | Ride ride; | |
| 126 | ||
| 127 |
1
1. deleteRide : negated conditional → KILLED |
if (getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_ADMIN")) || |
| 128 |
1
1. deleteRide : negated conditional → KILLED |
getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_DRIVER"))) { |
| 129 | ride = rideRepository.findById(id) | |
| 130 |
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));; |
| 131 | } else { | |
| 132 | ride = rideRepository.findByIdAndRiderId(id, getCurrentUser().getUser().getId()) | |
| 133 |
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)); |
| 134 | } | |
| 135 | ||
| 136 |
1
1. deleteRide : removed call to edu/ucsb/cs156/gauchoride/repositories/RideRepository::delete → KILLED |
rideRepository.delete(ride); |
| 137 |
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)); |
| 138 | } | |
| 139 | ||
| 140 | ||
| 141 | @ApiOperation(value = "Update a single ride, only user's if not admin/driver") | |
| 142 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER') || hasRole('ROLE_USER')") | |
| 143 | @PutMapping("") | |
| 144 | public Ride updateRide( | |
| 145 | @ApiParam(name="id", type="long", value = "Id of the Ride to be edited", | |
| 146 | required = true) | |
| 147 | @RequestParam Long id, | |
| 148 | @RequestBody @Valid Ride incoming) { | |
| 149 | ||
| 150 | Ride ride; | |
| 151 | ||
| 152 |
1
1. updateRide : negated conditional → KILLED |
if (getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_ADMIN")) || |
| 153 |
1
1. updateRide : negated conditional → KILLED |
getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_DRIVER"))) { |
| 154 | ride = rideRepository.findById(id) | |
| 155 |
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));; |
| 156 | } else { | |
| 157 | ride = rideRepository.findByIdAndRiderId(id, getCurrentUser().getUser().getId()) | |
| 158 |
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)); |
| 159 | } | |
| 160 | ||
| 161 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setDay → KILLED |
ride.setDay(incoming.getDay()); |
| 162 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setStartTime → KILLED |
ride.setStartTime(incoming.getStartTime()); |
| 163 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setEndTime → KILLED |
ride.setEndTime(incoming.getEndTime()); |
| 164 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setPickupLocation → KILLED |
ride.setPickupLocation(incoming.getPickupLocation()); |
| 165 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setDropoffLocation → KILLED |
ride.setDropoffLocation(incoming.getDropoffLocation()); |
| 166 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setRoom → KILLED |
ride.setRoom(incoming.getRoom()); |
| 167 |
1
1. updateRide : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setCourse → KILLED |
ride.setCourse(incoming.getCourse()); |
| 168 | ||
| 169 | rideRepository.save(ride); | |
| 170 | ||
| 171 |
1
1. updateRide : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideController::updateRide → KILLED |
return ride; |
| 172 | } | |
| 173 | } | |
Mutations | ||
| 41 |
1.1 |
|
| 42 |
1.1 |
|
| 48 |
1.1 |
|
| 60 |
1.1 |
|
| 61 |
1.1 |
|
| 63 |
1.1 |
|
| 66 |
1.1 |
|
| 69 |
1.1 |
|
| 102 |
1.1 |
|
| 103 |
1.1 |
|
| 104 |
1.1 |
|
| 105 |
1.1 |
|
| 106 |
1.1 |
|
| 107 |
1.1 |
|
| 108 |
1.1 |
|
| 109 |
1.1 |
|
| 110 |
1.1 |
|
| 114 |
1.1 |
|
| 127 |
1.1 |
|
| 128 |
1.1 |
|
| 130 |
1.1 |
|
| 133 |
1.1 |
|
| 136 |
1.1 |
|
| 137 |
1.1 |
|
| 152 |
1.1 |
|
| 153 |
1.1 |
|
| 155 |
1.1 |
|
| 158 |
1.1 |
|
| 161 |
1.1 |
|
| 162 |
1.1 |
|
| 163 |
1.1 |
|
| 164 |
1.1 |
|
| 165 |
1.1 |
|
| 166 |
1.1 |
|
| 167 |
1.1 |
|
| 171 |
1.1 |