| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.example.entities.UCSBDate; | |
| 4 | import edu.ucsb.cs156.example.entities.UCSBDiningCommons; | |
| 5 | import edu.ucsb.cs156.example.entities.UCSBDiningCommonsMenuItem; | |
| 6 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 7 | import edu.ucsb.cs156.example.repositories.UCSBDateRepository; | |
| 8 | import edu.ucsb.cs156.example.repositories.UCSBDiningCommonsMenuItemRepository; | |
| 9 | import io.swagger.v3.oas.annotations.Operation; | |
| 10 | import io.swagger.v3.oas.annotations.Parameter; | |
| 11 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 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.format.annotation.DateTimeFormat; | |
| 18 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 19 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 20 | import org.springframework.web.bind.annotation.GetMapping; | |
| 21 | import org.springframework.web.bind.annotation.PostMapping; | |
| 22 | import org.springframework.web.bind.annotation.PutMapping; | |
| 23 | import org.springframework.web.bind.annotation.RequestBody; | |
| 24 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 25 | import org.springframework.web.bind.annotation.RequestParam; | |
| 26 | import org.springframework.web.bind.annotation.RestController; | |
| 27 | ||
| 28 | import jakarta.validation.Valid; | |
| 29 | ||
| 30 | // import java.time.LocalDateTime; | |
| 31 | ||
| 32 | /** | |
| 33 |  * This is a REST controller for UCSBDiningCommonsMenuItem | |
| 34 |  */ | |
| 35 | ||
| 36 |  @Tag(name = "UCSBDiningCommonsMenuItem") | |
| 37 |  @RequestMapping("/api/ucsbdiningcommonsmenuitem") | |
| 38 |  @RestController | |
| 39 |  @Slf4j | |
| 40 | public class UCSBDiningCommonsMenuItemController extends ApiController{ | |
| 41 | ||
| 42 |     @Autowired | |
| 43 |     UCSBDiningCommonsMenuItemRepository ucsbDiningCommonsMenuItemRepository; | |
| 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> items = ucsbDiningCommonsMenuItemRepository.findAll(); | |
| 50 | 
1
1. allUCSBDiningCommonsMenuItems : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::allUCSBDiningCommonsMenuItems → KILLED | 
        return items; | 
| 51 |     } | |
| 52 | ||
| 53 |     @Operation(summary= "Create a new Menu Item") | |
| 54 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 55 |     @PostMapping("/post") | |
| 56 |     public UCSBDiningCommonsMenuItem postUcsbDiningCommonsMenuItem( | |
| 57 |             @Parameter(name="diningCommonsCode") @RequestParam String diningCommonsCode, | |
| 58 |             @Parameter(name="name") @RequestParam String name, | |
| 59 |             @Parameter(name="station") @RequestParam String station) | |
| 60 |             throws JsonProcessingException { | |
| 61 | ||
| 62 |         // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 63 |         // See: https://www.baeldung.com/spring-date-parameters | |
| 64 | ||
| 65 |         // log.info("localDateTime={}", localDateTime); | |
| 66 | ||
| 67 |         UCSBDiningCommonsMenuItem ucsbDiningCommonsMenuItem = new UCSBDiningCommonsMenuItem(); | |
| 68 | 
1
1. postUcsbDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED | 
        ucsbDiningCommonsMenuItem.setDiningCommonsCode(diningCommonsCode); | 
| 69 | 
1
1. postUcsbDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED | 
        ucsbDiningCommonsMenuItem.setName(name); | 
| 70 | 
1
1. postUcsbDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED | 
        ucsbDiningCommonsMenuItem.setStation(station); | 
| 71 | ||
| 72 |         UCSBDiningCommonsMenuItem savedUcsbDiningCommonsMenuItem = ucsbDiningCommonsMenuItemRepository.save(ucsbDiningCommonsMenuItem); | |
| 73 | ||
| 74 | 
1
1. postUcsbDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::postUcsbDiningCommonsMenuItem → KILLED | 
        return savedUcsbDiningCommonsMenuItem; | 
| 75 |     } | |
| 76 | ||
| 77 |     /** | |
| 78 |      * Get a single menu item by id | |
| 79 |      *  | |
| 80 |      * @param id the id of the menu item | |
| 81 |      * @return a UCSBDiningCommonsMenuItem | |
| 82 |      */ | |
| 83 |     @Operation(summary= "Get a single menu item by ID") | |
| 84 |     @PreAuthorize("hasRole('ROLE_USER')") | |
| 85 |     @GetMapping("") | |
| 86 |     public UCSBDiningCommonsMenuItem getById( | |
| 87 |             @Parameter(name="id") @RequestParam Long id) { | |
| 88 |         UCSBDiningCommonsMenuItem ucsbDiningCommonsMenuItem = ucsbDiningCommonsMenuItemRepository.findById(id) | |
| 89 | 
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$getById$0 → KILLED | 
                .orElseThrow(() -> new EntityNotFoundException(UCSBDate.class, id)); | 
| 90 | ||
| 91 | 
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::getById → KILLED | 
        return ucsbDiningCommonsMenuItem; | 
| 92 |     } | |
| 93 | ||
| 94 |     /** | |
| 95 |      * Update a single menu item | |
| 96 |      *  | |
| 97 |      * @param id       id of the menu item to update | |
| 98 |      * @param incoming the new menu item | |
| 99 |      * @return the updated menu item object | |
| 100 |      */ | |
| 101 |     @Operation(summary= "Update a single menu item") | |
| 102 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 103 |     @PutMapping("") | |
| 104 |     public UCSBDiningCommonsMenuItem updateUcsbDiningCommonsMenuItem( | |
| 105 |             @Parameter(name="id") @RequestParam Long id, | |
| 106 |             @RequestBody @Valid UCSBDiningCommonsMenuItem incoming) { | |
| 107 | ||
| 108 |         UCSBDiningCommonsMenuItem ucsbDiningCommonsMenuItem = ucsbDiningCommonsMenuItemRepository.findById(id) | |
| 109 | 
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)); | 
| 110 | ||
| 111 | 
1
1. updateUcsbDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED | 
        ucsbDiningCommonsMenuItem.setDiningCommonsCode(incoming.getDiningCommonsCode()); | 
