| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.example.entities.UCSBOrganizations; | |
| 4 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 5 | import edu.ucsb.cs156.example.repositories.UCSBOrganizationsRepository; | |
| 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 UCSBOrganizations | |
| 27 | */ | |
| 28 | ||
| 29 | @Tag(name = "UCSBOrganizations") | |
| 30 | @RequestMapping("/api/ucsborganizations") | |
| 31 | @RestController | |
| 32 | @Slf4j | |
| 33 | ||
| 34 | public class UCSBOrganizationsController extends ApiController { | |
| 35 | ||
| 36 | @Autowired | |
| 37 | ||
| 38 | UCSBOrganizationsRepository ucsbOrganizationsRepository; | |
| 39 | ||
| 40 | @Operation(summary= "List all ucsb organizations") | |
| 41 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 42 | @GetMapping("/all") | |
| 43 | public Iterable<UCSBOrganizations> allOrganizations() { | |
| 44 | Iterable<UCSBOrganizations> organizations = ucsbOrganizationsRepository.findAll(); | |
| 45 |
1
1. allOrganizations : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::allOrganizations → KILLED |
return organizations; |
| 46 | } | |
| 47 | ||
| 48 | /** | |
| 49 | * This method returns a single organizations. | |
| 50 | * @param code code of the organizations | |
| 51 | * @return a single organizations | |
| 52 | */ | |
| 53 | @Operation(summary= "Get a single organization") | |
| 54 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 55 | @GetMapping("") | |
| 56 | public UCSBOrganizations getById( | |
| 57 | @Parameter(name="id") @RequestParam String id) { | |
| 58 | UCSBOrganizations organizations = ucsbOrganizationsRepository.findById(id) | |
| 59 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBOrganizations.class, id)); |
| 60 | ||
| 61 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::getById → KILLED |
return organizations; |
| 62 | } | |
| 63 | ||
| 64 | /** | |
| 65 | * This method creates a new organizations. Accessible only to users with the role "ROLE_ADMIN". | |
| 66 | * @param code code of the organizations | |
| 67 | * @param name name of the organizations | |
| 68 | * @param hasSackMeal whether or not the commons has sack meals | |
| 69 | * @param hasTakeOutMeal whether or not the commons has take out meals | |
| 70 | * @param hasDiningCam whether or not the commons has a dining cam | |
| 71 | * @param latitude latitude of the commons | |
| 72 | * @param longitude logitude of the commons | |
| 73 | * @return the save organizations | |
| 74 | */ | |
| 75 | @Operation(summary= "Create a new organizations") | |
| 76 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 77 | @PostMapping("/post") | |
| 78 | public UCSBOrganizations postOrganizations( | |
| 79 | @Parameter(name="orgCode") @RequestParam String orgCode, | |
| 80 | @Parameter(name="orgTranslationShort") @RequestParam String orgTranslationShort, | |
| 81 | @Parameter(name="orgTranslation") @RequestParam String orgTranslation, | |
| 82 | @Parameter(name="inactive") @RequestParam boolean inactive | |
| 83 | ) | |
| 84 | { | |
| 85 | ||
| 86 | UCSBOrganizations organizations = new UCSBOrganizations(); | |
| 87 |
1
1. postOrganizations : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgCode → KILLED |
organizations.setOrgCode(orgCode); |
| 88 |
1
1. postOrganizations : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslationShort → KILLED |
organizations.setOrgTranslationShort(orgTranslationShort); |
| 89 |
1
1. postOrganizations : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslation → KILLED |
organizations.setOrgTranslation(orgTranslation); |
| 90 |
1
1. postOrganizations : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setInactive → KILLED |
organizations.setInactive(inactive); |
| 91 | ||
| 92 | UCSBOrganizations savedorganizations = ucsbOrganizationsRepository.save(organizations); | |
| 93 | ||
| 94 |
1
1. postOrganizations : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::postOrganizations → KILLED |
return savedorganizations; |
| 95 | } | |
| 96 | ||
| 97 | /** | |
| 98 | * Delete an organization. Accessible only to users with the role "ROLE_ADMIN". | |
| 99 | * @param code code of the organization | |
| 100 | * @return a message indiciating the commons was deleted | |
| 101 | */ | |
| 102 | @Operation(summary= "Delete a UCSBOrganization") | |
| 103 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 104 | @DeleteMapping("") | |
| 105 | public Object deleteOrganizations( | |
| 106 | @Parameter(name="id") @RequestParam String id) { | |
| 107 | UCSBOrganizations organizations = ucsbOrganizationsRepository.findById(id) | |
| 108 |
1
1. lambda$deleteOrganizations$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::lambda$deleteOrganizations$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBOrganizations.class, id)); |
| 109 | ||
| 110 |
1
1. deleteOrganizations : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationsRepository::delete → KILLED |
ucsbOrganizationsRepository.delete(organizations); |
| 111 |
1
1. deleteOrganizations : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::deleteOrganizations → KILLED |
return genericMessage("UCSBOrganizations with id %s deleted".formatted(id)); |
| 112 | } | |
| 113 | /** | |
| 114 | ** | |
| 115 | * Update a single organizations. Accessible only to users with the role "ROLE_ADMIN". | |
| 116 | * @param code code of the organizations | |
| 117 | * @param incoming the new commons contents | |
| 118 | * @return the updated commons object | |
| 119 | */ | |
| 120 | @Operation(summary= "Update a single organization") | |
| 121 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 122 | @PutMapping("") | |
| 123 | public UCSBOrganizations updateOrganization( | |
| 124 | @Parameter(name="id") @RequestParam String id, | |
| 125 | @RequestBody @Valid UCSBOrganizations incoming) { | |
| 126 | ||
| 127 | UCSBOrganizations organizations = ucsbOrganizationsRepository.findById(id) | |
| 128 |
1
1. lambda$updateOrganization$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::lambda$updateOrganization$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBOrganizations.class, id)); |
| 129 | ||
| 130 | ||
| 131 |
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgCode → KILLED |
organizations.setOrgCode(incoming.getOrgCode()); |
| 132 |
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslationShort → KILLED |
organizations.setOrgTranslationShort(incoming.getOrgTranslationShort()); |
| 133 |
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslation → KILLED |
organizations.setOrgTranslation(incoming.getOrgTranslation()); |
| 134 |
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setInactive → KILLED |
organizations.setInactive(incoming.getInactive()); |
| 135 | ||
| 136 | ucsbOrganizationsRepository.save(organizations); | |
| 137 | ||
| 138 |
1
1. updateOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::updateOrganization → KILLED |
return organizations; |
| 139 | } | |
| 140 | ||
| 141 | | |
| 142 | } | |
Mutations | ||
| 45 |
1.1 |
|
| 59 |
1.1 |
|
| 61 |
1.1 |
|
| 87 |
1.1 |
|
| 88 |
1.1 |
|
| 89 |
1.1 |
|
| 90 |
1.1 |
|
| 94 |
1.1 |
|
| 108 |
1.1 |
|
| 110 |
1.1 |
|
| 111 |
1.1 |
|
| 128 |
1.1 |
|
| 131 |
1.1 |
|
| 132 |
1.1 |
|
| 133 |
1.1 |
|
| 134 |
1.1 |
|
| 138 |
1.1 |