| 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 | import io.swagger.v3.oas.annotations.Operation; | |
| 7 | import io.swagger.v3.oas.annotations.Parameter; | |
| 8 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 9 | import jakarta.validation.Valid; | |
| 10 | import lombok.extern.slf4j.Slf4j; | |
| 11 | import org.springframework.beans.factory.annotation.Autowired; | |
| 12 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 13 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 14 | import org.springframework.web.bind.annotation.GetMapping; | |
| 15 | import org.springframework.web.bind.annotation.PostMapping; | |
| 16 | import org.springframework.web.bind.annotation.PutMapping; | |
| 17 | import org.springframework.web.bind.annotation.RequestBody; | |
| 18 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 19 | import org.springframework.web.bind.annotation.RequestParam; | |
| 20 | import org.springframework.web.bind.annotation.RestController; | |
| 21 | ||
| 22 | /** This is a REST controller for UCSBOrganizations */ | |
| 23 | @Tag(name = "UCSBOrganizations") | |
| 24 | @RequestMapping("/api/ucsborganizations") | |
| 25 | @RestController | |
| 26 | @Slf4j | |
| 27 | public class UCSBOrganizationsController extends ApiController { | |
| 28 | @Autowired UCSBOrganizationsRepository ucsbOrganizationsRepository; | |
| 29 | ||
| 30 | /** | |
| 31 | * This method returns a list of all ucsb organizations. | |
| 32 | * | |
| 33 | * @return a list of all ucsb organizations | |
| 34 | */ | |
| 35 | @Operation(summary = "List all ucsb organizations") | |
| 36 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 37 | @GetMapping("/all") | |
| 38 | public Iterable<UCSBOrganizations> allOrganizations() { | |
| 39 | Iterable<UCSBOrganizations> organizations = ucsbOrganizationsRepository.findAll(); | |
| 40 |
1
1. allOrganizations : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::allOrganizations → KILLED |
return organizations; |
| 41 | } | |
| 42 | ||
| 43 | /** | |
| 44 | * This method creates a new organization. Accessible only to users with the role "ROLE_ADMIN". | |
| 45 | * | |
| 46 | * @param orgCode code of the organization | |
| 47 | * @param orgTranslationShort organization translation short | |
| 48 | * @param orgTranslation organization translation | |
| 49 | * @param inactive whether or not the organization is inactive | |
| 50 | * @return the saved organization | |
| 51 | */ | |
| 52 | @Operation(summary = "Create a new organization") | |
| 53 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 54 | @PostMapping("/post") | |
| 55 | public UCSBOrganizations postCommons( | |
| 56 | @Parameter(name = "orgCode") @RequestParam String orgCode, | |
| 57 | @Parameter(name = "orgTranslationShort") @RequestParam String orgTranslationShort, | |
| 58 | @Parameter(name = "orgTranslation") @RequestParam String orgTranslation, | |
| 59 | @Parameter(name = "inactive") @RequestParam boolean inactive) { | |
| 60 | UCSBOrganizations commons = new UCSBOrganizations(); | |
| 61 |
1
1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgCode → KILLED |
commons.setOrgCode(orgCode); |
| 62 |
1
1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslationShort → KILLED |
commons.setOrgTranslationShort(orgTranslationShort); |
| 63 |
1
1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslation → KILLED |
commons.setOrgTranslation(orgTranslation); |
| 64 |
1
1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setInactive → KILLED |
commons.setInactive(inactive); |
| 65 | ||
| 66 | UCSBOrganizations savedOrganizations = ucsbOrganizationsRepository.save(commons); | |
| 67 | ||
| 68 |
1
1. postCommons : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::postCommons → KILLED |
return savedOrganizations; |
| 69 | } | |
| 70 | ||
| 71 | /** | |
| 72 | * This method returns a single organization. | |
| 73 | * | |
| 74 | * @param orgCode code of the organization | |
| 75 | * @return a single organization | |
| 76 | */ | |
| 77 | @Operation(summary = "Get a single organization") | |
| 78 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 79 | @GetMapping("") | |
| 80 | public UCSBOrganizations getById(@Parameter(name = "orgCode") @RequestParam String orgCode) { | |
| 81 | UCSBOrganizations org = | |
| 82 | ucsbOrganizationsRepository | |
| 83 | .findById(orgCode) | |
| 84 |
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, orgCode)); |
| 85 | ||
| 86 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::getById → KILLED |
return org; |
| 87 | } | |
| 88 | ||
| 89 | /** | |
| 90 | * Update a single organization. Accessible only to users with the role "ROLE_ADMIN". | |
| 91 | * | |
| 92 | * @param orgCode code of the organization | |
| 93 | * @param incoming the new organization contents | |
| 94 | * @return the updated organization object | |
| 95 | */ | |
| 96 | @Operation(summary = "Update a single organization") | |
| 97 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 98 | @PutMapping("") | |
| 99 | public UCSBOrganizations updateOrganization( | |
| 100 | @Parameter(name = "orgCode") @RequestParam String orgCode, | |
| 101 | @RequestBody @Valid UCSBOrganizations incoming) { | |
| 102 | ||
| 103 | UCSBOrganizations org = | |
| 104 | ucsbOrganizationsRepository | |
| 105 | .findById(orgCode) | |
| 106 |
1
1. lambda$updateOrganization$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::lambda$updateOrganization$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBOrganizations.class, orgCode)); |
| 107 | ||
| 108 |
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslationShort → KILLED |
org.setOrgTranslationShort(incoming.getOrgTranslationShort()); |
| 109 |
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslation → KILLED |
org.setOrgTranslation(incoming.getOrgTranslation()); |
| 110 |
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setInactive → KILLED |
org.setInactive(incoming.getInactive()); |
| 111 | ||
| 112 | ucsbOrganizationsRepository.save(org); | |
| 113 | ||
| 114 |
1
1. updateOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::updateOrganization → KILLED |
return org; |
| 115 | } | |
| 116 | ||
| 117 | /** | |
| 118 | * Delete an organization. Accessible only to users with the role "ROLE_ADMIN". | |
| 119 | * | |
| 120 | * @param orgCode code of the organization | |
| 121 | * @return a message indicating the organization was deleted | |
| 122 | */ | |
| 123 | @Operation(summary = "Delete an organization") | |
| 124 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 125 | @DeleteMapping("") | |
| 126 | public Object deleteOrganization(@Parameter(name = "orgCode") @RequestParam String orgCode) { | |
| 127 | UCSBOrganizations organization = | |
| 128 | ucsbOrganizationsRepository | |
| 129 | .findById(orgCode) | |
| 130 |
1
1. lambda$deleteOrganization$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::lambda$deleteOrganization$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBOrganizations.class, orgCode)); |
| 131 | ||
| 132 |
1
1. deleteOrganization : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationsRepository::delete → KILLED |
ucsbOrganizationsRepository.delete(organization); |
| 133 |
1
1. deleteOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::deleteOrganization → KILLED |
return genericMessage("UCSBOrganizations with id %s deleted".formatted(orgCode)); |
| 134 | } | |
| 135 | } | |
Mutations | ||
| 40 |
1.1 |
|
| 61 |
1.1 |
|
| 62 |
1.1 |
|
| 63 |
1.1 |
|
| 64 |
1.1 |
|
| 68 |
1.1 |
|
| 84 |
1.1 |
|
| 86 |
1.1 |
|
| 106 |
1.1 |
|
| 108 |
1.1 |
|
| 109 |
1.1 |
|
| 110 |
1.1 |
|
| 114 |
1.1 |
|
| 130 |
1.1 |
|
| 132 |
1.1 |
|
| 133 |
1.1 |