| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.example.entities.UCSBOrganization; | |
| 4 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 5 | import edu.ucsb.cs156.example.repositories.UCSBOrganizationRepository; | |
| 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 | /** REST endpoints for UCSB organizations. */ | |
| 23 | @Tag(name = "UCSBOrganization") | |
| 24 | @RequestMapping("/api/UCSBOrganization") | |
| 25 | @RestController | |
| 26 | @Slf4j | |
| 27 | public class UCSBOrganizationController extends ApiController { | |
| 28 | ||
| 29 | @Autowired UCSBOrganizationRepository ucsbOrganizationRepository; | |
| 30 | ||
| 31 | /** | |
| 32 | * Returns all organizations for a logged-in user. | |
| 33 | * | |
| 34 | * @return all organizations in the database | |
| 35 | */ | |
| 36 | @Operation(summary = "List all UCSB organizations") | |
| 37 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 38 | @GetMapping("/all") | |
| 39 | public Iterable<UCSBOrganization> allOrganizations() { | |
| 40 |
1
1. allOrganizations : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::allOrganizations → KILLED |
return ucsbOrganizationRepository.findAll(); |
| 41 | } | |
| 42 | ||
| 43 | /** | |
| 44 | * Returns a single organization by its organization code. | |
| 45 | * | |
| 46 | * @param orgCode the organization's unique code | |
| 47 | * @return the matching organization | |
| 48 | */ | |
| 49 | @Operation(summary = "Get a single UCSB organization by code") | |
| 50 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 51 | @GetMapping("") | |
| 52 | public UCSBOrganization getById( | |
| 53 | @Parameter(description = "Organization code to look up", example = "SKY") @RequestParam | |
| 54 | String orgCode) { | |
| 55 | UCSBOrganization organization = | |
| 56 | ucsbOrganizationRepository | |
| 57 | .findById(orgCode) | |
| 58 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode)); |
| 59 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::getById → KILLED |
return organization; |
| 60 | } | |
| 61 | ||
| 62 | /** | |
| 63 | * Creates an organization. Only administrators may create organizations. | |
| 64 | * | |
| 65 | * @param orgCode the organization's unique code | |
| 66 | * @param orgTranslationShort the organization's abbreviated name | |
| 67 | * @param orgTranslation the organization's full name | |
| 68 | * @param inactive whether the organization is inactive | |
| 69 | * @return the saved organization | |
| 70 | */ | |
| 71 | @Operation(summary = "Create a UCSB organization (admin only)") | |
| 72 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 73 | @PostMapping("/post") | |
| 74 | public UCSBOrganization postOrganization( | |
| 75 | @Parameter(description = "Unique organization code", example = "SKY") @RequestParam | |
| 76 | String orgCode, | |
| 77 | @Parameter(description = "Abbreviated organization name", example = "SKYDIVING CLUB") | |
| 78 | @RequestParam | |
| 79 | String orgTranslationShort, | |
| 80 | @Parameter(description = "Full organization name", example = "SKYDIVING CLUB AT UCSB") | |
| 81 | @RequestParam | |
| 82 | String orgTranslation, | |
| 83 | @Parameter(description = "Whether the organization is inactive", example = "false") | |
| 84 | @RequestParam | |
| 85 | boolean inactive) { | |
| 86 | UCSBOrganization organization = new UCSBOrganization(); | |
| 87 |
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED |
organization.setOrgCode(orgCode); |
| 88 |
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED |
organization.setOrgTranslationShort(orgTranslationShort); |
| 89 |
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED |
organization.setOrgTranslation(orgTranslation); |
| 90 |
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED |
organization.setInactive(inactive); |
| 91 |
1
1. postOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::postOrganization → KILLED |
return ucsbOrganizationRepository.save(organization); |
| 92 | } | |
| 93 | ||
| 94 | /** | |
| 95 | * Deletes an organization. Only administrators may delete organizations. | |
| 96 | * | |
| 97 | * @param orgCode the code of the organization to delete | |
| 98 | * @return a confirmation message | |
| 99 | */ | |
| 100 | @Operation(summary = "Delete a UCSB organization (admin only)") | |
| 101 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 102 | @DeleteMapping("") | |
| 103 | public Object deleteOrganization( | |
| 104 | @Parameter(description = "Organization code to delete", example = "SKY") @RequestParam | |
| 105 | String orgCode) { | |
| 106 | UCSBOrganization organization = | |
| 107 | ucsbOrganizationRepository | |
| 108 | .findById(orgCode) | |
| 109 |
1
1. lambda$deleteOrganization$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$deleteOrganization$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode)); |
| 110 | ||
| 111 |
1
1. deleteOrganization : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED |
ucsbOrganizationRepository.delete(organization); |
| 112 |
1
1. deleteOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::deleteOrganization → KILLED |
return genericMessage("UCSBOrganization with id %s deleted".formatted(orgCode)); |
| 113 | } | |
| 114 | ||
| 115 | /** | |
| 116 | * Updates an organization's fields while retaining its organization code. | |
| 117 | * | |
| 118 | * @param orgCode the code of the organization to update | |
| 119 | * @param incoming the new organization field values | |
| 120 | * @return the updated organization | |
| 121 | */ | |
| 122 | @Operation(summary = "Update a UCSB organization (admin only)") | |
| 123 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 124 | @PutMapping("") | |
| 125 | public UCSBOrganization updateOrganization( | |
| 126 | @Parameter(description = "Organization code to update", example = "SKY") @RequestParam | |
| 127 | String orgCode, | |
| 128 | @RequestBody @Valid UCSBOrganization incoming) { | |
| 129 | UCSBOrganization organization = | |
| 130 | ucsbOrganizationRepository | |
| 131 | .findById(orgCode) | |
| 132 |
1
1. lambda$updateOrganization$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$updateOrganization$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode)); |
| 133 | ||
| 134 |
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED |
organization.setOrgTranslationShort(incoming.getOrgTranslationShort()); |
| 135 |
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED |
organization.setOrgTranslation(incoming.getOrgTranslation()); |
| 136 |
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED |
organization.setInactive(incoming.getInactive()); |
| 137 | ucsbOrganizationRepository.save(organization); | |
| 138 |
1
1. updateOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::updateOrganization → KILLED |
return organization; |
| 139 | } | |
| 140 | } | |
Mutations | ||
| 40 |
1.1 |
|
| 58 |
1.1 |
|
| 59 |
1.1 |
|
| 87 |
1.1 |
|
| 88 |
1.1 |
|
| 89 |
1.1 |
|
| 90 |
1.1 |
|
| 91 |
1.1 |
|
| 109 |
1.1 |
|
| 111 |
1.1 |
|
| 112 |
1.1 |
|
| 132 |
1.1 |
|
| 134 |
1.1 |
|
| 135 |
1.1 |
|
| 136 |
1.1 |
|
| 138 |
1.1 |