1 | package edu.ucsb.cs156.example.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.example.entities.UCSBOrganizations; | |
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 com.fasterxml.jackson.core.JsonProcessingException; | |
24 | ||
25 | import jakarta.validation.Valid; | |
26 | ||
27 | @Tag(name = "UCSBOrganizations") | |
28 | @RequestMapping("/api/ucsborganizations") | |
29 | @RestController | |
30 | @Slf4j | |
31 | public class UCSBOrganizationController extends ApiController{ | |
32 | @Autowired | |
33 | UCSBOrganizationsRepository ucsbOrganizationsRepository; | |
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<UCSBOrganizations> allOrganizations() { | |
42 | Iterable<UCSBOrganizations> organizations = ucsbOrganizationsRepository.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 organization. | |
48 | * @param orgCode code of the organization | |
49 | * @return a single organization | |
50 | */ | |
51 | @Operation(summary= "Get a single organization") | |
52 | @PreAuthorize("hasRole('ROLE_USER')") | |
53 | @GetMapping("") | |
54 | public UCSBOrganizations getById( | |
55 | @Parameter(name="orgCode") @RequestParam String orgCode) { | |
56 | UCSBOrganizations org = ucsbOrganizationsRepository.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(UCSBOrganizations.class, orgCode)); |
58 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::getById → KILLED |
return org; |
59 | } | |
60 | ||
61 | /** | |
62 | * This method creates a new organiation. Accessible only to users with the role "ROLE_ADMIN". | |
63 | * @param orgCode code of the organization | |
64 | * @param orgTranslationShort short translation of the organization | |
65 | * @param orgTranslation translation of the organization | |
66 | * @param inactive whether the organization is inactive | |
67 | * @return the newly created organization | |
68 | */ | |
69 | @Operation(summary= "Create a new organization") | |
70 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
71 | @PostMapping("/post") | |
72 | public UCSBOrganizations postOrgs( | |
73 | @Parameter(name="orgCode") @RequestParam String orgCode, | |
74 | @Parameter(name="orgTranslationShort") @RequestParam String orgTranslationShort, | |
75 | @Parameter(name="orgTranslation") @RequestParam String orgTranslation, | |
76 | @Parameter(name="inactive") @RequestParam boolean inactive | |
77 | ) | |
78 | { | |
79 | UCSBOrganizations org = new UCSBOrganizations(); | |
80 |
1
1. postOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgCode → KILLED |
org.setOrgCode(orgCode); |
81 |
1
1. postOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslationShort → KILLED |
org.setOrgTranslationShort(orgTranslationShort); |
82 |
1
1. postOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslation → KILLED |
org.setOrgTranslation(orgTranslation); |
83 |
1
1. postOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setInactive → KILLED |
org.setInactive(inactive); |
84 | UCSBOrganizations savedOrg = ucsbOrganizationsRepository.save(org); | |
85 |
1
1. postOrgs : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::postOrgs → KILLED |
return savedOrg; |
86 | } | |
87 | ||
88 | /** | |
89 | * Update a single org. Accessible only to users with the role "ROLE_ADMIN". | |
90 | * @param orgCode the code of the org to update | |
91 | * @param incoming the new org contents | |
92 | * @return the updated org object | |
93 | */ | |
94 | @Operation(summary= "Update a single organization") | |
95 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
96 | @PutMapping("") | |
97 | public UCSBOrganizations updateOrgs( | |
98 | @Parameter(name="orgCode") @RequestParam String orgCode, | |
99 | @RequestBody @Valid UCSBOrganizations incoming) { | |
100 | UCSBOrganizations org = ucsbOrganizationsRepository.findById(orgCode) | |
101 |
1
1. lambda$updateOrgs$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$updateOrgs$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBOrganizations.class, orgCode)); |
102 |
1
1. updateOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgCode → KILLED |
org.setOrgCode(incoming.getOrgCode()); |
103 |
1
1. updateOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslationShort → KILLED |
org.setOrgTranslationShort(incoming.getOrgTranslationShort()); |
104 |
1
1. updateOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslation → KILLED |
org.setOrgTranslation(incoming.getOrgTranslation()); |
105 |
1
1. updateOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setInactive → KILLED |
org.setInactive(incoming.getInactive()); |
106 | ucsbOrganizationsRepository.save(org); | |
107 |
1
1. updateOrgs : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::updateOrgs → KILLED |
return org; |
108 | } | |
109 | ||
110 | /** | |
111 | * Delete an organization. Accessible only to users with the role "ROLE_ADMIN". | |
112 | * @param orgCode code of the organization | |
113 | * @return a message indiciating the organization was deleted | |
114 | */ | |
115 | @Operation(summary= "Delete a UCSBOrganization") | |
116 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
117 | @DeleteMapping("") | |
118 | public Object deleteOrgs( | |
119 | @Parameter(name="orgCode") @RequestParam String orgCode) { | |
120 | UCSBOrganizations org = ucsbOrganizationsRepository.findById(orgCode) | |
121 |
1
1. lambda$deleteOrgs$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$deleteOrgs$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBOrganizations.class, orgCode)); |
122 |
1
1. deleteOrgs : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationsRepository::delete → KILLED |
ucsbOrganizationsRepository.delete(org); |
123 |
1
1. deleteOrgs : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::deleteOrgs → KILLED |
return genericMessage("UCSBOrganizations with id %s deleted".formatted(orgCode)); |
124 | } | |
125 | } | |
Mutations | ||
43 |
1.1 |
|
57 |
1.1 |
|
58 |
1.1 |
|
80 |
1.1 |
|
81 |
1.1 |
|
82 |
1.1 |
|
83 |
1.1 |
|
85 |
1.1 |
|
101 |
1.1 |
|
102 |
1.1 |
|
103 |
1.1 |
|
104 |
1.1 |
|
105 |
1.1 |
|
107 |
1.1 |
|
121 |
1.1 |
|
122 |
1.1 |
|
123 |
1.1 |