| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.example.entities.UCSBDiningCommons; | |
| 4 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 5 | import edu.ucsb.cs156.example.repositories.UCSBDiningCommonsRepository; | |
| 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 org.springframework.beans.factory.annotation.Autowired; | |
| 13 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 14 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 15 | import org.springframework.web.bind.annotation.GetMapping; | |
| 16 | import org.springframework.web.bind.annotation.PostMapping; | |
| 17 | import org.springframework.web.bind.annotation.PutMapping; | |
| 18 | import org.springframework.web.bind.annotation.RequestBody; | |
| 19 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 20 | import org.springframework.web.bind.annotation.RequestParam; | |
| 21 | import org.springframework.web.bind.annotation.RestController; | |
| 22 | ||
| 23 | import jakarta.validation.Valid; | |
| 24 | ||
| 25 | /** | |
| 26 | * This is a REST controller for UCSBDiningCommons | |
| 27 | */ | |
| 28 | ||
| 29 | @Tag(name = "UCSBDiningCommons") | |
| 30 | @RequestMapping("/api/ucsbdiningcommons") | |
| 31 | @RestController | |
| 32 | @Slf4j | |
| 33 | public class UCSBDiningCommonsController extends ApiController { | |
| 34 | ||
| 35 | @Autowired | |
| 36 | UCSBDiningCommonsRepository ucsbDiningCommonsRepository; | |
| 37 | ||
| 38 | /** | |
| 39 | * THis method returns a list of all ucsbdiningcommons. | |
| 40 | * @return a list of all ucsbdiningcommons | |
| 41 | */ | |
| 42 | @Operation(summary= "List all ucsb dining commons") | |
| 43 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 44 | @GetMapping("/all") | |
| 45 | public Iterable<UCSBDiningCommons> allCommonss() { | |
| 46 | Iterable<UCSBDiningCommons> commons = ucsbDiningCommonsRepository.findAll(); | |
| 47 |
1
1. allCommonss : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::allCommonss → KILLED |
return commons; |
| 48 | } | |
| 49 | ||
| 50 | /** | |
| 51 | * This method creates a new diningcommons. Accessible only to users with the role "ROLE_ADMIN". | |
| 52 | * @param code code of the diningcommons | |
| 53 | * @param name name of the diningcommons | |
| 54 | * @param hasSackMeal whether or not the commons has sack meals | |
| 55 | * @param hasTakeOutMeal whether or not the commons has take out meals | |
| 56 | * @param hasDiningCam whether or not the commons has a dining cam | |
| 57 | * @param latitude latitude of the commons | |
| 58 | * @param longitude logitude of the commons | |
| 59 | * @return the save diningcommons | |
| 60 | */ | |
| 61 | @Operation(summary= "Create a new commons") | |
| 62 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 63 | @PostMapping("/post") | |
| 64 | public UCSBDiningCommons postCommons( | |
| 65 | @Parameter(name="code") @RequestParam String code, | |
| 66 | @Parameter(name="name") @RequestParam String name, | |
| 67 | @Parameter(name="hasSackMeal") @RequestParam boolean hasSackMeal, | |
| 68 | @Parameter(name="hasTakeOutMeal") @RequestParam boolean hasTakeOutMeal, | |
| 69 | @Parameter(name="hasDiningCam") @RequestParam boolean hasDiningCam, | |
| 70 | @Parameter(name="latitude") @RequestParam double latitude, | |
| 71 | @Parameter(name="longitude") @RequestParam double longitude | |
| 72 | ) | |
| 73 | { | |
| 74 | ||
| 75 | UCSBDiningCommons commons = new UCSBDiningCommons(); | |
| 76 |
1
1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setCode → KILLED |
commons.setCode(code); |
| 77 |
1
1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setName → KILLED |
commons.setName(name); |
| 78 |
1
1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasSackMeal → KILLED |
commons.setHasSackMeal(hasSackMeal); |
| 79 |
1
1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasTakeOutMeal → KILLED |
commons.setHasTakeOutMeal(hasTakeOutMeal); |
| 80 |
1
1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasDiningCam → KILLED |
commons.setHasDiningCam(hasDiningCam); |
| 81 |
1
1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setLatitude → KILLED |
commons.setLatitude(latitude); |
| 82 |
1
1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setLongitude → KILLED |
commons.setLongitude(longitude); |
| 83 | ||
| 84 | UCSBDiningCommons savedCommons = ucsbDiningCommonsRepository.save(commons); | |
| 85 | ||
| 86 |
1
1. postCommons : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::postCommons → KILLED |
return savedCommons; |
| 87 | } | |
| 88 | ||
| 89 | @Operation(summary= "Get a single commons") | |
| 90 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 91 | @GetMapping("") | |
| 92 | public UCSBDiningCommons getById( | |
| 93 | @Parameter(name="code") @RequestParam String code) { | |
| 94 | UCSBDiningCommons commons = ucsbDiningCommonsRepository.findById(code) | |
| 95 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommons.class, code)); |
| 96 | ||
| 97 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::getById → KILLED |
return commons; |
| 98 | } | |
| 99 | ||
| 100 | @Operation(summary= "Delete a UCSBDiningCommons") | |
| 101 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 102 | @DeleteMapping("") | |
| 103 | public Object deleteCommons( | |
| 104 | @Parameter(name="code") @RequestParam String code) { | |
| 105 | UCSBDiningCommons commons = ucsbDiningCommonsRepository.findById(code) | |
| 106 |
1
1. lambda$deleteCommons$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::lambda$deleteCommons$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommons.class, code)); |
| 107 | ||
| 108 |
1
1. deleteCommons : removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsRepository::delete → KILLED |
ucsbDiningCommonsRepository.delete(commons); |
| 109 |
1
1. deleteCommons : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::deleteCommons → KILLED |
return genericMessage("UCSBDiningCommons with id %s deleted".formatted(code)); |
| 110 | } | |
| 111 | ||
| 112 | /** | |
| 113 | * Update a single diningcommons. Accessible only to users with the role "ROLE_ADMIN". | |
| 114 | * @param code code of the diningcommons | |
| 115 | * @param incoming the new commons contents | |
| 116 | * @return the updated commons object | |
| 117 | */ | |
| 118 | @Operation(summary= "Update a single commons") | |
| 119 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 120 | @PutMapping("") | |
| 121 | public UCSBDiningCommons updateCommons( | |
| 122 | @Parameter(name="code") @RequestParam String code, | |
| 123 | @RequestBody @Valid UCSBDiningCommons incoming) { | |
| 124 | ||
| 125 | UCSBDiningCommons commons = ucsbDiningCommonsRepository.findById(code) | |
| 126 |
1
1. lambda$updateCommons$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::lambda$updateCommons$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommons.class, code)); |
| 127 | ||
| 128 | ||
| 129 |
1
1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setName → KILLED |
commons.setName(incoming.getName()); |
| 130 |
1
1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasSackMeal → KILLED |
commons.setHasSackMeal(incoming.getHasSackMeal()); |
| 131 |
1
1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasTakeOutMeal → KILLED |
commons.setHasTakeOutMeal(incoming.getHasTakeOutMeal()); |
| 132 |
1
1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasDiningCam → KILLED |
commons.setHasDiningCam(incoming.getHasDiningCam()); |
| 133 |
1
1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setLatitude → KILLED |
commons.setLatitude(incoming.getLatitude()); |
| 134 |
1
1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setLongitude → KILLED |
commons.setLongitude(incoming.getLongitude()); |
| 135 | ||
| 136 | ucsbDiningCommonsRepository.save(commons); | |
| 137 | ||
| 138 |
1
1. updateCommons : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::updateCommons → KILLED |
return commons; |
| 139 | } | |
| 140 | } | |
Mutations | ||
| 47 |
1.1 |
|
| 76 |
1.1 |
|
| 77 |
1.1 |
|
| 78 |
1.1 |
|
| 79 |
1.1 |
|
| 80 |
1.1 |
|
| 81 |
1.1 |
|
| 82 |
1.1 |
|
| 86 |
1.1 |
|
| 95 |
1.1 |
|
| 97 |
1.1 |
|
| 106 |
1.1 |
|
| 108 |
1.1 |
|
| 109 |
1.1 |
|
| 126 |
1.1 |
|
| 129 |
1.1 |
|
| 130 |
1.1 |
|
| 131 |
1.1 |
|
| 132 |
1.1 |
|
| 133 |
1.1 |
|
| 134 |
1.1 |
|
| 138 |
1.1 |