| 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.*; | |
| 14 | ||
| 15 | @Tag(name = "UCSBOrganization") | |
| 16 | @RequestMapping("/api/ucsborganization") | |
| 17 | @RestController | |
| 18 | @Slf4j | |
| 19 | public class UCSBOrganizationController extends ApiController { | |
| 20 | ||
| 21 | @Autowired UCSBOrganizationRepository ucsbOrganizationRepository; | |
| 22 | ||
| 23 | @Operation(summary = "List all UCSB organizations") | |
| 24 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 25 | @GetMapping("/all") | |
| 26 | public Iterable<UCSBOrganization> allOrganizations() { | |
| 27 |
1
1. allOrganizations : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::allOrganizations → KILLED |
return ucsbOrganizationRepository.findAll(); |
| 28 | } | |
| 29 | ||
| 30 | @Operation( | |
| 31 | summary = "Get a single UCSB organization by orgCode", | |
| 32 | description = | |
| 33 | "Returns the organization matching the supplied orgCode. Returns 404 if no organization exists with that code.") | |
| 34 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 35 | @GetMapping("") | |
| 36 | public UCSBOrganization getById(@Parameter(name = "orgCode") @RequestParam String orgCode) { | |
| 37 | ||
| 38 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::getById → KILLED |
return ucsbOrganizationRepository |
| 39 | .findById(orgCode) | |
| 40 |
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)); |
| 41 | } | |
| 42 | ||
| 43 | @Operation(summary = "Create a new UCSB organization") | |
| 44 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 45 | @PostMapping("/post") | |
| 46 | public UCSBOrganization postOrganization( | |
| 47 | @Parameter(name = "orgCode") @RequestParam String orgCode, | |
| 48 | @Parameter(name = "orgTranslationShort") @RequestParam String orgTranslationShort, | |
| 49 | @Parameter(name = "orgTranslation") @RequestParam String orgTranslation, | |
| 50 | @Parameter(name = "inactive") @RequestParam boolean inactive) { | |
| 51 | ||
| 52 | UCSBOrganization organization = new UCSBOrganization(); | |
| 53 | ||
| 54 |
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED |
organization.setOrgCode(orgCode); |
| 55 |
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED |
organization.setOrgTranslationShort(orgTranslationShort); |
| 56 |
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED |
organization.setOrgTranslation(orgTranslation); |
| 57 |
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED |
organization.setInactive(inactive); |
| 58 | ||
| 59 |
1
1. postOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::postOrganization → KILLED |
return ucsbOrganizationRepository.save(organization); |
| 60 | } | |
| 61 | ||
| 62 | @Operation( | |
| 63 | summary = "Delete a UCSB organization by orgCode", | |
| 64 | description = | |
| 65 | "Deletes the organization matching the supplied orgCode. Returns 404 if no organization exists with that code.") | |
| 66 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 67 | @DeleteMapping("") | |
| 68 | public String deleteOrganization(@Parameter(name = "orgCode") @RequestParam String orgCode) { | |
| 69 | ||
| 70 | UCSBOrganization organization = | |
| 71 | ucsbOrganizationRepository | |
| 72 | .findById(orgCode) | |
| 73 |
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)); |
| 74 | ||
| 75 |
1
1. deleteOrganization : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED |
ucsbOrganizationRepository.delete(organization); |
| 76 | ||
| 77 |
1
1. deleteOrganization : replaced return value with "" for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::deleteOrganization → KILLED |
return "record " + orgCode + " deleted"; |
| 78 | } | |
| 79 | ||
| 80 | @Operation( | |
| 81 | summary = "Update a UCSB organization by orgCode", | |
| 82 | description = | |
| 83 | "Updates the orgTranslationShort, orgTranslation, and inactive fields of an existing organization. " | |
| 84 | + "The organization is identified by orgCode, which cannot be changed. " | |
| 85 | + "Returns 404 if the organization does not exist.") | |
| 86 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 87 | @PutMapping("") | |
| 88 | public UCSBOrganization updateOrganization( | |
| 89 | @Parameter(name = "orgCode") @RequestParam String orgCode, | |
| 90 | @RequestBody @Valid UCSBOrganization incoming) { | |
| 91 | ||
| 92 | UCSBOrganization organization = | |
| 93 | ucsbOrganizationRepository | |
| 94 | .findById(orgCode) | |
| 95 |
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)); |
| 96 | ||
| 97 |
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED |
organization.setOrgTranslationShort(incoming.getOrgTranslationShort()); |
| 98 |
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED |
organization.setOrgTranslation(incoming.getOrgTranslation()); |
| 99 |
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED |
organization.setInactive(incoming.getInactive()); |
| 100 | ||
| 101 | ucsbOrganizationRepository.save(organization); | |
| 102 | ||
| 103 |
1
1. updateOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::updateOrganization → KILLED |
return organization; |
| 104 | } | |
| 105 | } | |
Mutations | ||
| 27 |
1.1 |
|
| 38 |
1.1 |
|
| 40 |
1.1 |
|
| 54 |
1.1 |
|
| 55 |
1.1 |
|
| 56 |
1.1 |
|
| 57 |
1.1 |
|
| 59 |
1.1 |
|
| 73 |
1.1 |
|
| 75 |
1.1 |
|
| 77 |
1.1 |
|
| 95 |
1.1 |
|
| 97 |
1.1 |
|
| 98 |
1.1 |
|
| 99 |
1.1 |
|
| 103 |
1.1 |