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