| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.example.controllers.ApiController; | |
| 4 | import edu.ucsb.cs156.example.entities.UCSBOrganization; | |
| 5 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 6 | import edu.ucsb.cs156.example.repositories.UCSBOrganizationRepository; | |
| 7 | ||
| 8 | import io.swagger.v3.oas.annotations.Operation; | |
| 9 | import io.swagger.v3.oas.annotations.Parameter; | |
| 10 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 11 | import lombok.extern.slf4j.Slf4j; | |
| 12 | import edu.ucsb.cs156.example.entities.UCSBOrganization; | |
| 13 | import edu.ucsb.cs156.example.repositories.UCSBOrganizationRepository; | |
| 14 | ||
| 15 | import org.springframework.beans.factory.annotation.Autowired; | |
| 16 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 17 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 18 | import org.springframework.web.bind.annotation.GetMapping; | |
| 19 | import org.springframework.web.bind.annotation.PostMapping; | |
| 20 | import org.springframework.web.bind.annotation.PutMapping; | |
| 21 | import org.springframework.web.bind.annotation.RequestBody; | |
| 22 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 23 | import org.springframework.web.bind.annotation.RequestParam; | |
| 24 | import org.springframework.web.bind.annotation.RestController; | |
| 25 | ||
| 26 | import jakarta.validation.Valid; | |
| 27 | ||
| 28 | /** | |
| 29 |  * This is a REST controller for UCSBOrganization | |
| 30 |  */ | |
| 31 | ||
| 32 | @Tag(name = "UCSBOrganization") | |
| 33 | @RequestMapping("/api/ucsborganization") | |
| 34 | @RestController | |
| 35 | @Slf4j | |
| 36 | public class UCSBOrganizationController extends ApiController{ | |
| 37 |     @Autowired | |
| 38 |     UCSBOrganizationRepository ucsbOrganizationRepository; | |
| 39 | ||
| 40 |     /** | |
| 41 |      * THis method returns a list of all ucsbdorganization. | |
| 42 |      * @return a list of all ucsborganizations | |
| 43 |      */ | |
| 44 |     @Operation(summary= "List all ucsb organizations") | |
| 45 |     @PreAuthorize("hasRole('ROLE_USER')") | |
| 46 |     @GetMapping("/all") | |
| 47 |     public Iterable<UCSBOrganization> allOrganizations() { | |
| 48 |         Iterable<UCSBOrganization> organization = ucsbOrganizationRepository.findAll(); | |
| 49 | 
1
1. allOrganizations : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::allOrganizations → KILLED | 
        return organization; | 
| 50 |     } | |
| 51 | ||
| 52 |     /** | |
| 53 |      * This method returns a single organization. | |
| 54 |      * @param orgCode code of the organization | |
| 55 |      * @return a single organization | |
| 56 |      */ | |
| 57 |     @Operation(summary= "Get a single organization") | |
| 58 |     @PreAuthorize("hasRole('ROLE_USER')") | |
| 59 |     @GetMapping("") | |
| 60 |     public UCSBOrganization getById( | |
| 61 |             @Parameter(name="orgCode") @RequestParam String orgCode) { | |
| 62 |         UCSBOrganization organization = ucsbOrganizationRepository.findById(orgCode) | |
| 63 | 
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)); | 
| 64 | ||
| 65 | 
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::getById → KILLED | 
        return organization; | 
