| 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 jakarta.validation.Valid; | |
| 10 | import lombok.extern.slf4j.Slf4j; | |
| 11 | ||
| 12 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 13 | ||
| 14 | import org.springframework.beans.factory.annotation.Autowired; | |
| 15 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 16 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 17 | import org.springframework.web.bind.annotation.GetMapping; | |
| 18 | import org.springframework.web.bind.annotation.PostMapping; | |
| 19 | import org.springframework.web.bind.annotation.PutMapping; | |
| 20 | import org.springframework.web.bind.annotation.RequestBody; | |
| 21 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 22 | import org.springframework.web.bind.annotation.RequestParam; | |
| 23 | import org.springframework.web.bind.annotation.RestController; | |
| 24 | ||
| 25 | /** | |
| 26 | * This is a REST controller for UCSBOrganizations. | |
| 27 | */ | |
| 28 | @Tag(name = "UCSBOrganizations") | |
| 29 | @RequestMapping("/api/ucsborganizations") | |
| 30 | @RestController | |
| 31 | @Slf4j | |
| 32 | public class UCSBOrganizationsController extends ApiController { | |
| 33 | ||
| 34 | @Autowired | |
| 35 | UCSBOrganizationsRepository ucsbOrganizationsRepository; | |
| 36 | ||
| 37 | /** | |
| 38 | * List all UCSB organizations | |
| 39 | * | |
| 40 | * @return an iterable of UCSBOrganizations | |
| 41 | */ | |
| 42 | @Operation(summary = "List all UCSB organizations") | |
| 43 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 44 | @GetMapping("/all") | |
| 45 | public Iterable<UCSBOrganizations> allUCSBOrganizations() { | |
| 46 | Iterable<UCSBOrganizations> organizations = ucsbOrganizationsRepository.findAll(); | |
| 47 |
1
1. allUCSBOrganizations : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::allUCSBOrganizations → KILLED |
return organizations; |
| 48 | } | |
| 49 | ||
| 50 | /** | |
| 51 | * Create a new organization | |
| 52 | * | |
| 53 | * @param orgCode organization code | |
| 54 | * @param orgTranslationShort organization's short translation | |
| 55 | * @param orgTranslation organizations full name | |
| 56 | * @param inactive Is the organization active or inactive? | |
| 57 | * @return the saved organization | |
| 58 | */ | |
| 59 | @Operation(summary = "Create a new organization") | |
| 60 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 61 | @PostMapping("/post") | |
| 62 | public UCSBOrganizations postUCSBOrganization( | |
| 63 | @Parameter(name = "orgCode") @RequestParam String orgCode, | |
| 64 | @Parameter(name = "orgTranslationShort") @RequestParam String orgTranslationShort, | |
| 65 | @Parameter(name = "orgTranslation") @RequestParam String orgTranslation, | |
| 66 | @Parameter(name = "inactive") @RequestParam boolean inactive) | |
| 67 | throws JsonProcessingException { | |
| 68 | ||
| 69 | UCSBOrganizations org = new UCSBOrganizations(); | |
| 70 |
1
1. postUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgCode → KILLED |
org.setOrgCode(orgCode); |
| 71 |
1
1. postUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslationShort → KILLED |
org.setOrgTranslationShort(orgTranslationShort); |
| 72 |
1
1. postUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslation → KILLED |
org.setOrgTranslation(orgTranslation); |
| 73 |
1
1. postUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setInactive → KILLED |
org.setInactive(Boolean.valueOf(inactive)); |
| 74 | UCSBOrganizations savedOrg = ucsbOrganizationsRepository.save(org); | |
| 75 | ||
| 76 |
1
1. postUCSBOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::postUCSBOrganization → KILLED |
return savedOrg; |
| 77 | } | |
| 78 | /** | |
| 79 | * Get a single organization by id | |
| 80 | * | |
| 81 | * @param id the id of the organization | |
| 82 | * @return a UCSBOrganization | |
| 83 | */ | |
| 84 | @Operation(summary= "Get a single organization") | |
| 85 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 86 | @GetMapping("") | |
| 87 | public UCSBOrganizations getByCode( | |
| 88 | @Parameter(name="id") @RequestParam Long id) { | |
| 89 | UCSBOrganizations ucsbOrganization = ucsbOrganizationsRepository.findById(id) | |
| 90 |
1
1. lambda$getByCode$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::lambda$getByCode$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBOrganizations.class, id)); |
| 91 | ||
| 92 |
1
1. getByCode : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::getByCode → KILLED |
return ucsbOrganization; |
| 93 | } | |
| 94 | ||
| 95 | /** | |
| 96 | * Update a single organization | |
| 97 | * | |
| 98 | * @param id id of the organization to update | |
| 99 | * @param incoming the new organization | |
| 100 | * @return the updated organization object | |
| 101 | */ | |
| 102 | @Operation(summary= "Update a organization date") | |
| 103 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 104 | @PutMapping("") | |
| 105 | public UCSBOrganizations updateUCSBOrganization( | |
| 106 | @Parameter(name="id") @RequestParam Long id, | |
| 107 | @RequestBody @Valid UCSBOrganizations incoming) { | |
| 108 | ||
| 109 | UCSBOrganizations ucsbOrganizations = ucsbOrganizationsRepository.findById(id) | |
| 110 |
1
1. lambda$updateUCSBOrganization$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::lambda$updateUCSBOrganization$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBOrganizations.class, id)); |
| 111 | ||
| 112 |
1
1. updateUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgCode → KILLED |
ucsbOrganizations.setOrgCode(incoming.getOrgCode()); |
| 113 |
1
1. updateUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslation → KILLED |
ucsbOrganizations.setOrgTranslation(incoming.getOrgTranslation()); |
| 114 |
1
1. updateUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslationShort → KILLED |
ucsbOrganizations.setOrgTranslationShort(incoming.getOrgTranslationShort()); |
| 115 |
1
1. updateUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setInactive → KILLED |
ucsbOrganizations.setInactive(incoming.getInactive()); |
| 116 | ||
| 117 | ucsbOrganizationsRepository.save(ucsbOrganizations); | |
| 118 | | |
| 119 |
1
1. updateUCSBOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::updateUCSBOrganization → KILLED |
return ucsbOrganizations; |
| 120 | } | |
| 121 | /** | |
| 122 | * Delete a UCSBOrganization | |
| 123 | * | |
| 124 | * @param id the id of the organization to delete | |
| 125 | * @return a message indicating the organization was deleted | |
| 126 | */ | |
| 127 | @Operation(summary= "Delete a UCSBOrganization") | |
| 128 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 129 | @DeleteMapping("") | |
| 130 | public Object deleteUCSBOrganization( | |
| 131 | @Parameter(name="id") @RequestParam Long id) { | |
| 132 | UCSBOrganizations ucsbOrganizations = ucsbOrganizationsRepository.findById(id) | |
| 133 |
1
1. lambda$deleteUCSBOrganization$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::lambda$deleteUCSBOrganization$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBOrganizations.class, id)); |
| 134 | ||
| 135 |
1
1. deleteUCSBOrganization : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationsRepository::delete → KILLED |
ucsbOrganizationsRepository.delete(ucsbOrganizations); |
| 136 |
1
1. deleteUCSBOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::deleteUCSBOrganization → KILLED |
return genericMessage("UCSBOrganization with id %s deleted".formatted(id)); |
| 137 | } | |
| 138 | ||
| 139 | ||
| 140 | } | |
Mutations | ||
| 47 |
1.1 |
|
| 70 |
1.1 |
|
| 71 |
1.1 |
|
| 72 |
1.1 |
|
| 73 |
1.1 |
|
| 76 |
1.1 |
|
| 90 |
1.1 |
|
| 92 |
1.1 |
|
| 110 |
1.1 |
|
| 112 |
1.1 |
|
| 113 |
1.1 |
|
| 114 |
1.1 |
|
| 115 |
1.1 |
|
| 119 |
1.1 |
|
| 133 |
1.1 |
|
| 135 |
1.1 |
|
| 136 |
1.1 |