| 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 java.util.Map; | |
| 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 | @Tag(name = "UCSBOrganization") | |
| 23 | @RequestMapping("/api/ucsborganizations") | |
| 24 | @RestController | |
| 25 | @Slf4j | |
| 26 | public class UCSBOrganizationController extends ApiController { | |
| 27 | ||
| 28 | @Autowired UCSBOrganizationRepository ucsbOrganizationRepository; | |
| 29 | ||
| 30 | @Operation(summary = "List all UCSB organizations") | |
| 31 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 32 | @GetMapping("/all") | |
| 33 | public Iterable<UCSBOrganization> allOrganizations() { | |
| 34 | Iterable<UCSBOrganization> orgs = ucsbOrganizationRepository.findAll(); | |
| 35 |
1
1. allOrganizations : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::allOrganizations → KILLED |
return orgs; |
| 36 | } | |
| 37 | ||
| 38 | @Operation(summary = "Create a new UCSBOrganization") | |
| 39 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 40 | @PostMapping("/post") | |
| 41 | public UCSBOrganization postOrganization( | |
| 42 | @Parameter(name = "orgCode") @RequestParam String orgCode, | |
| 43 | @Parameter(name = "orgTranslationShort") @RequestParam String orgTranslationShort, | |
| 44 | @Parameter(name = "orgTranslation") @RequestParam String orgTranslation, | |
| 45 | @Parameter(name = "inactive") @RequestParam boolean inactive) { | |
| 46 | ||
| 47 | UCSBOrganization org = new UCSBOrganization(); | |
| 48 |
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED |
org.setOrgCode(orgCode); |
| 49 |
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED |
org.setOrgTranslationShort(orgTranslationShort); |
| 50 |
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED |
org.setOrgTranslation(orgTranslation); |
| 51 |
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED |
org.setInactive(inactive); |
| 52 | ||
| 53 | UCSBOrganization saved = ucsbOrganizationRepository.save(org); | |
| 54 |
1
1. postOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::postOrganization → KILLED |
return saved; |
| 55 | } | |
| 56 | ||
| 57 | // get addtionals | |
| 58 | @Operation(summary = "Get a single organization by orgCode") | |
| 59 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 60 | @GetMapping("") | |
| 61 | public UCSBOrganization getById(@Parameter(name = "orgCode") @RequestParam String orgCode) { | |
| 62 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::getById → KILLED |
return ucsbOrganizationRepository |
| 63 | .findById(orgCode) | |
| 64 |
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)); |
| 65 | } | |
| 66 | ||
| 67 | // put endpoint | |
| 68 | @Operation(summary = "Update a single organization") | |
| 69 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 70 | @PutMapping("") | |
| 71 | public UCSBOrganization updateOrganization( | |
| 72 | @Parameter(name = "orgCode") @RequestParam String orgCode, | |
| 73 | @RequestBody UCSBOrganization incoming) { | |
| 74 | UCSBOrganization org = | |
| 75 | ucsbOrganizationRepository | |
| 76 | .findById(orgCode) | |
| 77 |
1
1. lambda$updateOrganization$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$updateOrganization$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode)); |
| 78 |
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED |
org.setOrgTranslationShort(incoming.getOrgTranslationShort()); |
| 79 |
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED |
org.setOrgTranslation(incoming.getOrgTranslation()); |
| 80 |
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED |
org.setInactive(incoming.getInactive()); |
| 81 | UCSBOrganization saved = ucsbOrganizationRepository.save(org); | |
| 82 |
1
1. updateOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::updateOrganization → KILLED |
return saved; |
| 83 | } | |
| 84 | ||
| 85 | // delete endpoint | |
| 86 | @Operation(summary = "Delete a single organization by orgCode") | |
| 87 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 88 | @DeleteMapping("") | |
| 89 | public Object deleteOrganization(@Parameter(name = "orgCode") @RequestParam String orgCode) { | |
| 90 | ||
| 91 | UCSBOrganization org = | |
| 92 | ucsbOrganizationRepository | |
| 93 | .findById(orgCode) | |
| 94 |
1
1. lambda$deleteOrganization$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$deleteOrganization$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode)); |
| 95 |
1
1. deleteOrganization : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED |
ucsbOrganizationRepository.delete(org); |
| 96 |
1
1. deleteOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::deleteOrganization → KILLED |
return Map.of("message", String.format("UCSBOrganization with id %s deleted", orgCode)); |
| 97 | } | |
| 98 | } | |
Mutations | ||
| 35 |
1.1 |
|
| 48 |
1.1 |
|
| 49 |
1.1 |
|
| 50 |
1.1 |
|
| 51 |
1.1 |
|
| 54 |
1.1 |
|
| 62 |
1.1 |
|
| 64 |
1.1 |
|
| 77 |
1.1 |
|
| 78 |
1.1 |
|
| 79 |
1.1 |
|
| 80 |
1.1 |
|
| 82 |
1.1 |
|
| 94 |
1.1 |
|
| 95 |
1.1 |
|
| 96 |
1.1 |