1 | package edu.ucsb.cs156.example.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.example.entities.UCSBDiningCommons; | |
4 | import edu.ucsb.cs156.example.entities.UCSBOrganization; | |
5 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
6 | import edu.ucsb.cs156.example.repositories.UCSBOrganizationRepository; | |
7 | ||
8 | import io.swagger.v3.oas.annotations.Operation; | |
9 | import io.swagger.v3.oas.annotations.Parameter; | |
10 | import io.swagger.v3.oas.annotations.tags.Tag; | |
11 | import lombok.extern.slf4j.Slf4j; | |
12 | ||
13 | import org.springframework.beans.factory.annotation.Autowired; | |
14 | import org.springframework.security.access.prepost.PreAuthorize; | |
15 | import org.springframework.web.bind.annotation.DeleteMapping; | |
16 | import org.springframework.web.bind.annotation.GetMapping; | |
17 | import org.springframework.web.bind.annotation.PostMapping; | |
18 | import org.springframework.web.bind.annotation.PutMapping; | |
19 | import org.springframework.web.bind.annotation.RequestBody; | |
20 | import org.springframework.web.bind.annotation.RequestMapping; | |
21 | import org.springframework.web.bind.annotation.RequestParam; | |
22 | import org.springframework.web.bind.annotation.RestController; | |
23 | ||
24 | import jakarta.validation.Valid; | |
25 | ||
26 | /** | |
27 | * This is a REST controller for UCSBOrganization | |
28 | */ | |
29 | ||
30 | @Tag(name = "UCSBOrganization") | |
31 | @RequestMapping("/api/ucsborganizations") | |
32 | @RestController | |
33 | @Slf4j | |
34 | public class UCSBOrganizationController extends ApiController { | |
35 | ||
36 | @Autowired | |
37 | UCSBOrganizationRepository ucsbOrganizationRepository; | |
38 | ||
39 | /** | |
40 | * THis method returns a list of all ucsborganizations. | |
41 | * @return a list of all ucsborganizations | |
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 organization. | |
53 | * @param orgCode code of the organization | |
54 | * @return a single organization | |
55 | */ | |
56 | @Operation(summary= "Get a single organization") | |
57 | @PreAuthorize("hasRole('ROLE_USER')") | |
58 | @GetMapping("") | |
59 | public UCSBOrganization getById( | |
60 | @Parameter(name="orgCode") @RequestParam String orgCode) { | |
61 | UCSBOrganization organization = 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 organization; |
65 | } | |
66 | ||
67 | /** | |
68 | * This method creates a new organization. Accessible only to users with the role "ROLE_ADMIN". | |
69 | * @param orgCode code of the organization | |
70 | * @param orgTranslationShort shortened name of the organization | |
71 | * @param orgTranslation full name of the organization | |
72 | * @param inactive whether or not the organization is inactive | |
73 | */ | |
74 | @Operation(summary= "Create a new organization") | |
75 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
76 | @PostMapping("/post") | |
77 | public UCSBOrganization postOrganization( | |
78 | @Parameter(name="orgCode") @RequestParam String orgCode, | |
79 | @Parameter(name="orgTranslationShort") @RequestParam String orgTranslationShort, | |
80 | @Parameter(name="orgTranslation") @RequestParam String orgTranslation, | |
81 | @Parameter(name="inactive") @RequestParam boolean inactive | |
82 | ) | |
83 | { | |
84 | ||
85 | UCSBOrganization organization = new UCSBOrganization(); | |
86 |
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED |
organization.setOrgCode(orgCode); |
87 |
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED |
organization.setOrgTranslationShort(orgTranslationShort); |
88 |
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED |
organization.setOrgTranslation(orgTranslation); |
89 |
1
1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED |
organization.setInactive(inactive); |
90 | ||
91 | UCSBOrganization savedOrganization = ucsbOrganizationRepository.save(organization); | |
92 | ||
93 |
1
1. postOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::postOrganization → KILLED |
return savedOrganization; |
94 | } | |
95 | ||
96 | /** | |
97 | * Delete an organization. Accessible only to users with the role "ROLE_ADMIN". | |
98 | * @param orgCode code of the organization | |
99 | * @return a message indiciating the organization was deleted | |
100 | */ | |
101 | @Operation(summary= "Delete a UCSBOrganization") | |
102 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
103 | @DeleteMapping("") | |
104 | public Object deleteCommons( | |
105 | @Parameter(name="orgCode") @RequestParam String orgCode) { | |
106 | UCSBOrganization organization = ucsbOrganizationRepository.findById(orgCode) | |
107 |
1
1. lambda$deleteCommons$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$deleteCommons$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode)); |
108 | ||
109 |
1
1. deleteCommons : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED |
ucsbOrganizationRepository.delete(organization); |
110 |
1
1. deleteCommons : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::deleteCommons → KILLED |
return genericMessage("UCSBOrganization with id %s deleted".formatted(orgCode)); |
111 | } | |
112 | ||
113 | /** | |
114 | * Update a single organization. Accessible only to users with the role "ROLE_ADMIN". | |
115 | * @param orgCode code of the organization | |
116 | * @param incoming the new organization contents | |
117 | * @return the updated organization object | |
118 | */ | |
119 | @Operation(summary= "Update a single organization") | |
120 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
121 | @PutMapping("") | |
122 | public UCSBOrganization updateOrganization( | |
123 | @Parameter(name="orgCode") @RequestParam String orgCode, | |
124 | @RequestBody @Valid UCSBOrganization incoming) { | |
125 | ||
126 | UCSBOrganization organization = ucsbOrganizationRepository.findById(orgCode) | |
127 |
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)); |
128 | ||
129 |
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED |
organization.setOrgTranslationShort(incoming.getOrgTranslationShort()); |
130 |
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED |
organization.setOrgTranslation(incoming.getOrgTranslation()); |
131 |
1
1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED |
organization.setInactive(incoming.getInactive()); |
132 | ||
133 | ucsbOrganizationRepository.save(organization); | |
134 | ||
135 |
1
1. updateOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::updateOrganization → KILLED |
return organization; |
136 | } | |
137 | ||
138 | ||
139 | } | |
Mutations | ||
48 |
1.1 |
|
62 |
1.1 |
|
64 |
1.1 |
|
86 |
1.1 |
|
87 |
1.1 |
|
88 |
1.1 |
|
89 |
1.1 |
|
93 |
1.1 |
|
107 |
1.1 |
|
109 |
1.1 |
|
110 |
1.1 |
|
127 |
1.1 |
|
129 |
1.1 |
|
130 |
1.1 |
|
131 |
1.1 |
|
135 |
1.1 |