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