| 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 | @Tag(name = "UCSBDiningCommonsMenuItem") | |
| 23 | @RequestMapping("/api/UCSBDiningCommonsMenuItem") | |
| 24 | @RestController | |
| 25 | @Slf4j | |
| 26 | public class UCSBDiningCommonsMenuItemController extends ApiController { | |
| 27 | ||
| 28 | @Autowired UCSBDiningCommonsMenuItemRepository repository; | |
| 29 | ||
| 30 | @Operation(summary = "List all UCSB Dining Commons menu items") | |
| 31 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 32 | @GetMapping("/all") | |
| 33 | public Iterable<UCSBDiningCommonsMenuItem> allMenuItems() { | |
| 34 |
1
1. allMenuItems : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::allMenuItems → KILLED |
return repository.findAll(); |
| 35 | } | |
| 36 | ||
| 37 | @Operation(summary = "Create a new UCSB Dining Commons menu item") | |
| 38 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 39 | @PostMapping("/post") | |
| 40 | public UCSBDiningCommonsMenuItem postMenuItem( | |
| 41 | @Parameter(description = "Dining commons code, e.g. ortega") @RequestParam | |
| 42 | String diningCommonsCode, | |
| 43 | @Parameter(description = "Name of the menu item") @RequestParam String name, | |
| 44 | @Parameter(description = "Station serving the item") @RequestParam String station) { | |
| 45 | UCSBDiningCommonsMenuItem item = new UCSBDiningCommonsMenuItem(); | |
| 46 | ||
| 47 |
1
1. postMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED |
item.setDiningCommonsCode(diningCommonsCode); |
| 48 |
1
1. postMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED |
item.setName(name); |
| 49 |
1
1. postMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED |
item.setStation(station); |
| 50 | ||
| 51 |
1
1. postMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::postMenuItem → KILLED |
return repository.save(item); |
| 52 | } | |
| 53 | ||
| 54 | @Operation(summary = "Get a single UCSB Dining Commons menu item by ID") | |
| 55 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 56 | @GetMapping("") | |
| 57 | public UCSBDiningCommonsMenuItem getMenuItem( | |
| 58 | @Parameter(description = "ID of the menu item") @RequestParam long id) { | |
| 59 | ||
| 60 |
1
1. getMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::getMenuItem → KILLED |
return repository |
| 61 | .findById(id) | |
| 62 |
1
1. lambda$getMenuItem$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$getMenuItem$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id)); |
| 63 | } | |
| 64 | ||
| 65 | @Operation(summary = "Update a single UCSB Dining Commons menu item") | |
| 66 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 67 | @PutMapping("") | |
| 68 | public UCSBDiningCommonsMenuItem updateMenuItem( | |
| 69 | @Parameter(name = "id") @RequestParam Long id, | |
| 70 | @RequestBody @Valid UCSBDiningCommonsMenuItem incoming) { | |
| 71 | ||
| 72 | UCSBDiningCommonsMenuItem item = | |
| 73 | repository | |
| 74 | .findById(id) | |
| 75 |
1
1. lambda$updateMenuItem$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$updateMenuItem$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id)); |
| 76 | ||
| 77 |
1
1. updateMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED |
item.setDiningCommonsCode(incoming.getDiningCommonsCode()); |
| 78 |
1
1. updateMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED |
item.setName(incoming.getName()); |
| 79 |
1
1. updateMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED |
item.setStation(incoming.getStation()); |
| 80 | ||
| 81 | repository.save(item); | |
| 82 | ||
| 83 |
1
1. updateMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::updateMenuItem → KILLED |
return item; |
| 84 | } | |
| 85 | ||
| 86 | /** | |
| 87 | * Delete a UCSBDiningCommonsMenuItem | |
| 88 | * | |
| 89 | * @param id the id of the menu item to delete | |
| 90 | * @return a message indicating the menu item was deleted | |
| 91 | */ | |
| 92 | @Operation(summary = "Delete a UCSBDiningCommonsMenuItem") | |
| 93 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 94 | @DeleteMapping("") | |
| 95 | public Object deleteMenuItem(@Parameter(name = "id") @RequestParam Long id) { | |
| 96 | UCSBDiningCommonsMenuItem item = | |
| 97 | repository | |
| 98 | .findById(id) | |
| 99 |
1
1. lambda$deleteMenuItem$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$deleteMenuItem$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id)); |
| 100 | ||
| 101 |
1
1. deleteMenuItem : removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsMenuItemRepository::delete → KILLED |
repository.delete(item); |
| 102 |
1
1. deleteMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::deleteMenuItem → KILLED |
return genericMessage("UCSBDiningCommonsMenuItem with id %s deleted".formatted(id)); |
| 103 | } | |
| 104 | } | |
Mutations | ||
| 34 |
1.1 |
|
| 47 |
1.1 |
|
| 48 |
1.1 |
|
| 49 |
1.1 |
|
| 51 |
1.1 |
|
| 60 |
1.1 |
|
| 62 |
1.1 |
|
| 75 |
1.1 |
|
| 77 |
1.1 |
|
| 78 |
1.1 |
|
| 79 |
1.1 |
|
| 83 |
1.1 |
|
| 99 |
1.1 |
|
| 101 |
1.1 |
|
| 102 |
1.1 |