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 | ||
32 | public class DriverAvailabilityController extends ApiController { | |
33 | ||
34 | @Autowired | |
35 | DriverAvailabilityRepository driverAvailabilityRepository; | |
36 | ||
37 | @Operation(summary = "List all availabilities if admin") | |
38 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
39 | @GetMapping("admin/all") | |
40 | public Iterable<DriverAvailability> allDriverAvailabilitys() { | |
41 |
1
1. allDriverAvailabilitys : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::allDriverAvailabilitys → KILLED |
return driverAvailabilityRepository.findAll(); |
42 | } | |
43 | ||
44 | @Operation(summary = "Get a single availability by id, if user is an admin") | |
45 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
46 | @GetMapping("admin") | |
47 | public DriverAvailability getByIdAdmin( | |
48 | @Parameter(name="id", description = "long, Id of the DriverAvailability to get", | |
49 | required = true) | |
50 | @RequestParam Long id) { | |
51 | DriverAvailability driverAvailability; | |
52 | driverAvailability = driverAvailabilityRepository.findById(id) | |
53 |
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));; |
54 |
1
1. getByIdAdmin : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::getByIdAdmin → KILLED |
return driverAvailability; |
55 | } | |
56 | ||
57 | @Operation(summary = "Create a new Driver Availability") | |
58 | @PreAuthorize("hasRole('ROLE_DRIVER')") | |
59 | @PostMapping("/post") | |
60 | public DriverAvailability postDriverAvailability( | |
61 | ||
62 | @Parameter(name="day", description="String, Day of the week the driver is available and allows Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday", | |
63 | example="Tuesday", required = true) | |
64 | @RequestParam String day, | |
65 | ||
66 | @Parameter(name="startTime", description="String, Time the driver starts drivingHH:MM(A/P)M", example="12:30AM", required = true) | |
67 | @RequestParam String startTime, | |
68 | ||
69 | @Parameter(name="endTime", description="String, Time the driver ends driving HH:MM(A/P)M", example="12:30AM", required = true) | |
70 | @RequestParam String endTime, | |
71 | ||
72 | @Parameter(name="notes", description="String, Extra information", example="We have two people riding", required = true) | |
73 | @RequestParam String notes | |
74 | ) | |
75 | { | |
76 | ||
77 | DriverAvailability driverAvailability = new DriverAvailability(); | |
78 | | |
79 |
1
1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setDriverId → KILLED |
driverAvailability.setDriverId(getCurrentUser().getUser().getId()); |
80 |
1
1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setDay → KILLED |
driverAvailability.setDay(day); |
81 |
1
1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setStartTime → KILLED |
driverAvailability.setStartTime(startTime); |
82 |
1
1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setEndTime → KILLED |
driverAvailability.setEndTime(endTime); |
83 |
1
1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setNotes → KILLED |
driverAvailability.setNotes(notes); |
84 | ||
85 | DriverAvailability savedDriverAvailability = driverAvailabilityRepository.save(driverAvailability); | |
86 | ||
87 |
1
1. postDriverAvailability : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::postDriverAvailability → KILLED |
return savedDriverAvailability; |
88 | } | |
89 | ||
90 | @Operation(summary = "Delete an availability if owned by current user") | |
91 | @PreAuthorize("hasRole('ROLE_USER')") | |
92 | @DeleteMapping("") | |
93 | public Object deleteDriverAvailability( | |
94 | @Parameter(name="id", description="long, Id of the DriverAvailability to be deleted", | |
95 | required = true) @RequestParam long id) { | |
96 | ||
97 | DriverAvailability availability; | |
98 | ||
99 | availability = driverAvailabilityRepository.findByIdAndDriverId(id, getCurrentUser().getUser().getId()) | |
100 |
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)); |
101 |
1
1. deleteDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/repositories/DriverAvailabilityRepository::delete → KILLED |
driverAvailabilityRepository.delete(availability); |
102 | | |
103 |
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)); |
104 | } | |
105 | } | |
106 | ||
Mutations | ||
41 |
1.1 |
|
53 |
1.1 |
|
54 |
1.1 |
|
79 |
1.1 |
|
80 |
1.1 |
|
81 |
1.1 |
|
82 |
1.1 |
|
83 |
1.1 |
|
87 |
1.1 |
|
100 |
1.1 |
|
101 |
1.1 |
|
103 |
1.1 |