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