| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | import edu.ucsb.cs156.example.entities.Restaurant; | |
| 3 | import edu.ucsb.cs156.example.entities.UCSBDiningCommons; | |
| 4 | import edu.ucsb.cs156.example.entities.UCSBDiningCommonsMenuItem; | |
| 5 | ||
| 6 | ||
| 7 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 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 | ||
| 31 | ||
| 32 | import java.time.LocalDateTime; | |
| 33 | ||
| 34 | /** | |
| 35 | * This is a REST controller for UCSBDates | |
| 36 | */ | |
| 37 | ||
| 38 | @Tag(name = "UCSBDiningCommonsMenuItem") | |
| 39 | @RequestMapping("/api/ucsbdiningcommonsmenuitem") | |
| 40 | @RestController | |
| 41 | @Slf4j | |
| 42 | public class UCSBDiningCommonsMenuItemController extends ApiController { | |
| 43 | ||
| 44 | @Autowired | |
| 45 | UCSBDiningCommonsMenuItemRepository repo; | |
| 46 | ||
| 47 | /** | |
| 48 | * List all UCSB Dining Commons Menu Items | |
| 49 | * | |
| 50 | * @return an iterable of UCSB Dining Commons Menu Items | |
| 51 | */ | |
| 52 | @Operation(summary= "List all ucsb Dinning Commons Menu items") | |
| 53 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 54 | @GetMapping("/all") | |
| 55 | public Iterable<UCSBDiningCommonsMenuItem> allUCSBDiningCommonsMenuItem() { | |
| 56 | Iterable<UCSBDiningCommonsMenuItem> items = repo.findAll(); | |
| 57 |
1
1. allUCSBDiningCommonsMenuItem : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::allUCSBDiningCommonsMenuItem → KILLED |
return items; |
| 58 | } | |
| 59 | /** | |
| 60 | * This method returns a single UCSB Dining Commons Menu Item. | |
| 61 | * @param id id of the UCSB Dining Commons Menu Item to get | |
| 62 | * @return a single UCSB Dining Commons Menu Item | |
| 63 | */ | |
| 64 | @Operation(summary = "Get a single restaurant") | |
| 65 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 66 | @GetMapping("") | |
| 67 | public UCSBDiningCommonsMenuItem getById( | |
| 68 | @Parameter(name = "id") @RequestParam Long id) { | |
| 69 | UCSBDiningCommonsMenuItem item = repo.findById(id) | |
| 70 |
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)); |
| 71 | ||
| 72 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::getById → KILLED |
return item; |
| 73 | } | |
| 74 | ||
| 75 | /** | |
| 76 | * This method creates a new UCSB Dining Commons Menu Item. Accessible only to users with the role "ROLE_ADMIN". | |
| 77 | * @param name name of the UCSB Dining Commons Menu Item | |
| 78 | * | |
| 79 | | |
| 80 | * @return the save UCSB Dining Commons Menu Item (with it's id field set by the database) | |
| 81 | */ | |
| 82 | @Operation(summary = "Create a new UCSB Dining Commons Menu Item") | |
| 83 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 84 | @PostMapping("/post") | |
| 85 | public UCSBDiningCommonsMenuItem postUCSBDiningCommonsMenuItem( | |
| 86 | @Parameter(name = "name") @RequestParam String name, | |
| 87 | @Parameter(name = "station") @RequestParam String station, | |
| 88 | @Parameter(name = "diningCommonsCode") @RequestParam String diningCommonsCode){ | |
| 89 | UCSBDiningCommonsMenuItem item= new UCSBDiningCommonsMenuItem(); | |
| 90 | ||
| 91 |
1
1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED |
item.setName(name); |
| 92 |
1
1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED |
item.setStation(station); |
| 93 |
1
1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED |
item.setDiningCommonsCode(diningCommonsCode); |
| 94 | | |
| 95 | UCSBDiningCommonsMenuItem savedrestaurant = repo.save(item); | |
| 96 |
1
1. postUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::postUCSBDiningCommonsMenuItem → KILLED |
return savedrestaurant; |
| 97 | } | |
| 98 | ||
| 99 | /** | |
| 100 | * Deletes a UCSB Dining Commons Menu Item. Accessible only to users with the role "ROLE_ADMIN". | |
| 101 | * @param id id of the UCSB Dining Commons Menu Item to delete | |
| 102 | * @return a message indicating that the UCSB Dining Commons Menu Item was deleted | |
| 103 | */ | |
| 104 | @Operation(summary = "Delete a UCSB Dining Commons Menu Item") | |
| 105 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 106 | @DeleteMapping("") | |
| 107 | public Object deleteUCSBDiningCommonsMenuItem( | |
| 108 | @Parameter(name = "id") @RequestParam Long id) { | |
| 109 | UCSBDiningCommonsMenuItem item = repo.findById(id) | |
| 110 |
1
1. lambda$deleteUCSBDiningCommonsMenuItem$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$deleteUCSBDiningCommonsMenuItem$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id)); |
| 111 | ||
| 112 |
1
1. deleteUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsMenuItemRepository::delete → KILLED |
repo.delete(item); |
| 113 |
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)); |
| 114 | } | |
| 115 | ||
| 116 | @Operation(summary = "Update a single UCSB Dining Commons Menu Item") | |
| 117 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 118 | @PutMapping("") | |
| 119 | public UCSBDiningCommonsMenuItem updateRestaurant( | |
| 120 | @Parameter(name = "id") @RequestParam Long id, | |
| 121 | @RequestBody @Valid UCSBDiningCommonsMenuItem incoming) { | |
| 122 | ||
| 123 | UCSBDiningCommonsMenuItem item = repo.findById(id) | |
| 124 |
1
1. lambda$updateRestaurant$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$updateRestaurant$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Restaurant.class, id)); |
| 125 | ||
| 126 |
1
1. updateRestaurant : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED |
item.setName(incoming.getName()); |
| 127 |
1
1. updateRestaurant : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED |
item.setStation(incoming.getStation()); |
| 128 |
1
1. updateRestaurant : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED |
item.setDiningCommonsCode(incoming.getDiningCommonsCode()); |
| 129 | ||
| 130 | repo.save(item); | |
| 131 | ||
| 132 |
1
1. updateRestaurant : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::updateRestaurant → KILLED |
return item; |
| 133 | } | |
| 134 | } | |
Mutations | ||
| 57 |
1.1 |
|
| 70 |
1.1 |
|
| 72 |
1.1 |
|
| 91 |
1.1 |
|
| 92 |
1.1 |
|
| 93 |
1.1 |
|
| 96 |
1.1 |
|
| 110 |
1.1 |
|
| 112 |
1.1 |
|
| 113 |
1.1 |
|
| 124 |
1.1 |
|
| 126 |
1.1 |
|
| 127 |
1.1 |
|
| 128 |
1.1 |
|
| 132 |
1.1 |