| 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.DriverShift; | |
| 7 | import edu.ucsb.cs156.gauchoride.repositories.DriverShiftRepository; | |
| 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 = "Driver shift information") | |
| 32 | @RequestMapping("/api/drivershifts") | |
| 33 | @RestController | |
| 34 | public class DriverShiftController extends ApiController { | |
| 35 | @Autowired | |
| 36 | DriverShiftRepository driverShiftRepository; | |
| 37 | ||
| 38 | @Autowired | |
| 39 | ObjectMapper mapper; | |
| 40 | ||
| 41 | @ApiOperation(value = "Get a list of all driver shifts") | |
| 42 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER') || hasRole('ROLE_RIDER')") | |
| 43 | @GetMapping("/all") | |
| 44 | public ResponseEntity<String> getDriverShifts() | |
| 45 | throws JsonProcessingException { | |
| 46 | Iterable<DriverShift> driverShifts = driverShiftRepository.findAll(); | |
| 47 | String body = mapper.writeValueAsString(driverShifts); | |
| 48 |
1
1. getDriverShifts : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverShiftController::getDriverShifts → KILLED |
return ResponseEntity.ok().body(body); |
| 49 | } | |
| 50 | ||
| 51 | @ApiOperation(value = "Get list of shifts for driver with id") | |
| 52 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER') || hasRole('ROLE_RIDER')") | |
| 53 | @GetMapping("/all_driver") | |
| 54 | public ResponseEntity<String> getDriverShiftsById( | |
| 55 | @ApiParam(name="driverid", type="Long", value="driverid of the driver", example="123", required=true) @RequestParam Long driverid | |
| 56 | ) | |
| 57 | throws JsonProcessingException { | |
| 58 | ||
| 59 | Iterable<DriverShift> driverShifts = driverShiftRepository.findAllByDriverid(driverid); | |
| 60 | String body = mapper.writeValueAsString(driverShifts); | |
| 61 |
1
1. getDriverShiftsById : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverShiftController::getDriverShiftsById → KILLED |
return ResponseEntity.ok().body(body); |
| 62 | } | |
| 63 | ||
| 64 | @ApiOperation(value = "Create a new shift") | |
| 65 | @PreAuthorize("hasRole('ROLE_DRIVER')") | |
| 66 | @PostMapping("/post") | |
| 67 | public DriverShift postDriverShift( | |
| 68 | @ApiParam(name="userid", type="Long", value="driverid of the driver", example="123", required=true) @RequestParam Long driverid, | |
| 69 | @ApiParam(name="fullName", type="String", value="name of the driver", example="Joe", required=true) @RequestParam String fullName, | |
| 70 | @ApiParam(name="day", type="String", value="day, one of [Monday, Tuesday,..., Sunday]", example="Monday", required=true) @RequestParam String day, | |
| 71 | @ApiParam(name="startTime", type="String", value="start time, format: HH:MM XM", example="12:00 AM", required=true) @RequestParam String startTime, | |
| 72 | @ApiParam(name="stopTime", type="String", value="stop time, format: HH:MM XM", example="12:00 AM", required=true) @RequestParam String stopTime, | |
| 73 | @ApiParam(name="backupDriver", type="String", value="name of backup driver", example="Bob", required=true) @RequestParam String backupDriver | |
| 74 | ) | |
| 75 | throws JsonProcessingException { | |
| 76 | ||
| 77 | DriverShift driverShift = new DriverShift(); | |
| 78 |
1
1. postDriverShift : removed call to edu/ucsb/cs156/gauchoride/entities/DriverShift::setDriverid → KILLED |
driverShift.setDriverid(driverid); |
| 79 |
1
1. postDriverShift : removed call to edu/ucsb/cs156/gauchoride/entities/DriverShift::setFullName → KILLED |
driverShift.setFullName(fullName); |
| 80 |
1
1. postDriverShift : removed call to edu/ucsb/cs156/gauchoride/entities/DriverShift::setDay → KILLED |
driverShift.setDay(day); |
| 81 |
1
1. postDriverShift : removed call to edu/ucsb/cs156/gauchoride/entities/DriverShift::setStartTime → KILLED |
driverShift.setStartTime(startTime); |
| 82 |
1
1. postDriverShift : removed call to edu/ucsb/cs156/gauchoride/entities/DriverShift::setStopTime → KILLED |
driverShift.setStopTime(stopTime); |
| 83 |
1
1. postDriverShift : removed call to edu/ucsb/cs156/gauchoride/entities/DriverShift::setBackupDriver → KILLED |
driverShift.setBackupDriver(backupDriver); |
| 84 | ||
| 85 | DriverShift saved = driverShiftRepository.save(driverShift); | |
| 86 | ||
| 87 |
1
1. postDriverShift : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverShiftController::postDriverShift → KILLED |
return saved; |
| 88 | } | |
| 89 | ||
| 90 | @ApiOperation(value = "Delete a driver shift") | |
| 91 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER')") | |
| 92 | @DeleteMapping("/delete") | |
| 93 | public Object deleteDriverShift( | |
| 94 | @ApiParam("id") @RequestParam Long id) { | |
| 95 | DriverShift driverShift = driverShiftRepository.findById(id) | |
| 96 |
1
1. lambda$deleteDriverShift$0 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverShiftController::lambda$deleteDriverShift$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(DriverShift.class, id)); |
| 97 | ||
| 98 |
1
1. deleteDriverShift : removed call to edu/ucsb/cs156/gauchoride/repositories/DriverShiftRepository::delete → KILLED |
driverShiftRepository.delete(driverShift); |
| 99 | ||
| 100 |
1
1. deleteDriverShift : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverShiftController::deleteDriverShift → KILLED |
return genericMessage("Driver shift with id %s deleted".formatted(id)); |
| 101 | } | |
| 102 | ||
| 103 | @ApiOperation(value = "Update a driver shift") | |
| 104 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER')") | |
| 105 | @PutMapping("/put") | |
| 106 | public DriverShift updateDriverShift( | |
| 107 | @ApiParam("id") @RequestParam Long id, | |
| 108 | @RequestBody @Valid DriverShift incoming) { | |
| 109 | ||
| 110 | DriverShift driverShift = driverShiftRepository.findById(id) | |
| 111 |
1
1. lambda$updateDriverShift$1 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverShiftController::lambda$updateDriverShift$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(DriverShift.class, id)); |
| 112 | ||
| 113 |
1
1. updateDriverShift : removed call to edu/ucsb/cs156/gauchoride/entities/DriverShift::setFullName → KILLED |
driverShift.setFullName(incoming.getFullName()); |
| 114 |
1
1. updateDriverShift : removed call to edu/ucsb/cs156/gauchoride/entities/DriverShift::setDay → KILLED |
driverShift.setDay(incoming.getDay()); |
| 115 |
1
1. updateDriverShift : removed call to edu/ucsb/cs156/gauchoride/entities/DriverShift::setStartTime → KILLED |
driverShift.setStartTime(incoming.getStartTime()); |
| 116 |
1
1. updateDriverShift : removed call to edu/ucsb/cs156/gauchoride/entities/DriverShift::setStopTime → KILLED |
driverShift.setStopTime(incoming.getStopTime()); |
| 117 |
1
1. updateDriverShift : removed call to edu/ucsb/cs156/gauchoride/entities/DriverShift::setBackupDriver → KILLED |
driverShift.setBackupDriver(incoming.getBackupDriver()); |
| 118 | ||
| 119 | driverShiftRepository.save(driverShift); | |
| 120 | ||
| 121 |
1
1. updateDriverShift : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverShiftController::updateDriverShift → KILLED |
return driverShift; |
| 122 | } | |
| 123 | } | |
Mutations | ||
| 48 |
1.1 |
|
| 61 |
1.1 |
|
| 78 |
1.1 |
|
| 79 |
1.1 |
|
| 80 |
1.1 |
|
| 81 |
1.1 |
|
| 82 |
1.1 |
|
| 83 |
1.1 |
|
| 87 |
1.1 |
|
| 96 |
1.1 |
|
| 98 |
1.1 |
|
| 100 |
1.1 |
|
| 111 |
1.1 |
|
| 113 |
1.1 |
|
| 114 |
1.1 |
|
| 115 |
1.1 |
|
| 116 |
1.1 |
|
| 117 |
1.1 |
|
| 121 |
1.1 |