| 1 | package edu.ucsb.cs156.dining.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.dining.entities.UCSBDiningCommons; | |
| 4 | import edu.ucsb.cs156.dining.errors.EntityNotFoundException; | |
| 5 | import edu.ucsb.cs156.dining.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/dining/controllers/UCSBDiningCommonsController::allCommonss → KILLED | 
        return commons; | 
| 48 |     } | |
| 49 | ||
| 50 |     /** | |
| 51 |      * This method returns a single diningcommons. | |
| 52 |      * @param code code of the diningcommons | |
| 53 |      * @return a single diningcommons | |
| 54 |      */ | |
| 55 |     @Operation(summary= "Get a single commons") | |
| 56 |     @PreAuthorize("hasRole('ROLE_USER')") | |
| 57 |     @GetMapping("") | |
| 58 |     public UCSBDiningCommons getById( | |
| 59 |             @Parameter(name="code") @RequestParam String code) { | |
| 60 |         UCSBDiningCommons commons = ucsbDiningCommonsRepository.findById(code) | |
| 61 | 
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/dining/controllers/UCSBDiningCommonsController::lambda$getById$0 → KILLED | 
                .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommons.class, code)); | 
| 62 | ||
| 63 | 
1
1. getById : replaced return value with null for edu/ucsb/cs156/dining/controllers/UCSBDiningCommonsController::getById → KILLED | 
        return commons; | 
| 64 |     } | |
| 65 | ||
| 66 |     /** | |
| 67 |      * This method creates a new diningcommons. Accessible only to users with the role "ROLE_ADMIN". | |
| 68 |      * @param code code of the diningcommons | |
| 69 |      * @param name name of the diningcommons | |
| 70 |      * @param hasSackMeal whether or not the commons has sack meals | |
| 71 |      * @param hasTakeOutMeal whether or not the commons has take out meals | |
| 72 |      * @param hasDiningCam whether or not the commons has a dining cam | |
| 73 |      * @param latitude latitude of the commons | |
| 74 |      * @param longitude logitude of the commons | |
| 75 |      * @return the save diningcommons | |
| 76 |      */ | |
| 77 |     @Operation(summary= "Create a new commons") | |
| 78 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 79 |     @PostMapping("/post") | |
| 80 |     public UCSBDiningCommons postCommons( | |
| 81 |         @Parameter(name="code") @RequestParam String code, | |
| 82 |         @Parameter(name="name") @RequestParam String name, | |
| 83 |         @Parameter(name="hasSackMeal") @RequestParam boolean hasSackMeal, | |
| 84 |         @Parameter(name="hasTakeOutMeal") @RequestParam boolean hasTakeOutMeal, | |
| 85 |         @Parameter(name="hasDiningCam") @RequestParam boolean hasDiningCam, | |
| 86 |         @Parameter(name="latitude") @RequestParam double latitude, | |
| 87 |         @Parameter(name="longitude") @RequestParam double longitude | |
| 88 |         ) | |
| 89 |         { | |
| 90 | ||
| 91 |         UCSBDiningCommons commons = new UCSBDiningCommons(); | |
| 92 | 
1
1. postCommons : removed call to edu/ucsb/cs156/dining/entities/UCSBDiningCommons::setCode → KILLED | 
        commons.setCode(code); | 
| 93 | 
1
1. postCommons : removed call to edu/ucsb/cs156/dining/entities/UCSBDiningCommons::setName → KILLED | 
        commons.setName(name); | 
| 94 | 
1
1. postCommons : removed call to edu/ucsb/cs156/dining/entities/UCSBDiningCommons::setHasSackMeal → KILLED | 
        commons.setHasSackMeal(hasSackMeal); | 
| 95 | 
1
1. postCommons : removed call to edu/ucsb/cs156/dining/entities/UCSBDiningCommons::setHasTakeOutMeal → KILLED | 
        commons.setHasTakeOutMeal(hasTakeOutMeal); | 
| 96 | 
1
1. postCommons : removed call to edu/ucsb/cs156/dining/entities/UCSBDiningCommons::setHasDiningCam → KILLED | 
        commons.setHasDiningCam(hasDiningCam); | 
| 97 | 
1
1. postCommons : removed call to edu/ucsb/cs156/dining/entities/UCSBDiningCommons::setLatitude → KILLED | 
        commons.setLatitude(latitude); | 
| 98 | 
1
1. postCommons : removed call to edu/ucsb/cs156/dining/entities/UCSBDiningCommons::setLongitude → KILLED | 
        commons.setLongitude(longitude); | 
| 99 | ||
| 100 |         UCSBDiningCommons savedCommons = ucsbDiningCommonsRepository.save(commons); | |
| 101 | ||
| 102 | 
1
1. postCommons : replaced return value with null for edu/ucsb/cs156/dining/controllers/UCSBDiningCommonsController::postCommons → KILLED | 
        return savedCommons; | 
| 103 |     } | |
| 104 | ||
| 105 |     /** | |
| 106 |      * Delete a diningcommons. Accessible only to users with the role "ROLE_ADMIN". | |
| 107 |      * @param code code of the commons | |
| 108 |      * @return a message indiciating the commons was deleted | |
| 109 |      */ | |
| 110 |     @Operation(summary= "Delete a UCSBDiningCommons") | |
| 111 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 112 |     @DeleteMapping("") | |
| 113 |     public Object deleteCommons( | |
| 114 |             @Parameter(name="code") @RequestParam String code) { | |
| 115 |         UCSBDiningCommons commons = ucsbDiningCommonsRepository.findById(code) | |
| 116 | 
1
1. lambda$deleteCommons$1 : replaced return value with null for edu/ucsb/cs156/dining/controllers/UCSBDiningCommonsController::lambda$deleteCommons$1 → KILLED | 
                .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommons.class, code)); | 
