| 1 | package edu.ucsb.cs156.gauchoride.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.gauchoride.repositories.UserRepository; | |
| 4 | import edu.ucsb.cs156.gauchoride.entities.Ride; | |
| 5 | import edu.ucsb.cs156.gauchoride.entities.User; | |
| 6 | import edu.ucsb.cs156.gauchoride.errors.EntityNotFoundException; | |
| 7 | import edu.ucsb.cs156.gauchoride.errors.IllegalRequestException; | |
| 8 | import edu.ucsb.cs156.gauchoride.repositories.RideRepository; | |
| 9 | import io.swagger.annotations.Api; | |
| 10 | import io.swagger.annotations.ApiOperation; | |
| 11 | import io.swagger.annotations.ApiParam; | |
| 12 | import lombok.extern.slf4j.Slf4j; | |
| 13 | ||
| 14 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 15 | ||
| 16 | import org.springframework.beans.factory.annotation.Autowired; | |
| 17 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 18 | import org.springframework.web.bind.annotation.GetMapping; | |
| 19 | import org.springframework.web.bind.annotation.PostMapping; | |
| 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 | @Api(description = "Ride") | |
| 29 | @RequestMapping("/api/rides") | |
| 30 | @RestController | |
| 31 | @Slf4j | |
| 32 | public class RideController extends ApiController { | |
| 33 | | |
| 34 | @Autowired | |
| 35 | RideRepository rideRepository; | |
| 36 | ||
| 37 | @Autowired | |
| 38 | UserRepository userRepository; | |
| 39 | ||
| 40 | @ApiOperation(value = "Create a new ride request") | |
| 41 | @PreAuthorize("hasRole('ROLE_RIDER')") | |
| 42 | @PostMapping("/post") | |
| 43 | public Ride postRides( | |
| 44 | @RequestBody @Valid Ride ride | |
| 45 | ) | |
| 46 | throws JsonProcessingException | |
| 47 | { | |
| 48 | User currentUser = getCurrentUser().getUser(); | |
| 49 |
1
1. postRides : removed call to edu/ucsb/cs156/gauchoride/entities/Ride::setRider → KILLED |
ride.setRider(currentUser); |
| 50 | User driver = ride.getDriver(); | |
| 51 |
1
1. postRides : negated conditional → KILLED |
if(!(driver.getDriver())){ |
| 52 | throw new IllegalRequestException(); | |
| 53 | } | |
| 54 | Ride savedRide = rideRepository.save(ride); | |
| 55 |
1
1. postRides : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideController::postRides → KILLED |
return savedRide; |
| 56 | } | |
| 57 | ||
| 58 | @ApiOperation(value = "Get a ride request by its id") | |
| 59 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 60 | @GetMapping("") | |
| 61 | public Ride getById( | |
| 62 | @ApiParam(name = "id", type = "Long", value = "id number of the ride request", example = "7", required = true) | |
| 63 | @RequestParam Long id | |
| 64 | ) | |
| 65 | { | |
| 66 | Ride ride = rideRepository.findById(id) | |
| 67 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Ride.class, id)); |
| 68 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideController::getById → KILLED |
return ride; |
| 69 | } | |
| 70 | } | |
Mutations | ||
| 49 |
1.1 |
|
| 51 |
1.1 |
|
| 55 |
1.1 |
|
| 67 |
1.1 |
|
| 68 |
1.1 |