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