| 1 | package edu.ucsb.cs156.courses.controllers; | |
| 2 | ||
| 3 | import com.fasterxml.jackson.databind.JsonNode; | |
| 4 | import com.fasterxml.jackson.databind.ObjectMapper; | |
| 5 | import edu.ucsb.cs156.courses.entities.PSCourse; | |
| 6 | import edu.ucsb.cs156.courses.entities.PersonalSchedule; | |
| 7 | import edu.ucsb.cs156.courses.entities.User; | |
| 8 | import edu.ucsb.cs156.courses.errors.BadEnrollCdException; | |
| 9 | import edu.ucsb.cs156.courses.errors.EntityNotFoundException; | |
| 10 | import edu.ucsb.cs156.courses.models.CurrentUser; | |
| 11 | import edu.ucsb.cs156.courses.repositories.PSCourseRepository; | |
| 12 | import edu.ucsb.cs156.courses.repositories.PersonalScheduleRepository; | |
| 13 | import edu.ucsb.cs156.courses.services.UCSBCurriculumService; | |
| 14 | import io.swagger.v3.oas.annotations.Operation; | |
| 15 | import io.swagger.v3.oas.annotations.Parameter; | |
| 16 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 17 | import java.util.ArrayList; | |
| 18 | import java.util.Iterator; | |
| 19 | import java.util.Optional; | |
| 20 | import javax.validation.Valid; | |
| 21 | import lombok.extern.slf4j.Slf4j; | |
| 22 | import org.springframework.beans.factory.annotation.Autowired; | |
| 23 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 24 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 25 | import org.springframework.web.bind.annotation.GetMapping; | |
| 26 | import org.springframework.web.bind.annotation.PostMapping; | |
| 27 | import org.springframework.web.bind.annotation.PutMapping; | |
| 28 | import org.springframework.web.bind.annotation.RequestBody; | |
| 29 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 30 | import org.springframework.web.bind.annotation.RequestParam; | |
| 31 | import org.springframework.web.bind.annotation.RestController; | |
| 32 | ||
| 33 | @Tag(name = "PSCourse") | |
| 34 | @RequestMapping("/api/courses") | |
| 35 | @RestController | |
| 36 | @Slf4j | |
| 37 | public class PSCourseController extends ApiController { | |
| 38 | ||
| 39 | @Autowired PSCourseRepository coursesRepository; | |
| 40 | @Autowired PersonalScheduleRepository personalScheduleRepository; | |
| 41 | @Autowired UCSBCurriculumService ucsbCurriculumService; | |
| 42 | @Autowired ObjectMapper mapper; | |
| 43 | ||
| 44 | @Operation(summary = "List all courses (admin)") | |
| 45 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 46 | @GetMapping("/admin/all") | |
| 47 | public Iterable<PSCourse> allUsersCourses() { | |
| 48 | Iterable<PSCourse> courses = coursesRepository.findAll(); | |
| 49 |
1
1. allUsersCourses : replaced return value with Collections.emptyList for edu/ucsb/cs156/courses/controllers/PSCourseController::allUsersCourses → KILLED |
return courses; |
| 50 | } | |
| 51 | ||
| 52 | @Operation(summary = "List all courses (user)") | |
| 53 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 54 | @GetMapping("/user/all") | |
| 55 | public Iterable<PSCourse> thisUsersCourses() { | |
| 56 | CurrentUser currentUser = getCurrentUser(); | |
| 57 | Iterable<PSCourse> courses = coursesRepository.findAllByUserId(currentUser.getUser().getId()); | |
| 58 |
1
1. thisUsersCourses : replaced return value with Collections.emptyList for edu/ucsb/cs156/courses/controllers/PSCourseController::thisUsersCourses → KILLED |
return courses; |
| 59 | } | |
| 60 | ||
| 61 | @Operation(summary = "List all courses for a specified psId (admin)") | |
| 62 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 63 | @GetMapping("/admin/psid/all") | |
| 64 | public Iterable<PSCourse> allCoursesForPsId(@Parameter(name = "psId") @RequestParam Long psId) { | |
| 65 | Iterable<PSCourse> courses = coursesRepository.findAllByPsId(psId); | |
| 66 |
1
1. allCoursesForPsId : replaced return value with Collections.emptyList for edu/ucsb/cs156/courses/controllers/PSCourseController::allCoursesForPsId → KILLED |
return courses; |
| 67 | } | |
| 68 | ||
| 69 | @Operation(summary = "List all courses for a specified psId (user)") | |
| 70 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 71 | @GetMapping("/user/psid/all") | |
| 72 | public Iterable<PSCourse> thisUsersCoursesForPsId( | |
| 73 | @Parameter(name = "psId") @RequestParam Long psId) { | |
| 74 | User currentUser = getCurrentUser().getUser(); | |
| 75 | Iterable<PSCourse> courses = coursesRepository.findAllByPsIdAndUser(psId, currentUser); | |
| 76 |
1
1. thisUsersCoursesForPsId : replaced return value with Collections.emptyList for edu/ucsb/cs156/courses/controllers/PSCourseController::thisUsersCoursesForPsId → KILLED |
return courses; |
| 77 | } | |
| 78 | ||
| 79 | @Operation(summary = "Get a single course (admin)") | |
| 80 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 81 | @GetMapping("/admin") | |
| 82 | public PSCourse getCourseById_admin(@Parameter(name = "id") @RequestParam Long id) { | |
| 83 | PSCourse courses = | |
| 84 | coursesRepository | |
| 85 | .findById(id) | |
| 86 |
1
1. lambda$getCourseById_admin$0 : replaced return value with null for edu/ucsb/cs156/courses/controllers/PSCourseController::lambda$getCourseById_admin$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(PSCourse.class, id)); |
| 87 | ||
| 88 |
1
1. getCourseById_admin : replaced return value with null for edu/ucsb/cs156/courses/controllers/PSCourseController::getCourseById_admin → KILLED |
return courses; |
| 89 | } | |
| 90 | ||
| 91 | @Operation(summary = "Get a single course (user)") | |
| 92 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 93 | @GetMapping("/user") | |
| 94 | public PSCourse getCourseById(@Parameter(name = "id") @RequestParam Long id) { | |
| 95 | User currentUser = getCurrentUser().getUser(); | |
| 96 | PSCourse courses = | |
| 97 | coursesRepository | |
| 98 | .findByIdAndUser(id, currentUser) | |
| 99 |
1
1. lambda$getCourseById$1 : replaced return value with null for edu/ucsb/cs156/courses/controllers/PSCourseController::lambda$getCourseById$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(PSCourse.class, id)); |
| 100 | ||
| 101 |
1
1. getCourseById : replaced return value with null for edu/ucsb/cs156/courses/controllers/PSCourseController::getCourseById → KILLED |
return courses; |
| 102 | } | |
| 103 | ||
| 104 | @Operation(summary = "Create a new course") | |
| 105 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 106 | @PostMapping("/post") | |
| 107 | public ArrayList<PSCourse> postCourses( | |
| 108 | @Parameter(name = "enrollCd") @RequestParam String enrollCd, | |
| 109 | @Parameter(name = "psId") @RequestParam Long psId) | |
| 110 | throws Exception { | |
| 111 | CurrentUser currentUser = getCurrentUser(); | |
| 112 | log.info("currentUser={}", currentUser); | |
| 113 | ||
| 114 | PersonalSchedule checkPsId = | |
| 115 | personalScheduleRepository | |
| 116 | .findByIdAndUser(psId, currentUser.getUser()) | |
| 117 |
1
1. lambda$postCourses$2 : replaced return value with null for edu/ucsb/cs156/courses/controllers/PSCourseController::lambda$postCourses$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(PersonalSchedule.class, psId)); |
| 118 | ||
| 119 | String body = ucsbCurriculumService.getAllSections(enrollCd, checkPsId.getQuarter()); | |
| 120 |
1
1. postCourses : negated conditional → KILLED |
if (body.equals("{\"error\": \"401: Unauthorized\"}") |
| 121 |
1
1. postCourses : negated conditional → KILLED |
|| body.equals("{\"error\": \"Enroll code doesn't exist in that quarter.\"}")) { |
| 122 | throw new BadEnrollCdException(enrollCd); | |
| 123 | } | |
| 124 | ||
| 125 | // may cause significant slowdowns if there are very large sections | |
| 126 | String enrollCdPrimary = null; | |
| 127 | String enrollCdPreviousSecondary = null; | |
| 128 | boolean hasSecondary = false; | |
| 129 | boolean hasPreviousSecondary = false; | |
| 130 | Iterator<JsonNode> it = mapper.readTree(body).path("classSections").elements(); | |
| 131 |
1
1. postCourses : negated conditional → KILLED |
while (it.hasNext()) { |
| 132 | JsonNode classSection = it.next(); | |
| 133 | String section = classSection.path("section").asText(); | |
| 134 | String currentEnrollCd = classSection.path("enrollCode").asText(); | |
| 135 | ||
| 136 |
1
1. postCourses : negated conditional → KILLED |
if (section.endsWith("00")) { |
| 137 | enrollCdPrimary = currentEnrollCd; | |
| 138 |
1
1. postCourses : negated conditional → KILLED |
} else if (coursesRepository.findByPsIdAndEnrollCd(psId, currentEnrollCd).isPresent()) { |
| 139 | enrollCdPreviousSecondary = currentEnrollCd; | |
| 140 | hasPreviousSecondary = true; | |
| 141 | } else { | |
| 142 | hasSecondary = true; | |
| 143 | } | |
| 144 | } | |
| 145 | ||
| 146 |
1
1. postCourses : negated conditional → KILLED |
if (enrollCdPrimary == null) { |
| 147 | enrollCdPrimary = enrollCd; | |
| 148 | hasSecondary = false; | |
| 149 | hasPreviousSecondary = false; | |
| 150 | } | |
| 151 | ||
| 152 |
1
1. postCourses : negated conditional → KILLED |
if (!hasPreviousSecondary |
| 153 |
1
1. postCourses : negated conditional → KILLED |
&& coursesRepository.findByPsIdAndEnrollCd(psId, enrollCdPrimary).isPresent()) { |
| 154 | throw new IllegalArgumentException("class exists in schedule"); | |
| 155 | } | |
| 156 | ||
| 157 | ArrayList<PSCourse> savedCourses = new ArrayList<>(); | |
| 158 | ||
| 159 |
1
1. postCourses : negated conditional → KILLED |
if (hasPreviousSecondary) { |
| 160 | Optional<PSCourse> secondaryOptional = | |
| 161 | coursesRepository.findByPsIdAndEnrollCd(psId, enrollCdPreviousSecondary); | |
| 162 | PSCourse secondary = secondaryOptional.get(); | |
| 163 | ||
| 164 | PSCourse oldSection = new PSCourse(); | |
| 165 |
1
1. postCourses : removed call to edu/ucsb/cs156/courses/entities/PSCourse::setUser → KILLED |
oldSection.setUser(currentUser.getUser()); |
| 166 |
1
1. postCourses : removed call to edu/ucsb/cs156/courses/entities/PSCourse::setEnrollCd → KILLED |
oldSection.setEnrollCd(secondary.getEnrollCd()); |
| 167 |
1
1. postCourses : removed call to edu/ucsb/cs156/courses/entities/PSCourse::setPsId → KILLED |
oldSection.setPsId(secondary.getPsId()); |
| 168 | ||
| 169 |
1
1. postCourses : removed call to edu/ucsb/cs156/courses/entities/PSCourse::setEnrollCd → KILLED |
secondary.setEnrollCd(enrollCd); |
| 170 | PSCourse newSection = coursesRepository.save(secondary); | |
| 171 | ||
| 172 | PSCourse primary = new PSCourse(); | |
| 173 |
1
1. postCourses : removed call to edu/ucsb/cs156/courses/entities/PSCourse::setUser → KILLED |
primary.setUser(currentUser.getUser()); |
| 174 |
1
1. postCourses : removed call to edu/ucsb/cs156/courses/entities/PSCourse::setEnrollCd → KILLED |
primary.setEnrollCd(enrollCdPrimary); |
| 175 |
1
1. postCourses : removed call to edu/ucsb/cs156/courses/entities/PSCourse::setPsId → KILLED |
primary.setPsId(psId); |
| 176 | ||
| 177 | savedCourses.add(primary); | |
| 178 | savedCourses.add(newSection); | |
| 179 | savedCourses.add(oldSection); | |
| 180 |
1
1. postCourses : replaced return value with null for edu/ucsb/cs156/courses/controllers/PSCourseController::postCourses → KILLED |
return savedCourses; |
| 181 | } | |
| 182 | ||
| 183 |
1
1. postCourses : negated conditional → KILLED |
if (!enrollCdPrimary.equals(enrollCd)) { |
| 184 | String enrollCdSecondary = enrollCd; | |
| 185 | PSCourse secondary = new PSCourse(); | |
| 186 |
1
1. postCourses : removed call to edu/ucsb/cs156/courses/entities/PSCourse::setUser → KILLED |
secondary.setUser(currentUser.getUser()); |
| 187 |
1
1. postCourses : removed call to edu/ucsb/cs156/courses/entities/PSCourse::setEnrollCd → KILLED |
secondary.setEnrollCd(enrollCdSecondary); |
| 188 |
1
1. postCourses : removed call to edu/ucsb/cs156/courses/entities/PSCourse::setPsId → KILLED |
secondary.setPsId(psId); |
| 189 | coursesRepository.save(secondary); | |
| 190 | savedCourses.add(secondary); | |
| 191 |
1
1. postCourses : negated conditional → KILLED |
} else if (hasSecondary) { |
| 192 | throw new IllegalArgumentException( | |
| 193 | enrollCd | |
| 194 | + " is for a course with sections; please add a specific section and the lecture will be automatically added"); | |
| 195 | } | |
| 196 | ||
| 197 | PSCourse primary = new PSCourse(); | |
| 198 |
1
1. postCourses : removed call to edu/ucsb/cs156/courses/entities/PSCourse::setUser → KILLED |
primary.setUser(currentUser.getUser()); |
| 199 |
1
1. postCourses : removed call to edu/ucsb/cs156/courses/entities/PSCourse::setEnrollCd → KILLED |
primary.setEnrollCd(enrollCdPrimary); |
| 200 |
1
1. postCourses : removed call to edu/ucsb/cs156/courses/entities/PSCourse::setPsId → KILLED |
primary.setPsId(psId); |
| 201 | coursesRepository.save(primary); | |
| 202 | savedCourses.add(primary); | |
| 203 | ||
| 204 |
1
1. postCourses : replaced return value with null for edu/ucsb/cs156/courses/controllers/PSCourseController::postCourses → KILLED |
return savedCourses; |
| 205 | } | |
| 206 | ||
| 207 | @Operation(summary = "Delete a course (admin)") | |
| 208 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 209 | @DeleteMapping("/admin") | |
| 210 | public Object deleteCourses_Admin(@Parameter(name = "id") @RequestParam Long id) { | |
| 211 | PSCourse courses = | |
| 212 | coursesRepository | |
| 213 | .findById(id) | |
| 214 |
1
1. lambda$deleteCourses_Admin$3 : replaced return value with null for edu/ucsb/cs156/courses/controllers/PSCourseController::lambda$deleteCourses_Admin$3 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(PSCourse.class, id)); |
| 215 | ||
| 216 |
1
1. deleteCourses_Admin : removed call to edu/ucsb/cs156/courses/repositories/PSCourseRepository::delete → KILLED |
coursesRepository.delete(courses); |
| 217 | ||
| 218 |
1
1. deleteCourses_Admin : replaced return value with null for edu/ucsb/cs156/courses/controllers/PSCourseController::deleteCourses_Admin → KILLED |
return genericMessage("PSCourse with id %s deleted".formatted(id)); |
| 219 | } | |
| 220 | ||
| 221 | @Operation(summary = "Delete a course (user)") | |
| 222 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 223 | @DeleteMapping("/user") | |
| 224 | public Object deleteCourses(@Parameter(name = "id") @RequestParam Long id) throws Exception { | |
| 225 | User currentUser = getCurrentUser().getUser(); | |
| 226 | PSCourse psCourse = | |
| 227 | coursesRepository | |
| 228 | .findByIdAndUser(id, currentUser) | |
| 229 |
1
1. lambda$deleteCourses$4 : replaced return value with null for edu/ucsb/cs156/courses/controllers/PSCourseController::lambda$deleteCourses$4 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(PSCourse.class, id)); |
| 230 | long psId = psCourse.getPsId(); | |
| 231 | PersonalSchedule checkPsId = | |
| 232 | personalScheduleRepository | |
| 233 | .findByIdAndUser(psId, currentUser) | |
| 234 |
1
1. lambda$deleteCourses$5 : replaced return value with null for edu/ucsb/cs156/courses/controllers/PSCourseController::lambda$deleteCourses$5 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(PersonalSchedule.class, psId)); |
| 235 | ||
| 236 | String body = | |
| 237 | ucsbCurriculumService.getAllSections(psCourse.getEnrollCd(), checkPsId.getQuarter()); | |
| 238 |
1
1. deleteCourses : negated conditional → KILLED |
if (body.equals("{\"error\": \"401: Unauthorized\"}") |
| 239 |
1
1. deleteCourses : negated conditional → KILLED |
|| body.equals("{\"error\": \"Enroll code doesn't exist in that quarter.\"}")) { |
| 240 |
1
1. deleteCourses : removed call to edu/ucsb/cs156/courses/repositories/PSCourseRepository::delete → KILLED |
coursesRepository.delete(psCourse); |
| 241 |
1
1. deleteCourses : replaced return value with null for edu/ucsb/cs156/courses/controllers/PSCourseController::deleteCourses → KILLED |
return genericMessage("PSCourse with id %s deleted".formatted(id)); |
| 242 | } | |
| 243 | ||
| 244 | Iterator<JsonNode> it = mapper.readTree(body).path("classSections").elements(); | |
| 245 | Optional<Long> primaryId = Optional.empty(); | |
| 246 | Optional<Long> secondaryId = Optional.empty(); | |
| 247 |
1
1. deleteCourses : negated conditional → KILLED |
while (it.hasNext()) { |
| 248 | JsonNode classSection = it.next(); | |
| 249 | String section = classSection.path("section").asText(); | |
| 250 | String currentEnrollCd = classSection.path("enrollCode").asText(); | |
| 251 | Optional<PSCourse> currentPsCourse = | |
| 252 | coursesRepository.findByPsIdAndEnrollCd(psId, currentEnrollCd); | |
| 253 |
1
1. deleteCourses : negated conditional → KILLED |
if (!currentPsCourse.isPresent()) continue; |
| 254 | Optional<Long> idOpt = Optional.of(currentPsCourse.get().getId()); | |
| 255 |
1
1. deleteCourses : negated conditional → KILLED |
if (section.endsWith("00")) primaryId = idOpt; |
| 256 | else secondaryId = idOpt; | |
| 257 |
1
1. deleteCourses : removed call to edu/ucsb/cs156/courses/repositories/PSCourseRepository::delete → KILLED |
coursesRepository.delete(currentPsCourse.get()); |
| 258 | } | |
| 259 | ||
| 260 |
2
1. deleteCourses : negated conditional → KILLED 2. deleteCourses : negated conditional → KILLED |
if (primaryId.isPresent() && secondaryId.isPresent()) { |
| 261 |
1
1. deleteCourses : negated conditional → KILLED |
if (primaryId.get() == id) |
| 262 |
1
1. deleteCourses : replaced return value with null for edu/ucsb/cs156/courses/controllers/PSCourseController::deleteCourses → KILLED |
return genericMessage( |
| 263 | "PSCourse with id %s and matching secondary with id %s deleted" | |
| 264 | .formatted(id, secondaryId.get())); | |
| 265 | else | |
| 266 |
1
1. deleteCourses : replaced return value with null for edu/ucsb/cs156/courses/controllers/PSCourseController::deleteCourses → KILLED |
return genericMessage( |
| 267 | "PSCourse with id %s and matching primary with id %s deleted" | |
| 268 | .formatted(id, primaryId.get())); | |
| 269 | } | |
| 270 | ||
| 271 |
1
1. deleteCourses : replaced return value with null for edu/ucsb/cs156/courses/controllers/PSCourseController::deleteCourses → KILLED |
return genericMessage("PSCourse with id %s deleted".formatted(id)); |
| 272 | } | |
| 273 | ||
| 274 | @Operation(summary = "Delete a course with psid and enroll code (user)") | |
| 275 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 276 | @DeleteMapping("/user/psid") | |
| 277 | public Object deleteCourses_PSID( | |
| 278 | @Parameter(name = "enrollCd") @RequestParam String enrollCd, | |
| 279 | @Parameter(name = "psId") @RequestParam Long psId) | |
| 280 | throws Exception { | |
| 281 | User currentUser = getCurrentUser().getUser(); | |
| 282 | ||
| 283 | PSCourse psCourse = | |
| 284 | coursesRepository | |
| 285 | .findByPsIdAndEnrollCd(psId, enrollCd) | |
| 286 | .orElseThrow( | |
| 287 | () -> | |
| 288 |
1
1. lambda$deleteCourses_PSID$6 : replaced return value with null for edu/ucsb/cs156/courses/controllers/PSCourseController::lambda$deleteCourses_PSID$6 → KILLED |
new EntityNotFoundException( |
| 289 | PSCourse.class, "psId", psId, "enrollCode", enrollCd)); | |
| 290 | long id = psCourse.getId(); | |
| 291 | PersonalSchedule checkPsId = | |
| 292 | personalScheduleRepository | |
| 293 | .findByIdAndUser(psId, currentUser) | |
| 294 |
1
1. lambda$deleteCourses_PSID$7 : replaced return value with null for edu/ucsb/cs156/courses/controllers/PSCourseController::lambda$deleteCourses_PSID$7 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(PersonalSchedule.class, psId)); |
| 295 | ||
| 296 | String body = | |
| 297 | ucsbCurriculumService.getAllSections(psCourse.getEnrollCd(), checkPsId.getQuarter()); | |
| 298 |
1
1. deleteCourses_PSID : negated conditional → KILLED |
if (body.equals("{\"error\": \"401: Unauthorized\"}") |
| 299 |
1
1. deleteCourses_PSID : negated conditional → KILLED |
|| body.equals("{\"error\": \"Enroll code doesn't exist in that quarter.\"}")) { |
| 300 |
1
1. deleteCourses_PSID : removed call to edu/ucsb/cs156/courses/repositories/PSCourseRepository::delete → KILLED |
coursesRepository.delete(psCourse); |
| 301 |
1
1. deleteCourses_PSID : replaced return value with null for edu/ucsb/cs156/courses/controllers/PSCourseController::deleteCourses_PSID → KILLED |
return genericMessage( |
| 302 | "PSCourse with psId %s and enroll code %s deleted".formatted(psId, enrollCd)); | |
| 303 | } | |
| 304 | ||
| 305 | Iterator<JsonNode> it = mapper.readTree(body).path("classSections").elements(); | |
| 306 | Optional<Long> primaryId = Optional.empty(); | |
| 307 | Optional<Long> secondaryId = Optional.empty(); | |
| 308 |
1
1. deleteCourses_PSID : negated conditional → KILLED |
while (it.hasNext()) { |
| 309 | JsonNode classSection = it.next(); | |
| 310 | String section = classSection.path("section").asText(); | |
| 311 | String currentEnrollCd = classSection.path("enrollCode").asText(); | |
| 312 | Optional<PSCourse> currentPsCourse = | |
| 313 | coursesRepository.findByPsIdAndEnrollCd(psId, currentEnrollCd); | |
| 314 |
1
1. deleteCourses_PSID : negated conditional → KILLED |
if (!currentPsCourse.isPresent()) continue; |
| 315 | Optional<Long> idOpt = Optional.of(currentPsCourse.get().getId()); | |
| 316 |
1
1. deleteCourses_PSID : negated conditional → KILLED |
if (section.endsWith("00")) primaryId = idOpt; |
| 317 | else secondaryId = idOpt; | |
| 318 |
1
1. deleteCourses_PSID : removed call to edu/ucsb/cs156/courses/repositories/PSCourseRepository::delete → KILLED |
coursesRepository.delete(currentPsCourse.get()); |
| 319 | } | |
| 320 | ||
| 321 |
2
1. deleteCourses_PSID : negated conditional → KILLED 2. deleteCourses_PSID : negated conditional → KILLED |
if (primaryId.isPresent() && secondaryId.isPresent()) { |
| 322 |
1
1. deleteCourses_PSID : negated conditional → KILLED |
if (primaryId.get() == id) |
| 323 |
1
1. deleteCourses_PSID : replaced return value with null for edu/ucsb/cs156/courses/controllers/PSCourseController::deleteCourses_PSID → KILLED |
return genericMessage( |
| 324 | "PSCourse with id %s and matching secondary with id %s deleted" | |
| 325 | .formatted(id, secondaryId.get())); | |
| 326 | else | |
| 327 |
1
1. deleteCourses_PSID : replaced return value with null for edu/ucsb/cs156/courses/controllers/PSCourseController::deleteCourses_PSID → KILLED |
return genericMessage( |
| 328 | "PSCourse with id %s and matching primary with id %s deleted" | |
| 329 | .formatted(id, primaryId.get())); | |
| 330 | } | |
| 331 | ||
| 332 |
1
1. deleteCourses_PSID : replaced return value with null for edu/ucsb/cs156/courses/controllers/PSCourseController::deleteCourses_PSID → KILLED |
return genericMessage( |
| 333 | "PSCourse with psId %s and enroll code %s deleted".formatted(psId, enrollCd)); | |
| 334 | } | |
| 335 | ||
| 336 | @Operation(summary = "Update a single Course (admin)") | |
| 337 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 338 | @PutMapping("/admin") | |
| 339 | public PSCourse putCourseById_admin( | |
| 340 | @Parameter(name = "id") @RequestParam Long id, @RequestBody @Valid PSCourse incomingCourses) { | |
| 341 | PSCourse courses = | |
| 342 | coursesRepository | |
| 343 | .findById(id) | |
| 344 |
1
1. lambda$putCourseById_admin$8 : replaced return value with null for edu/ucsb/cs156/courses/controllers/PSCourseController::lambda$putCourseById_admin$8 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(PSCourse.class, id)); |
| 345 | ||
| 346 |
1
1. putCourseById_admin : removed call to edu/ucsb/cs156/courses/entities/PSCourse::setEnrollCd → KILLED |
courses.setEnrollCd(incomingCourses.getEnrollCd()); |
| 347 |
1
1. putCourseById_admin : removed call to edu/ucsb/cs156/courses/entities/PSCourse::setPsId → KILLED |
courses.setPsId(incomingCourses.getPsId()); |
| 348 | ||
| 349 | coursesRepository.save(courses); | |
| 350 | ||
| 351 |
1
1. putCourseById_admin : replaced return value with null for edu/ucsb/cs156/courses/controllers/PSCourseController::putCourseById_admin → KILLED |
return courses; |
| 352 | } | |
| 353 | ||
| 354 | @Operation(summary = "Update a single course (user)") | |
| 355 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 356 | @PutMapping("/user") | |
| 357 | public PSCourse putCoursesById( | |
| 358 | @Parameter(name = "id") @RequestParam Long id, @RequestBody @Valid PSCourse incomingCourses) { | |
| 359 | User currentUser = getCurrentUser().getUser(); | |
| 360 | PSCourse courses = | |
| 361 | coursesRepository | |
| 362 | .findByIdAndUser(id, currentUser) | |
| 363 |
1
1. lambda$putCoursesById$9 : replaced return value with null for edu/ucsb/cs156/courses/controllers/PSCourseController::lambda$putCoursesById$9 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(PSCourse.class, id)); |
| 364 | ||
| 365 |
1
1. putCoursesById : removed call to edu/ucsb/cs156/courses/entities/PSCourse::setEnrollCd → KILLED |
courses.setEnrollCd(incomingCourses.getEnrollCd()); |
| 366 |
1
1. putCoursesById : removed call to edu/ucsb/cs156/courses/entities/PSCourse::setPsId → KILLED |
courses.setPsId(incomingCourses.getPsId()); |
| 367 | ||
| 368 | coursesRepository.save(courses); | |
| 369 | ||
| 370 |
1
1. putCoursesById : replaced return value with null for edu/ucsb/cs156/courses/controllers/PSCourseController::putCoursesById → KILLED |
return courses; |
| 371 | } | |
| 372 | } | |
Mutations | ||
| 49 |
1.1 |
|
| 58 |
1.1 |
|
| 66 |
1.1 |
|
| 76 |
1.1 |
|
| 86 |
1.1 |
|
| 88 |
1.1 |
|
| 99 |
1.1 |
|
| 101 |
1.1 |
|
| 117 |
1.1 |
|
| 120 |
1.1 |
|
| 121 |
1.1 |
|
| 131 |
1.1 |
|
| 136 |
1.1 |
|
| 138 |
1.1 |
|
| 146 |
1.1 |
|
| 152 |
1.1 |
|
| 153 |
1.1 |
|
| 159 |
1.1 |
|
| 165 |
1.1 |
|
| 166 |
1.1 |
|
| 167 |
1.1 |
|
| 169 |
1.1 |
|
| 173 |
1.1 |
|
| 174 |
1.1 |
|
| 175 |
1.1 |
|
| 180 |
1.1 |
|
| 183 |
1.1 |
|
| 186 |
1.1 |
|
| 187 |
1.1 |
|
| 188 |
1.1 |
|
| 191 |
1.1 |
|
| 198 |
1.1 |
|
| 199 |
1.1 |
|
| 200 |
1.1 |
|
| 204 |
1.1 |
|
| 214 |
1.1 |
|
| 216 |
1.1 |
|
| 218 |
1.1 |
|
| 229 |
1.1 |
|
| 234 |
1.1 |
|
| 238 |
1.1 |
|
| 239 |
1.1 |
|
| 240 |
1.1 |
|
| 241 |
1.1 |
|
| 247 |
1.1 |
|
| 253 |
1.1 |
|
| 255 |
1.1 |
|
| 257 |
1.1 |
|
| 260 |
1.1 2.2 |
|
| 261 |
1.1 |
|
| 262 |
1.1 |
|
| 266 |
1.1 |
|
| 271 |
1.1 |
|
| 288 |
1.1 |
|
| 294 |
1.1 |
|
| 298 |
1.1 |
|
| 299 |
1.1 |
|
| 300 |
1.1 |
|
| 301 |
1.1 |
|
| 308 |
1.1 |
|
| 314 |
1.1 |
|
| 316 |
1.1 |
|
| 318 |
1.1 |
|
| 321 |
1.1 2.2 |
|
| 322 |
1.1 |
|
| 323 |
1.1 |
|
| 327 |
1.1 |
|
| 332 |
1.1 |
|
| 344 |
1.1 |
|
| 346 |
1.1 |
|
| 347 |
1.1 |
|
| 351 |
1.1 |
|
| 363 |
1.1 |
|
| 365 |
1.1 |
|
| 366 |
1.1 |
|
| 370 |
1.1 |