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