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