1 | package edu.ucsb.cs156.example.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.example.entities.UCSBDate; | |
4 | import edu.ucsb.cs156.example.entities.UCSBOrganization; | |
5 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
6 | import edu.ucsb.cs156.example.repositories.UCSBDateRepository; | |
7 | import edu.ucsb.cs156.example.repositories.UCSBOrganizationRepository; | |
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 com.fasterxml.jackson.core.JsonProcessingException; | |
14 | ||
15 | import org.springframework.beans.factory.annotation.Autowired; | |
16 | import org.springframework.format.annotation.DateTimeFormat; | |
17 | import org.springframework.security.access.prepost.PreAuthorize; | |
18 | import org.springframework.web.bind.annotation.DeleteMapping; | |
19 | import org.springframework.web.bind.annotation.GetMapping; | |
20 | import org.springframework.web.bind.annotation.PostMapping; | |
21 | import org.springframework.web.bind.annotation.PutMapping; | |
22 | import org.springframework.web.bind.annotation.RequestBody; | |
23 | import org.springframework.web.bind.annotation.RequestMapping; | |
24 | import org.springframework.web.bind.annotation.RequestParam; | |
25 | import org.springframework.web.bind.annotation.RestController; | |
26 | ||
27 | import jakarta.validation.Valid; | |
28 | ||
29 | import java.time.LocalDateTime; | |
30 | ||
31 | /** | |
32 | * This is a REST controller for UCSBOrganization | |
33 | */ | |
34 | ||
35 | @Tag(name = "UCSBOrganization") | |
36 | @RequestMapping("/api/ucsborganization") | |
37 | @RestController | |
38 | @Slf4j | |
39 | public class UCSBOrganizationController extends ApiController { | |
40 | ||
41 | @Autowired | |
42 | UCSBOrganizationRepository ucsbOrganizationRepository; | |
43 | ||
44 | /** | |
45 | * List all UCSB Organizations | |
46 | * | |
47 | * @return an iterable of UCSBOrganization | |
48 | */ | |
49 | @Operation(summary = "List all ucsb organizations") | |
50 | @PreAuthorize("hasRole('ROLE_USER')") | |
51 | @GetMapping("/all") | |
52 | public Iterable<UCSBOrganization> allUCSBOrganization() { | |
53 | Iterable<UCSBOrganization> ucsborganization = ucsbOrganizationRepository.findAll(); | |
54 |
1
1. allUCSBOrganization : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::allUCSBOrganization → KILLED |
return ucsborganization; |
55 | } | |
56 | ||
57 | /** | |
58 | * Create a new organization | |
59 | * | |
60 | * @param orgCode the ucsb organization code | |
61 | * @param orgTranslationShort the ucsb organization translation short | |
62 | * @param orgTranslation the ucsb organization translation | |
63 | * @param inactive inactive boolean | |
64 | * @return the saved ucsborganization | |
65 | */ | |
66 | @Operation(summary = "Create a new organization") | |
67 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
68 | @PostMapping("/post") | |
69 | public UCSBOrganization postUCSBOrganization( | |
70 | @Parameter(name = "orgCode") @RequestParam String orgCode, | |
71 | @Parameter(name = "orgTranslationShort") @RequestParam String orgTranslationShort, | |
72 | @Parameter(name = "orgTranslation") @RequestParam String orgTranslation, | |
73 | @Parameter(name = "inactive") @RequestParam boolean inactive) | |
74 | throws JsonProcessingException { | |
75 | ||
76 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
77 | // See: https://www.baeldung.com/spring-date-parameters | |
78 | ||
79 | // NO TIME CONSTRAINTS FOR UCSB ORGANIZATION | |
80 | // log.info("localDateTime={}", localDateTime); | |
81 | ||
82 | UCSBOrganization ucsbOrganization = new UCSBOrganization(); | |
83 |
1
1. postUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED |
ucsbOrganization.setOrgCode(orgCode); |
84 |
1
1. postUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED |
ucsbOrganization.setOrgTranslationShort(orgTranslationShort); |
85 |
1
1. postUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED |
ucsbOrganization.setOrgTranslation(orgTranslation); |
86 |
1
1. postUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED |
ucsbOrganization.setInactive(inactive); |
87 | ||
88 | UCSBOrganization savedUcsbOrganization = ucsbOrganizationRepository.save(ucsbOrganization); | |
89 | ||
90 |
1
1. postUCSBOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::postUCSBOrganization → KILLED |
return savedUcsbOrganization; |
91 | } | |
92 | ||
93 | /** | |
94 | * Get a single ucsborganization by id | |
95 | * | |
96 | * @param id the id of the ucsb organization | |
97 | * @return a UCSBOrganization | |
98 | */ | |
99 | @Operation(summary = "Get a single ucsb Organization") | |
100 | @PreAuthorize("hasRole('ROLE_USER')") | |
101 | @GetMapping("") | |
102 | public UCSBOrganization getById( | |
103 | @Parameter(name = "id") @RequestParam Long id) { | |
104 | UCSBOrganization ucsbOrganization = ucsbOrganizationRepository.findById(id) | |
105 |
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, id)); |
106 | ||
107 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::getById → KILLED |
return ucsbOrganization; |
108 | } | |
109 | ||
110 | /** | |
111 | * Update a single ucsborganization | |
112 | * | |
113 | * @param id id of the ucsborganization to update | |
114 | * @param incoming the new ucsborganization | |
115 | * @return the updated ucsborganization object | |
116 | */ | |
117 | @Operation(summary = "Update a single ucsborganization") | |
118 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
119 | @PutMapping("") | |
120 | public UCSBOrganization updateUCSBOrganization( | |
121 | @Parameter(name = "id") @RequestParam Long id, | |
122 | @RequestBody @Valid UCSBOrganization incoming) { | |
123 | ||
124 | UCSBOrganization ucsbOrganization = ucsbOrganizationRepository.findById(id) | |
125 |
1
1. lambda$updateUCSBOrganization$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$updateUCSBOrganization$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, id)); |
126 | ||
127 |
1
1. updateUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED |
ucsbOrganization.setInactive(incoming.getInactive()); |
128 |
1
1. updateUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED |
ucsbOrganization.setOrgCode(incoming.getOrgCode()); |
129 |
1
1. updateUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED |
ucsbOrganization.setOrgTranslation(incoming.getOrgTranslation()); |
130 |
1
1. updateUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED |
ucsbOrganization.setOrgTranslationShort(incoming.getOrgTranslationShort()); |
131 | ||
132 | ucsbOrganizationRepository.save(ucsbOrganization); | |
133 | ||
134 |
1
1. updateUCSBOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::updateUCSBOrganization → KILLED |
return ucsbOrganization; |
135 | } | |
136 | ||
137 | /** | |
138 | * Delete a UCSBOrganization | |
139 | * | |
140 | * @param id the id of the ucsborganization to delete | |
141 | * @return a message indicating the ucsborganization was deleted | |
142 | */ | |
143 | @Operation(summary = "Delete a UCSBOrganization") | |
144 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
145 | @DeleteMapping("") | |
146 | public Object deleteUCSBOrganization( | |
147 | @Parameter(name = "id") @RequestParam Long id) { | |
148 | UCSBOrganization ucsbOrganization = ucsbOrganizationRepository.findById(id) | |
149 |
1
1. lambda$deleteUCSBOrganization$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$deleteUCSBOrganization$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, id)); |
150 | ||
151 |
1
1. deleteUCSBOrganization : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED |
ucsbOrganizationRepository.delete(ucsbOrganization); |
152 |
1
1. deleteUCSBOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::deleteUCSBOrganization → KILLED |
return genericMessage("UCSBOrganization with id %s deleted".formatted(id)); |
153 | } | |
154 | } | |
Mutations | ||
54 |
1.1 |
|
83 |
1.1 |
|
84 |
1.1 |
|
85 |
1.1 |
|
86 |
1.1 |
|
90 |
1.1 |
|
105 |
1.1 |
|
107 |
1.1 |
|
125 |
1.1 |
|
127 |
1.1 |
|
128 |
1.1 |
|
129 |
1.1 |
|
130 |
1.1 |
|
134 |
1.1 |
|
149 |
1.1 |
|
151 |
1.1 |
|
152 |
1.1 |