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