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.DriverAvailability; | |
7 | import edu.ucsb.cs156.gauchoride.entities.Ride; | |
8 | import edu.ucsb.cs156.gauchoride.repositories.DriverAvailabilityRepository; | |
9 | import edu.ucsb.cs156.gauchoride.repositories.UserRepository; | |
10 | import edu.ucsb.cs156.gauchoride.errors.EntityNotFoundException; | |
11 | import edu.ucsb.cs156.gauchoride.models.CurrentUser; | |
12 | ||
13 | import java.sql.Driver; | |
14 | import java.time.LocalTime; | |
15 | ||
16 | import org.springframework.beans.factory.annotation.Autowired; | |
17 | import org.springframework.http.ResponseEntity; | |
18 | import org.springframework.security.access.prepost.PreAuthorize; | |
19 | import org.springframework.security.core.authority.SimpleGrantedAuthority; | |
20 | import org.springframework.web.bind.annotation.DeleteMapping; | |
21 | import org.springframework.web.bind.annotation.GetMapping; | |
22 | import org.springframework.web.bind.annotation.PostMapping; | |
23 | import org.springframework.web.bind.annotation.PathVariable; | |
24 | import org.springframework.web.bind.annotation.RequestMapping; | |
25 | import org.springframework.web.bind.annotation.RequestParam; | |
26 | import org.springframework.web.bind.annotation.RestController; | |
27 | import org.springframework.web.bind.annotation.PutMapping; | |
28 | import org.springframework.web.bind.annotation.RequestBody; | |
29 | ||
30 | import javax.validation.Valid; | |
31 | ||
32 | import io.swagger.v3.oas.annotations.tags.Tag; | |
33 | import io.swagger.v3.oas.annotations.Operation; | |
34 | import io.swagger.v3.oas.annotations.Parameter; | |
35 | ||
36 | ||
37 | @Tag(name = "DriverAvailability Information") | |
38 | @RequestMapping("/api/driverAvailability") | |
39 | @RestController | |
40 | public class DriverAvailabilityController extends ApiController { | |
41 | @Autowired | |
42 | DriverAvailabilityRepository driverAvailabilityRepository; | |
43 | ||
44 | @Autowired | |
45 | ObjectMapper mapper; | |
46 | ||
47 | @Operation(summary = "Create a new driver availability for the table") | |
48 | @PreAuthorize("hasAnyRole('ADMIN', 'DRIVER')") | |
49 | @PostMapping("/new") | |
50 | public DriverAvailability postDriverAvailability( | |
51 | @Parameter(name="day") @RequestParam String day, | |
52 | @Parameter(name="startTime") @RequestParam String startTime, | |
53 | @Parameter(name="endTime") @RequestParam String endTime, | |
54 | @Parameter(name="notes") @RequestParam String notes | |
55 | ) | |
56 | { | |
57 | ||
58 | DriverAvailability driverAvailability = new DriverAvailability(); | |
59 | ||
60 |
1
1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setDriverId → KILLED |
driverAvailability.setDriverId(getCurrentUser().getUser().getId()); |
61 |
1
1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setDay → KILLED |
driverAvailability.setDay(day); |
62 |
1
1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setStartTime → KILLED |
driverAvailability.setStartTime(startTime); |
63 |
1
1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setEndTime → KILLED |
driverAvailability.setEndTime(endTime); |
64 |
1
1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setNotes → KILLED |
driverAvailability.setNotes(notes); |
65 | ||
66 | DriverAvailability savedDriverAvailability = driverAvailabilityRepository.save(driverAvailability); | |
67 | ||
68 |
1
1. postDriverAvailability : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::postDriverAvailability → KILLED |
return savedDriverAvailability; |
69 | } | |
70 | ||
71 | @Operation(summary= "Delete Driver Availability") | |
72 | @PreAuthorize("hasAnyRole('ADMIN', 'DRIVER')") | |
73 | @DeleteMapping("") | |
74 | public Object deletemenuitem( | |
75 | @Parameter(name="id") @RequestParam Long id) | |
76 | { | |
77 | | |
78 | DriverAvailability drivav; | |
79 |
1
1. deletemenuitem : negated conditional → KILLED |
if (getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_ADMIN"))) { |
80 | drivav = driverAvailabilityRepository.findById(id) | |
81 |
1
1. lambda$deletemenuitem$0 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::lambda$deletemenuitem$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(DriverAvailability.class, id)); |
82 | } else { | |
83 | drivav = driverAvailabilityRepository.findByIdAndDriverId(id, getCurrentUser().getUser().getId()) | |
84 |
1
1. lambda$deletemenuitem$1 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::lambda$deletemenuitem$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(DriverAvailability.class, id)); |
85 | } | |
86 | | |
87 |
1
1. deletemenuitem : removed call to edu/ucsb/cs156/gauchoride/repositories/DriverAvailabilityRepository::delete → KILLED |
driverAvailabilityRepository.delete(drivav); |
88 |
1
1. deletemenuitem : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::deletemenuitem → KILLED |
return genericMessage("Driver Availability with id %s deleted".formatted(id)); |
89 | } | |
90 | ||
91 | ||
92 | @Operation(summary= "Update Driver Availability") | |
93 | @PreAuthorize("hasAnyRole('ADMIN', 'DRIVER')") | |
94 | @PutMapping("") | |
95 | public DriverAvailability updatemenuitem( | |
96 | @Parameter(name="id") @RequestParam Long id, | |
97 | @RequestBody @Valid DriverAvailability incoming) { | |
98 | | |
99 | DriverAvailability drivav; | |
100 |
1
1. updatemenuitem : negated conditional → KILLED |
if (getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_ADMIN"))) { |
101 | drivav = driverAvailabilityRepository.findById(id) | |
102 |
1
1. lambda$updatemenuitem$2 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::lambda$updatemenuitem$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(DriverAvailability.class, id)); |
103 | } else { | |
104 | drivav = driverAvailabilityRepository.findByIdAndDriverId(id, getCurrentUser().getUser().getId()) | |
105 |
1
1. lambda$updatemenuitem$3 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::lambda$updatemenuitem$3 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(DriverAvailability.class, id)); |
106 | } | |
107 | | |
108 |
1
1. updatemenuitem : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setDriverId → KILLED |
drivav.setDriverId(incoming.getDriverId()); |
109 |
1
1. updatemenuitem : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setDay → KILLED |
drivav.setDay(incoming.getDay()); |
110 |
1
1. updatemenuitem : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setStartTime → KILLED |
drivav.setStartTime(incoming.getStartTime()); |
111 |
1
1. updatemenuitem : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setEndTime → KILLED |
drivav.setEndTime(incoming.getEndTime()); |
112 |
1
1. updatemenuitem : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setNotes → KILLED |
drivav.setNotes(incoming.getNotes()); |
113 | | |
114 | driverAvailabilityRepository.save(drivav); | |
115 | | |
116 |
1
1. updatemenuitem : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::updatemenuitem → KILLED |
return drivav; |
117 | } | |
118 | ||
119 | ||
120 | @Operation(summary= "List all Driver Availability") | |
121 | @PreAuthorize("hasAnyRole('ADMIN', 'DRIVER')") | |
122 | @GetMapping("/all") | |
123 | public Iterable<DriverAvailability> allmenuitems() { | |
124 | Iterable<DriverAvailability> driveravail; | |
125 | ||
126 |
1
1. allmenuitems : negated conditional → KILLED |
if (getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_ADMIN"))) { |
127 | driveravail = driverAvailabilityRepository.findAll(); | |
128 | } else { | |
129 | driveravail = driverAvailabilityRepository.findAllByDriverId(getCurrentUser().getUser().getId()); | |
130 | } | |
131 | ||
132 |
1
1. allmenuitems : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::allmenuitems → KILLED |
return driveravail; |
133 | } | |
134 | ||
135 | ||
136 | @Operation(summary= "Get Driver Availability") | |
137 | @PreAuthorize("hasAnyRole('ADMIN', 'DRIVER')") | |
138 | @GetMapping("") | |
139 | public DriverAvailability getById( | |
140 | @Parameter(name="id") @RequestParam Long id) { | |
141 | DriverAvailability drivav = driverAvailabilityRepository.findById(id) | |
142 |
1
1. lambda$getById$4 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::lambda$getById$4 → KILLED |
.orElseThrow(() -> new EntityNotFoundException( DriverAvailability.class, id)); |
143 | ||
144 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::getById → KILLED |
return drivav; |
145 | } | |
146 | ||
147 | @Operation(summary = "Get a list of all driver availabilities") | |
148 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
149 | @GetMapping("/admin/all") | |
150 | public ResponseEntity<String> allDriverAvailabilities() | |
151 | throws JsonProcessingException { | |
152 | Iterable<DriverAvailability> driverAvailabilities = driverAvailabilityRepository.findAll(); | |
153 | String body = mapper.writeValueAsString(driverAvailabilities); | |
154 |
1
1. allDriverAvailabilities : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::allDriverAvailabilities → KILLED |
return ResponseEntity.ok().body(body); |
155 | } | |
156 | ||
157 | @Operation(summary = "Get driver availability by id") | |
158 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
159 | @GetMapping("/admin") | |
160 | public DriverAvailability driverAvailabilityByID( | |
161 | @Parameter(name = "id", description = "Long, id number of driver availability to get", example = "1", required = true) @RequestParam Long id) | |
162 | throws JsonProcessingException { | |
163 | DriverAvailability driverAvailability = driverAvailabilityRepository.findById(id) | |
164 |
1
1. lambda$driverAvailabilityByID$5 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::lambda$driverAvailabilityByID$5 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(DriverAvailability.class, id)); |
165 |
1
1. driverAvailabilityByID : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::driverAvailabilityByID → KILLED |
return driverAvailability; |
166 | } | |
167 | } | |
Mutations | ||
60 |
1.1 |
|
61 |
1.1 |
|
62 |
1.1 |
|
63 |
1.1 |
|
64 |
1.1 |
|
68 |
1.1 |
|
79 |
1.1 |
|
81 |
1.1 |
|
84 |
1.1 |
|
87 |
1.1 |
|
88 |
1.1 |
|
100 |
1.1 |
|
102 |
1.1 |
|
105 |
1.1 |
|
108 |
1.1 |
|
109 |
1.1 |
|
110 |
1.1 |
|
111 |
1.1 |
|
112 |
1.1 |
|
116 |
1.1 |
|
126 |
1.1 |
|
132 |
1.1 |
|
142 |
1.1 |
|
144 |
1.1 |
|
154 |
1.1 |
|
164 |
1.1 |
|
165 |
1.1 |