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 (admin, driver, rider)") | |
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 | @ApiParam(name="userid", type="Long", value="userid of the rider", example="123", required=true) @RequestParam Long userid | |
56 | ) | |
57 | throws JsonProcessingException { | |
58 | ||
59 | Iterable<RideRequest> rideRequests = rideRequestRepository.findAllByUserid(userid); | |
60 | String body = mapper.writeValueAsString(rideRequests); | |
61 |
1
1. rideRequestsRider : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::rideRequestsRider → KILLED |
return ResponseEntity.ok().body(body); |
62 | } | |
63 | ||
64 | @ApiOperation(value = "Create a new ride request") | |
65 | @PreAuthorize("hasRole('ROLE_RIDER')") | |
66 | @PostMapping("/post") | |
67 | public RideRequest postRideRequest( | |
68 | @ApiParam(name="userid", type="Long", value="userid of the rider", example="123", required=true) @RequestParam Long userid, | |
69 | @ApiParam(name="day", type="String", value="day, one of [Monday, Tuesday,..., Sunday]", example="Monday", required=true) @RequestParam String day, | |
70 | @ApiParam(name="fullName", type="String", value="name of the rider", example="Joe", required=true) @RequestParam String fullName, | |
71 | @ApiParam(name="course", type="String", value="course to attend", example="CS 156", required=true) @RequestParam String course, | |
72 | @ApiParam(name="startTime", type="String", value="start time, format: HH:MM XM", example="12:00 AM", required=true) @RequestParam String startTime, | |
73 | @ApiParam(name="stopTime", type="String", value="stop time, format: HH:MM XM", example="12:00 AM", required=true) @RequestParam String stopTime, | |
74 | @ApiParam(name="building", type="String", value="destination building", example="Phelps", required=true) @RequestParam String building, | |
75 | @ApiParam(name="room", type="String", value="destination room", example="EUCR, 3525", required=true) @RequestParam String room, | |
76 | @ApiParam(name="pickup", type="String", value="pickup location", example="San Rafael Hall", required=true) @RequestParam String pickup | |
77 | ) | |
78 | throws JsonProcessingException { | |
79 | ||
80 | RideRequest rideRequest = new RideRequest(); | |
81 |
1
1. postRideRequest : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setUserid → KILLED |
rideRequest.setUserid(userid); |
82 |
1
1. postRideRequest : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setDay → KILLED |
rideRequest.setDay(day); |
83 |
1
1. postRideRequest : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setFullName → KILLED |
rideRequest.setFullName(fullName); |
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::setPickup → KILLED |
rideRequest.setPickup(pickup); |
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 | ||
96 | @ApiOperation(value = "Delete a ride request") | |
97 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_RIDER')") | |
98 | @DeleteMapping("/delete") | |
99 | public Object deleteRideRequest_Admin( | |
100 | @ApiParam("id") @RequestParam Long id) { | |
101 | RideRequest rideRequest = rideRequestRepository.findById(id) | |
102 |
1
1. lambda$deleteRideRequest_Admin$0 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::lambda$deleteRideRequest_Admin$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RideRequest.class, id)); |
103 | ||
104 |
1
1. deleteRideRequest_Admin : removed call to edu/ucsb/cs156/gauchoride/repositories/RideRequestRepository::delete → KILLED |
rideRequestRepository.delete(rideRequest); |
105 | ||
106 |
1
1. deleteRideRequest_Admin : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::deleteRideRequest_Admin → KILLED |
return genericMessage("Ride request with id %s deleted".formatted(id)); |
107 | } | |
108 | ||
109 | @ApiOperation(value = "Update a ride request") | |
110 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_RIDER')") | |
111 | @PutMapping("/put") | |
112 | public RideRequest updateRideRequest( | |
113 | @ApiParam("id") @RequestParam Long id, | |
114 | @RequestBody @Valid RideRequest incoming) { | |
115 | ||
116 | RideRequest rideRequest = rideRequestRepository.findById(id) | |
117 |
1
1. lambda$updateRideRequest$1 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::lambda$updateRideRequest$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RideRequest.class, id)); |
118 | ||
119 |
1
1. updateRideRequest : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setDay → KILLED |
rideRequest.setDay(incoming.getDay()); |
120 |
1
1. updateRideRequest : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setFullName → KILLED |
rideRequest.setFullName(incoming.getFullName()); |
121 |
1
1. updateRideRequest : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setCourse → KILLED |
rideRequest.setCourse(incoming.getCourse()); |
122 |
1
1. updateRideRequest : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setStartTime → KILLED |
rideRequest.setStartTime(incoming.getStartTime()); |
123 |
1
1. updateRideRequest : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setStopTime → KILLED |
rideRequest.setStopTime(incoming.getStopTime()); |
124 |
1
1. updateRideRequest : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setBuilding → KILLED |
rideRequest.setBuilding(incoming.getBuilding()); |
125 |
1
1. updateRideRequest : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setRoom → KILLED |
rideRequest.setRoom(incoming.getRoom()); |
126 |
1
1. updateRideRequest : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setPickup → KILLED |
rideRequest.setPickup(incoming.getPickup()); |
127 | ||
128 | rideRequestRepository.save(rideRequest); | |
129 | ||
130 |
1
1. updateRideRequest : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::updateRideRequest → KILLED |
return rideRequest; |
131 | } | |
132 | } | |
Mutations | ||
48 |
1.1 |
|
61 |
1.1 |
|
81 |
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 |
|
102 |
1.1 |
|
104 |
1.1 |
|
106 |
1.1 |
|
117 |
1.1 |
|
119 |
1.1 |
|
120 |
1.1 |
|
121 |
1.1 |
|
122 |
1.1 |
|
123 |
1.1 |
|
124 |
1.1 |
|
125 |
1.1 |
|
126 |
1.1 |
|
130 |
1.1 |