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