1 | package edu.ucsb.cs156.example.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.example.entities.UCSBDiningCommons; | |
4 | import edu.ucsb.cs156.example.entities.UCSBDiningCommonsMenuItem; | |
5 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
6 | import edu.ucsb.cs156.example.repositories.UCSBDiningCommonsMenuItemRepository; | |
7 | import edu.ucsb.cs156.example.repositories.UCSBDiningCommonsRepository; | |
8 | import io.swagger.v3.oas.annotations.Operation; | |
9 | import io.swagger.v3.oas.annotations.Parameter; | |
10 | import io.swagger.v3.oas.annotations.tags.Tag; | |
11 | import lombok.extern.slf4j.Slf4j; | |
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 jakarta.validation.Valid; | |
25 | ||
26 | @Tag(name = "UCSBDiningCommonsMenuItems") | |
27 | @RequestMapping("/api/ucsbdiningcommonsmenuitems") | |
28 | @RestController | |
29 | @Slf4j | |
30 | public class UCSBDiningCommonsMenuItemsController extends ApiController{ | |
31 | | |
32 | @Autowired | |
33 | UCSBDiningCommonsMenuItemRepository ucsbDiningCommonsMenuItemRepository; | |
34 | ||
35 | /** | |
36 | * This method returns a list of all ucsbdiningcommonsmenuitems. | |
37 | * @return a list of all ucsbdiningcommonsmenuitems | |
38 | */ | |
39 | @Operation(summary= "List all ucsb dining commons menu items") | |
40 | @PreAuthorize("hasRole('ROLE_USER')") | |
41 | @GetMapping("/all") | |
42 | public Iterable<UCSBDiningCommonsMenuItem> allItems() { | |
43 | Iterable<UCSBDiningCommonsMenuItem> items = ucsbDiningCommonsMenuItemRepository.findAll(); | |
44 |
1
1. allItems : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::allItems → KILLED |
return items; |
45 | } | |
46 | ||
47 | /** | |
48 | * This method creates a new diningcommonsmenuitem. Accessible only to users with the role "ROLE_ADMIN". | |
49 | * @param diningCommonsCode name of the diningcommons | |
50 | * @param name name of the menu item | |
51 | * @param station station where item is served in dining hall | |
52 | * @return the saved menu item | |
53 | */ | |
54 | @Operation(summary= "Create a new menu item") | |
55 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
56 | @PostMapping("/post") | |
57 | public UCSBDiningCommonsMenuItem postItem( | |
58 | @Parameter(name="diningCommonsCode") @RequestParam String diningCommonsCode, | |
59 | @Parameter(name="name") @RequestParam String name, | |
60 | @Parameter(name="station") @RequestParam String station | |
61 | ) | |
62 | { | |
63 | ||
64 | UCSBDiningCommonsMenuItem item = new UCSBDiningCommonsMenuItem(); | |
65 |
1
1. postItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED |
item.setDiningCommonsCode(diningCommonsCode); |
66 |
1
1. postItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED |
item.setName(name); |
67 |
1
1. postItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED |
item.setStation(station); |
68 | ||
69 | UCSBDiningCommonsMenuItem savedItem = ucsbDiningCommonsMenuItemRepository.save(item); | |
70 | ||
71 |
1
1. postItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::postItem → KILLED |
return savedItem; |
72 | } | |
73 | ||
74 | /** | |
75 | * This method returns a single diningcommonsmenuitem. | |
76 | * @param id code of the diningcommonsmenuitem | |
77 | * @return a single diningcommonsmenuitem | |
78 | */ | |
79 | @Operation(summary= "Get a single dining commons menu item") | |
80 | @PreAuthorize("hasRole('ROLE_USER')") | |
81 | @GetMapping("") | |
82 | public UCSBDiningCommonsMenuItem getById( | |
83 | @Parameter(name="id") @RequestParam Long id) { | |
84 | UCSBDiningCommonsMenuItem menuitem = ucsbDiningCommonsMenuItemRepository.findById(id) | |
85 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id)); |
86 | ||
87 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::getById → KILLED |
return menuitem; |
88 | } | |
89 | ||
90 | /** | |
91 | * Delete a diningcommonsmenuitem. Accessible only to users with the role "ROLE_ADMIN". | |
92 | * @param id id of the menu item | |
93 | * @return a message indiciating the menu item was deleted | |
94 | */ | |
95 | @Operation(summary= "Delete a UCSBDiningCommonsMenuItem") | |
96 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
97 | @DeleteMapping("") | |
98 | public Object deleteMenuItem( | |
99 | @Parameter(name="id") @RequestParam Long id) { | |
100 | UCSBDiningCommonsMenuItem menuItem = ucsbDiningCommonsMenuItemRepository.findById(id) | |
101 |
1
1. lambda$deleteMenuItem$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::lambda$deleteMenuItem$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id)); |
102 | ||
103 |
1
1. deleteMenuItem : removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsMenuItemRepository::delete → KILLED |
ucsbDiningCommonsMenuItemRepository.delete(menuItem); |
104 |
1
1. deleteMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::deleteMenuItem → KILLED |
return genericMessage("UCSBDiningCommonsMenuItem with id %s deleted".formatted(id)); |
105 | } | |
106 | ||
107 | /** | |
108 | * Update a single diningcommonsmenuitem. Accessible only to users with the role "ROLE_ADMIN". | |
109 | * @param id id of the diningcommonsmenuitem | |
110 | * @param incoming the new menu item contents | |
111 | * @return the updated menu item object | |
112 | */ | |
113 | @Operation(summary= "Update a single menu item") | |
114 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
115 | @PutMapping("") | |
116 | public UCSBDiningCommonsMenuItem updateMenuItem( | |
117 | @Parameter(name="id") @RequestParam Long id, | |
118 | @RequestBody @Valid UCSBDiningCommonsMenuItem incoming) { | |
119 | ||
120 | UCSBDiningCommonsMenuItem menuItem = ucsbDiningCommonsMenuItemRepository.findById(id) | |
121 |
1
1. lambda$updateMenuItem$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::lambda$updateMenuItem$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id)); |
122 | ||
123 | ||
124 |
1
1. updateMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED |
menuItem.setDiningCommonsCode(incoming.getDiningCommonsCode()); |
125 |
1
1. updateMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED |
menuItem.setName(incoming.getName()); |
126 |
1
1. updateMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED |
menuItem.setStation(incoming.getStation()); |
127 | ||
128 | ucsbDiningCommonsMenuItemRepository.save(menuItem); | |
129 | ||
130 |
1
1. updateMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::updateMenuItem → KILLED |
return menuItem; |
131 | } | |
132 | } | |
Mutations | ||
44 |
1.1 |
|
65 |
1.1 |
|
66 |
1.1 |
|
67 |
1.1 |
|
71 |
1.1 |
|
85 |
1.1 |
|
87 |
1.1 |
|
101 |
1.1 |
|
103 |
1.1 |
|
104 |
1.1 |
|
121 |
1.1 |
|
124 |
1.1 |
|
125 |
1.1 |
|
126 |
1.1 |
|
130 |
1.1 |