| 117 | ||
| 118 | 
1
1. deleteCommons : removed call to edu/ucsb/cs156/dining/repositories/UCSBDiningCommonsRepository::delete → KILLED | 
        ucsbDiningCommonsRepository.delete(commons); | 
| 119 | 
1
1. deleteCommons : replaced return value with null for edu/ucsb/cs156/dining/controllers/UCSBDiningCommonsController::deleteCommons → KILLED | 
        return genericMessage("UCSBDiningCommons with id %s deleted".formatted(code)); | 
| 120 |     } | |
| 121 | ||
| 122 |     /** | |
| 123 |      * Update a single diningcommons. Accessible only to users with the role "ROLE_ADMIN". | |
| 124 |      * @param code code of the diningcommons | |
| 125 |      * @param incoming the new commons contents | |
| 126 |      * @return the updated commons object | |
| 127 |      */ | |
| 128 |     @Operation(summary= "Update a single commons") | |
| 129 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 130 |     @PutMapping("") | |
| 131 |     public UCSBDiningCommons updateCommons( | |
| 132 |             @Parameter(name="code") @RequestParam String code, | |
| 133 |             @RequestBody @Valid UCSBDiningCommons incoming) { | |
| 134 | ||
| 135 |         UCSBDiningCommons commons = ucsbDiningCommonsRepository.findById(code) | |
| 136 | 
1
1. lambda$updateCommons$2 : replaced return value with null for edu/ucsb/cs156/dining/controllers/UCSBDiningCommonsController::lambda$updateCommons$2 → KILLED | 
                .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommons.class, code)); | 
| 137 | ||
| 138 | ||
| 139 | 
1
1. updateCommons : removed call to edu/ucsb/cs156/dining/entities/UCSBDiningCommons::setName → KILLED | 
        commons.setName(incoming.getName());   | 
| 140 | 
1
1. updateCommons : removed call to edu/ucsb/cs156/dining/entities/UCSBDiningCommons::setHasSackMeal → KILLED | 
        commons.setHasSackMeal(incoming.getHasSackMeal()); | 
| 141 | 
1
1. updateCommons : removed call to edu/ucsb/cs156/dining/entities/UCSBDiningCommons::setHasTakeOutMeal → KILLED | 
        commons.setHasTakeOutMeal(incoming.getHasTakeOutMeal()); | 
| 142 | 
1
1. updateCommons : removed call to edu/ucsb/cs156/dining/entities/UCSBDiningCommons::setHasDiningCam → KILLED | 
        commons.setHasDiningCam(incoming.getHasDiningCam()); | 
| 143 | 
1
1. updateCommons : removed call to edu/ucsb/cs156/dining/entities/UCSBDiningCommons::setLatitude → KILLED | 
        commons.setLatitude(incoming.getLatitude()); | 
| 144 | 
1
1. updateCommons : removed call to edu/ucsb/cs156/dining/entities/UCSBDiningCommons::setLongitude → KILLED | 
        commons.setLongitude(incoming.getLongitude()); | 
| 145 | ||
| 146 |         ucsbDiningCommonsRepository.save(commons); | |
| 147 | ||
| 148 | 
1
1. updateCommons : replaced return value with null for edu/ucsb/cs156/dining/controllers/UCSBDiningCommonsController::updateCommons → KILLED | 
        return commons; | 
| 149 |     } | |
| 150 | } | |
Mutations | ||
| 47 | 
 
 1.1  | 
|
| 61 | 
 
 1.1  | 
|
| 63 | 
 
 1.1  | 
|
| 92 | 
 
 1.1  | 
|
| 93 | 
 
 1.1  | 
|
| 94 | 
 
 1.1  | 
|
| 95 | 
 
 1.1  | 
|
| 96 | 
 
 1.1  | 
|
| 97 | 
 
 1.1  | 
|
| 98 | 
 
 1.1  | 
|
| 102 | 
 
 1.1  | 
|
| 116 | 
 
 1.1  | 
|
| 118 | 
 
 1.1  | 
|
| 119 | 
 
 1.1  | 
|
| 136 | 
 
 1.1  | 
|
| 139 | 
 
 1.1  | 
|
| 140 | 
 
 1.1  | 
|
| 141 | 
 
 1.1  | 
|
| 142 | 
 
 1.1  | 
|
| 143 | 
 
 1.1  | 
|
| 144 | 
 
 1.1  | 
|
| 148 | 
 
 1.1  |