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