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