| 66 |     } | |
| 67 | ||
| 68 |     /** | |
| 69 |      * This method creates a new organization. Accessible only to users with the role "ROLE_ADMIN". | |
| 70 |      * @param orgCode orgCode of the organization | |
| 71 |      * @param orgTranslationShort the shortened name of the organization | |
| 72 |      * @param orgTranslation full name of the organization | |
| 73 |      * @param inactive whether or not organization is active | |
| 74 |      * @return the save organization | |
| 75 |      */ | |
| 76 |     @Operation(summary= "Create a new organization") | |
| 77 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 78 |     @PostMapping("/post") | |
| 79 |     public UCSBOrganization postOrganization( | |
| 80 |         @Parameter(name="orgCode") @RequestParam String orgCode, | |
| 81 |         @Parameter(name="orgTranslationShort") @RequestParam String orgTranslationShort, | |
| 82 |         @Parameter(name="orgTranslation") @RequestParam String orgTranslation, | |
| 83 |         @Parameter(name="inactive") @RequestParam boolean inactive | |
| 84 |         ) | |
| 85 |         { | |
| 86 | ||
| 87 |         UCSBOrganization organization = new UCSBOrganization(); | |
| 88 | 
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED | 
        organization.setOrgCode(orgCode); | 
| 89 | 
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED | 
        organization.setOrgTranslationShort(orgTranslationShort); | 
| 90 | 
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED | 
        organization.setOrgTranslation(orgTranslation); | 
| 91 | 
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED | 
        organization.setInactive(inactive); | 
| 92 | ||
| 93 |         UCSBOrganization savedOrganization = ucsbOrganizationRepository.save(organization); | |
| 94 | ||
| 95 | 
1
1. postOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::postOrganization → KILLED | 
        return savedOrganization; | 
| 96 |     } | |
| 97 | ||
| 98 |     /** | |
| 99 |      * Update a single organization. Accessible only to users with the role "ROLE_ADMIN". | |
| 100 |      * @param orgCode code of the organization | |
| 101 |      * @param incoming the new organization contents | |
| 102 |      * @return the updated organization object | |
| 103 |      */ | |
| 104 |     @Operation(summary= "Update a single organization") | |
| 105 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 106 |     @PutMapping("") | |
| 107 |     public UCSBOrganization updateOrganization( | |
| 108 |             @Parameter(name="orgCode") @RequestParam String orgCode, | |
| 109 |             @RequestBody @Valid UCSBOrganization incoming) { | |
| 110 | ||
| 111 |         UCSBOrganization organization = ucsbOrganizationRepository.findById(orgCode) | |
| 112 | 
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)); | 
| 113 | ||
| 114 | ||
| 115 | 
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED | 
        organization.setOrgCode(incoming.getOrgCode()); | 
| 116 | 
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED | 
        organization.setOrgTranslationShort(incoming.getOrgTranslationShort()); | 
| 117 | 
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED | 
        organization.setOrgTranslation(incoming.getOrgTranslation()); | 
| 118 | 
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED | 
        organization.setInactive(incoming.getInactive()); | 
| 119 | ||
| 120 |         ucsbOrganizationRepository.save(organization); | |
| 121 | ||
| 122 | 
1
1. updateOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::updateOrganization → KILLED | 
        return organization; | 
| 123 |     } | |
| 124 | ||
| 125 |     @Operation(summary= "Delete a UCSBOrganization") | |
| 126 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 127 |     @DeleteMapping("") | |
| 128 |     public Object deleteOrganization( | |
| 129 |             @Parameter(name="orgCode") @RequestParam String orgCode) { | |
| 130 |         UCSBOrganization organization = ucsbOrganizationRepository.findById(orgCode) | |
| 131 | 
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)); | 
| 132 | ||
| 133 | 
1
1. deleteOrganization : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED | 
        ucsbOrganizationRepository.delete(organization); | 
| 134 | 
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)); | 
| 135 |     } | |
| 136 | ||
| 137 | } | |
Mutations | ||
| 49 | 
 
 1.1  | 
|
| 63 | 
 
 1.1  | 
|
| 65 | 
 
 1.1  | 
|
| 88 | 
 
 1.1  | 
|
| 89 | 
 
 1.1  | 
|
| 90 | 
 
 1.1  | 
|
| 91 | 
 
 1.1  | 
|
| 95 | 
 
 1.1  | 
|
| 112 | 
 
 1.1  | 
|
| 115 | 
 
 1.1  | 
|
| 116 | 
 
 1.1  | 
|
| 117 | 
 
 1.1  | 
|
| 118 | 
 
 1.1  | 
|
| 122 | 
 
 1.1  | 
|
| 131 | 
 
 1.1  | 
|
| 133 | 
 
 1.1  | 
|
| 134 | 
 
 1.1  |