| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.example.entities.UCSBDate; | |
| 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 | ||
| 8 | import io.swagger.v3.oas.annotations.Operation; | |
| 9 | import io.swagger.v3.oas.annotations.Parameter; | |
| 10 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 11 | import jakarta.validation.Valid; | |
| 12 | import lombok.extern.slf4j.Slf4j; | |
| 13 | ||
| 14 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 15 | ||
| 16 | import org.springframework.beans.factory.annotation.Autowired; | |
| 17 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 18 | import org.springframework.web.bind.annotation.GetMapping; | |
| 19 | import org.springframework.web.bind.annotation.PostMapping; | |
| 20 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 21 | import org.springframework.web.bind.annotation.PutMapping; | |
| 22 | import org.springframework.web.bind.annotation.RequestBody; | |
| 23 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 24 | import org.springframework.web.bind.annotation.RequestParam; | |
| 25 | import org.springframework.web.bind.annotation.RestController; | |
| 26 | ||
| 27 | /** | |
| 28 | * This is a REST controller for UCSBDiningCommonsMenuItems | |
| 29 | */ | |
| 30 | ||
| 31 | @Tag(name = "UCSBDiningCommonsMenuItems") | |
| 32 | @RequestMapping("/api/ucsbdiningcommonsmenuitems") | |
| 33 | @RestController | |
| 34 | @Slf4j | |
| 35 | public class UCSBDiningCommonsMenuItemsController extends ApiController { | |
| 36 | ||
| 37 | @Autowired | |
| 38 | UCSBDiningCommonsMenuItemRepository ucsbDiningCommonsMenuItemRepository; | |
| 39 | ||
| 40 | /** | |
| 41 | * List all UCSB Dining Commons Menu Items | |
| 42 | * | |
| 43 | * @return an iterable of UCSBDiningCommonsMenuItems | |
| 44 | */ | |
| 45 | @Operation(summary = "List all UCSB Dining Commons Menu Items") | |
| 46 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 47 | @GetMapping("/all") | |
| 48 | public Iterable<UCSBDiningCommonsMenuItem> allUCSBDiningCommonsMenuItems() { | |
| 49 | Iterable<UCSBDiningCommonsMenuItem> menuItems = ucsbDiningCommonsMenuItemRepository.findAll(); | |
| 50 |
1
1. allUCSBDiningCommonsMenuItems : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::allUCSBDiningCommonsMenuItems → KILLED |
return menuItems; |
| 51 | } | |
| 52 | ||
| 53 | /** | |
| 54 | * Create a new ucsb dining commons menu item | |
| 55 | * | |
| 56 | * @param diningCommonsCode code for each dining common | |
| 57 | * @param name menu item | |
| 58 | * @param station which station it is served at | |
| 59 | * @return the saved ucsbdiningcommonsmenuitem | |
| 60 | */ | |
| 61 | @Operation(summary = "Create a new UCSB 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 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 71 | // See: https://www.baeldung.com/spring-date-parameters | |
| 72 | ||
| 73 | log.info("name={}", name); | |
| 74 | ||
| 75 | UCSBDiningCommonsMenuItem ucsbDiningCommonsMenuItem = new UCSBDiningCommonsMenuItem(); | |
| 76 |
1
1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED |
ucsbDiningCommonsMenuItem.setDiningCommonsCode(diningCommonsCode); |
| 77 |
1
1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED |
ucsbDiningCommonsMenuItem.setName(name); |
| 78 |
1
1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED |
ucsbDiningCommonsMenuItem.setStation(station); |
| 79 | ||
| 80 | UCSBDiningCommonsMenuItem savedUcsbDiningCommonsMenuItem = ucsbDiningCommonsMenuItemRepository | |
| 81 | .save(ucsbDiningCommonsMenuItem); | |
| 82 | ||
| 83 |
1
1. postUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::postUCSBDiningCommonsMenuItem → KILLED |
return savedUcsbDiningCommonsMenuItem; |
| 84 | } | |
| 85 | ||
| 86 | /** | |
| 87 | * Get a single UCSB Dining Commons Menu Item by id | |
| 88 | * | |
| 89 | * @param id the id of the UCSB Dining Commons Menu Item | |
| 90 | * @return a UCSB Dining Commons Menu Item | |
| 91 | */ | |
| 92 | @Operation(summary = "Get a single UCSB Dining Commons Menu Item") | |
| 93 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 94 | @GetMapping("") | |
| 95 | public UCSBDiningCommonsMenuItem getById( | |
| 96 | @Parameter(name = "id") @RequestParam Long id) { | |
| 97 | UCSBDiningCommonsMenuItem ucsbDiningCommonsMenuItem = ucsbDiningCommonsMenuItemRepository.findById(id) | |
| 98 |
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)); |
| 99 | ||
| 100 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::getById → KILLED |
return ucsbDiningCommonsMenuItem; |
| 101 | } | |
| 102 | ||
| 103 | /** | |
| 104 | * Update a single UCSB Dining Commons Menu Item | |
| 105 | * | |
| 106 | * @param id id of the menu item to update | |
| 107 | * @param incoming the new menu item | |
| 108 | * @return the updated menu item object | |
| 109 | */ | |
| 110 | @Operation(summary = "Update a single UCSB Dining Commons Menu Item") | |
| 111 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 112 | @PutMapping("") | |
| 113 | public UCSBDiningCommonsMenuItem updateUCSBDiningCommonsMenuItem( | |
| 114 | @Parameter(name = "id") @RequestParam Long id, | |
| 115 | @RequestBody @Valid UCSBDiningCommonsMenuItem incoming) { | |
| 116 | ||
| 117 | UCSBDiningCommonsMenuItem ucsbDiningCommonsMenuItem = ucsbDiningCommonsMenuItemRepository.findById(id) | |
| 118 |
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)); |
| 119 | ||
| 120 |
1
1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED |
ucsbDiningCommonsMenuItem.setDiningCommonsCode(incoming.getDiningCommonsCode()); |
| 121 |
1
1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED |
ucsbDiningCommonsMenuItem.setName(incoming.getName()); |
| 122 |
1
1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED |
ucsbDiningCommonsMenuItem.setStation(incoming.getStation()); |
| 123 | ||
| 124 | ucsbDiningCommonsMenuItemRepository.save(ucsbDiningCommonsMenuItem); | |
| 125 | ||
| 126 |
1
1. updateUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::updateUCSBDiningCommonsMenuItem → KILLED |
return ucsbDiningCommonsMenuItem; |
| 127 | } | |
| 128 | ||
| 129 | /** | |
| 130 | * Delete a UCSB Dining Commons Menu Item | |
| 131 | * | |
| 132 | * @param id the id of the menu item to delete | |
| 133 | * @return a message indicating the menu item was deleted | |
| 134 | */ | |
| 135 | @Operation(summary = "Delete a UCSB Dining Commons Menu Item") | |
| 136 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 137 | @DeleteMapping("") | |
| 138 | public Object deleteUCSBDiningCommonsMenuItem( | |
| 139 | @Parameter(name = "id") @RequestParam Long id) { | |
| 140 | ||
| 141 | UCSBDiningCommonsMenuItem ucsbDiningCommonsMenuItem = ucsbDiningCommonsMenuItemRepository.findById(id) | |
| 142 |
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)); |
| 143 | ||
| 144 |
1
1. deleteUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsMenuItemRepository::delete → KILLED |
ucsbDiningCommonsMenuItemRepository.delete(ucsbDiningCommonsMenuItem); |
| 145 |
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)); |
| 146 | } | |
| 147 | } | |
Mutations | ||
| 50 |
1.1 |
|
| 76 |
1.1 |
|
| 77 |
1.1 |
|
| 78 |
1.1 |
|
| 83 |
1.1 |
|
| 98 |
1.1 |
|
| 100 |
1.1 |
|
| 118 |
1.1 |
|
| 120 |
1.1 |
|
| 121 |
1.1 |
|
| 122 |
1.1 |
|
| 126 |
1.1 |
|
| 142 |
1.1 |
|
| 144 |
1.1 |
|
| 145 |
1.1 |