1 | package edu.ucsb.cs156.gauchoride.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.gauchoride.entities.DriverAvailability; | |
4 | import edu.ucsb.cs156.gauchoride.errors.EntityNotFoundException; | |
5 | import edu.ucsb.cs156.gauchoride.repositories.DriverAvailabilityRepository; | |
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 java.lang.Iterable; | |
12 | import org.springframework.beans.factory.annotation.Autowired; | |
13 | import org.springframework.security.access.prepost.PreAuthorize; | |
14 | import org.springframework.security.core.authority.SimpleGrantedAuthority; | |
15 | import org.springframework.security.oauth2.jwt.NimbusReactiveJwtDecoder.SecretKeyReactiveJwtDecoderBuilder; | |
16 | import org.springframework.web.bind.annotation.DeleteMapping; | |
17 | import org.springframework.web.bind.annotation.GetMapping; | |
18 | import org.springframework.web.bind.annotation.PostMapping; | |
19 | import org.springframework.web.bind.annotation.PutMapping; | |
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 javax.validation.Valid; | |
26 | ||
27 | ||
28 | @Tag(name = "DriverAvailability Request") | |
29 | @RequestMapping("/api/driverAvailability") | |
30 | @RestController | |
31 | public class DriverAvailabilityController extends ApiController { | |
32 | ||
33 | @Autowired | |
34 | DriverAvailabilityRepository driverAvailabilityRepository; | |
35 | ||
36 | @Operation(summary = "List all availabilities if admin") | |
37 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
38 | @GetMapping("admin/all") | |
39 | public Iterable<DriverAvailability> allDriverAvailabilitys() { | |
40 |
1
1. allDriverAvailabilitys : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::allDriverAvailabilitys → KILLED |
return driverAvailabilityRepository.findAll(); |
41 | } | |
42 | ||
43 | @Operation(summary = "Get a single availability by id, if user is an admin") | |
44 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
45 | @GetMapping("admin") | |
46 | public DriverAvailability getByIdAdmin( | |
47 | @Parameter(name="id", description = "long, Id of the DriverAvailability to get", | |
48 | required = true) | |
49 | @RequestParam Long id) { | |
50 | DriverAvailability driverAvailability; | |
51 | driverAvailability = driverAvailabilityRepository.findById(id) | |
52 |
1
1. lambda$getByIdAdmin$0 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::lambda$getByIdAdmin$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(DriverAvailability.class, id));; |
53 |
1
1. getByIdAdmin : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::getByIdAdmin → KILLED |
return driverAvailability; |
54 | } | |
55 | ||
56 | @Operation(summary = "Create a new Driver Availability") | |
57 | @PreAuthorize("hasRole('ROLE_DRIVER')") | |
58 | @PostMapping("/post") | |
59 | public DriverAvailability postDriverAvailability( | |
60 | ||
61 | @Parameter(name="day", description="String, Day of the week the driver is available and allows Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday", | |
62 | example="Tuesday", required = true) | |
63 | @RequestParam String day, | |
64 | ||
65 | @Parameter(name="startTime", description="String, Time the driver starts drivingHH:MM(A/P)M", example="12:30AM", required = true) | |
66 | @RequestParam String startTime, | |
67 | ||
68 | @Parameter(name="endTime", description="String, Time the driver ends driving HH:MM(A/P)M", example="12:30AM", required = true) | |
69 | @RequestParam String endTime, | |
70 | ||
71 | @Parameter(name="notes", description="String, Extra information", example="We have two people riding", required = true) | |
72 | @RequestParam String notes | |
73 | ) | |
74 | { | |
75 | ||
76 | DriverAvailability driverAvailability = new DriverAvailability(); | |
77 | | |
78 |
1
1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setDriverId → KILLED |
driverAvailability.setDriverId(getCurrentUser().getUser().getId()); |
79 |
1
1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setDay → KILLED |
driverAvailability.setDay(day); |
80 |
1
1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setStartTime → KILLED |
driverAvailability.setStartTime(startTime); |
81 |
1
1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setEndTime → KILLED |
driverAvailability.setEndTime(endTime); |
82 |
1
1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setNotes → KILLED |
driverAvailability.setNotes(notes); |
83 | ||
84 | DriverAvailability savedDriverAvailability = driverAvailabilityRepository.save(driverAvailability); | |
85 | ||
86 |
1
1. postDriverAvailability : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::postDriverAvailability → KILLED |
return savedDriverAvailability; |
87 | } | |
88 | ||
89 | @Operation(summary = "Delete an availability if owned by current user") | |
90 | @PreAuthorize("hasRole('ROLE_USER')") | |
91 | @DeleteMapping("") | |
92 | public Object deleteDriverAvailability( | |
93 | @Parameter(name="id", description="long, Id of the DriverAvailability to be deleted", | |
94 | required = true) @RequestParam long id) { | |
95 | ||
96 | DriverAvailability availability; | |
97 | ||
98 | availability = driverAvailabilityRepository.findByIdAndDriverId(id, getCurrentUser().getUser().getId()) | |
99 |
1
1. lambda$deleteDriverAvailability$1 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::lambda$deleteDriverAvailability$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(DriverAvailability.class, id)); |
100 |
1
1. deleteDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/repositories/DriverAvailabilityRepository::delete → KILLED |
driverAvailabilityRepository.delete(availability); |
101 | | |
102 |
1
1. deleteDriverAvailability : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::deleteDriverAvailability → KILLED |
return genericMessage("DriverAvailability with id %s deleted".formatted(id)); |
103 | } | |
104 | @Operation(summary = "List all availabilities of current user") | |
105 | @PreAuthorize("hasRole('ROLE_USER')") | |
106 | @GetMapping("") | |
107 | public Iterable<DriverAvailability> allUserDriverAvailabilities() { | |
108 | Iterable<DriverAvailability> availabilities; | |
109 | availabilities = driverAvailabilityRepository.findAllByDriverId(getCurrentUser().getUser().getId()); | |
110 |
1
1. allUserDriverAvailabilities : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::allUserDriverAvailabilities → KILLED |
return availabilities; |
111 | } | |
112 | ||
113 | @Operation(summary = "Get a single availability by id, if user owns it") | |
114 | @PreAuthorize("hasRole('ROLE_USER')") | |
115 | @GetMapping("/id") | |
116 | public DriverAvailability getById( | |
117 | @Parameter(name="id", description = "long, Id of the DriverAvailability to get", | |
118 | required = true) | |
119 | @RequestParam Long id) { | |
120 | DriverAvailability driverAvailability; | |
121 | driverAvailability = driverAvailabilityRepository.findByIdAndDriverId(id, getCurrentUser().getUser().getId()) | |
122 |
1
1. lambda$getById$2 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::lambda$getById$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(DriverAvailability.class, id));; |
123 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::getById → KILLED |
return driverAvailability; |
124 | } | |
125 | ||
126 | } | |
127 | ||
Mutations | ||
40 |
1.1 |
|
52 |
1.1 |
|
53 |
1.1 |
|
78 |
1.1 |
|
79 |
1.1 |
|
80 |
1.1 |
|
81 |
1.1 |
|
82 |
1.1 |
|
86 |
1.1 |
|
99 |
1.1 |
|
100 |
1.1 |
|
102 |
1.1 |
|
110 |
1.1 |
|
122 |
1.1 |
|
123 |
1.1 |