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 | import org.springframework.security.access.AccessDeniedException; | |
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 = "Delete a ride request (admin)") | |
42 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
43 | @DeleteMapping("/delete") | |
44 | public Object deleteRideRequest_Admin( | |
45 | @ApiParam("id") @RequestParam Long id) { | |
46 | RideRequest rideRequest = rideRequestRepository.findById(id) | |
47 |
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)); |
48 | ||
49 |
1
1. deleteRideRequest_Admin : removed call to edu/ucsb/cs156/gauchoride/repositories/RideRequestRepository::delete → KILLED |
rideRequestRepository.delete(rideRequest); |
50 | ||
51 |
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)); |
52 | } | |
53 | ||
54 | @ApiOperation(value = "Delete a ride request (rider)") | |
55 | @PreAuthorize("hasRole('ROLE_RIDER')") | |
56 | @DeleteMapping("/delete/rider") | |
57 | public Object deleteRideRequest_Rider( | |
58 | @ApiParam("id") @RequestParam Long id) { | |
59 | RideRequest rideRequest = rideRequestRepository.findById(id) | |
60 |
1
1. lambda$deleteRideRequest_Rider$1 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::lambda$deleteRideRequest_Rider$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RideRequest.class, id)); |
61 | ||
62 | Long userId = getCurrentUser().getUser().getId(); | |
63 |
1
1. deleteRideRequest_Rider : negated conditional → KILLED |
if(userId == rideRequest.getRiderId()){ |
64 |
1
1. deleteRideRequest_Rider : removed call to edu/ucsb/cs156/gauchoride/repositories/RideRequestRepository::delete → KILLED |
rideRequestRepository.delete(rideRequest); |
65 |
1
1. deleteRideRequest_Rider : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::deleteRideRequest_Rider → KILLED |
return genericMessage("Ride request with id %s deleted".formatted(id)); |
66 | }else{ | |
67 | throw new AccessDeniedException("403 returned"); | |
68 | } | |
69 | } | |
70 | ||
71 | @ApiOperation(value = "Update a ride request (admin)") | |
72 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
73 | @PutMapping("/put") | |
74 | public RideRequest updateRideRequest_Admin( | |
75 | @ApiParam("id") @RequestParam Long id, | |
76 | @RequestBody @Valid RideRequest incoming) { | |
77 | ||
78 | RideRequest rideRequest = rideRequestRepository.findById(id) | |
79 |
1
1. lambda$updateRideRequest_Admin$2 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::lambda$updateRideRequest_Admin$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RideRequest.class, id)); |
80 | ||
81 |
1
1. updateRideRequest_Admin : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setDay → KILLED |
rideRequest.setDay(incoming.getDay()); |
82 |
1
1. updateRideRequest_Admin : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setCourse → KILLED |
rideRequest.setCourse(incoming.getCourse()); |
83 |
1
1. updateRideRequest_Admin : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setStartTime → KILLED |
rideRequest.setStartTime(incoming.getStartTime()); |
84 |
1
1. updateRideRequest_Admin : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setStopTime → KILLED |
rideRequest.setStopTime(incoming.getStopTime()); |
85 |
1
1. updateRideRequest_Admin : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setBuilding → KILLED |
rideRequest.setBuilding(incoming.getBuilding()); |
86 |
1
1. updateRideRequest_Admin : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setRoom → KILLED |
rideRequest.setRoom(incoming.getRoom()); |
87 |
1
1. updateRideRequest_Admin : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setPickupLocation → KILLED |
rideRequest.setPickupLocation(incoming.getPickupLocation()); |
88 | ||
89 | rideRequestRepository.save(rideRequest); | |
90 | ||
91 |
1
1. updateRideRequest_Admin : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::updateRideRequest_Admin → KILLED |
return rideRequest; |
92 | } | |
93 | ||
94 | @ApiOperation(value = "Update a ride request (rider)") | |
95 | @PreAuthorize("hasRole('ROLE_RIDER')") | |
96 | @PutMapping("/put/rider") | |
97 | public RideRequest updateRideRequest_Rider( | |
98 | @ApiParam("id") @RequestParam Long id, | |
99 | @RequestBody @Valid RideRequest incoming) { | |
100 | ||
101 | Long userId = getCurrentUser().getUser().getId(); | |
102 | ||
103 | RideRequest rideRequest = rideRequestRepository.findById(id) | |
104 |
1
1. lambda$updateRideRequest_Rider$3 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::lambda$updateRideRequest_Rider$3 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RideRequest.class, id)); |
105 | ||
106 |
1
1. updateRideRequest_Rider : negated conditional → KILLED |
if(userId == rideRequest.getRiderId()){ |
107 |
1
1. updateRideRequest_Rider : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setDay → KILLED |
rideRequest.setDay(incoming.getDay()); |
108 |
1
1. updateRideRequest_Rider : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setCourse → KILLED |
rideRequest.setCourse(incoming.getCourse()); |
109 |
1
1. updateRideRequest_Rider : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setStartTime → KILLED |
rideRequest.setStartTime(incoming.getStartTime()); |
110 |
1
1. updateRideRequest_Rider : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setStopTime → KILLED |
rideRequest.setStopTime(incoming.getStopTime()); |
111 |
1
1. updateRideRequest_Rider : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setBuilding → KILLED |
rideRequest.setBuilding(incoming.getBuilding()); |
112 |
1
1. updateRideRequest_Rider : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setRoom → KILLED |
rideRequest.setRoom(incoming.getRoom()); |
113 |
1
1. updateRideRequest_Rider : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setPickupLocation → KILLED |
rideRequest.setPickupLocation(incoming.getPickupLocation()); |
114 | ||
115 | rideRequestRepository.save(rideRequest); | |
116 | ||
117 |
1
1. updateRideRequest_Rider : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::updateRideRequest_Rider → KILLED |
return rideRequest; |
118 | }else{ | |
119 | throw new AccessDeniedException("403 returned"); | |
120 | } | |
121 | } | |
122 | } | |
Mutations | ||
47 |
1.1 |
|
49 |
1.1 |
|
51 |
1.1 |
|
60 |
1.1 |
|
63 |
1.1 |
|
64 |
1.1 |
|
65 |
1.1 |
|
79 |
1.1 |
|
81 |
1.1 |
|
82 |
1.1 |
|
83 |
1.1 |
|
84 |
1.1 |
|
85 |
1.1 |
|
86 |
1.1 |
|
87 |
1.1 |
|
91 |
1.1 |
|
104 |
1.1 |
|
106 |
1.1 |
|
107 |
1.1 |
|
108 |
1.1 |
|
109 |
1.1 |
|
110 |
1.1 |
|
111 |
1.1 |
|
112 |
1.1 |
|
113 |
1.1 |
|
117 |
1.1 |