| 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.DriverShiftProjection; | |
| 8 | import edu.ucsb.cs156.gauchoride.repositories.DriverShiftRepository; | |
| 9 | ||
| 10 | import edu.ucsb.cs156.gauchoride.entities.User; | |
| 11 | ||
| 12 | import edu.ucsb.cs156.gauchoride.errors.EntityNotFoundException; | |
| 13 | ||
| 14 | ||
| 15 | import org.springframework.beans.factory.annotation.Autowired; | |
| 16 | import org.springframework.http.ResponseEntity; | |
| 17 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 18 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 19 | import org.springframework.web.bind.annotation.PutMapping; | |
| 20 | import org.springframework.web.bind.annotation.GetMapping; | |
| 21 | import org.springframework.web.bind.annotation.PostMapping; | |
| 22 | import org.springframework.web.bind.annotation.PathVariable; | |
| 23 | import org.springframework.web.bind.annotation.RequestBody; | |
| 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 | ||
| 28 | import io.swagger.annotations.Api; | |
| 29 | import io.swagger.annotations.ApiOperation; | |
| 30 | import io.swagger.annotations.ApiParam; | |
| 31 | ||
| 32 | @Api(description = "Driver shift information") | |
| 33 | @RequestMapping("/api/drivershifts") | |
| 34 | @RestController | |
| 35 | public class DriverShiftController extends ApiController { | |
| 36 | @Autowired | |
| 37 | DriverShiftRepository driverShiftRepository; | |
| 38 | ||
| 39 | @Autowired | |
| 40 | ObjectMapper mapper; | |
| 41 | ||
| 42 | @ApiOperation(value = "Get a list of all driver shifts") | |
| 43 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER') || hasRole('ROLE_RIDER')") | |
| 44 | @GetMapping("/all") | |
| 45 | public ResponseEntity<String> allDriverShifts() | |
| 46 | throws JsonProcessingException { | |
| 47 | Iterable<DriverShiftProjection> driverShifts = driverShiftRepository.getAll(); | |
| 48 | String body = mapper.writeValueAsString(driverShifts); | |
| 49 |
1
1. allDriverShifts : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverShiftController::allDriverShifts → KILLED |
return ResponseEntity.ok().body(body); |
| 50 | } | |
| 51 | ||
| 52 | @ApiOperation(value = "Create a new driver shift") | |
| 53 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER')") | |
| 54 | @PostMapping("/post") | |
| 55 | public DriverShift postDriverShift( | |
| 56 | @ApiParam(name="day", type="String", value="day, one of [Monday, Tuesday,..., Sunday]", example="Monday", required=true) @RequestParam String day, | |
| 57 | @ApiParam(name="startTime", type="String", value="start time, format: HH:MM XM", example="12:00 AM", required=true) @RequestParam String startTime, | |
| 58 | @ApiParam(name="stopTime", type="String", value="stop time, format: HH:MM XM", example="12:00 AM", required=true) @RequestParam String stopTime | |
| 59 | ) | |
| 60 | throws JsonProcessingException { | |
| 61 | ||
| 62 | User user = getCurrentUser().getUser(); | |
| 63 | ||
| 64 | DriverShift driverShift = new DriverShift(); | |
| 65 |
1
1. postDriverShift : removed call to edu/ucsb/cs156/gauchoride/entities/DriverShift::setDriver → KILLED |
driverShift.setDriver(user); |
| 66 |
1
1. postDriverShift : removed call to edu/ucsb/cs156/gauchoride/entities/DriverShift::setDay → KILLED |
driverShift.setDay(day); |
| 67 |
1
1. postDriverShift : removed call to edu/ucsb/cs156/gauchoride/entities/DriverShift::setStartTime → KILLED |
driverShift.setStartTime(startTime); |
| 68 |
1
1. postDriverShift : removed call to edu/ucsb/cs156/gauchoride/entities/DriverShift::setStopTime → KILLED |
driverShift.setStopTime(stopTime); |
| 69 | ||
| 70 | DriverShift saved = driverShiftRepository.save(driverShift); | |
| 71 | ||
| 72 |
1
1. postDriverShift : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverShiftController::postDriverShift → KILLED |
return saved; |
| 73 | } | |
| 74 | } | |
Mutations | ||
| 49 |
1.1 |
|
| 65 |
1.1 |
|
| 66 |
1.1 |
|
| 67 |
1.1 |
|
| 68 |
1.1 |
|
| 72 |
1.1 |