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.v3.oas.annotations.Operation; | |
7 | import io.swagger.v3.oas.annotations.Parameter; | |
8 | import io.swagger.v3.oas.annotations.tags.Tag; | |
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 | @Tag(name = "Restaurants") | |
25 | @RequestMapping("/api/restaurants") | |
26 | @RestController | |
27 | public class RestaurantsController extends ApiController { | |
28 | ||
29 | @Autowired | |
30 | RestaurantRepository restaurantRepository; | |
31 | ||
32 | @Operation(summary = "List all restaurants") | |
33 | @PreAuthorize("hasRole('ROLE_USER')") | |
34 | @GetMapping("/all") | |
35 | public Iterable<Restaurant> allRestaurants() { | |
36 | Iterable<Restaurant> restaurants = restaurantRepository.findAll(); | |
37 |
1
1. allRestaurants : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::allRestaurants → KILLED |
return restaurants; |
38 | } | |
39 | ||
40 | @Operation(summary = "Get a single restaurant") | |
41 | @PreAuthorize("hasRole('ROLE_USER')") | |
42 | @GetMapping("") | |
43 | public Restaurant getById( | |
44 | @Parameter(name = "id") @RequestParam Long id) { | |
45 | Restaurant restaurant = restaurantRepository.findById(id) | |
46 |
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)); |
47 | ||
48 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::getById → KILLED |
return restaurant; |
49 | } | |
50 | ||
51 | @Operation(summary = "Create a new restaurant") | |
52 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
53 | @PostMapping("/post") | |
54 | public Restaurant postRestaurant( | |
55 | @Parameter(name = "name") @RequestParam String name, | |
56 | @Parameter(name = "description") @RequestParam String description) { | |
57 | Restaurant restaurant = new Restaurant(); | |
58 | ||
59 |
1
1. postRestaurant : removed call to edu/ucsb/cs156/example/entities/Restaurant::setName → KILLED |
restaurant.setName(name); |
60 |
1
1. postRestaurant : removed call to edu/ucsb/cs156/example/entities/Restaurant::setDescription → KILLED |
restaurant.setDescription(description); |
61 | | |
62 | Restaurant savedrestaurant = restaurantRepository.save(restaurant); | |
63 |
1
1. postRestaurant : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::postRestaurant → KILLED |
return savedrestaurant; |
64 | } | |
65 | ||
66 | @Operation(summary = "Delete a Restaurant") | |
67 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
68 | @DeleteMapping("") | |
69 | public Object deleteRestaurant( | |
70 | @Parameter(name = "id") @RequestParam Long id) { | |
71 | Restaurant restaurant = restaurantRepository.findById(id) | |
72 |
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)); |
73 | ||
74 |
1
1. deleteRestaurant : removed call to edu/ucsb/cs156/example/repositories/RestaurantRepository::delete → KILLED |
restaurantRepository.delete(restaurant); |
75 |
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)); |
76 | } | |
77 | ||
78 | @Operation(summary = "Update a single restaurant") | |
79 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
80 | @PutMapping("") | |
81 | public Restaurant updateRestaurant( | |
82 | @Parameter(name = "id") @RequestParam Long id, | |
83 | @RequestBody @Valid Restaurant incoming) { | |
84 | ||
85 | Restaurant restaurant = restaurantRepository.findById(id) | |
86 |
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)); |
87 | ||
88 |
1
1. updateRestaurant : removed call to edu/ucsb/cs156/example/entities/Restaurant::setName → KILLED |
restaurant.setName(incoming.getName()); |
89 |
1
1. updateRestaurant : removed call to edu/ucsb/cs156/example/entities/Restaurant::setDescription → KILLED |
restaurant.setDescription(incoming.getDescription()); |
90 | ||
91 | restaurantRepository.save(restaurant); | |
92 | ||
93 |
1
1. updateRestaurant : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::updateRestaurant → KILLED |
return restaurant; |
94 | } | |
95 | } | |
Mutations | ||
37 |
1.1 |
|
46 |
1.1 |
|
48 |
1.1 |
|
59 |
1.1 |
|
60 |
1.1 |
|
63 |
1.1 |
|
72 |
1.1 |
|
74 |
1.1 |
|
75 |
1.1 |
|
86 |
1.1 |
|
88 |
1.1 |
|
89 |
1.1 |
|
93 |
1.1 |