| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 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 io.swagger.v3.oas.annotations.Operation; | |
| 8 | import io.swagger.v3.oas.annotations.Parameter; | |
| 9 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 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.*; | |
| 14 | ||
| 15 | /** This is a REST controller for UCSBDiningCommonsMenuItem */ | |
| 16 | @Tag(name = "UCSBDiningCommonsMenuItem") | |
| 17 | @RequestMapping("/api/ucsbdiningcommonsmenuitem") | |
| 18 | @RestController | |
| 19 | @Slf4j | |
| 20 | public class UCSBDiningCommonsMenuItemController extends ApiController { | |
| 21 | @Autowired UCSBDiningCommonsMenuItemRepository ucsbDiningCommonsMenuItemRepository; | |
| 22 | ||
| 23 | /** | |
| 24 | * List all UCSB Dining Commons menu items | |
| 25 | * | |
| 26 | * @return an iterable of UCSBDiningCommonsMenuItem | |
| 27 | */ | |
| 28 | @Operation(summary = "List all UCSB Dining Commons menu items") | |
| 29 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 30 | @GetMapping("/all") | |
| 31 | public Iterable<UCSBDiningCommonsMenuItem> allUCSBDiningCommonsMenuItems() { | |
| 32 | Iterable<UCSBDiningCommonsMenuItem> menuItems = ucsbDiningCommonsMenuItemRepository.findAll(); | |
| 33 |
1
1. allUCSBDiningCommonsMenuItems : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::allUCSBDiningCommonsMenuItems → KILLED |
return menuItems; |
| 34 | } | |
| 35 | ||
| 36 | /** | |
| 37 | * Create a new menu item | |
| 38 | * | |
| 39 | * @param diningCommonsCode the code of the dining commons (e.g. "ortega", "dlg") | |
| 40 | * @param name the name of the menu item | |
| 41 | * @param station the station where the item is served (e.g. "Entrees", "Desserts") | |
| 42 | * @return the saved menu item | |
| 43 | */ | |
| 44 | @Operation(summary = "Create a new menu item") | |
| 45 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 46 | @PostMapping("/post") | |
| 47 | public UCSBDiningCommonsMenuItem postUCSBDiningCommonsMenuItem( | |
| 48 | @Parameter( | |
| 49 | name = "diningCommonsCode", | |
| 50 | description = "Code of the dining commons (e.g. ortega, dlg)") | |
| 51 | @RequestParam | |
| 52 | String diningCommonsCode, | |
| 53 | @Parameter(name = "name", description = "Name of the menu item (e.g. 'chicken')") | |
| 54 | @RequestParam | |
| 55 | String name, | |
| 56 | @Parameter( | |
| 57 | name = "station", | |
| 58 | description = "Station where the item is served (e.g. Entrees, Desserts)") | |
| 59 | @RequestParam | |
| 60 | String station) | |
| 61 | throws JsonProcessingException { | |
| 62 | // if any of the parameters are empty or null, ?? | |
| 63 | ||
| 64 | UCSBDiningCommonsMenuItem menuItem = | |
| 65 | UCSBDiningCommonsMenuItem.builder() | |
| 66 | .diningCommonsCode(diningCommonsCode) | |
| 67 | .name(name) | |
| 68 | .station(station) | |
| 69 | .build(); | |
| 70 | UCSBDiningCommonsMenuItem savedMenuItem = ucsbDiningCommonsMenuItemRepository.save(menuItem); | |
| 71 | ||
| 72 |
1
1. postUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::postUCSBDiningCommonsMenuItem → KILLED |
return savedMenuItem; |
| 73 | } | |
| 74 | ||
| 75 | /** | |
| 76 | * Delete a single menu item by id, ex: /api/ucsbdiningcommonsmenuitem?id=XXX | |
| 77 | * | |
| 78 | * @param id the id of the menu item | |
| 79 | * @return if exists "record XXX deleted" if DNE "record XXX not found" | |
| 80 | */ | |
| 81 | @Operation( | |
| 82 | summary = "Delete a single menu item by id, ex: DELETE /api/ucsbdiningcommonsmenuitem?id=XXX") | |
| 83 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 84 | @DeleteMapping("") | |
| 85 | public Object deleteById(@Parameter(name = "id") @RequestParam Long id) { | |
| 86 | UCSBDiningCommonsMenuItem menuItem = | |
| 87 | ucsbDiningCommonsMenuItemRepository | |
| 88 | .findById(id) | |
| 89 |
1
1. lambda$deleteById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$deleteById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException("record %s not found".formatted(id))); |
| 90 |
1
1. deleteById : removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsMenuItemRepository::delete → KILLED |
ucsbDiningCommonsMenuItemRepository.delete(menuItem); |
| 91 |
1
1. deleteById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::deleteById → KILLED |
return genericMessage("record %s deleted".formatted(id)); |
| 92 | } | |
| 93 | ||
| 94 | /** | |
| 95 | * Get a single record from the table by databse id | |
| 96 | * | |
| 97 | * @param id of the menu item record | |
| 98 | * @return JSON of the database record with id XXX if exists, error message "id XXX not found" if | |
| 99 | * DNE | |
| 100 | */ | |
| 101 | @Operation( | |
| 102 | summary = | |
| 103 | "Get a single record from the table by databse id, ex: GET /api/ucsbdiningcommonsmenuitem?id=XXX") | |
| 104 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 105 | @GetMapping("") | |
| 106 | public UCSBDiningCommonsMenuItem getById(@Parameter(name = "id") @RequestParam Long id) { | |
| 107 | UCSBDiningCommonsMenuItem menuItem = | |
| 108 | ucsbDiningCommonsMenuItemRepository | |
| 109 | .findById(id) | |
| 110 |
1
1. lambda$getById$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$getById$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException("id %s not found".formatted(id))); |
| 111 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::getById → KILLED |
return menuItem; |
| 112 | } | |
| 113 | ||
| 114 | /** | |
| 115 | * Update a single menu item | |
| 116 | * | |
| 117 | * @param id database id of the menu item to update | |
| 118 | * @param incoming the new menu item values | |
| 119 | * @return the updated menu item | |
| 120 | */ | |
| 121 | @Operation( | |
| 122 | summary = | |
| 123 | "Update a single menu item, ex: PUT /api/ucsbdiningcommonsmenuitem?id=xxx, takes JSON of new values") | |
| 124 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 125 | @PutMapping("") | |
| 126 | public UCSBDiningCommonsMenuItem updateUCSBDiningCommonsMenuItem( | |
| 127 | @Parameter(name = "id") @RequestParam Long id, | |
| 128 | @RequestBody UCSBDiningCommonsMenuItem incoming) { | |
| 129 | ||
| 130 | UCSBDiningCommonsMenuItem menuItem = | |
| 131 | ucsbDiningCommonsMenuItemRepository | |
| 132 | .findById(id) | |
| 133 |
1
1. lambda$updateUCSBDiningCommonsMenuItem$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$updateUCSBDiningCommonsMenuItem$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id)); |
| 134 | ||
| 135 |
1
1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED |
menuItem.setDiningCommonsCode(incoming.getDiningCommonsCode()); |
| 136 |
1
1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED |
menuItem.setName(incoming.getName()); |
| 137 |
1
1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED |
menuItem.setStation(incoming.getStation()); |
| 138 | ||
| 139 | ucsbDiningCommonsMenuItemRepository.save(menuItem); | |
| 140 | ||
| 141 |
1
1. updateUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::updateUCSBDiningCommonsMenuItem → KILLED |
return menuItem; |
| 142 | } | |
| 143 | } | |
Mutations | ||
| 33 |
1.1 |
|
| 72 |
1.1 |
|
| 89 |
1.1 |
|
| 90 |
1.1 |
|
| 91 |
1.1 |
|
| 110 |
1.1 |
|
| 111 |
1.1 |
|
| 133 |
1.1 |
|
| 135 |
1.1 |
|
| 136 |
1.1 |
|
| 137 |
1.1 |
|
| 141 |
1.1 |