1 | package edu.ucsb.cs156.courses.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.courses.entities.PersonalSchedule; | |
4 | import edu.ucsb.cs156.courses.entities.PSCourse; | |
5 | import edu.ucsb.cs156.courses.entities.User; | |
6 | import edu.ucsb.cs156.courses.errors.EntityNotFoundException; | |
7 | import edu.ucsb.cs156.courses.models.CurrentUser; | |
8 | import edu.ucsb.cs156.courses.repositories.PersonalScheduleRepository; | |
9 | import edu.ucsb.cs156.courses.repositories.PSCourseRepository; | |
10 | import edu.ucsb.cs156.courses.services.UCSBCurriculumService; | |
11 | import edu.ucsb.cs156.courses.documents.Course; | |
12 | import edu.ucsb.cs156.courses.documents.CourseInfo; | |
13 | import io.swagger.annotations.Api; | |
14 | import io.swagger.annotations.ApiOperation; | |
15 | import io.swagger.annotations.ApiParam; | |
16 | import io.swagger.annotations.ApiResponse; | |
17 | import lombok.extern.slf4j.Slf4j; | |
18 | ||
19 | import com.fasterxml.jackson.core.JsonProcessingException; | |
20 | import com.fasterxml.jackson.databind.ObjectMapper; | |
21 | ||
22 | import org.springframework.beans.factory.annotation.Autowired; | |
23 | import org.springframework.http.ResponseEntity; | |
24 | import org.springframework.security.access.prepost.PreAuthorize; | |
25 | import org.springframework.web.bind.annotation.DeleteMapping; | |
26 | import org.springframework.web.bind.annotation.GetMapping; | |
27 | import org.springframework.web.bind.annotation.PostMapping; | |
28 | import org.springframework.web.bind.annotation.PutMapping; | |
29 | import org.springframework.web.bind.annotation.RequestBody; | |
30 | import org.springframework.web.bind.annotation.RequestMapping; | |
31 | import org.springframework.web.bind.annotation.RequestParam; | |
32 | import org.springframework.web.bind.annotation.RestController; | |
33 | ||
34 | import java.util.ArrayList; | |
35 | import java.util.List; | |
36 | ||
37 | ||
38 | import javax.validation.Valid; | |
39 | import java.util.Optional; | |
40 | ||
41 | @Api(description = "Personal Sections") | |
42 | @RequestMapping("/api/personalSections") | |
43 | @RestController | |
44 | @Slf4j | |
45 | public class PersonalSectionsController extends ApiController { | |
46 | @Autowired | |
47 | PersonalScheduleRepository personalScheduleRepository; | |
48 | ||
49 | @Autowired | |
50 | PSCourseRepository coursesRepository; | |
51 | ||
52 | @Autowired | |
53 | private ObjectMapper objectMapper; | |
54 | ||
55 | @Autowired | |
56 | UCSBCurriculumService ucsbCurriculumService; | |
57 | ||
58 | @ApiOperation(value = "List all sections given a psId") | |
59 | @PreAuthorize("hasRole('ROLE_USER')") | |
60 | @GetMapping(value = "/all", produces = "application/json") | |
61 | public ArrayList<Course> getSectionsByPsId(@ApiParam("psId") @RequestParam Long psId) throws JsonProcessingException{ | |
62 | User us = getCurrentUser().getUser(); | |
63 | PersonalSchedule ps = personalScheduleRepository.findByIdAndUser(psId,us) | |
64 |
1
1. lambda$getSectionsByPsId$0 : replaced return value with null for edu/ucsb/cs156/courses/controllers/PersonalSectionsController::lambda$getSectionsByPsId$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(PersonalSchedule.class, psId)); |
65 | ArrayList<Course> sections = new ArrayList<Course>(); | |
66 | ArrayList<String> jsons = new ArrayList<String>(); | |
67 | Iterable<PSCourse> courses = coursesRepository.findAllByPsId(psId); | |
68 | for (PSCourse crs:courses) { | |
69 | ||
70 | User u = crs.getUser(); | |
71 | String qtr = ps.getQuarter(); | |
72 | String responseBody = ucsbCurriculumService.getJSONbyQtrEnrollCd(qtr, crs.getEnrollCd()); | |
73 | jsons.add(responseBody); | |
74 | Course course = objectMapper.readValue(responseBody, Course.class); | |
75 | sections.add(course); | |
76 | ||
77 | } | |
78 |
1
1. getSectionsByPsId : replaced return value with null for edu/ucsb/cs156/courses/controllers/PersonalSectionsController::getSectionsByPsId → KILLED |
return sections; |
79 | } | |
80 | ||
81 | } | |
Mutations | ||
64 |
1.1 |
|
78 |
1.1 |