| 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 ucsborganizations. | |
| 40 |      * @return a list of all ucsborganizations | |
| 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 |      * Get a single UCSBOrganization by its orgCode. | |
| 52 |      * @param orgCode  the primary‐key of the org | |
| 53 |      * @return the matching UCSBOrganization, or 404 if not found | |
| 54 |      */ | |
| 55 |     @Operation(summary = "Get a single organization") | |
| 56 |     @PreAuthorize("hasRole('ROLE_USER')") | |
| 57 |     @GetMapping("")  | |
| 58 |     public UCSBOrganization getById( | |
| 59 |         @Parameter(name="orgCode") @RequestParam String orgCode | |
| 60 |     ) { | |
| 61 |         UCSBOrganization org = ucsbOrganizationRepository.findById(orgCode) | |
| 62 | 
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)); | 
| 63 | 
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::getById → KILLED | 
        return org; | 
| 64 |     } | |
| 65 | ||
| 66 |     /** | |
| 67 |      * Update a single UCSBOrganization. Accessible only to users with the role "ROLE_ADMIN". | |
| 68 |      * @param orgCode       the orgCode (String) – (@Id field) | |
| 69 |      * @param incoming the new organization contents | |
| 70 |      * @return the updated UCSBOrganization | |
| 71 |      */ | |
| 72 |     @Operation(summary = "Update a single organization") | |
| 73 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 74 |     @PutMapping("")  | |
| 75 |     public UCSBOrganization updateOrganization( | |
| 76 |             @Parameter(name="id") @RequestParam(name="id") String orgCode, | |
| 77 |             @RequestBody @Valid UCSBOrganization incoming) { | |
| 78 | ||
| 79 |         UCSBOrganization org = ucsbOrganizationRepository.findById(orgCode) | |
| 80 | 
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)); | 
| 81 | ||
| 82 | 
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED | 
        org.setOrgTranslationShort(incoming.getOrgTranslationShort()); | 
| 83 | 
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED | 
        org.setOrgTranslation(incoming.getOrgTranslation()); | 
| 84 | 
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED | 
        org.setInactive(incoming.getInactive()); | 
| 85 | ||
| 86 |         ucsbOrganizationRepository.save(org); | |
| 87 | 
1
1. updateOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::updateOrganization → KILLED | 
        return org; | 
| 88 |     } | |
| 89 | ||
| 90 |     /** | |
| 91 |      * Creates a new UCSBOrganization.  Accessible only to users with the role "ROLE_ADMIN". | |
| 92 |      * | |
| 93 |      * @param orgCode            the orgCode (String) – this will be the @Id field | |
| 94 |      * @param orgTranslationShort a short name/abbreviation | |
| 95 |      * @param orgTranslation     the full name | |
| 96 |      * @param inactive           whether the org is inactive | |
| 97 |      * @return the saved UCSBOrganization | |
| 98 |      */ | |
| 99 |     @Operation(summary = "Create a new organization") | |
| 100 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 101 |     @PostMapping("/post") | |
| 102 |     public UCSBOrganization postOrganization( | |
| 103 |         @Parameter(name="orgCode") @RequestParam String orgCode, | |
| 104 |         @Parameter(name="orgTranslationShort") @RequestParam String orgTranslationShort, | |
| 105 |         @Parameter(name="orgTranslation") @RequestParam String orgTranslation, | |
| 106 |         @Parameter(name="inactive") @RequestParam boolean inactive | |
| 107 |     ) { | |
| 108 | ||
| 109 |         UCSBOrganization org = new UCSBOrganization(orgCode, orgTranslationShort, orgTranslation, inactive); | |
| 110 | ||
| 111 |         UCSBOrganization savedOrg = ucsbOrganizationRepository.save(org); | |
| 112 | 
1
1. postOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::postOrganization → KILLED | 
        return savedOrg; | 
| 113 |     } | |
| 114 | ||
| 115 |     /** | |
| 116 |      * Delete a UCSBOrganization. Accessible only to users with the role "ROLE_ADMIN". | |
| 117 |      * @param orgCode the orgCode (String) (@Id field) | |
| 118 |      * @return a message indicating the organization was deleted | |
| 119 |      */ | |
| 120 |     @Operation(summary = "Delete a single organization") | |
| 121 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 122 |     @DeleteMapping("") | |
| 123 |     public Object deleteOrganization( | |
| 124 |         @Parameter(name="id") @RequestParam(name="id") String orgCode | |
| 125 |     ) { | |
| 126 |         UCSBOrganization org = ucsbOrganizationRepository.findById(orgCode) | |
| 127 | 
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)); | 
| 128 | ||
| 129 | 
1
1. deleteOrganization : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED | 
        ucsbOrganizationRepository.delete(org); | 
| 130 | 
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)); | 
| 131 |     } | |
| 132 | } | |
Mutations | ||
| 47 | 
 
 1.1  | 
|
| 62 | 
 
 1.1  | 
|
| 63 | 
 
 1.1  | 
|
| 80 | 
 
 1.1  | 
|
| 82 | 
 
 1.1  | 
|
| 83 | 
 
 1.1  | 
|
| 84 | 
 
 1.1  | 
|
| 87 | 
 
 1.1  | 
|
| 112 | 
 
 1.1  | 
|
| 127 | 
 
 1.1  | 
|
| 129 | 
 
 1.1  | 
|
| 130 | 
 
 1.1  |