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