| 1 | package edu.ucsb.cs156.gauchoride.controllers; | |
| 2 | ||
| 3 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 4 | import com.fasterxml.jackson.databind.ObjectMapper; | |
| 5 | ||
| 6 | import edu.ucsb.cs156.gauchoride.entities.RideRequest; | |
| 7 | import edu.ucsb.cs156.gauchoride.repositories.RideRequestRepository; | |
| 8 | ||
| 9 | import edu.ucsb.cs156.gauchoride.errors.EntityNotFoundException; | |
| 10 | ||
| 11 | ||
| 12 | import org.springframework.beans.factory.annotation.Autowired; | |
| 13 | import org.springframework.http.ResponseEntity; | |
| 14 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 15 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 16 | import org.springframework.web.bind.annotation.PutMapping; | |
| 17 | import org.springframework.web.bind.annotation.GetMapping; | |
| 18 | import org.springframework.web.bind.annotation.PostMapping; | |
| 19 | import org.springframework.web.bind.annotation.PathVariable; | |
| 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 io.swagger.annotations.Api; | |
| 26 | import io.swagger.annotations.ApiOperation; | |
| 27 | import io.swagger.annotations.ApiParam; | |
| 28 | ||
| 29 | import javax.validation.Valid; | |
| 30 | ||
| 31 | @Api(description = "Ride request information") | |
| 32 | @RequestMapping("/api/riderequests") | |
| 33 | @RestController | |
| 34 | public class RideRequestController extends ApiController { | |
| 35 | @Autowired | |
| 36 | RideRequestRepository rideRequestRepository; | |
| 37 | ||
| 38 | @Autowired | |
| 39 | ObjectMapper mapper; | |
| 40 | ||
| 41 | @ApiOperation(value = "Get a list of all ride requests") | |
| 42 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER')") | |
| 43 | @GetMapping("/all") | |
| 44 | public ResponseEntity<String> rideRequestsAdmin() | |
| 45 | throws JsonProcessingException { | |
| 46 | Iterable<RideRequest> rideRequests = rideRequestRepository.findAll(); | |
| 47 | String body = mapper.writeValueAsString(rideRequests); | |
| 48 |
1
1. rideRequestsAdmin : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::rideRequestsAdmin → KILLED |
return ResponseEntity.ok().body(body); |
| 49 | } | |
| 50 | ||
| 51 | @ApiOperation(value = "Get a list of all ride requests for current rider") | |
| 52 | @PreAuthorize("hasRole('ROLE_RIDER')") | |
| 53 | @GetMapping("/all/rider") | |
| 54 | public ResponseEntity<String> rideRequestsRider( | |
| 55 | ) | |
| 56 | throws JsonProcessingException { | |
| 57 | ||
| 58 | Long userId = getCurrentUser().getUser().getId(); | |
| 59 | ||
| 60 | Iterable<RideRequest> rideRequests = rideRequestRepository.findAllByRiderId(userId); | |
| 61 | String body = mapper.writeValueAsString(rideRequests); | |
| 62 |
1
1. rideRequestsRider : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::rideRequestsRider → KILLED |
return ResponseEntity.ok().body(body); |
| 63 | } | |
| 64 | ||
| 65 | @ApiOperation(value = "Create a new ride request") | |
| 66 | @PreAuthorize("hasRole('ROLE_RIDER')") | |
| 67 | @PostMapping("/post") | |
| 68 | public RideRequest postRideRequest( | |
| 69 | @ApiParam(name="day", type="String", value="day, one of [Monday, Tuesday,..., Sunday]", example="Monday", required=true) @RequestParam String day, | |
| 70 | @ApiParam(name="course", type="String", value="course to attend", example="CS 156", required=true) @RequestParam String course, | |
| 71 | @ApiParam(name="startTime", type="String", value="start time, format: HH:MM XM", example="12:00 AM", required=true) @RequestParam String startTime, | |
| 72 | @ApiParam(name="stopTime", type="String", value="stop time, format: HH:MM XM", example="12:00 AM", required=true) @RequestParam String stopTime, | |
| 73 | @ApiParam(name="building", type="String", value="destination building", example="Phelps", required=true) @RequestParam String building, | |
| 74 | @ApiParam(name="room", type="String", value="destination room", example="EUCR", required=true) @RequestParam String room, | |
| 75 | @ApiParam(name="pickupLocation", type="String", value="pickup location", example="San Rafael Hall", required=true) @RequestParam String pickupLocation | |
| 76 | ) | |
| 77 | throws JsonProcessingException { | |
| 78 | ||
| 79 | Long userId = getCurrentUser().getUser().getId(); | |
| 80 | ||
| 81 | RideRequest rideRequest = new RideRequest(); | |
| 82 |
1
1. postRideRequest : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setRiderId → KILLED |
rideRequest.setRiderId(userId); |
| 83 |
1
1. postRideRequest : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setDay → KILLED |
rideRequest.setDay(day); |
| 84 |
1
1. postRideRequest : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setCourse → KILLED |
rideRequest.setCourse(course); |
| 85 |
1
1. postRideRequest : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setStartTime → KILLED |
rideRequest.setStartTime(startTime); |
| 86 |
1
1. postRideRequest : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setStopTime → KILLED |
rideRequest.setStopTime(stopTime); |
| 87 |
1
1. postRideRequest : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setBuilding → KILLED |
rideRequest.setBuilding(building); |
| 88 |
1
1. postRideRequest : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setRoom → KILLED |
rideRequest.setRoom(room); |
| 89 |
1
1. postRideRequest : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setPickupLocation → KILLED |
rideRequest.setPickupLocation(pickupLocation); |
| 90 | ||
| 91 | RideRequest saved = rideRequestRepository.save(rideRequest); | |
| 92 | ||
| 93 |
1
1. postRideRequest : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::postRideRequest → KILLED |
return saved; |
| 94 | } | |
| 95 | } | |
Mutations | ||
| 48 |
1.1 |
|
| 62 |
1.1 |
|
| 82 |
1.1 |
|
| 83 |
1.1 |
|
| 84 |
1.1 |
|
| 85 |
1.1 |
|
| 86 |
1.1 |
|
| 87 |
1.1 |
|
| 88 |
1.1 |
|
| 89 |
1.1 |
|
| 93 |
1.1 |