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 = "UCSBOrganizations") | |
26 | @RequestMapping("/api/ucsborganizations") | |
27 | @RestController | |
28 | @Slf4j | |
29 | public class UCSBOrganizationController extends ApiController { | |
30 | @Autowired | |
31 | UCSBOrganizationRepository ucsbOrganizationRepository; | |
32 | ||
33 | /** | |
34 | * This method returns a list of all ucsborganizations. | |
35 | * @return a list of all ucsborganizations | |
36 | */ | |
37 | @Operation(summary= "List all ucsb organizations") | |
38 | @PreAuthorize("hasRole('ROLE_USER')") | |
39 | @GetMapping("/all") | |
40 | public Iterable<UCSBOrganization> allOrganizations() { | |
41 | Iterable<UCSBOrganization> orgs = ucsbOrganizationRepository.findAll(); | |
42 |
1
1. allOrganizations : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::allOrganizations → KILLED |
return orgs; |
43 | } | |
44 | ||
45 | /** | |
46 | * This method returns a single organization. | |
47 | * @param orgCode code of the organization | |
48 | * @return a single organization | |
49 | */ | |
50 | @Operation(summary= "Get a single organization") | |
51 | @PreAuthorize("hasRole('ROLE_USER')") | |
52 | @GetMapping("") | |
53 | public UCSBOrganization getById( | |
54 | @Parameter(name="orgCode") @RequestParam String orgCode) { | |
55 | UCSBOrganization org = ucsbOrganizationRepository.findById(orgCode) | |
56 |
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)); |
57 | ||
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 UCSBOrganization 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 | ||
80 | UCSBOrganization org = new UCSBOrganization(); | |
81 |
1
1. postOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED |
org.setOrgCode(orgCode); |
82 |
1
1. postOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED |
org.setOrgTranslationShort(orgTranslationShort); |
83 |
1
1. postOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED |
org.setOrgTranslation(orgTranslation); |
84 |
1
1. postOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED |
org.setInactive(inactive); |
85 | ||
86 | UCSBOrganization savedOrg = ucsbOrganizationRepository.save(org); | |
87 | ||
88 |
1
1. postOrgs : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::postOrgs → KILLED |
return savedOrg; |
89 | } | |
90 | ||
91 | /** | |
92 | * Delete an organization. Accessible only to users with the role "ROLE_ADMIN". | |
93 | * @param orgCode code of the organization | |
94 | * @return a message indiciating the organization was deleted | |
95 | */ | |
96 | @Operation(summary= "Delete a UCSBOrganization") | |
97 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
98 | @DeleteMapping("") | |
99 | public Object deleteOrgs( | |
100 | @Parameter(name="orgCode") @RequestParam String orgCode) { | |
101 | UCSBOrganization orgs = ucsbOrganizationRepository.findById(orgCode) | |
102 |
1
1. lambda$deleteOrgs$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$deleteOrgs$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode)); |
103 | ||
104 |
1
1. deleteOrgs : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED |
ucsbOrganizationRepository.delete(orgs); |
105 |
1
1. deleteOrgs : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::deleteOrgs → KILLED |
return genericMessage("UCSBOrganization with id %s deleted".formatted(orgCode)); |
106 | } | |
107 | ||
108 | /** | |
109 | * Update a single org. Accessible only to users with the role "ROLE_ADMIN". | |
110 | * @param orgCode the code of the org to update | |
111 | * @param incoming the new org contents | |
112 | * @return the updated org object | |
113 | */ | |
114 | @Operation(summary= "Update a single organization") | |
115 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
116 | @PutMapping("") | |
117 | public UCSBOrganization updateOrgs( | |
118 | @Parameter(name="orgCode") @RequestParam String orgCode, | |
119 | @RequestBody @Valid UCSBOrganization incoming) { | |
120 | ||
121 | UCSBOrganization orgs = ucsbOrganizationRepository.findById(orgCode) | |
122 |
1
1. lambda$updateOrgs$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$updateOrgs$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode)); |
123 | ||
124 |
1
1. updateOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED |
orgs.setOrgCode(incoming.getOrgCode()); |
125 |
1
1. updateOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED |
orgs.setOrgTranslationShort(incoming.getOrgTranslationShort()); |
126 |
1
1. updateOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED |
orgs.setOrgTranslation(incoming.getOrgTranslation()); |
127 |
1
1. updateOrgs : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED |
orgs.setInactive(incoming.getInactive()); |
128 | ||
129 | ucsbOrganizationRepository.save(orgs); | |
130 | ||
131 |
1
1. updateOrgs : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::updateOrgs → KILLED |
return orgs; |
132 | } | |
133 | } | |
Mutations | ||
42 |
1.1 |
|
56 |
1.1 |
|
58 |
1.1 |
|
81 |
1.1 |
|
82 |
1.1 |
|
83 |
1.1 |
|
84 |
1.1 |
|
88 |
1.1 |
|
102 |
1.1 |
|
104 |
1.1 |
|
105 |
1.1 |
|
122 |
1.1 |
|
124 |
1.1 |
|
125 |
1.1 |
|
126 |
1.1 |
|
127 |
1.1 |
|
131 |
1.1 |