1 | package edu.ucsb.cs156.example.controllers; | |
2 | ||
3 | ||
4 | import edu.ucsb.cs156.example.entities.UCSBDate; | |
5 | import edu.ucsb.cs156.example.entities.UCSBDiningCommons; | |
6 | import edu.ucsb.cs156.example.entities.UCSBOrganization; | |
7 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
8 | import edu.ucsb.cs156.example.repositories.UCSBDateRepository; | |
9 | import edu.ucsb.cs156.example.repositories.UCSBDiningCommonsRepository; | |
10 | import edu.ucsb.cs156.example.repositories.UCSBOrganizationRepository; | |
11 | import io.swagger.v3.oas.annotations.Operation; | |
12 | import io.swagger.v3.oas.annotations.Parameter; | |
13 | import io.swagger.v3.oas.annotations.tags.Tag; | |
14 | import lombok.extern.slf4j.Slf4j; | |
15 | ||
16 | ||
17 | import com.fasterxml.jackson.core.JsonProcessingException; | |
18 | ||
19 | ||
20 | import org.springframework.beans.factory.annotation.Autowired; | |
21 | import org.springframework.format.annotation.DateTimeFormat; | |
22 | import org.springframework.security.access.prepost.PreAuthorize; | |
23 | import org.springframework.web.bind.annotation.DeleteMapping; | |
24 | import org.springframework.web.bind.annotation.GetMapping; | |
25 | import org.springframework.web.bind.annotation.PostMapping; | |
26 | import org.springframework.web.bind.annotation.PutMapping; | |
27 | import org.springframework.web.bind.annotation.RequestBody; | |
28 | import org.springframework.web.bind.annotation.RequestMapping; | |
29 | import org.springframework.web.bind.annotation.RequestParam; | |
30 | import org.springframework.web.bind.annotation.RestController; | |
31 | ||
32 | ||
33 | import jakarta.validation.Valid; | |
34 | ||
35 | ||
36 | import java.time.LocalDateTime; | |
37 | ||
38 | ||
39 | /** | |
40 | * This is a REST controller for UCSBOrganizations | |
41 | */ | |
42 | ||
43 | ||
44 | @Tag(name = "UCSBOrganizations") | |
45 | @RequestMapping("/api/ucsborganizations") | |
46 | @RestController | |
47 | @Slf4j | |
48 | ||
49 | ||
50 | public class UCSBOrganizationsController extends ApiController{ | |
51 | ||
52 | ||
53 | @Autowired | |
54 | UCSBOrganizationRepository ucsborganizationRepository; | |
55 | ||
56 | ||
57 | /** | |
58 | * THis method returns a list of all ucsborganizations. | |
59 | * @return a list of all ucsborganizations | |
60 | */ | |
61 | @Operation(summary= "List all ucsb organizations") | |
62 | @PreAuthorize("hasRole('ROLE_USER')") | |
63 | @GetMapping("/all") | |
64 | public Iterable<UCSBOrganization> allOrganizations() { | |
65 | Iterable<UCSBOrganization> organizations = ucsborganizationRepository.findAll(); | |
66 |
1
1. allOrganizations : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::allOrganizations → KILLED |
return organizations; |
67 | } | |
68 | ||
69 | ||
70 | /** | |
71 | * This method creates a new ucsborganizations. Accessible only to users with the role "ROLE_ADMIN". | |
72 | * @param orgCode the ucsborganizations code | |
73 | * @param orgTranslationShort the ucsborganizations translation short | |
74 | * @param orgTranslation the ucsb organizations translation | |
75 | * @param inactive whether or not the ucsb organizations is active | |
76 | * @return the save ucsborganizations | |
77 | */ | |
78 | @Operation(summary= "Create a new organizations") | |
79 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
80 | @PostMapping("/post") | |
81 | public UCSBOrganization postOrganizationss( | |
82 | @Parameter(name="orgCode") @RequestParam String orgCode, | |
83 | @Parameter(name="orgTranslationShort") @RequestParam String orgTranslationShort, | |
84 | @Parameter(name="orgTranslation") @RequestParam String orgTranslation, | |
85 | @Parameter(name="inactive") @RequestParam boolean inactive | |
86 | ) | |
87 | { | |
88 | ||
89 | ||
90 | UCSBOrganization organizations = new UCSBOrganization(); | |
91 |
1
1. postOrganizationss : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED |
organizations.setOrgCode(orgCode); |
92 |
1
1. postOrganizationss : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED |
organizations.setOrgTranslationShort(orgTranslationShort); |
93 |
1
1. postOrganizationss : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED |
organizations.setOrgTranslation(orgTranslation); |
94 |
1
1. postOrganizationss : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED |
organizations.setInactive(inactive); |
95 | ||
96 | ||
97 | UCSBOrganization savedOrganizations = ucsborganizationRepository.save(organizations); | |
98 | ||
99 | ||
100 |
1
1. postOrganizationss : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::postOrganizationss → KILLED |
return savedOrganizations; |
101 | } | |
102 | @Operation(summary = "Get a single UCSBOrganization by orgCode") | |
103 | @PreAuthorize("hasRole('ROLE_USER')") | |
104 | @GetMapping("") | |
105 | public UCSBOrganization getById( | |
106 | @Parameter(name="orgCode") @RequestParam String orgCode) { | |
107 | | |
108 | UCSBOrganization organization = ucsborganizationRepository.findByOrgCode(orgCode) | |
109 |
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, orgCode)); |
110 | | |
111 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::getById → KILLED |
return organization; |
112 | } | |
113 | ||
114 | /** | |
115 | * Update a single UCSB Organization | |
116 | * | |
117 | * @param orgCode orgCode of the Organization to update | |
118 | * @param incoming the new Organization Item | |
119 | * @return the updated Organization object | |
120 | */ | |
121 | @Operation(summary = "Update a Organization") | |
122 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
123 | @PutMapping("") | |
124 | public UCSBOrganization updateUCSBOrganization( | |
125 | @Parameter(name = "orgCode") @RequestParam String orgCode, | |
126 | @RequestBody @Valid UCSBOrganization incoming) { | |
127 | | |
128 | | |
129 | UCSBOrganization ucsbOrganization = ucsborganizationRepository.findByOrgCode(orgCode) | |
130 |
1
1. lambda$updateUCSBOrganization$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::lambda$updateUCSBOrganization$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode)); |
131 | | |
132 | | |
133 |
1
1. updateUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED |
ucsbOrganization.setOrgTranslationShort(incoming.getOrgTranslationShort()); |
134 |
1
1. updateUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED |
ucsbOrganization.setOrgTranslation(incoming.getOrgTranslation()); |
135 |
1
1. updateUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED |
ucsbOrganization.setInactive(incoming.getInactive()); |
136 | | |
137 | | |
138 | ucsborganizationRepository.save(ucsbOrganization); | |
139 | | |
140 | | |
141 |
1
1. updateUCSBOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::updateUCSBOrganization → KILLED |
return ucsbOrganization; |
142 | } | |
143 | | |
144 | /** | |
145 | * Delete a ucsborganizations. Accessible only to users with the role "ROLE_ADMIN". | |
146 | * @param orgCode orgCode of the organizations | |
147 | * @return a message indiciating the organizations was deleted | |
148 | */ | |
149 | @Operation(summary= "Delete a UCSBOrganizations") | |
150 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
151 | @DeleteMapping("") | |
152 | public Object deleteCommons( | |
153 | @Parameter(name="orgCode") @RequestParam String orgCode) { | |
154 | UCSBOrganization organizations = ucsborganizationRepository.findByOrgCode(orgCode) | |
155 |
1
1. lambda$deleteCommons$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::lambda$deleteCommons$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode)); |
156 | ||
157 |
1
1. deleteCommons : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED |
ucsborganizationRepository.delete(organizations); |
158 |
1
1. deleteCommons : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::deleteCommons → KILLED |
return genericMessage("UCSBOrganization with id %s deleted".formatted(orgCode)); |
159 | } | |
160 | } | |
Mutations | ||
66 |
1.1 |
|
91 |
1.1 |
|
92 |
1.1 |
|
93 |
1.1 |
|
94 |
1.1 |
|
100 |
1.1 |
|
109 |
1.1 |
|
111 |
1.1 |
|
130 |
1.1 |
|
133 |
1.1 |
|
134 |
1.1 |
|
135 |
1.1 |
|
141 |
1.1 |
|
155 |
1.1 |
|
157 |
1.1 |
|
158 |
1.1 |