PersonalSectionsController.java

1
package edu.ucsb.cs156.courses.controllers;
2
3
import com.fasterxml.jackson.databind.ObjectMapper;
4
import edu.ucsb.cs156.courses.documents.Course;
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.EntityNotFoundException;
9
import edu.ucsb.cs156.courses.repositories.PSCourseRepository;
10
import edu.ucsb.cs156.courses.repositories.PersonalScheduleRepository;
11
import edu.ucsb.cs156.courses.services.UCSBCurriculumService;
12
import io.swagger.v3.oas.annotations.Operation;
13
import io.swagger.v3.oas.annotations.Parameter;
14
import io.swagger.v3.oas.annotations.tags.Tag;
15
import java.util.ArrayList;
16
import lombok.extern.slf4j.Slf4j;
17
import org.springframework.beans.factory.annotation.Autowired;
18
import org.springframework.security.access.prepost.PreAuthorize;
19
import org.springframework.web.bind.annotation.GetMapping;
20
import org.springframework.web.bind.annotation.RequestMapping;
21
import org.springframework.web.bind.annotation.RequestParam;
22
import org.springframework.web.bind.annotation.RestController;
23
24
@Tag(name = "Personal Sections")
25
@RequestMapping("/api/personalSections")
26
@RestController
27
@Slf4j
28
public class PersonalSectionsController 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 given a psId")
38
  @PreAuthorize("hasRole('ROLE_USER')")
39
  @GetMapping(value = "/all", produces = "application/json")
40
  public ArrayList<Course> getSectionsByPsId(@Parameter(name = "psId") @RequestParam Long psId)
41
      throws Exception {
42
    User us = getCurrentUser().getUser();
43
    PersonalSchedule ps =
44
        personalScheduleRepository
45
            .findByIdAndUser(psId, us)
46 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));
47
    ArrayList<Course> sections = new ArrayList<Course>();
48
    ArrayList<String> jsons = new ArrayList<String>();
49
    Iterable<PSCourse> courses = coursesRepository.findAllByPsId(psId);
50
    for (PSCourse crs : courses) {
51
52
      User u = crs.getUser();
53
      String qtr = ps.getQuarter();
54
      String responseBody = ucsbCurriculumService.getJSONbyQtrEnrollCd(qtr, crs.getEnrollCd());
55
      jsons.add(responseBody);
56
      Course course = objectMapper.readValue(responseBody, Course.class);
57
      sections.add(course);
58
    }
59 1 1. getSectionsByPsId : replaced return value with null for edu/ucsb/cs156/courses/controllers/PersonalSectionsController::getSectionsByPsId → KILLED
    return sections;
60
  }
61
}

Mutations

46

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

59

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.17.0