Skip to content

Commit

Permalink
feat: coursetype 반환값 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Soundbar91 committed Dec 21, 2024
1 parent 2af5b15 commit caa6f54
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package in.koreatech.koin.domain.timetableV2.factory;

import static in.koreatech.koin.domain.timetableV2.dto.request.TimetableLectureCreateRequest.*;
import static in.koreatech.koin.domain.timetableV2.dto.request.TimetableLectureCreateRequest.InnerTimeTableLectureRequest;

import org.springframework.stereotype.Component;

import in.koreatech.koin.domain.graduation.model.Catalog;
import in.koreatech.koin.domain.graduation.model.CourseType;
import in.koreatech.koin.domain.graduation.model.Department;
import in.koreatech.koin.domain.graduation.repository.CatalogRepository;
import in.koreatech.koin.domain.graduation.repository.DepartmentRepository;
import in.koreatech.koin.domain.student.model.Student;
import in.koreatech.koin.domain.student.repository.StudentRepository;
import in.koreatech.koin.domain.student.util.StudentUtil;
import in.koreatech.koin.domain.timetable.model.Lecture;
import in.koreatech.koin.domain.timetableV2.dto.request.TimetableLectureCreateRequest;
import in.koreatech.koin.domain.timetableV2.model.TimetableFrame;
Expand All @@ -18,16 +26,36 @@ public class TimetableLectureCreator {

private final LectureRepositoryV2 lectureRepositoryV2;
private final TimetableLectureRepositoryV2 timetableLectureRepositoryV2;
private final CatalogRepository catalogRepository;
private final DepartmentRepository departmentRepository;
private final StudentRepository studentRepository;

public void createTimetableLectures(TimetableLectureCreateRequest request, TimetableFrame frame) {
public void createTimetableLectures(TimetableLectureCreateRequest request, Integer userId, TimetableFrame frame) {
for (InnerTimeTableLectureRequest lectureRequest : request.timetableLecture()) {
Lecture lecture = determineLecture(lectureRequest.lectureId());
TimetableLecture timetableLecture = lectureRequest.toTimetableLecture(frame, lecture);
CourseType courseType = determineCourseType(lecture, userId);
TimetableLecture timetableLecture = lectureRequest.toTimetableLecture(frame, lecture, courseType);
frame.addTimeTableLecture(timetableLecture);
timetableLectureRepositoryV2.save(timetableLecture);
}
}

private CourseType determineCourseType(Lecture lecture, Integer userId) {
if (lecture != null) {
return getCourseType(userId, lecture);
}
return null;
}

private CourseType getCourseType(Integer userId, Lecture lecture) {
Student student = studentRepository.getById(userId);
String year = StudentUtil.parseStudentNumberYear(student.getStudentNumber()).toString();
Department department = departmentRepository.getByName(student.getDepartment());
String code = lecture.getCode();
Catalog catalog = catalogRepository.getByYearAndDepartmentAndCode(year, department, code);
return catalog.getCourseType();
}

private Lecture determineLecture(Integer lectureId) {
if (lectureId != null) {
return lectureRepositoryV2.getLectureById(lectureId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class TimetableLectureService {
public TimetableLectureResponse createTimetableLectures(Integer userId, TimetableLectureCreateRequest request) {
TimetableFrame frame = timetableFrameRepositoryV2.getById(request.timetableFrameId());
validateUserAuthorization(frame.getUser().getId(), userId);
timetableLectureCreator.createTimetableLectures(request, frame);
timetableLectureCreator.createTimetableLectures(request, userId, frame);
return getTimetableLectureResponse(userId, frame);
}

Expand Down

0 comments on commit caa6f54

Please sign in to comment.