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