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