1 | package edu.ucsb.cs156.gauchoride.controllers; | |
2 | ||
3 | import com.fasterxml.jackson.core.JsonProcessingException; | |
4 | ||
5 | import edu.ucsb.cs156.gauchoride.entities.Cart; | |
6 | import edu.ucsb.cs156.gauchoride.repositories.CartRepository; | |
7 | ||
8 | import edu.ucsb.cs156.gauchoride.errors.EntityNotFoundException; | |
9 | ||
10 | ||
11 | import org.springframework.beans.factory.annotation.Autowired; | |
12 | ||
13 | import org.springframework.security.access.prepost.PreAuthorize; | |
14 | import org.springframework.web.bind.annotation.DeleteMapping; | |
15 | import org.springframework.web.bind.annotation.GetMapping; | |
16 | import org.springframework.web.bind.annotation.PostMapping; | |
17 | import org.springframework.web.bind.annotation.PutMapping; | |
18 | ||
19 | import org.springframework.web.bind.annotation.RequestMapping; | |
20 | import org.springframework.web.bind.annotation.RequestBody; | |
21 | import org.springframework.web.bind.annotation.RequestParam; | |
22 | import org.springframework.web.bind.annotation.RestController; | |
23 | ||
24 | import io.swagger.annotations.Api; | |
25 | import io.swagger.annotations.ApiOperation; | |
26 | import io.swagger.annotations.ApiParam; | |
27 | import javax.validation.Valid; | |
28 | ||
29 | ||
30 | @Api(description = "Cart") | |
31 | @RequestMapping("/api/carts") | |
32 | @RestController | |
33 | ||
34 | public class CartController extends ApiController { | |
35 | ||
36 | @Autowired | |
37 | CartRepository cartRepository; | |
38 | ||
39 | @ApiOperation(value = "List all carts") | |
40 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER')") | |
41 | @GetMapping("/all") | |
42 | public Iterable<Cart> allCart() { | |
43 | Iterable<Cart> carts = cartRepository.findAll(); | |
44 |
1
1. allCart : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/CartController::allCart → KILLED |
return carts; |
45 | } | |
46 | ||
47 | @ApiOperation(value = "Get a single cart") | |
48 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER')") | |
49 | @GetMapping("") | |
50 | public Cart getById( | |
51 | @ApiParam("id") @RequestParam Long id) { | |
52 | Cart cart = cartRepository.findById(id) | |
53 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/CartController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Cart.class, id)); |
54 | ||
55 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/CartController::getById → KILLED |
return cart; |
56 | } | |
57 | ||
58 | | |
59 | @ApiOperation(value = "Create a new cart") | |
60 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
61 | @PostMapping("/post") | |
62 | public Cart postCart( | |
63 | @ApiParam(name = "name", type = "String", value = "name of the cart", example = "Cart1", required = true) | |
64 | @RequestParam String name, | |
65 | @ApiParam(name = "capacityPeople", type = "Int", value = "Capacity of the Cart to fit People (e.g. 2 for 2 people)", example = "2", required = true ) | |
66 | @RequestParam int capacityPeople, | |
67 | @ApiParam(name = "capacityWheelchair", type = "Int", value = "Capacity of the Cart to fit Wheelchairs (e.g. 1 for 1 wheelchair)", example = "1", required = true ) | |
68 | @RequestParam int capacityWheelchair | |
69 | ) throws JsonProcessingException { | |
70 | | |
71 | Cart cart = new Cart(); | |
72 |
1
1. postCart : removed call to edu/ucsb/cs156/gauchoride/entities/Cart::setName → KILLED |
cart.setName(name); |
73 |
1
1. postCart : removed call to edu/ucsb/cs156/gauchoride/entities/Cart::setCapacityPeople → KILLED |
cart.setCapacityPeople(capacityPeople); |
74 |
1
1. postCart : removed call to edu/ucsb/cs156/gauchoride/entities/Cart::setCapacityWheelchair → KILLED |
cart.setCapacityWheelchair(capacityWheelchair); |
75 | ||
76 | Cart savedCart = cartRepository.save(cart); | |
77 |
1
1. postCart : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/CartController::postCart → KILLED |
return savedCart; |
78 | } | |
79 | ||
80 | @ApiOperation(value = "Delete a Cart") | |
81 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
82 | @DeleteMapping("") | |
83 | public Object deleteCart( | |
84 | @ApiParam(name = "id", type = "Long", value = "ID value of Cart wanting to be deleted (e.g. 4 for cart with ID of 4)", example = "4", required = true ) | |
85 | @RequestParam Long id) { | |
86 | Cart cart = cartRepository.findById(id) | |
87 |
1
1. lambda$deleteCart$1 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/CartController::lambda$deleteCart$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Cart.class, id)); |
88 | ||
89 |
1
1. deleteCart : removed call to edu/ucsb/cs156/gauchoride/repositories/CartRepository::delete → KILLED |
cartRepository.delete(cart); |
90 |
1
1. deleteCart : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/CartController::deleteCart → KILLED |
return genericMessage("Cart with id %s deleted".formatted(id)); |
91 | } | |
92 | ||
93 | @ApiOperation(value = "Update a single cart") | |
94 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
95 | @PutMapping("") | |
96 | public Cart updateCart( | |
97 | @ApiParam(name = "id", type = "Long", value = "ID value of Cart wanting to be updated (e.g. 4 for cart with ID of 4)", example = "4", required = true ) | |
98 | @RequestParam Long id, | |
99 | @RequestBody @Valid Cart incoming) { | |
100 | ||
101 | Cart cart = cartRepository.findById(id) | |
102 |
1
1. lambda$updateCart$2 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/CartController::lambda$updateCart$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Cart.class, id)); |
103 | ||
104 |
1
1. updateCart : removed call to edu/ucsb/cs156/gauchoride/entities/Cart::setName → KILLED |
cart.setName(incoming.getName()); |
105 |
1
1. updateCart : removed call to edu/ucsb/cs156/gauchoride/entities/Cart::setCapacityPeople → KILLED |
cart.setCapacityPeople(incoming.getCapacityPeople()); |
106 |
1
1. updateCart : removed call to edu/ucsb/cs156/gauchoride/entities/Cart::setCapacityWheelchair → KILLED |
cart.setCapacityWheelchair(incoming.getCapacityWheelchair()); |
107 | ||
108 | cartRepository.save(cart); | |
109 | ||
110 |
1
1. updateCart : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/CartController::updateCart → KILLED |
return cart; |
111 | } | |
112 | } | |
Mutations | ||
44 |
1.1 |
|
53 |
1.1 |
|
55 |
1.1 |
|
72 |
1.1 |
|
73 |
1.1 |
|
74 |
1.1 |
|
77 |
1.1 |
|
87 |
1.1 |
|
89 |
1.1 |
|
90 |
1.1 |
|
102 |
1.1 |
|
104 |
1.1 |
|
105 |
1.1 |
|
106 |
1.1 |
|
110 |
1.1 |