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