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