| 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 | /** This is a REST controller for UCSBDiningCommonsMenuItem */ | |
| 23 | @Tag(name = "UCSBDiningCommonsMenuItem") | |
| 24 | @RequestMapping("/api/UCSBDiningCommonsMenuItem") | |
| 25 | @RestController | |
| 26 | @Slf4j | |
| 27 | public class UCSBDiningCommonsMenuItemController extends ApiController { | |
| 28 | ||
| 29 | @Autowired UCSBDiningCommonsMenuItemRepository ucsbDiningCommonsMenuItemRepository; | |
| 30 | ||
| 31 | /** | |
| 32 | * List all UCSBDiningCommonsMenuItems | |
| 33 | * | |
| 34 | * @return an iterable of UCSBDiningCommonsMenuItems | |
| 35 | */ | |
| 36 | @Operation(summary = "List all UCSB Dining Commons Menu Items") | |
| 37 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 38 | @GetMapping("/all") | |
| 39 | public Iterable<UCSBDiningCommonsMenuItem> allUCSBDiningCommonsMenuItems() { | |
| 40 | Iterable<UCSBDiningCommonsMenuItem> menuItems = ucsbDiningCommonsMenuItemRepository.findAll(); | |
| 41 |
1
1. allUCSBDiningCommonsMenuItems : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::allUCSBDiningCommonsMenuItems → KILLED |
return menuItems; |
| 42 | } | |
| 43 | ||
| 44 | /** | |
| 45 | * Create a new UCSBDiningCommonsMenuItem | |
| 46 | * | |
| 47 | * @param diningCommonsCode code for the dining commons | |
| 48 | * @param name name of the menu item | |
| 49 | * @param station station where the item is served | |
| 50 | * @return the saved UCSBDiningCommonsMenuItem | |
| 51 | */ | |
| 52 | @Operation(summary = "Create a new UCSB Dining Commons Menu Item") | |
| 53 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 54 | @PostMapping("/post") | |
| 55 | public UCSBDiningCommonsMenuItem postUCSBDiningCommonsMenuItem( | |
| 56 | @Parameter(name = "diningCommonsCode") @RequestParam String diningCommonsCode, | |
| 57 | @Parameter(name = "name") @RequestParam String name, | |
| 58 | @Parameter(name = "station") @RequestParam String station) { | |
| 59 | ||
| 60 | UCSBDiningCommonsMenuItem menuItem = new UCSBDiningCommonsMenuItem(); | |
| 61 |
1
1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED |
menuItem.setDiningCommonsCode(diningCommonsCode); |
| 62 |
1
1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED |
menuItem.setName(name); |
| 63 |
1
1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED |
menuItem.setStation(station); |
| 64 | ||
| 65 | UCSBDiningCommonsMenuItem savedMenuItem = ucsbDiningCommonsMenuItemRepository.save(menuItem); | |
| 66 | ||
| 67 |
1
1. postUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::postUCSBDiningCommonsMenuItem → KILLED |
return savedMenuItem; |
| 68 | } | |
| 69 | ||
| 70 | /** | |
| 71 | * Get a single UCSBDiningCommonsMenuItem by id | |
| 72 | * | |
| 73 | * @param id the id of the menu item | |
| 74 | * @return the UCSBDiningCommonsMenuItem with the given id | |
| 75 | */ | |
| 76 | @Operation(summary = "Get a single UCSB 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/UCSBDiningCommonsMenuItemController::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/UCSBDiningCommonsMenuItemController::getById → KILLED |
return menuItem; |
| 86 | } | |
| 87 | ||
| 88 | /** | |
| 89 | * Update a single UCSBDiningCommonsMenuItem | |
| 90 | * | |
| 91 | * @param id id of the menu item to update | |
| 92 | * @param incoming the new menu item values | |
| 93 | * @return the updated menu item object | |
| 94 | */ | |
| 95 | @Operation(summary = "Update a single UCSB Dining Commons Menu Item") | |
| 96 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 97 | @PutMapping("") | |
| 98 | public UCSBDiningCommonsMenuItem updateUCSBDiningCommonsMenuItem( | |
| 99 | @Parameter(name = "id") @RequestParam Long id, | |
| 100 | @RequestBody @Valid UCSBDiningCommonsMenuItem incoming) { | |
| 101 | ||
| 102 | UCSBDiningCommonsMenuItem menuItem = | |
| 103 | ucsbDiningCommonsMenuItemRepository | |
| 104 | .findById(id) | |
| 105 |
1
1. lambda$updateUCSBDiningCommonsMenuItem$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$updateUCSBDiningCommonsMenuItem$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id)); |
| 106 | ||
| 107 |
1
1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED |
menuItem.setDiningCommonsCode(incoming.getDiningCommonsCode()); |
| 108 |
1
1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED |
menuItem.setName(incoming.getName()); |
| 109 |
1
1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED |
menuItem.setStation(incoming.getStation()); |
| 110 | ||
| 111 | ucsbDiningCommonsMenuItemRepository.save(menuItem); | |
| 112 | ||
| 113 |
1
1. updateUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::updateUCSBDiningCommonsMenuItem → KILLED |
return menuItem; |
| 114 | } | |
| 115 | ||
| 116 | /** | |
| 117 | * Delete a UCSBDiningCommonsMenuItem | |
| 118 | * | |
| 119 | * @param id the id of the menu item to delete | |
| 120 | * @return a message indicating the menu item was deleted | |
| 121 | */ | |
| 122 | @Operation(summary = "Delete a UCSB Dining Commons Menu Item") | |
| 123 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 124 | @DeleteMapping("") | |
| 125 | public Object deleteUCSBDiningCommonsMenuItem(@Parameter(name = "id") @RequestParam Long id) { | |
| 126 | UCSBDiningCommonsMenuItem menuItem = | |
| 127 | ucsbDiningCommonsMenuItemRepository | |
| 128 | .findById(id) | |
| 129 |
1
1. lambda$deleteUCSBDiningCommonsMenuItem$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$deleteUCSBDiningCommonsMenuItem$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id)); |
| 130 | ||
| 131 |
1
1. deleteUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsMenuItemRepository::delete → KILLED |
ucsbDiningCommonsMenuItemRepository.delete(menuItem); |
| 132 |
1
1. deleteUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::deleteUCSBDiningCommonsMenuItem → KILLED |
return genericMessage("UCSBDiningCommonsMenuItem with id %s deleted".formatted(id)); |
| 133 | } | |
| 134 | } | |
Mutations | ||
| 41 |
1.1 |
|
| 61 |
1.1 |
|
| 62 |
1.1 |
|
| 63 |
1.1 |
|
| 67 |
1.1 |
|
| 83 |
1.1 |
|
| 85 |
1.1 |
|
| 105 |
1.1 |
|
| 107 |
1.1 |
|
| 108 |
1.1 |
|
| 109 |
1.1 |
|
| 113 |
1.1 |
|
| 129 |
1.1 |
|
| 131 |
1.1 |
|
| 132 |
1.1 |