| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.example.entities.UCSBDate; | |
| 4 | import edu.ucsb.cs156.example.entities.UCSBDiningCommons; | |
| 5 | import edu.ucsb.cs156.example.entities.UCSBOrganization; | |
| 6 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 7 | import edu.ucsb.cs156.example.repositories.UCSBDiningCommonsRepository; | |
| 8 | import edu.ucsb.cs156.example.repositories.UCSBOrganizationRepository; | |
| 9 | import io.swagger.v3.oas.annotations.Operation; | |
| 10 | import io.swagger.v3.oas.annotations.Parameter; | |
| 11 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 12 | import lombok.extern.slf4j.Slf4j; | |
| 13 | ||
| 14 | import org.springframework.beans.factory.annotation.Autowired; | |
| 15 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 16 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 17 | import org.springframework.web.bind.annotation.GetMapping; | |
| 18 | import org.springframework.web.bind.annotation.PostMapping; | |
| 19 | import org.springframework.web.bind.annotation.PutMapping; | |
| 20 | import org.springframework.web.bind.annotation.RequestBody; | |
| 21 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 22 | import org.springframework.web.bind.annotation.RequestParam; | |
| 23 | import org.springframework.web.bind.annotation.RestController; | |
| 24 | ||
| 25 | import jakarta.validation.Valid; | |
| 26 | ||
| 27 | @Tag(name = "UCSBOrganization") | |
| 28 | @RequestMapping("/api/ucsborganization") | |
| 29 | @RestController | |
| 30 | @Slf4j | |
| 31 | public class UCSBOrganizationController extends ApiController { | |
| 32 | ||
| 33 |     @Autowired | |
| 34 |     UCSBOrganizationRepository ucsbOrganizationRepository; | |
| 35 | ||
| 36 |     /** | |
| 37 |      * List all UCSB organizations | |
| 38 |      *  | |
| 39 |      * @return an iterable of UCSBOrganization | |
| 40 |      */ | |
| 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 |     @Operation(summary = "Create a new organization") | |
| 51 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 52 |     @PostMapping("/post") | |
| 53 |     public UCSBOrganization postOrganization( | |
| 54 |             @Parameter(name = "orgCode") @RequestParam String orgCode, | |
| 55 |             @Parameter(name = "orgTranslationShort") @RequestParam String orgTranslationShort, | |
| 56 |             @Parameter(name = "orgTranslation") @RequestParam String orgTranslation, | |
| 57 |             @Parameter(name = "inactive") @RequestParam boolean inactive) { | |
| 58 | ||
| 59 |         UCSBOrganization organization = new UCSBOrganization(); | |
| 60 | 
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED | 
        organization.setOrgCode(orgCode); | 
| 61 | 
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED | 
        organization.setOrgTranslationShort(orgTranslationShort); | 
| 62 | 
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED | 
        organization.setOrgTranslation(orgTranslation); | 
| 63 | 
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED | 
        organization.setInactive(inactive); | 
| 64 | ||
| 65 |         UCSBOrganization savedOrganization = ucsbOrganizationRepository.save(organization); | |
| 66 | ||
| 67 | 
1
1. postOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::postOrganization → KILLED | 
        return savedOrganization; | 
| 68 |     } | |
| 69 | ||
| 70 |     @Operation(summary = "Get a single UCSB organization by id (@Id)") | |
| 71 |     @PreAuthorize("hasRole('ROLE_USER')") | |
| 72 |     @GetMapping("") | |
| 73 |     public UCSBOrganization getById( | |
| 74 |             @Parameter(name = "id") @RequestParam String id) { | |
| 75 |         UCSBOrganization organization = ucsbOrganizationRepository | |
| 76 |                 .findById(id) | |
| 77 | 
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, id)); | 
| 78 | 
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::getById → KILLED | 
        return organization; | 
| 79 |     } | |
| 80 | ||
| 81 |     @Operation(summary = "Update a single organization") | |
| 82 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 83 |     @PutMapping("") | |
| 84 |     public UCSBOrganization updateOrganization( | |
| 85 |             @Parameter(name = "id") @RequestParam String id, | |
| 86 |             @RequestBody @Valid UCSBOrganization incoming) { | |
| 87 | ||
| 88 |         UCSBOrganization organization = ucsbOrganizationRepository.findById(id) | |
| 89 | 
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, id)); | 
| 90 | ||
| 91 |         // Remove this line since we don't want to change the ID | |
| 92 |         // organization.setOrgCode(incoming.getOrgCode()); | |
| 93 | ||
| 94 | 
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED | 
        organization.setOrgTranslationShort(incoming.getOrgTranslationShort()); | 
| 95 | 
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED | 
        organization.setOrgTranslation(incoming.getOrgTranslation()); | 
| 96 | 
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED | 
        organization.setInactive(incoming.getInactive()); | 
| 97 | ||
| 98 |         ucsbOrganizationRepository.save(organization); | |
| 99 | ||
| 100 | 
1
1. updateOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::updateOrganization → KILLED | 
        return organization; | 
| 101 |     } | |
| 102 | ||
| 103 |     @Operation(summary = "Delete a UCSB Organization") | |
| 104 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 105 |     @DeleteMapping("") | |
| 106 |     public Object deleteOrganization( | |
| 107 |             @Parameter(name = "id") @RequestParam String id) { | |
| 108 |         UCSBOrganization organization = ucsbOrganizationRepository.findById(id) | |
| 109 | 
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, id)); | 
| 110 | ||
| 111 | 
1
1. deleteOrganization : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED | 
        ucsbOrganizationRepository.delete(organization); | 
| 112 | 
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(id)); | 
| 113 |     } | |
| 114 | ||
| 115 | } | |
Mutations | ||
| 47 | 
 
 1.1  | 
|
| 60 | 
 
 1.1  | 
|
| 61 | 
 
 1.1  | 
|
| 62 | 
 
 1.1  | 
|
| 63 | 
 
 1.1  | 
|
| 67 | 
 
 1.1  | 
|
| 77 | 
 
 1.1  | 
|
| 78 | 
 
 1.1  | 
|
| 89 | 
 
 1.1  | 
|
| 94 | 
 
 1.1  | 
|
| 95 | 
 
 1.1  | 
|
| 96 | 
 
 1.1  | 
|
| 100 | 
 
 1.1  | 
|
| 109 | 
 
 1.1  | 
|
| 111 | 
 
 1.1  | 
|
| 112 | 
 
 1.1  |