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.format.annotation.DateTimeFormat; | |
15 | import org.springframework.security.access.prepost.PreAuthorize; | |
16 | import org.springframework.web.bind.annotation.DeleteMapping; | |
17 | import org.springframework.web.bind.annotation.GetMapping; | |
18 | import org.springframework.web.bind.annotation.PutMapping; | |
19 | import org.springframework.web.bind.annotation.PostMapping; | |
20 | import org.springframework.web.bind.annotation.RequestBody; | |
21 | import org.springframework.web.bind.annotation.RequestMapping; | |
22 | import org.springframework.web.bind.annotation.RequestParam; | |
23 | import org.springframework.web.bind.annotation.RestController; | |
24 | ||
25 | import javax.validation.Valid; | |
26 | ||
27 | import java.time.LocalDateTime; | |
28 | ||
29 | @Api(description = "Restaurants") | |
30 | @RequestMapping("/api/Restaurant") | |
31 | @RestController | |
32 | @Slf4j | |
33 | public class RestaurantController extends ApiController { | |
34 | ||
35 | @Autowired | |
36 | RestaurantRepository restaurantRepository; | |
37 | ||
38 | @ApiOperation(value = "List all Restaurants") | |
39 | @PreAuthorize("hasRole('ROLE_USER')") | |
40 | @GetMapping("/all") | |
41 | public Iterable<Restaurant> allRestaurants() { | |
42 | Iterable<Restaurant> restaurants = restaurantRepository.findAll(); | |
43 |
1
1. allRestaurants : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantController::allRestaurants → KILLED |
return restaurants; |
44 | } | |
45 | ||
46 | @ApiOperation(value = "Get a single Restaurant") | |
47 | @PreAuthorize("hasRole('ROLE_USER')") | |
48 | @GetMapping("") | |
49 | public Restaurant getById( | |
50 | @ApiParam("id") @RequestParam Long id) { | |
51 | Restaurant restaurant = restaurantRepository.findById(id) | |
52 |
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)); |
53 | ||
54 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantController::getById → KILLED |
return restaurant; |
55 | } | |
56 | ||
57 | @ApiOperation(value = "Create a new Restaurant") | |
58 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
59 | @PostMapping("/post") | |
60 | public Restaurant postRestaurant( | |
61 | @ApiParam("name") @RequestParam String name, | |
62 | @ApiParam("description") @RequestParam String description) | |
63 | throws JsonProcessingException { | |
64 | ||
65 | Restaurant restaurant = new Restaurant(); | |
66 |
1
1. postRestaurant : removed call to edu/ucsb/cs156/example/entities/Restaurant::setName → KILLED |
restaurant.setName(name); |
67 |
1
1. postRestaurant : removed call to edu/ucsb/cs156/example/entities/Restaurant::setDescription → KILLED |
restaurant.setDescription(description); |
68 | ||
69 | Restaurant savedRestaurant = restaurantRepository.save(restaurant); | |
70 |
1
1. postRestaurant : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantController::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/RestaurantController::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/RestaurantController::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/RestaurantController::lambda$updateRestaurant$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Restaurant.class, id)); |
94 | | |
95 |
1
1. updateRestaurant : removed call to edu/ucsb/cs156/example/entities/Restaurant::updateFrom → KILLED |
restaurant.updateFrom(incoming); |
96 | | |
97 | restaurantRepository.save(restaurant); | |
98 | | |
99 |
1
1. updateRestaurant : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantController::updateRestaurant → KILLED |
return restaurant; |
100 | } | |
101 | } | |
Mutations | ||
43 |
1.1 |
|
52 |
1.1 |
|
54 |
1.1 |
|
66 |
1.1 |
|
67 |
1.1 |
|
70 |
1.1 |
|
79 |
1.1 |
|
81 |
1.1 |
|
82 |
1.1 |
|
93 |
1.1 |
|
95 |
1.1 |
|
99 |
1.1 |