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 | ||
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 = "Restaurant") | |
26 | @RequestMapping("/api/restaurant") | |
27 | @RestController | |
28 | @Slf4j | |
29 | public class RestaurantController extends ApiController { | |
30 | ||
31 | @Autowired | |
32 | RestaurantRepository restaurantRepository; | |
33 | ||
34 | @ApiOperation(value = "List all restaurants") | |
35 | @PreAuthorize("hasRole('ROLE_USER')") | |
36 | @GetMapping("/all") | |
37 | public Iterable<Restaurant> allRestaurants() { | |
38 | Iterable<Restaurant> restaurants = restaurantRepository.findAll(); | |
39 |
1
1. allRestaurants : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantController::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 restaurant = restaurantRepository.findById(id) | |
48 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantController::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/RestaurantController::getById → KILLED |
return restaurant; |
51 | } | |
52 | ||
53 | @ApiOperation(value = "Create a new restaurant") | |
54 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
55 | @PostMapping("/post") | |
56 | public Restaurant postRestaurant( | |
57 | @ApiParam("name") @RequestParam String name, | |
58 | @ApiParam("address") @RequestParam String address, | |
59 | @ApiParam("city") @RequestParam String city, | |
60 | @ApiParam("state") @RequestParam String state, | |
61 | @ApiParam("zip") @RequestParam String zip, | |
62 | @ApiParam("description") @RequestParam String description | |
63 | ) | |
64 | { | |
65 | ||
66 | Restaurant restaurant = new Restaurant(); | |
67 |
1
1. postRestaurant : removed call to edu/ucsb/cs156/example/entities/Restaurant::setName → KILLED |
restaurant.setName(name); |
68 |
1
1. postRestaurant : removed call to edu/ucsb/cs156/example/entities/Restaurant::setAddress → KILLED |
restaurant.setAddress(address); |
69 |
1
1. postRestaurant : removed call to edu/ucsb/cs156/example/entities/Restaurant::setCity → KILLED |
restaurant.setCity(city); |
70 |
1
1. postRestaurant : removed call to edu/ucsb/cs156/example/entities/Restaurant::setState → KILLED |
restaurant.setState(state); |
71 |
1
1. postRestaurant : removed call to edu/ucsb/cs156/example/entities/Restaurant::setZip → KILLED |
restaurant.setZip(zip); |
72 |
1
1. postRestaurant : removed call to edu/ucsb/cs156/example/entities/Restaurant::setDescription → KILLED |
restaurant.setDescription(description); |
73 | ||
74 | Restaurant savedRestaurant = restaurantRepository.save(restaurant); | |
75 | ||
76 |
1
1. postRestaurant : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantController::postRestaurant → KILLED |
return savedRestaurant; |
77 | } | |
78 | ||
79 | @ApiOperation(value = "Delete a restaurant") | |
80 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
81 | @DeleteMapping("") | |
82 | public Object deleteRestaurant( | |
83 | @ApiParam("id") @RequestParam Long id) { | |
84 | Restaurant restaurant = restaurantRepository.findById(id) | |
85 |
1
1. lambda$deleteRestaurant$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantController::lambda$deleteRestaurant$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Restaurant.class, id)); |
86 | ||
87 |
1
1. deleteRestaurant : removed call to edu/ucsb/cs156/example/repositories/RestaurantRepository::delete → KILLED |
restaurantRepository.delete(restaurant); |
88 |
1
1. deleteRestaurant : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantController::deleteRestaurant → KILLED |
return genericMessage("Restaurant with id %s deleted".formatted(id)); |
89 | } | |
90 | ||
91 | @ApiOperation(value = "Update a single restaurant") | |
92 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
93 | @PutMapping("") | |
94 | public Restaurant updateRestaurant( | |
95 | @ApiParam("id") @RequestParam Long id, | |
96 | @RequestBody @Valid Restaurant incoming) { | |
97 | ||
98 | Restaurant restaurant = restaurantRepository.findById(id) | |
99 |
1
1. lambda$updateRestaurant$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantController::lambda$updateRestaurant$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Restaurant.class, id)); |
100 | ||
101 |
1
1. updateRestaurant : removed call to edu/ucsb/cs156/example/entities/Restaurant::setName → KILLED |
restaurant.setName(incoming.getName()); |
102 |
1
1. updateRestaurant : removed call to edu/ucsb/cs156/example/entities/Restaurant::setAddress → KILLED |
restaurant.setAddress(incoming.getAddress()); |
103 |
1
1. updateRestaurant : removed call to edu/ucsb/cs156/example/entities/Restaurant::setCity → KILLED |
restaurant.setCity(incoming.getCity()); |
104 |
1
1. updateRestaurant : removed call to edu/ucsb/cs156/example/entities/Restaurant::setState → KILLED |
restaurant.setState(incoming.getState()); |
105 |
1
1. updateRestaurant : removed call to edu/ucsb/cs156/example/entities/Restaurant::setZip → KILLED |
restaurant.setZip(incoming.getZip()); |
106 |
1
1. updateRestaurant : removed call to edu/ucsb/cs156/example/entities/Restaurant::setDescription → KILLED |
restaurant.setDescription(incoming.getDescription()); |
107 | ||
108 | restaurantRepository.save(restaurant); | |
109 | ||
110 |
1
1. updateRestaurant : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantController::updateRestaurant → KILLED |
return restaurant; |
111 | } | |
112 | ||
113 | } | |
Mutations | ||
39 |
1.1 |
|
48 |
1.1 |
|
50 |
1.1 |
|
67 |
1.1 |
|
68 |
1.1 |
|
69 |
1.1 |
|
70 |
1.1 |
|
71 |
1.1 |
|
72 |
1.1 |
|
76 |
1.1 |
|
85 |
1.1 |
|
87 |
1.1 |
|
88 |
1.1 |
|
99 |
1.1 |
|
101 |
1.1 |
|
102 |
1.1 |
|
103 |
1.1 |
|
104 |
1.1 |
|
105 |
1.1 |
|
106 |
1.1 |
|
110 |
1.1 |