| 112 | 
1
1. updateUcsbDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED | 
        ucsbDiningCommonsMenuItem.setName(incoming.getName()); | 
| 113 | 
1
1. updateUcsbDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED | 
        ucsbDiningCommonsMenuItem.setStation(incoming.getStation()); | 
| 114 | ||
| 115 |         ucsbDiningCommonsMenuItemRepository.save(ucsbDiningCommonsMenuItem); | |
| 116 | ||
| 117 | 
1
1. updateUcsbDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::updateUcsbDiningCommonsMenuItem → KILLED | 
        return ucsbDiningCommonsMenuItem; | 
| 118 |     } | |
| 119 | ||
| 120 |     /** | |
| 121 |      * Delete a UCSBDiningCommonsMenuItem | |
| 122 |      *  | |
| 123 |      * @param id the id of the menu item to delete | |
| 124 |      * @return a message indicating the menu item was deleted | |
| 125 |      */ | |
| 126 |     @Operation(summary= "Delete a UCSBDiningCommonsMenuItem") | |
| 127 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 128 |     @DeleteMapping("") | |
| 129 |     public Object deleteUCSBDiningCommonsMenuItem( | |
| 130 |             @Parameter(name="id") @RequestParam Long id) { | |
| 131 |         UCSBDiningCommonsMenuItem ucsbDiningCommonsMenuItem = ucsbDiningCommonsMenuItemRepository.findById(id) | |
| 132 | 
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)); | 
| 133 | ||
| 134 | 
1
1. deleteUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsMenuItemRepository::delete → KILLED | 
        ucsbDiningCommonsMenuItemRepository.delete(ucsbDiningCommonsMenuItem); | 
| 135 | 
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)); | 
| 136 |     } | |
| 137 | } | |
Mutations | ||
| 50 | 
 
 1.1  | 
|
| 68 | 
 
 1.1  | 
|
| 69 | 
 
 1.1  | 
|
| 70 | 
 
 1.1  | 
|
| 74 | 
 
 1.1  | 
|
| 89 | 
 
 1.1  | 
|
| 91 | 
 
 1.1  | 
|
| 109 | 
 
 1.1  | 
|
| 111 | 
 
 1.1  | 
|
| 112 | 
 
 1.1  | 
|
| 113 | 
 
 1.1  | 
|
| 117 | 
 
 1.1  | 
|
| 132 | 
 
 1.1  | 
|
| 134 | 
 
 1.1  | 
|
| 135 | 
 
 1.1  |