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 | ||
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 = "UCSBOrganization") | |
26 | @RequestMapping("/api/ucsborganization") | |
27 | @RestController | |
28 | @Slf4j | |
29 | ||
30 | public class UCSBOrganizationController extends ApiController { | |
31 | ||
32 | @Autowired | |
33 | UCSBOrganizationRepository ucsbOrganizationRepository; | |
34 | ||
35 | /** | |
36 | * THis method returns a list of all ucsborganizations. | |
37 | * @return a list of all ucsborganizations | |
38 | */ | |
39 | @Operation(summary= "List all ucsb organizations") | |
40 | @PreAuthorize("hasRole('ROLE_USER')") | |
41 | @GetMapping("/all") | |
42 | public Iterable<UCSBOrganization> allOrgs() { | |
43 | Iterable<UCSBOrganization> orgs = ucsbOrganizationRepository.findAll(); | |
44 |
1
1. allOrgs : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::allOrgs → KILLED |
return orgs; |
45 | } | |
46 | ||
47 | ||
48 | /** | |
49 | * This method returns a single diningcommons. | |
50 | * @param orgCode orgCode of the diningcommons | |
51 | * @return a single diningcommons | |
52 | */ | |
53 | @Operation(summary= "Get a single organization") | |
54 | @PreAuthorize("hasRole('ROLE_USER')") | |
55 | @GetMapping("") | |
56 | public UCSBOrganization getById( | |
57 | @Parameter(name="orgCode") @RequestParam String orgCode) { | |
58 | UCSBOrganization org = ucsbOrganizationRepository.findById(orgCode) | |
59 |
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)); |
60 | ||
61 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::getById → KILLED |
return org; |
62 | } | |
63 | ||
64 | /** | |
65 | * This method creates a new organization. Accessible only to users with the role "ROLE_ADMIN". | |
66 | * @param orgCode code of the organization | |
67 | * @param orgTranslationShort shortened translation of org name | |
68 | * @param orgTranslation full org name | |
69 | * @param inactive whether the org is active or not | |
70 | * @return the saved organization | |
71 | */ | |
72 | @Operation(summary= "Create a new organization") | |
73 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
74 | @PostMapping("/post") | |
75 | public UCSBOrganization postOrgs( | |
76 | @Parameter(name="orgCode") @RequestParam String orgCode, | |
77 | @Parameter(name="orgTranslationShort") @RequestParam String orgTranslationShort, | |
78 | @Parameter(name="orgTranslation") @RequestParam String orgTranslation, | |
79 | @Parameter(name="inactive") @RequestParam boolean inactive | |
80 | ) | |
81 | { | |
82 | ||
83 | UCSBOrganization org = new UCSBOrganization(); | |
84 |
1
1. postOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED |
org.setOrgCode(orgCode); |
85 |
1
1. postOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED |
org.setOrgTranslationShort(orgTranslationShort); |
86 |
1
1. postOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED |
org.setOrgTranslation(orgTranslation); |
87 |
1
1. postOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED |
org.setInactive(inactive); |
88 | ||
89 | UCSBOrganization savedOrg = ucsbOrganizationRepository.save(org); | |
90 | ||
91 |
1
1. postOrgs : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::postOrgs → KILLED |
return savedOrg; |
92 | } | |
93 | ||
94 | /** | |
95 | * Delete a organization. Accessible only to users with the role "ROLE_ADMIN". | |
96 | * @param orgCode orgCode of the commons | |
97 | * @return a message indiciating the organization was deleted | |
98 | */ | |
99 | @Operation(summary= "Delete a UCSBOrganization") | |
100 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
101 | @DeleteMapping("") | |
102 | public Object deleteOrganization( | |
103 | @Parameter(name="orgCode") @RequestParam String orgCode) { | |
104 | UCSBOrganization org = ucsbOrganizationRepository.findById(orgCode) | |
105 |
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)); |
106 | ||
107 |
1
1. deleteOrganization : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED |
ucsbOrganizationRepository.delete(org); |
108 |
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)); |
109 | } | |
110 | ||
111 | /** | |
112 | * Update a single organization. Accessible only to users with the role "ROLE_ADMIN". | |
113 | * @param orgCode code of the organization | |
114 | * @param incoming the new organization contents | |
115 | * @return the updated organization object | |
116 | */ | |
117 | @Operation(summary= "Update a single organization") | |
118 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
119 | @PutMapping("") | |
120 | public UCSBOrganization updateOrganization( | |
121 | @Parameter(name="orgCode") @RequestParam String orgCode, | |
122 | @RequestBody @Valid UCSBOrganization incoming) { | |
123 | ||
124 | UCSBOrganization org = ucsbOrganizationRepository.findById(orgCode) | |
125 |
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)); |
126 | ||
127 | ||
128 |
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED |
org.setOrgCode(incoming.getOrgCode()); |
129 |
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED |
org.setOrgTranslationShort(incoming.getOrgTranslationShort()); |
130 |
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED |
org.setOrgTranslation(incoming.getOrgTranslation()); |
131 |
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED |
org.setInactive(incoming.getInactive()); |
132 | ||
133 | ucsbOrganizationRepository.save(org); | |
134 | ||
135 |
1
1. updateOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::updateOrganization → KILLED |
return org; |
136 | } | |
137 | ||
138 | } | |
Mutations | ||
44 |
1.1 |
|
59 |
1.1 |
|
61 |
1.1 |
|
84 |
1.1 |
|
85 |
1.1 |
|
86 |
1.1 |
|
87 |
1.1 |
|
91 |
1.1 |
|
105 |
1.1 |
|
107 |
1.1 |
|
108 |
1.1 |
|
125 |
1.1 |
|
128 |
1.1 |
|
129 |
1.1 |
|
130 |
1.1 |
|
131 |
1.1 |
|
135 |
1.1 |