| 1 | package edu.ucsb.cs156.courses.controllers; | |
| 2 | ||
| 3 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 4 | import com.fasterxml.jackson.databind.ObjectMapper; | |
| 5 | import edu.ucsb.cs156.courses.documents.Course; | |
| 6 | import edu.ucsb.cs156.courses.entities.PSCourse; | |
| 7 | import edu.ucsb.cs156.courses.entities.PersonalSchedule; | |
| 8 | import edu.ucsb.cs156.courses.entities.User; | |
| 9 | import edu.ucsb.cs156.courses.models.CourseWithSchedule; | |
| 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.tags.Tag; | |
| 16 | import java.util.ArrayList; | |
| 17 | import lombok.extern.slf4j.Slf4j; | |
| 18 | import org.springframework.beans.factory.annotation.Autowired; | |
| 19 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 20 | import org.springframework.web.bind.annotation.GetMapping; | |
| 21 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 22 | import org.springframework.web.bind.annotation.RestController; | |
| 23 | ||
| 24 | @Tag(name = "PS Course Details") | |
| 25 | @RequestMapping("/api/courseDetails") | |
| 26 | @RestController | |
| 27 | @Slf4j | |
| 28 | public class PSCourseDetailsController extends ApiController { | |
| 29 | @Autowired PersonalScheduleRepository personalScheduleRepository; | |
| 30 | ||
| 31 | @Autowired PSCourseRepository coursesRepository; | |
| 32 | ||
| 33 | @Autowired private ObjectMapper objectMapper; | |
| 34 | ||
| 35 | @Autowired UCSBCurriculumService ucsbCurriculumService; | |
| 36 | ||
| 37 | @Operation(summary = "List all sections for a user") | |
| 38 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 39 | @GetMapping(value = "/all", produces = "application/json") | |
| 40 | public ArrayList<CourseWithSchedule> allSections() throws JsonProcessingException { | |
| 41 | CurrentUser currentUser = getCurrentUser(); | |
| 42 | Iterable<PersonalSchedule> personalSchedules = | |
| 43 | personalScheduleRepository.findAllByUserId(currentUser.getUser().getId()); | |
| 44 | ||
| 45 | ArrayList<CourseWithSchedule> sections = new ArrayList<CourseWithSchedule>(); | |
| 46 | ArrayList<String> jsons = new ArrayList<String>(); | |
| 47 | for (PersonalSchedule personalSchedule : personalSchedules) { | |
| 48 | Iterable<PSCourse> courses = coursesRepository.findAllByPsId(personalSchedule.getId()); | |
| 49 | for (PSCourse crs : courses) { | |
| 50 | CourseWithSchedule courseWithSchedule = new CourseWithSchedule(); | |
| 51 |
1
1. allSections : removed call to edu/ucsb/cs156/courses/models/CourseWithSchedule::setPersonalSchedule → KILLED |
courseWithSchedule.setPersonalSchedule(personalSchedule); |
| 52 | ||
| 53 | User u = crs.getUser(); | |
| 54 | String qtr = personalSchedule.getQuarter(); | |
| 55 | String responseBody = ucsbCurriculumService.getJSONbyQtrEnrollCd(qtr, crs.getEnrollCd()); | |
| 56 | jsons.add(responseBody); | |
| 57 | Course course = objectMapper.readValue(responseBody, Course.class); | |
| 58 |
1
1. allSections : removed call to edu/ucsb/cs156/courses/models/CourseWithSchedule::setCourse → KILLED |
courseWithSchedule.setCourse(course); |
| 59 | sections.add(courseWithSchedule); | |
| 60 | } | |
| 61 | } | |
| 62 |
1
1. allSections : replaced return value with null for edu/ucsb/cs156/courses/controllers/PSCourseDetailsController::allSections → KILLED |
return sections; |
| 63 | } | |
| 64 | } | |
Mutations | ||
| 51 |
1.1 |
|
| 58 |
1.1 |
|
| 62 |
1.1 |