| 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 | ||
| 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 | @Tag(name = "UCSBOrganizations") | |
| 26 | @RequestMapping("/api/ucsborganizations") | |
| 27 | @RestController | |
| 28 | @Slf4j | |
| 29 | public class UCSBOrganizationController extends ApiController { | |
| 30 | ||
| 31 | @Autowired | |
| 32 | UCSBOrganizationRepository ucsbOrganizationRepository; | |
| 33 | ||
| 34 | /** | |
| 35 | * This method returns a list of all UCSB organizations. | |
| 36 | * @return a list of all UCSB organizations | |
| 37 | */ | |
| 38 | @Operation(summary = "List all UCSB Organizations") | |
| 39 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 40 | @GetMapping("/all") | |
| 41 | public Iterable<UCSBOrganization> allOrganizations() { | |
| 42 |
1
1. allOrganizations : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::allOrganizations → KILLED |
return ucsbOrganizationRepository.findAll(); |
| 43 | } | |
| 44 | ||
| 45 | /** | |
| 46 | * This method returns a single UCSB organization. | |
| 47 | * Accepts both `id` and `orgCode` as parameters. | |
| 48 | * @param id the id of the UCSB organization | |
| 49 | * @param orgCode the orgCode of the UCSB organization | |
| 50 | * @return a single UCSB organization | |
| 51 | */ | |
| 52 | @Operation(summary = "Get a single UCSB Organization") | |
| 53 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 54 | @GetMapping("") | |
| 55 | public UCSBOrganization getById( | |
| 56 | @RequestParam(required = false) String id, | |
| 57 | @RequestParam(required = false) String orgCode) { | |
| 58 | String identifier = orgCode; | |
| 59 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::getById → KILLED |
return ucsbOrganizationRepository.findById(identifier) |
| 60 |
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, identifier)); |
| 61 | } | |
| 62 | ||
| 63 | /** | |
| 64 | * This method creates a new UCSB organization. | |
| 65 | * Accessible only to users with the role "ROLE_ADMIN". | |
| 66 | */ | |
| 67 | @Operation(summary = "Create a new UCSB Organization") | |
| 68 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 69 | @PostMapping("/post") | |
| 70 | public UCSBOrganization postOrganization( | |
| 71 | @Parameter(name = "orgCode") @RequestParam String orgCode, | |
| 72 | @Parameter(name = "orgTranslationShort") @RequestParam String orgTranslationShort, | |
| 73 | @Parameter(name = "orgTranslation") @RequestParam String orgTranslation, | |
| 74 | @Parameter(name = "inactive") @RequestParam boolean inactive) { | |
| 75 | ||
| 76 | UCSBOrganization organization = UCSBOrganization.builder() | |
| 77 | .orgCode(orgCode) | |
| 78 | .orgTranslationShort(orgTranslationShort) | |
| 79 | .orgTranslation(orgTranslation) | |
| 80 | .inactive(inactive) | |
| 81 | .build(); | |
| 82 | ||
| 83 |
1
1. postOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::postOrganization → KILLED |
return ucsbOrganizationRepository.save(organization); |
| 84 | } | |
| 85 | ||
| 86 | /** | |
| 87 | * Delete a UCSB organization. | |
| 88 | * Accessible only to users with the role "ROLE_ADMIN". | |
| 89 | * Accepts both `id` and `orgCode` as parameters. | |
| 90 | */ | |
| 91 | @Operation(summary = "Delete a UCSB Organization") | |
| 92 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 93 | @DeleteMapping("") | |
| 94 | public Object deleteOrganization( | |
| 95 | @RequestParam(required = false) String id, | |
| 96 | @RequestParam(required = false) String orgCode) { | |
| 97 | String identifier = orgCode; | |
| 98 | ||
| 99 | UCSBOrganization organization = ucsbOrganizationRepository.findById(identifier) | |
| 100 |
1
1. lambda$deleteOrganization$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$deleteOrganization$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, identifier)); |
| 101 | ||
| 102 |
1
1. deleteOrganization : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED |
ucsbOrganizationRepository.delete(organization); |
| 103 |
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(identifier)); |
| 104 | } | |
| 105 | ||
| 106 | /** | |
| 107 | * Update a single UCSB organization. | |
| 108 | * Accessible only to users with the role "ROLE_ADMIN". | |
| 109 | * Accepts both `id` and `orgCode` as parameters. | |
| 110 | */ | |
| 111 | @Operation(summary = "Update a single UCSB Organization") | |
| 112 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 113 | @PutMapping("") | |
| 114 | public UCSBOrganization updateOrganization( | |
| 115 | @RequestParam(required = false) String id, | |
| 116 | @RequestParam(required = true) String orgCode, | |
| 117 | @RequestBody @Valid UCSBOrganization incoming) { | |
| 118 | ||
| 119 | String identifier = orgCode; | |
| 120 | ||
| 121 | UCSBOrganization organization = ucsbOrganizationRepository.findById(identifier) | |
| 122 |
1
1. lambda$updateOrganization$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$updateOrganization$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, identifier)); |
| 123 | ||
| 124 | // organization.setOrgCode(incoming.getOrgCode()); | |
| 125 |
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED |
organization.setOrgTranslationShort(incoming.getOrgTranslationShort()); |
| 126 |
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED |
organization.setOrgTranslation(incoming.getOrgTranslation()); |
| 127 |
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED |
organization.setInactive(incoming.getInactive()); |
| 128 | ||
| 129 | ucsbOrganizationRepository.save(organization); | |
| 130 | ||
| 131 |
1
1. updateOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::updateOrganization → KILLED |
return organization; |
| 132 | } | |
| 133 | } | |
Mutations | ||
| 42 |
1.1 |
|
| 59 |
1.1 |
|
| 60 |
1.1 |
|
| 83 |
1.1 |
|
| 100 |
1.1 |
|
| 102 |
1.1 |
|
| 103 |
1.1 |
|
| 122 |
1.1 |
|
| 125 |
1.1 |
|
| 126 |
1.1 |
|
| 127 |
1.1 |
|
| 131 |
1.1 |