| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.example.entities.Restaurant; | |
| 4 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 5 | import edu.ucsb.cs156.example.repositories.RestaurantRepository; | |
| 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 | import org.springframework.beans.factory.annotation.Autowired; | |
| 11 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 12 | import org.springframework.web.bind.annotation.*; | |
| 13 | ||
| 14 | import javax.validation.Valid; | |
| 15 | ||
| 16 | @Api(description = "Restaurants") | |
| 17 | @RequestMapping("/api/restaurants") | |
| 18 | @RestController | |
| 19 | @Slf4j | |
| 20 | public class RestaurantsController extends ApiController { | |
| 21 | ||
| 22 | @Autowired | |
| 23 | RestaurantRepository restaurantRepository; | |
| 24 | ||
| 25 | @ApiOperation(value = "List all restaurants") | |
| 26 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 27 | @GetMapping("/all") | |
| 28 | public Iterable<Restaurant> allRestaurants() { | |
| 29 |
1
1. allRestaurants : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::allRestaurants → KILLED |
return restaurantRepository.findAll(); |
| 30 | } | |
| 31 | ||
| 32 | ||
| 33 | @ApiOperation(value = "Get a single restaurant") | |
| 34 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 35 | @GetMapping("") | |
| 36 | public Restaurant getById( | |
| 37 | @ApiParam("id") @RequestParam Long id | |
| 38 | ) { | |
| 39 | ||
| 40 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::getById → KILLED |
return restaurantRepository.findById(id) |
| 41 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Restaurant.class, id)); |
| 42 | } | |
| 43 | ||
| 44 | @ApiOperation(value = "Create a restaurant") | |
| 45 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 46 | @PostMapping("/post") | |
| 47 | public Restaurant postRestaurant( | |
| 48 | @ApiParam("name") @RequestParam String name, | |
| 49 | @ApiParam("address") @RequestParam String address, | |
| 50 | @ApiParam("description") @RequestParam String description) { | |
| 51 | ||
| 52 | var restaurant = Restaurant.builder() | |
| 53 | .name(name) | |
| 54 | .address(address) | |
| 55 | .description(description) | |
| 56 | .build(); | |
| 57 | ||
| 58 |
1
1. postRestaurant : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::postRestaurant → KILLED |
return restaurantRepository.save(restaurant); |
| 59 | } | |
| 60 | ||
| 61 | @ApiOperation(value = "Delete a restaurant") | |
| 62 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 63 | @DeleteMapping("") | |
| 64 | public Object deleteRestaurant( | |
| 65 | @ApiParam("id") @RequestParam Long id) { | |
| 66 | Restaurant restaurant = restaurantRepository.findById(id) | |
| 67 |
1
1. lambda$deleteRestaurant$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::lambda$deleteRestaurant$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Restaurant.class, id)); |
| 68 | ||
| 69 |
1
1. deleteRestaurant : removed call to edu/ucsb/cs156/example/repositories/RestaurantRepository::delete → KILLED |
restaurantRepository.delete(restaurant); |
| 70 |
1
1. deleteRestaurant : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::deleteRestaurant → KILLED |
return genericMessage("Restaurant with id %s deleted".formatted(id)); |
| 71 | } | |
| 72 | ||
| 73 | @ApiOperation(value = "Update a single restaurant") | |
| 74 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 75 | @PutMapping("") | |
| 76 | public Restaurant updateRestaurant( | |
| 77 | @ApiParam("id") @RequestParam Long id, | |
| 78 | @RequestBody @Valid Restaurant incoming) { | |
| 79 | ||
| 80 | Restaurant restaurant = restaurantRepository.findById(id) | |
| 81 |
1
1. lambda$updateRestaurant$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::lambda$updateRestaurant$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Restaurant.class, id)); |
| 82 | ||
| 83 |
1
1. updateRestaurant : removed call to edu/ucsb/cs156/example/entities/Restaurant::setName → KILLED |
restaurant.setName(incoming.getName()); |
| 84 |
1
1. updateRestaurant : removed call to edu/ucsb/cs156/example/entities/Restaurant::setAddress → KILLED |
restaurant.setAddress(incoming.getAddress()); |
| 85 |
1
1. updateRestaurant : removed call to edu/ucsb/cs156/example/entities/Restaurant::setDescription → KILLED |
restaurant.setDescription(incoming.getDescription()); |
| 86 | ||
| 87 | restaurantRepository.save(restaurant); | |
| 88 | ||
| 89 |
1
1. updateRestaurant : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::updateRestaurant → KILLED |
return restaurant; |
| 90 | } | |
| 91 | } | |
Mutations | ||
| 29 |
1.1 |
|
| 40 |
1.1 |
|
| 41 |
1.1 |
|
| 58 |
1.1 |
|
| 67 |
1.1 |
|
| 69 |
1.1 |
|
| 70 |
1.1 |
|
| 81 |
1.1 |
|
| 83 |
1.1 |
|
| 84 |
1.1 |
|
| 85 |
1.1 |
|
| 89 |
1.1 |