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