| 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 | ||
| 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 | ||
| 12 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 13 | ||
| 14 | import org.springframework.beans.factory.annotation.Autowired; | |
| 15 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 16 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 17 | import org.springframework.web.bind.annotation.GetMapping; | |
| 18 | import org.springframework.web.bind.annotation.PostMapping; | |
| 19 | import org.springframework.web.bind.annotation.PutMapping; | |
| 20 | import org.springframework.web.bind.annotation.RequestBody; | |
| 21 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 22 | import org.springframework.web.bind.annotation.RequestParam; | |
| 23 | import org.springframework.web.bind.annotation.RestController; | |
| 24 | ||
| 25 | import jakarta.validation.Valid; | |
| 26 | ||
| 27 | /** | |
| 28 | * This is a REST controller for UCSBDiningCommonsMenuItem | |
| 29 | */ | |
| 30 | ||
| 31 | ||
| 32 | @Tag(name = "UCSBDiningCommonsMenuItems") | |
| 33 | @RequestMapping("/api/ucsbdiningcommonsmenuitems") | |
| 34 | @RestController | |
| 35 | @Slf4j | |
| 36 | public class UCSBDiningCommonsMenuItemsController extends ApiController { | |
| 37 | ||
| 38 | @Autowired | |
| 39 | UCSBDiningCommonsMenuItemRepository ucsbDiningCommonsMenuItemRepository; | |
| 40 | ||
| 41 | ||
| 42 | /** | |
| 43 | * List all UCSB dining commons menu items | |
| 44 | * | |
| 45 | * @return an iterable of UCSBDiningCommonsMenuitem | |
| 46 | */ | |
| 47 | @Operation(summary= "List all ucsb dining commons menu items") | |
| 48 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 49 | @GetMapping("/all") | |
| 50 | public Iterable<UCSBDiningCommonsMenuItem> allUCSBDiningCommonsMenuItems() { | |
| 51 | Iterable<UCSBDiningCommonsMenuItem> items = ucsbDiningCommonsMenuItemRepository.findAll(); | |
| 52 |
1
1. allUCSBDiningCommonsMenuItems : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::allUCSBDiningCommonsMenuItems → KILLED |
return items; |
| 53 | } | |
| 54 | ||
| 55 | /** | |
| 56 | * Create a new dining commons menu item | |
| 57 | * @param diningCommonsCode; dining commons code as as string | |
| 58 | * @param name; name of the item | |
| 59 | * @param station; the station | |
| 60 | */ | |
| 61 | @Operation(summary= "Create a new dining commons menu item") | |
| 62 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 63 | @PostMapping("/post") | |
| 64 | public UCSBDiningCommonsMenuItem postUCSBDiningCommonsMenuItem( | |
| 65 | @Parameter(name="diningCommonsCode") @RequestParam String diningCommonsCode, | |
| 66 | @Parameter(name="name") @RequestParam String name, | |
| 67 | @Parameter(name="station") @RequestParam String station) | |
| 68 | throws JsonProcessingException { | |
| 69 | ||
| 70 | log.info("diningCommonsCode={}", diningCommonsCode); | |
| 71 | ||
| 72 | UCSBDiningCommonsMenuItem ucsbDiningCommonsMenuItem = new UCSBDiningCommonsMenuItem(); | |
| 73 |
1
1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED |
ucsbDiningCommonsMenuItem.setDiningCommonsCode(diningCommonsCode); |
| 74 |
1
1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED |
ucsbDiningCommonsMenuItem.setName(name); |
| 75 |
1
1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED |
ucsbDiningCommonsMenuItem.setStation(station); |
| 76 | ||
| 77 | UCSBDiningCommonsMenuItem savedUcsbDiningCommonsMenuItem = ucsbDiningCommonsMenuItemRepository.save(ucsbDiningCommonsMenuItem); | |
| 78 | ||
| 79 |
1
1. postUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::postUCSBDiningCommonsMenuItem → KILLED |
return savedUcsbDiningCommonsMenuItem; |
| 80 | } | |
| 81 | ||
| 82 | /** | |
| 83 | * Get a single record from the table; | |
| 84 | * use the value passed in as a @RequestParam to do a lookup by id. | |
| 85 | * If a matching row is found, return the row as a JSON object, | |
| 86 | * otherwise throw an EntityNotFoundException. | |
| 87 | * @return a UCSBDiningCommonsMenuitem JSON object | |
| 88 | */ | |
| 89 | @Operation(summary= "List a particular ucsb dining commons menu item by id") | |
| 90 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 91 | @GetMapping("") | |
| 92 | public UCSBDiningCommonsMenuItem getUCSBDiningCommonsMenuItem(@Parameter(name="id") @RequestParam Long id) { | |
| 93 |
1
1. lambda$getUCSBDiningCommonsMenuItem$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::lambda$getUCSBDiningCommonsMenuItem$0 → KILLED |
UCSBDiningCommonsMenuItem item = ucsbDiningCommonsMenuItemRepository.findById(id).orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id)); |
| 94 |
1
1. getUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::getUCSBDiningCommonsMenuItem → KILLED |
return item; |
| 95 | } | |
| 96 | ||
| 97 | /** | |
| 98 | * Update a single menu item | |
| 99 | * | |
| 100 | * @param id id of the menu item to update | |
| 101 | * @param incoming the new menu item | |
| 102 | * @return the updated menu item object | |
| 103 | */ | |
| 104 | @Operation(summary= "Update a single menu item") | |
| 105 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 106 | @PutMapping("") | |
| 107 | public UCSBDiningCommonsMenuItem updateUCSBDiningCommonsMenuItem( | |
| 108 | @Parameter(name="id") @RequestParam Long id, | |
| 109 | @RequestBody @Valid UCSBDiningCommonsMenuItem incoming) { | |
| 110 | ||
| 111 | UCSBDiningCommonsMenuItem ucsbDiningCommonsMenuItem = ucsbDiningCommonsMenuItemRepository.findById(id) | |
| 112 |
1
1. lambda$updateUCSBDiningCommonsMenuItem$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::lambda$updateUCSBDiningCommonsMenuItem$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id)); |
| 113 | ||
| 114 |
1
1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED |
ucsbDiningCommonsMenuItem.setDiningCommonsCode(incoming.getDiningCommonsCode()); |
| 115 |
1
1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED |
ucsbDiningCommonsMenuItem.setName(incoming.getName()); |
| 116 |
1
1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED |
ucsbDiningCommonsMenuItem.setStation(incoming.getStation()); |
| 117 | ||
| 118 | ucsbDiningCommonsMenuItemRepository.save(ucsbDiningCommonsMenuItem); | |
| 119 | ||
| 120 |
1
1. updateUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::updateUCSBDiningCommonsMenuItem → KILLED |
return ucsbDiningCommonsMenuItem; |
| 121 | } | |
| 122 | ||
| 123 | /** | |
| 124 | * Delete a UCSBDiningCommonsMenuItem | |
| 125 | * | |
| 126 | * @param id the id of the menu item to delete | |
| 127 | * @return a message indicating the menu item was deleted | |
| 128 | */ | |
| 129 | @Operation(summary= "Delete a UCSBDiningCommonsMenuItem") | |
| 130 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 131 | @DeleteMapping("") | |
| 132 | public Object deleteUCSBDiningCommonsMenuItem( | |
| 133 | @Parameter(name="id") @RequestParam Long id) { | |
| 134 | UCSBDiningCommonsMenuItem ucsbDiningCommonsMenuItem = ucsbDiningCommonsMenuItemRepository.findById(id) | |
| 135 |
1
1. lambda$deleteUCSBDiningCommonsMenuItem$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::lambda$deleteUCSBDiningCommonsMenuItem$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id)); |
| 136 | ||
| 137 |
1
1. deleteUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsMenuItemRepository::delete → KILLED |
ucsbDiningCommonsMenuItemRepository.delete(ucsbDiningCommonsMenuItem); |
| 138 |
1
1. deleteUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::deleteUCSBDiningCommonsMenuItem → KILLED |
return genericMessage("UCSBDiningCommonsMenuItem with id %s deleted".formatted(id)); |
| 139 | } | |
| 140 | } | |
Mutations | ||
| 52 |
1.1 |
|
| 73 |
1.1 |
|
| 74 |
1.1 |
|
| 75 |
1.1 |
|
| 79 |
1.1 |
|
| 93 |
1.1 |
|
| 94 |
1.1 |
|
| 112 |
1.1 |
|
| 114 |
1.1 |
|
| 115 |
1.1 |
|
| 116 |
1.1 |
|
| 120 |
1.1 |
|
| 135 |
1.1 |
|
| 137 |
1.1 |
|
| 138 |
1.1 |