| 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 | import io.swagger.v3.oas.annotations.Operation; | |
| 7 | import io.swagger.v3.oas.annotations.Parameter; | |
| 8 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 9 | import lombok.extern.slf4j.Slf4j; | |
| 10 | ||
| 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 |     UCSBOrganizationRepository ucsbOrganizationRepository; | |
| 33 | ||
| 34 |     // GET request for all organizations in the database | |
| 35 |     @Operation(summary= "List all ucsb organizations") | |
| 36 |     @PreAuthorize("hasRole('ROLE_USER')") | |
| 37 |     @GetMapping("/all") | |
| 38 |     public Iterable<UCSBOrganization> allOrganizations() { | |
| 39 |         Iterable<UCSBOrganization> organizations = ucsbOrganizationRepository.findAll(); | |
| 40 | 
1
1. allOrganizations : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::allOrganizations → KILLED | 
        return organizations; | 
| 41 |     } | |
| 42 | ||
| 43 |     // GET request for specific organization by org field (id) | |
| 44 |     @Operation(summary= "Get a single organization") | |
| 45 |     @PreAuthorize("hasRole('ROLE_USER')") | |
| 46 |     @GetMapping("") | |
| 47 |     public UCSBOrganization getById( | |
| 48 |             @Parameter(name="orgField") @RequestParam String orgField) { | |
| 49 |         UCSBOrganization organization = ucsbOrganizationRepository.findById(orgField) | |
| 50 | 
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, orgField)); | 
| 51 | ||
| 52 | 
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::getById → KILLED | 
        return organization; | 
| 53 |     } | |
| 54 | ||
| 55 |     // POST request to add a new organization to the database | |
| 56 |     @Operation(summary="Create a new organization") | |
| 57 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 58 |     @PostMapping("/post") | |
| 59 |     public UCSBOrganization postOrganization( | |
| 60 |         @Parameter(name="orgField") @RequestParam String orgField, | |
| 61 |         @Parameter(name="orgTranslationShort") @RequestParam String orgTranslationShort, | |
| 62 |         @Parameter(name="orgTranslation") @RequestParam String orgTranslation, | |
| 63 |         @Parameter(name="inactive") @RequestParam boolean inactive | |
| 64 |         ) | |
| 65 |         { | |
| 66 | ||
| 67 |         UCSBOrganization organization = new UCSBOrganization(); | |
| 68 | 
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgField → KILLED | 
        organization.setOrgField(orgField); | 
| 69 | 
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED | 
        organization.setOrgTranslationShort(orgTranslationShort); | 
| 70 | 
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED | 
        organization.setOrgTranslation(orgTranslation); | 
| 71 | 
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED | 
        organization.setInactive(inactive); | 
| 72 | ||
| 73 |         UCSBOrganization savedOrganization = ucsbOrganizationRepository.save(organization); | |
| 74 | ||
| 75 | 
1
1. postOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::postOrganization → KILLED | 
        return savedOrganization; | 
| 76 |     } | |
| 77 | ||
| 78 |     // DELETE request to delete a single record by id | |
| 79 |     @Operation(summary= "Delete a UCSBOrganization") | |
| 80 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 81 |     @DeleteMapping("") | |
| 82 |     public Object deleteOrganization( | |
| 83 |             @Parameter(name="orgField") @RequestParam String orgField) { | |
| 84 |         UCSBOrganization organization = ucsbOrganizationRepository.findById(orgField) | |
| 85 | 
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, orgField)); | 
| 86 | ||
| 87 | 
1
1. deleteOrganization : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED | 
        ucsbOrganizationRepository.delete(organization); | 
| 88 | 
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(orgField)); | 
| 89 |     } | |
| 90 | ||
| 91 |     // PUT request to update single organization record | |
| 92 |     @Operation(summary= "Update a single organization") | |
| 93 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 94 |     @PutMapping("") | |
| 95 |     public UCSBOrganization updateCommons( | |
| 96 |             @Parameter(name="orgField") @RequestParam String orgField, | |
| 97 |             @RequestBody @Valid UCSBOrganization incoming) { | |
| 98 | ||
| 99 |         UCSBOrganization organization = ucsbOrganizationRepository.findById(orgField) | |
| 100 | 
1
1. lambda$updateCommons$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$updateCommons$2 → KILLED | 
                .orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgField)); | 
| 101 | ||
| 102 | 
1
1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgField → KILLED | 
        organization.setOrgField(incoming.getOrgField()); | 
| 103 | 
1
1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED | 
        organization.setOrgTranslationShort(incoming.getOrgTranslationShort()); | 
| 104 | 
1
1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED | 
        organization.setOrgTranslation(incoming.getOrgTranslation()); | 
| 105 | 
1
1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED | 
        organization.setInactive(incoming.getInactive()); | 
| 106 | ||
| 107 |         ucsbOrganizationRepository.save(organization); | |
| 108 | ||
| 109 | 
1
1. updateCommons : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::updateCommons → KILLED | 
        return organization; | 
| 110 |     } | |
| 111 | } | |
Mutations | ||
| 40 | 
 
 1.1  | 
|
| 50 | 
 
 1.1  | 
|
| 52 | 
 
 1.1  | 
|
| 68 | 
 
 1.1  | 
|
| 69 | 
 
 1.1  | 
|
| 70 | 
 
 1.1  | 
|
| 71 | 
 
 1.1  | 
|
| 75 | 
 
 1.1  | 
|
| 85 | 
 
 1.1  | 
|
| 87 | 
 
 1.1  | 
|
| 88 | 
 
 1.1  | 
|
| 100 | 
 
 1.1  | 
|
| 102 | 
 
 1.1  | 
|
| 103 | 
 
 1.1  | 
|
| 104 | 
 
 1.1  | 
|
| 105 | 
 
 1.1  | 
|
| 109 | 
 
 1.1  |