| 1 | package edu.ucsb.cs156.gauchoride.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.gauchoride.entities.IndividualRides; | |
| 4 | import edu.ucsb.cs156.gauchoride.errors.EntityNotFoundException; | |
| 5 | import edu.ucsb.cs156.gauchoride.repositories.IndividualRidesRepository; | |
| 6 | import io.swagger.annotations.Api; | |
| 7 | import io.swagger.annotations.ApiOperation; | |
| 8 | import io.swagger.annotations.ApiParam; | |
| 9 | import lombok.extern.slf4j.Slf4j; | |
| 10 | ||
| 11 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 12 | ||
| 13 | import org.springframework.beans.factory.annotation.Autowired; | |
| 14 | import org.springframework.format.annotation.DateTimeFormat; | |
| 15 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 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 | import java.util.ArrayList; | |
| 28 | import java.util.Arrays; | |
| 29 | import java.util.List; | |
| 30 | import java.time.LocalDate; | |
| 31 | import java.time.LocalDateTime; | |
| 32 | ||
| 33 | @Api(description = "IndividualRides") | |
| 34 | @RequestMapping("/api/individualRides") | |
| 35 | @RestController | |
| 36 | @Slf4j | |
| 37 | public class IndividualRidesController extends ApiController { | |
| 38 | | |
| 39 | @Autowired | |
| 40 | IndividualRidesRepository individualRidesRepository; | |
| 41 | | |
| 42 | @ApiOperation(value = "List all individualRides") | |
| 43 | @PreAuthorize("hasRole('ROLE_DRIVER') || hasRole('ROLE_ADMIN') || hasRole('ROLE_RIDER')") | |
| 44 | @GetMapping("/all") | |
| 45 | public Iterable<IndividualRides> allIndividualRides() { | |
| 46 | Iterable<IndividualRides> individualRides = individualRidesRepository.findAll(); | |
| 47 |
1
1. allIndividualRides : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/IndividualRidesController::allIndividualRides → KILLED |
return individualRides; |
| 48 | } | |
| 49 | ||
| 50 | @ApiOperation(value = "List all individualRides with driverId") | |
| 51 | @PreAuthorize("hasRole('ROLE_DRIVER') || hasRole('ROLE_ADMIN') || hasRole('ROLE_RIDER')") | |
| 52 | @GetMapping("/allWithDriverId") | |
| 53 | public Iterable<IndividualRides> allIndividualRidesWithDriverId( | |
| 54 | @ApiParam("driverId") @RequestParam Long id) { | |
| 55 | ||
| 56 | Iterable<IndividualRides> individualRides = individualRidesRepository.findAll(); | |
| 57 | List<IndividualRides> filteredList = new ArrayList<>(); | |
| 58 | ||
| 59 | for(IndividualRides ride : individualRides){ | |
| 60 |
1
1. allIndividualRidesWithDriverId : negated conditional → KILLED |
if(ride.getDriverId() == id) |
| 61 | filteredList.add(ride); | |
| 62 | } | |
| 63 | ||
| 64 |
1
1. allIndividualRidesWithDriverId : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/IndividualRidesController::allIndividualRidesWithDriverId → KILLED |
return (Iterable<IndividualRides>)filteredList; |
| 65 | } | |
| 66 | ||
| 67 | @ApiOperation(value = "List all individualRides with riderId") | |
| 68 | @PreAuthorize("hasRole('ROLE_DRIVER') || hasRole('ROLE_ADMIN') || hasRole('ROLE_RIDER')") | |
| 69 | @GetMapping("/allWithRiderId") | |
| 70 | public Iterable<IndividualRides> allIndividualRidesWithRiderId( | |
| 71 | @ApiParam("riderId") @RequestParam Long id) { | |
| 72 | ||
| 73 | Iterable<IndividualRides> individualRides = individualRidesRepository.findAll(); | |
| 74 | List<IndividualRides> filteredList = new ArrayList<>(); | |
| 75 | ||
| 76 | for(IndividualRides ride : individualRides){ | |
| 77 |
1
1. allIndividualRidesWithRiderId : negated conditional → KILLED |
if(ride.getRiderId() == id) |
| 78 | filteredList.add(ride); | |
| 79 | } | |
| 80 | ||
| 81 |
1
1. allIndividualRidesWithRiderId : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/IndividualRidesController::allIndividualRidesWithRiderId → KILLED |
return (Iterable<IndividualRides>)filteredList; |
| 82 | } | |
| 83 | ||
| 84 | @ApiOperation(value = "Get a single ride") | |
| 85 | @PreAuthorize("hasRole('ROLE_DRIVER') || hasRole('ROLE_ADMIN') || hasRole('ROLE_RIDER')") | |
| 86 | @GetMapping("") | |
| 87 | public IndividualRides getById( | |
| 88 | @ApiParam("id") @RequestParam Long id) { | |
| 89 | IndividualRides individualRide = individualRidesRepository.findById(id) | |
| 90 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/IndividualRidesController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(IndividualRides.class, id)); |
| 91 | ||
| 92 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/IndividualRidesController::getById → KILLED |
return individualRide; |
| 93 | } | |
| 94 | ||
| 95 | @ApiOperation(value = "Delete a ride") | |
| 96 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 97 | @DeleteMapping("") | |
| 98 | public Object deleteRide( | |
| 99 | @ApiParam("id") @RequestParam Long id) { | |
| 100 | IndividualRides individualRide = individualRidesRepository.findById(id) | |
| 101 |
1
1. lambda$deleteRide$1 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/IndividualRidesController::lambda$deleteRide$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(IndividualRides.class, id)); |
| 102 | ||
| 103 |
1
1. deleteRide : removed call to edu/ucsb/cs156/gauchoride/repositories/IndividualRidesRepository::delete → KILLED |
individualRidesRepository.delete(individualRide); |
| 104 |
1
1. deleteRide : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/IndividualRidesController::deleteRide → KILLED |
return genericMessage("Ride with id %s deleted".formatted(id)); |
| 105 | } | |
| 106 | ||
| 107 | @ApiOperation(value = "Update a single ride") | |
| 108 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 109 | @PutMapping("") | |
| 110 | public IndividualRides updateIndividualRide( | |
| 111 | @ApiParam("id") @RequestParam Long id, | |
| 112 | @RequestBody @Valid IndividualRides incoming) { | |
| 113 | ||
| 114 | IndividualRides individualRide = individualRidesRepository.findById(id) | |
| 115 |
1
1. lambda$updateIndividualRide$2 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/IndividualRidesController::lambda$updateIndividualRide$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(IndividualRides.class, id)); |
| 116 | ||
| 117 |
1
1. updateIndividualRide : removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setDriverId → KILLED |
individualRide.setDriverId(incoming.getDriverId()); |
| 118 |
1
1. updateIndividualRide : removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setRiderId → KILLED |
individualRide.setRiderId(incoming.getRiderId()); |
| 119 |
1
1. updateIndividualRide : removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setStartTime → KILLED |
individualRide.setStartTime(incoming.getStartTime()); |
| 120 |
1
1. updateIndividualRide : removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setEndTime → KILLED |
individualRide.setEndTime(incoming.getEndTime()); |
| 121 |
1
1. updateIndividualRide : removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setPickupLocation → KILLED |
individualRide.setPickupLocation(incoming.getPickupLocation()); |
| 122 |
1
1. updateIndividualRide : removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setDropoffLocation → KILLED |
individualRide.setDropoffLocation(incoming.getDropoffLocation()); |
| 123 | individualRidesRepository.save(individualRide); | |
| 124 | ||
| 125 |
1
1. updateIndividualRide : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/IndividualRidesController::updateIndividualRide → KILLED |
return individualRide; |
| 126 | } | |
| 127 | ||
| 128 | @ApiOperation(value = "Create a new individualRide") | |
| 129 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 130 | @PostMapping("/post") | |
| 131 | public IndividualRides postIndividualRide( | |
| 132 | @ApiParam("driverId") @RequestParam Long driverId, | |
| 133 | @ApiParam("riderId") @RequestParam Long riderId, | |
| 134 | @ApiParam("startTime") @RequestParam String startTimeString, | |
| 135 | @ApiParam("endTime") @RequestParam String endTimeString, | |
| 136 | @ApiParam("pickupLocation") @RequestParam String pickupLocation, | |
| 137 | @ApiParam("dropoffLocation") @RequestParam String dropoffLocation | |
| 138 | ) | |
| 139 | { | |
| 140 | LocalDateTime startTime = LocalDateTime.parse(startTimeString); | |
| 141 | LocalDateTime endTime = LocalDateTime.parse(endTimeString); | |
| 142 | ||
| 143 | IndividualRides individualRide = new IndividualRides(); | |
| 144 |
1
1. postIndividualRide : removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setDriverId → KILLED |
individualRide.setDriverId(driverId); |
| 145 |
1
1. postIndividualRide : removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setRiderId → KILLED |
individualRide.setRiderId(riderId); |
| 146 |
1
1. postIndividualRide : removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setStartTime → KILLED |
individualRide.setStartTime(startTime); |
| 147 |
1
1. postIndividualRide : removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setEndTime → KILLED |
individualRide.setEndTime(endTime); |
| 148 |
1
1. postIndividualRide : removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setPickupLocation → KILLED |
individualRide.setPickupLocation(pickupLocation); |
| 149 |
1
1. postIndividualRide : removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setDropoffLocation → KILLED |
individualRide.setDropoffLocation(dropoffLocation); |
| 150 | ||
| 151 | IndividualRides savedRide = individualRidesRepository.save(individualRide); | |
| 152 |
1
1. postIndividualRide : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/IndividualRidesController::postIndividualRide → KILLED |
return savedRide; |
| 153 | } | |
| 154 | } | |
| 155 | ||
Mutations | ||
| 47 |
1.1 |
|
| 60 |
1.1 |
|
| 64 |
1.1 |
|
| 77 |
1.1 |
|
| 81 |
1.1 |
|
| 90 |
1.1 |
|
| 92 |
1.1 |
|
| 101 |
1.1 |
|
| 103 |
1.1 |
|
| 104 |
1.1 |
|
| 115 |
1.1 |
|
| 117 |
1.1 |
|
| 118 |
1.1 |
|
| 119 |
1.1 |
|
| 120 |
1.1 |
|
| 121 |
1.1 |
|
| 122 |
1.1 |
|
| 125 |
1.1 |
|
| 144 |
1.1 |
|
| 145 |
1.1 |
|
| 146 |
1.1 |
|
| 147 |
1.1 |
|
| 148 |
1.1 |
|
| 149 |
1.1 |
|
| 152 |
1.1 |