| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.example.entities.UCSBDiningCommons; | |
| 4 | import edu.ucsb.cs156.example.entities.UCSBOrganization; | |
| 5 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 6 | import edu.ucsb.cs156.example.repositories.UCSBDiningCommonsRepository; | |
| 7 | import edu.ucsb.cs156.example.repositories.UCSBOrganizationRepository; | |
| 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 | ||
| 13 | import java.util.Collections; | |
| 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 | @Tag(name = "UCSBOrganizations") | |
| 29 | @RequestMapping("/api/ucsborganizations") | |
| 30 | @RestController | |
| 31 | @Slf4j | |
| 32 | public class UCSBOrganizationController extends ApiController { | |
| 33 | | |
| 34 | @Autowired | |
| 35 | UCSBOrganizationRepository ucsbOrganizationRepository; | |
| 36 | ||
| 37 | // GET request for all organizations in the database | |
| 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 | // GET request for specific organization by org field (id) | |
| 47 | @Operation(summary= "Get a single organization") | |
| 48 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 49 | @GetMapping("") | |
| 50 | public UCSBOrganization getById( | |
| 51 | @Parameter(name="orgField") @RequestParam String orgField) { | |
| 52 | UCSBOrganization organization = ucsbOrganizationRepository.findById(orgField) | |
| 53 |
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)); |
| 54 | ||
| 55 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::getById → KILLED |
return organization; |
| 56 | } | |
| 57 | ||
| 58 | // POST request to add a new organization to the database | |
| 59 | @Operation(summary="Create a new organization") | |
| 60 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 61 | @PostMapping("/post") | |
| 62 | public UCSBOrganization postOrganization( | |
| 63 | @Parameter(name="orgField") @RequestParam String orgField, | |
| 64 | @Parameter(name="orgTranslationShort") @RequestParam String orgTranslationShort, | |
| 65 | @Parameter(name="orgTranslation") @RequestParam String orgTranslation, | |
| 66 | @Parameter(name="inactive") @RequestParam boolean inactive | |
| 67 | ) | |
| 68 | { | |
| 69 | ||
| 70 | UCSBOrganization organization = new UCSBOrganization(); | |
| 71 |
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgField → KILLED |
organization.setOrgField(orgField); |
| 72 |
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED |
organization.setOrgTranslationShort(orgTranslationShort); |
| 73 |
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED |
organization.setOrgTranslation(orgTranslation); |
| 74 |
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED |
organization.setInactive(inactive); |
| 75 | ||
| 76 | UCSBOrganization savedOrganization = ucsbOrganizationRepository.save(organization); | |
| 77 | ||
| 78 |
1
1. postOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::postOrganization → KILLED |
return savedOrganization; |
| 79 | } | |
| 80 | ||
| 81 | // DELETE request to delete a single record by id | |
| 82 | @Operation(summary= "Delete a UCSBOrganization") | |
| 83 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 84 | @DeleteMapping("") | |
| 85 | public Object deleteOrganization( | |
| 86 | @Parameter(name="orgField") @RequestParam String orgField) { | |
| 87 | UCSBOrganization organization = ucsbOrganizationRepository.findById(orgField) | |
| 88 |
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)); |
| 89 | ||
| 90 |
1
1. deleteOrganization : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED |
ucsbOrganizationRepository.delete(organization); |
| 91 |
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)); |
| 92 | } | |
| 93 | ||
| 94 | // PUT request to update single organization record | |
| 95 | @Operation(summary= "Update a single organization") | |
| 96 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 97 | @PutMapping("") | |
| 98 | public UCSBOrganization updateCommons( | |
| 99 | @Parameter(name="orgField") @RequestParam String orgField, | |
| 100 | @RequestBody @Valid UCSBOrganization incoming) { | |
| 101 | ||
| 102 | UCSBOrganization organization = ucsbOrganizationRepository.findById(orgField) | |
| 103 |
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)); |
| 104 | ||
| 105 |
1
1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgField → KILLED |
organization.setOrgField(incoming.getOrgField()); |
| 106 |
1
1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED |
organization.setOrgTranslationShort(incoming.getOrgTranslationShort()); |
| 107 |
1
1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED |
organization.setOrgTranslation(incoming.getOrgTranslation()); |
| 108 |
1
1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED |
organization.setInactive(incoming.getInactive()); |
| 109 | ||
| 110 | ucsbOrganizationRepository.save(organization); | |
| 111 | ||
| 112 |
1
1. updateCommons : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::updateCommons → KILLED |
return organization; |
| 113 | } | |
| 114 | } | |
Mutations | ||
| 43 |
1.1 |
|
| 53 |
1.1 |
|
| 55 |
1.1 |
|
| 71 |
1.1 |
|
| 72 |
1.1 |
|
| 73 |
1.1 |
|
| 74 |
1.1 |
|
| 78 |
1.1 |
|
| 88 |
1.1 |
|
| 90 |
1.1 |
|
| 91 |
1.1 |
|
| 103 |
1.1 |
|
| 105 |
1.1 |
|
| 106 |
1.1 |
|
| 107 |
1.1 |
|
| 108 |
1.1 |
|
| 112 |
1.1 |