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