PersonalSectionsController.java

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.errors.EntityNotFoundException;
10
import edu.ucsb.cs156.courses.repositories.PSCourseRepository;
11
import edu.ucsb.cs156.courses.repositories.PersonalScheduleRepository;
12
import edu.ucsb.cs156.courses.services.UCSBCurriculumService;
13
import io.swagger.v3.oas.annotations.Operation;
14
import io.swagger.v3.oas.annotations.Parameter;
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.RequestParam;
23
import org.springframework.web.bind.annotation.RestController;
24
25
@Tag(name = "Personal Sections")
26
@RequestMapping("/api/personalSections")
27
@RestController
28
@Slf4j
29
public class PersonalSectionsController extends ApiController {
30
  @Autowired PersonalScheduleRepository personalScheduleRepository;
31
32
  @Autowired PSCourseRepository coursesRepository;
33
34
  @Autowired private ObjectMapper objectMapper;
35
36
  @Autowired UCSBCurriculumService ucsbCurriculumService;
37
38
  @Operation(summary = "List all sections given a psId")
39
  @PreAuthorize("hasRole('ROLE_USER')")
40
  @GetMapping(value = "/all", produces = "application/json")
41
  public ArrayList<Course> getSectionsByPsId(@Parameter(name = "psId") @RequestParam Long psId)
42
      throws JsonProcessingException {
43
    User us = getCurrentUser().getUser();
44
    PersonalSchedule ps =
45
        personalScheduleRepository
46
            .findByIdAndUser(psId, us)
47 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));
48
    ArrayList<Course> sections = new ArrayList<Course>();
49
    ArrayList<String> jsons = new ArrayList<String>();
50
    Iterable<PSCourse> courses = coursesRepository.findAllByPsId(psId);
51
    for (PSCourse crs : courses) {
52
53
      User u = crs.getUser();
54
      String qtr = ps.getQuarter();
55
      String responseBody = ucsbCurriculumService.getJSONbyQtrEnrollCd(qtr, crs.getEnrollCd());
56
      jsons.add(responseBody);
57
      Course course = objectMapper.readValue(responseBody, Course.class);
58
      sections.add(course);
59
    }
60 1 1. getSectionsByPsId : replaced return value with null for edu/ucsb/cs156/courses/controllers/PersonalSectionsController::getSectionsByPsId → KILLED
    return sections;
61
  }
62
}

Mutations

47

1.1
Location : lambda$getSectionsByPsId$0
Killed by : edu.ucsb.cs156.courses.controllers.PersonalSectionsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.PersonalSectionsControllerTests]/[method:api_psid_sections__user_logged_in__no_personal_schedule()]
replaced return value with null for edu/ucsb/cs156/courses/controllers/PersonalSectionsController::lambda$getSectionsByPsId$0 → KILLED

60

1.1
Location : getSectionsByPsId
Killed by : edu.ucsb.cs156.courses.controllers.PersonalSectionsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.PersonalSectionsControllerTests]/[method:api_psid_sections__user_logged_in__returns_existing_course()]
replaced return value with null for edu/ucsb/cs156/courses/controllers/PersonalSectionsController::getSectionsByPsId → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3