From 8d9d75f0866293371dcdfdd175624ae500e87696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=A0=EA=B4=80=EA=B7=9C?= Date: Wed, 18 Dec 2024 14:19:18 +0900 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20repository=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/CatalogRepository.java | 19 ++++++++++++++++++ .../repository/CourseTypeRepository.java | 20 +++++++++++++++++++ .../repository/DepartmentRepository.java | 17 ++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 src/main/java/in/koreatech/koin/domain/graduation/repository/CatalogRepository.java create mode 100644 src/main/java/in/koreatech/koin/domain/graduation/repository/CourseTypeRepository.java create mode 100644 src/main/java/in/koreatech/koin/domain/graduation/repository/DepartmentRepository.java diff --git a/src/main/java/in/koreatech/koin/domain/graduation/repository/CatalogRepository.java b/src/main/java/in/koreatech/koin/domain/graduation/repository/CatalogRepository.java new file mode 100644 index 000000000..d68adc26e --- /dev/null +++ b/src/main/java/in/koreatech/koin/domain/graduation/repository/CatalogRepository.java @@ -0,0 +1,19 @@ +package in.koreatech.koin.domain.graduation.repository; + +import java.util.Optional; + +import org.springframework.data.repository.Repository; + +import in.koreatech.koin.domain.graduation.exception.CatalogNotFoundException; +import in.koreatech.koin.domain.graduation.model.Catalog; +import in.koreatech.koin.domain.graduation.model.Department; + +public interface CatalogRepository extends Repository { + Optional findByYearAndDepartmentAndCode(String year, Department department, String code); + + default Catalog getByYearAndDepartmentAndCode(String year, Department department, String code) { + return findByYearAndDepartmentAndCode(year, department, code) + .orElseThrow(() -> CatalogNotFoundException.withDetail( + "year: " + year + ", department: " + department + ", code: " + code)); + } +} diff --git a/src/main/java/in/koreatech/koin/domain/graduation/repository/CourseTypeRepository.java b/src/main/java/in/koreatech/koin/domain/graduation/repository/CourseTypeRepository.java new file mode 100644 index 000000000..763c826e9 --- /dev/null +++ b/src/main/java/in/koreatech/koin/domain/graduation/repository/CourseTypeRepository.java @@ -0,0 +1,20 @@ +package in.koreatech.koin.domain.graduation.repository; + +import java.util.Optional; + +import org.springframework.data.repository.Repository; + +import in.koreatech.koin.domain.graduation.exception.CourseTypeNotFoundException; +import in.koreatech.koin.domain.graduation.model.CourseType; + +public interface CourseTypeRepository extends Repository { + + CourseType save(CourseType courseType); + + Optional findById(Integer id); + + default CourseType getCourseTypeById(Integer id) { + return findById(id) + .orElseThrow(() -> CourseTypeNotFoundException.withDetail("course_type_id: " + id)); + } +} diff --git a/src/main/java/in/koreatech/koin/domain/graduation/repository/DepartmentRepository.java b/src/main/java/in/koreatech/koin/domain/graduation/repository/DepartmentRepository.java new file mode 100644 index 000000000..6c6b64666 --- /dev/null +++ b/src/main/java/in/koreatech/koin/domain/graduation/repository/DepartmentRepository.java @@ -0,0 +1,17 @@ +package in.koreatech.koin.domain.graduation.repository; + +import java.util.Optional; + +import org.springframework.data.repository.Repository; + +import in.koreatech.koin.domain.graduation.exception.DepartmentNotFoundException; +import in.koreatech.koin.domain.graduation.model.Department; + +public interface DepartmentRepository extends Repository { + Optional findByName(String name); + + default Department getByName(String name) { + return findByName(name) + .orElseThrow(() -> DepartmentNotFoundException.withDetail("name: " + name)); + } +} From 2b7fc1518238de472e9195462c0c77140d9523d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=A0=EA=B4=80=EA=B7=9C?= Date: Wed, 18 Dec 2024 14:19:27 +0900 Subject: [PATCH 2/6] =?UTF-8?q?feat:=20exception=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/CatalogNotFoundException.java | 20 +++++++++++++++++++ .../CourseTypeNotFoundException.java | 20 +++++++++++++++++++ .../DepartmentNotFoundException.java | 20 +++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 src/main/java/in/koreatech/koin/domain/graduation/exception/CatalogNotFoundException.java create mode 100644 src/main/java/in/koreatech/koin/domain/graduation/exception/CourseTypeNotFoundException.java create mode 100644 src/main/java/in/koreatech/koin/domain/graduation/exception/DepartmentNotFoundException.java diff --git a/src/main/java/in/koreatech/koin/domain/graduation/exception/CatalogNotFoundException.java b/src/main/java/in/koreatech/koin/domain/graduation/exception/CatalogNotFoundException.java new file mode 100644 index 000000000..ce889e50b --- /dev/null +++ b/src/main/java/in/koreatech/koin/domain/graduation/exception/CatalogNotFoundException.java @@ -0,0 +1,20 @@ +package in.koreatech.koin.domain.graduation.exception; + +import in.koreatech.koin.global.exception.DataNotFoundException; + +public class CatalogNotFoundException extends DataNotFoundException { + + private static final String DEFAULT_MESSAGE = "존재하지 않는 대학 요람입니다."; + + protected CatalogNotFoundException(String message) { + super(message); + } + + protected CatalogNotFoundException(String message, String detail) { + super(message, detail); + } + + public static CatalogNotFoundException withDetail(String detail) { + return new CatalogNotFoundException(DEFAULT_MESSAGE, detail); + } +} diff --git a/src/main/java/in/koreatech/koin/domain/graduation/exception/CourseTypeNotFoundException.java b/src/main/java/in/koreatech/koin/domain/graduation/exception/CourseTypeNotFoundException.java new file mode 100644 index 000000000..33d92714b --- /dev/null +++ b/src/main/java/in/koreatech/koin/domain/graduation/exception/CourseTypeNotFoundException.java @@ -0,0 +1,20 @@ +package in.koreatech.koin.domain.graduation.exception; + +import in.koreatech.koin.global.exception.DataNotFoundException; + +public class CourseTypeNotFoundException extends DataNotFoundException { + + private static final String DEFAULT_MESSAGE = "존재하지 않는 이수 구분입니다."; + + protected CourseTypeNotFoundException(String message) { + super(message); + } + + protected CourseTypeNotFoundException(String message, String detail) { + super(message, detail); + } + + public static CourseTypeNotFoundException withDetail(String detail) { + return new CourseTypeNotFoundException(DEFAULT_MESSAGE, detail); + } +} diff --git a/src/main/java/in/koreatech/koin/domain/graduation/exception/DepartmentNotFoundException.java b/src/main/java/in/koreatech/koin/domain/graduation/exception/DepartmentNotFoundException.java new file mode 100644 index 000000000..94f34dc80 --- /dev/null +++ b/src/main/java/in/koreatech/koin/domain/graduation/exception/DepartmentNotFoundException.java @@ -0,0 +1,20 @@ +package in.koreatech.koin.domain.graduation.exception; + +import in.koreatech.koin.global.exception.DataNotFoundException; + +public class DepartmentNotFoundException extends DataNotFoundException { + + private static final String DEFAULT_MESSAGE = "존재하지 않는 학과입니다."; + + protected DepartmentNotFoundException(String message) { + super(message); + } + + protected DepartmentNotFoundException(String message, String detail) { + super(message, detail); + } + + public static DepartmentNotFoundException withDetail(String detail) { + return new DepartmentNotFoundException(DEFAULT_MESSAGE, detail); + } +} From 2af5b15dc1fdf1bc7280dbbe7a8b875df7821d22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=A0=EA=B4=80=EA=B7=9C?= Date: Wed, 18 Dec 2024 14:23:49 +0900 Subject: [PATCH 3/6] =?UTF-8?q?feat:=20=EC=9D=B4=EC=88=98=20=EA=B5=AC?= =?UTF-8?q?=EB=B6=84=20=EB=B0=98=ED=99=98=EA=B0=92=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/TimetableLectureCreateRequest.java | 10 +++++++--- .../dto/response/TimetableLectureResponse.java | 9 +++++++-- .../domain/timetableV2/model/TimetableLecture.java | 9 ++++++++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/main/java/in/koreatech/koin/domain/timetableV2/dto/request/TimetableLectureCreateRequest.java b/src/main/java/in/koreatech/koin/domain/timetableV2/dto/request/TimetableLectureCreateRequest.java index 4c52f7324..95ebe9f72 100644 --- a/src/main/java/in/koreatech/koin/domain/timetableV2/dto/request/TimetableLectureCreateRequest.java +++ b/src/main/java/in/koreatech/koin/domain/timetableV2/dto/request/TimetableLectureCreateRequest.java @@ -11,6 +11,7 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; import com.fasterxml.jackson.databind.annotation.JsonNaming; +import in.koreatech.koin.domain.graduation.model.CourseType; import in.koreatech.koin.domain.timetable.model.Lecture; import in.koreatech.koin.domain.timetableV2.exception.TimetableLectureClassTimeNullException; import in.koreatech.koin.domain.timetableV2.model.TimetableFrame; @@ -91,11 +92,13 @@ public TimetableLecture toTimetableLecture(TimetableFrame timetableFrame) { memo, false, null, - timetableFrame + timetableFrame, + null ); } - public TimetableLecture toTimetableLecture(TimetableFrame timetableFrame, Lecture lecture) { + public TimetableLecture toTimetableLecture(TimetableFrame timetableFrame, Lecture lecture, + CourseType courseType) { return new TimetableLecture( classTitle, getClassTimeToString(), @@ -105,7 +108,8 @@ public TimetableLecture toTimetableLecture(TimetableFrame timetableFrame, Lectur memo, false, lecture, - timetableFrame + timetableFrame, + courseType ); } diff --git a/src/main/java/in/koreatech/koin/domain/timetableV2/dto/response/TimetableLectureResponse.java b/src/main/java/in/koreatech/koin/domain/timetableV2/dto/response/TimetableLectureResponse.java index e55bbe476..7f7424142 100644 --- a/src/main/java/in/koreatech/koin/domain/timetableV2/dto/response/TimetableLectureResponse.java +++ b/src/main/java/in/koreatech/koin/domain/timetableV2/dto/response/TimetableLectureResponse.java @@ -69,7 +69,10 @@ public record InnerTimetableLectureResponse( String professor, @Schema(description = "학부", example = "디자인ㆍ건축공학부", requiredMode = NOT_REQUIRED) - String department + String department, + + @Schema(description = "이수 구분", example = "전공필수", requiredMode = NOT_REQUIRED) + String courseType ) { @JsonNaming(value = SnakeCaseStrategy.class) public record ClassInfo( @@ -156,6 +159,7 @@ public static List from(List ti null, null, timetableLecture.getProfessor(), + null, null ); } else { @@ -172,7 +176,8 @@ public static List from(List ti lecture.getLectureClass(), lecture.getTarget(), getProfessor(timetableLecture, lecture), - lecture.getDepartment() + lecture.getDepartment(), + timetableLecture.getCourseType().getName() ); } timetableLectureList.add(response); diff --git a/src/main/java/in/koreatech/koin/domain/timetableV2/model/TimetableLecture.java b/src/main/java/in/koreatech/koin/domain/timetableV2/model/TimetableLecture.java index 3d260945f..9c34ff02a 100644 --- a/src/main/java/in/koreatech/koin/domain/timetableV2/model/TimetableLecture.java +++ b/src/main/java/in/koreatech/koin/domain/timetableV2/model/TimetableLecture.java @@ -5,6 +5,7 @@ import org.hibernate.annotations.Where; +import in.koreatech.koin.domain.graduation.model.CourseType; import in.koreatech.koin.domain.timetable.dto.TimetableUpdateRequest; import in.koreatech.koin.domain.timetable.model.Lecture; import in.koreatech.koin.global.domain.BaseEntity; @@ -71,9 +72,14 @@ public class TimetableLecture extends BaseEntity { @JoinColumn(name = "frame_id") private TimetableFrame timetableFrame; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "course_type_id") + private CourseType courseType; + @Builder public TimetableLecture(String classTitle, String classTime, String classPlace, String professor, - String grades, String memo, boolean isDeleted, Lecture lecture, TimetableFrame timetableFrame) { + String grades, String memo, boolean isDeleted, Lecture lecture, TimetableFrame timetableFrame, + CourseType courseType) { this.classTitle = classTitle; this.classTime = classTime; this.classPlace = classPlace; @@ -83,6 +89,7 @@ public TimetableLecture(String classTitle, String classTime, String classPlace, this.isDeleted = isDeleted; this.lecture = lecture; this.timetableFrame = timetableFrame; + this.courseType = courseType; } public void update( From caa6f542e1e8c8247537392be7704f64a57a6ea9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=A0=EA=B4=80=EA=B7=9C?= Date: Sun, 22 Dec 2024 00:58:10 +0900 Subject: [PATCH 4/6] =?UTF-8?q?feat:=20coursetype=20=EB=B0=98=ED=99=98?= =?UTF-8?q?=EA=B0=92=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../factory/TimetableLectureCreator.java | 34 +++++++++++++++++-- .../service/TimetableLectureService.java | 2 +- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/main/java/in/koreatech/koin/domain/timetableV2/factory/TimetableLectureCreator.java b/src/main/java/in/koreatech/koin/domain/timetableV2/factory/TimetableLectureCreator.java index 645345d44..6e3499a8a 100644 --- a/src/main/java/in/koreatech/koin/domain/timetableV2/factory/TimetableLectureCreator.java +++ b/src/main/java/in/koreatech/koin/domain/timetableV2/factory/TimetableLectureCreator.java @@ -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; @@ -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); diff --git a/src/main/java/in/koreatech/koin/domain/timetableV2/service/TimetableLectureService.java b/src/main/java/in/koreatech/koin/domain/timetableV2/service/TimetableLectureService.java index e15c34d8c..29e932a02 100644 --- a/src/main/java/in/koreatech/koin/domain/timetableV2/service/TimetableLectureService.java +++ b/src/main/java/in/koreatech/koin/domain/timetableV2/service/TimetableLectureService.java @@ -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); } From 6f65812cf4cab0ba7ef9933427d0784df316b571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=A0=EA=B4=80=EA=B7=9C?= Date: Sun, 22 Dec 2024 01:20:10 +0900 Subject: [PATCH 5/6] =?UTF-8?q?test:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../koin/acceptance/TimetableApiTest.java | 8 +-- .../acceptance/TimetableFrameApiTest.java | 9 ++- .../acceptance/TimetableLectureApiTest.java | 65 ++++++++++++++----- .../koin/fixture/CourseTypeFixture.java | 41 ++++++++++++ .../koin/fixture/TimeTableV2Fixture.java | 24 +++++-- 5 files changed, 119 insertions(+), 28 deletions(-) create mode 100644 src/test/java/in/koreatech/koin/fixture/CourseTypeFixture.java diff --git a/src/test/java/in/koreatech/koin/acceptance/TimetableApiTest.java b/src/test/java/in/koreatech/koin/acceptance/TimetableApiTest.java index 125f4de22..afd4b27a8 100644 --- a/src/test/java/in/koreatech/koin/acceptance/TimetableApiTest.java +++ b/src/test/java/in/koreatech/koin/acceptance/TimetableApiTest.java @@ -242,7 +242,7 @@ void setup() { Lecture 건축구조의_이해_및_실습 = lectureFixture.건축구조의_이해_및_실습(semester.getSemester()); Lecture HRD_개론 = lectureFixture.HRD_개론(semester.getSemester()); - timetableV2Fixture.시간표6(user, semester, 건축구조의_이해_및_실습, HRD_개론); + timetableV2Fixture.시간표6(user, semester, 건축구조의_이해_및_실습, HRD_개론, null, null); mockMvc.perform( get("/timetables") @@ -324,8 +324,8 @@ void setup() { Semester semester2 = semesterFixture.semester("20201"); Lecture HRD_개론 = lectureFixture.HRD_개론(semester1.getSemester()); Lecture 건축구조의_이해_및_실습 = lectureFixture.건축구조의_이해_및_실습(semester2.getSemester()); - timetableV2Fixture.시간표6(user, semester1, HRD_개론, null); - timetableV2Fixture.시간표6(user, semester2, 건축구조의_이해_및_실습, null); + timetableV2Fixture.시간표6(user, semester1, HRD_개론, null, null, null); + timetableV2Fixture.시간표6(user, semester2, 건축구조의_이해_및_실습, null, null, null); mockMvc.perform( get("/semesters/check") @@ -553,7 +553,7 @@ void setup() { Lecture 건축구조의_이해_및_실습 = lectureFixture.건축구조의_이해_및_실습(semester.getSemester()); Lecture HRD_개론 = lectureFixture.HRD_개론(semester.getSemester()); - timetableV2Fixture.시간표6(user, semester, 건축구조의_이해_및_실습, HRD_개론); + timetableV2Fixture.시간표6(user, semester, 건축구조의_이해_및_실습, HRD_개론, null, null); mockMvc.perform( delete("/timetable") diff --git a/src/test/java/in/koreatech/koin/acceptance/TimetableFrameApiTest.java b/src/test/java/in/koreatech/koin/acceptance/TimetableFrameApiTest.java index 0a66b6e6f..69626f886 100644 --- a/src/test/java/in/koreatech/koin/acceptance/TimetableFrameApiTest.java +++ b/src/test/java/in/koreatech/koin/acceptance/TimetableFrameApiTest.java @@ -14,12 +14,14 @@ import org.springframework.transaction.annotation.Transactional; import in.koreatech.koin.AcceptanceTest; +import in.koreatech.koin.domain.graduation.model.CourseType; import in.koreatech.koin.domain.timetable.model.Lecture; import in.koreatech.koin.domain.timetable.model.Semester; import in.koreatech.koin.domain.timetableV2.model.TimetableFrame; import in.koreatech.koin.domain.timetableV2.repository.TimetableFrameRepositoryV2; import in.koreatech.koin.domain.timetableV2.repository.TimetableLectureRepositoryV2; import in.koreatech.koin.domain.user.model.User; +import in.koreatech.koin.fixture.CourseTypeFixture; import in.koreatech.koin.fixture.LectureFixture; import in.koreatech.koin.fixture.SemesterFixture; import in.koreatech.koin.fixture.TimeTableV2Fixture; @@ -48,6 +50,9 @@ public class TimetableFrameApiTest extends AcceptanceTest { @Autowired private TimetableLectureRepositoryV2 timetableLectureRepositoryV2; + @Autowired + private CourseTypeFixture courseTypeFixture; + private User user; private String token; private Semester semester; @@ -165,8 +170,8 @@ void setup() { @Test void 강의를_담고_있는_특정_시간표_frame을_삭제한다() throws Exception { Lecture lecture = lectureFixture.HRD_개론(semester.getSemester()); - - TimetableFrame frame1 = timetableV2Fixture.시간표5(user, semester, lecture); + CourseType courseType = courseTypeFixture.HRD_필수(); + TimetableFrame frame1 = timetableV2Fixture.시간표5(user, semester, lecture, courseType); mockMvc.perform( delete("/v2/timetables/frame") diff --git a/src/test/java/in/koreatech/koin/acceptance/TimetableLectureApiTest.java b/src/test/java/in/koreatech/koin/acceptance/TimetableLectureApiTest.java index 8f8883f8f..0f13e9dcb 100644 --- a/src/test/java/in/koreatech/koin/acceptance/TimetableLectureApiTest.java +++ b/src/test/java/in/koreatech/koin/acceptance/TimetableLectureApiTest.java @@ -15,11 +15,13 @@ import org.springframework.transaction.annotation.Transactional; import in.koreatech.koin.AcceptanceTest; +import in.koreatech.koin.domain.graduation.model.CourseType; import in.koreatech.koin.domain.timetable.model.Lecture; import in.koreatech.koin.domain.timetable.model.Semester; import in.koreatech.koin.domain.timetableV2.model.TimetableFrame; import in.koreatech.koin.domain.timetableV2.model.TimetableLecture; import in.koreatech.koin.domain.user.model.User; +import in.koreatech.koin.fixture.CourseTypeFixture; import in.koreatech.koin.fixture.LectureFixture; import in.koreatech.koin.fixture.SemesterFixture; import in.koreatech.koin.fixture.TimeTableV2Fixture; @@ -42,6 +44,9 @@ public class TimetableLectureApiTest extends AcceptanceTest { @Autowired private LectureFixture lectureFixture; + @Autowired + private CourseTypeFixture courseTypeFixture; + private User user; private String token; private Semester semester; @@ -75,7 +80,7 @@ void setup() { ], "professor" : "서정빈", "grades": "2", - "memo" : "메모" + "memo" : "메모", }, { "class_title": "커스텀생성2", @@ -117,7 +122,8 @@ void setup() { "lecture_class": null, "target": null, "professor": "서정빈", - "department": null + "department": null, + "course_type": null }, { "id": 2, @@ -137,7 +143,8 @@ void setup() { "lecture_class": null, "target": null, "professor": "감사 서정빈", - "department": null + "department": null, + "course_type": null } ], "grades": 3, @@ -211,7 +218,8 @@ void setup() { "lecture_class": null, "target": null, "professor": "서정빈", - "department": null + "department": null, + "course_type": null }, { "id": 2, @@ -231,7 +239,8 @@ void setup() { "lecture_class": null, "target": null, "professor": "알바 서정빈", - "department": null + "department": null, + "course_type": null } ], "grades": 0, @@ -245,7 +254,10 @@ void setup() { Lecture 건축구조의_이해_및_실습 = lectureFixture.건축구조의_이해_및_실습(semester.getSemester()); Lecture HRD_개론 = lectureFixture.HRD_개론(semester.getSemester()); - TimetableFrame frame = timetableV2Fixture.시간표6(user, semester, 건축구조의_이해_및_실습, HRD_개론); + CourseType 전공_필수 = courseTypeFixture.전공_필수(); + CourseType HRD_필수 = courseTypeFixture.HRD_필수(); + + TimetableFrame frame = timetableV2Fixture.시간표6(user, semester, 건축구조의_이해_및_실습, HRD_개론, 전공_필수, HRD_필수); mockMvc.perform( get("/v2/timetables/lecture") @@ -276,7 +288,8 @@ void setup() { "lecture_class": "01", "target": "디자 1 건축", "professor": "황현식", - "department": "디자인ㆍ건축공학부" + "department": "디자인ㆍ건축공학부", + "course_type": "전공 필수" }, { "id": 2, @@ -296,7 +309,8 @@ void setup() { "lecture_class": "06", "target": "기공1", "professor": "박한수,최준호", - "department": "기계공학부" + "department": "기계공학부", + "course_type": "MSC 필수" } ], "grades": 6, @@ -309,7 +323,10 @@ void setup() { void 시간표에서_특정_강의를_삭제한다() throws Exception { Lecture lecture1 = lectureFixture.HRD_개론("20192"); Lecture lecture2 = lectureFixture.영어청해("20192"); - TimetableFrame frame = timetableV2Fixture.시간표4(user, semester, lecture1, lecture2); + CourseType courseType1 = courseTypeFixture.HRD_필수(); + CourseType courseType2 = courseTypeFixture.교양_필수(); + + TimetableFrame frame = timetableV2Fixture.시간표4(user, semester, lecture1, lecture2, courseType1, courseType2); Integer lectureId = lecture1.getId(); @@ -326,7 +343,10 @@ void setup() { void 시간표에서_특정_강의를_삭제한다_V2() throws Exception { Lecture lecture1 = lectureFixture.HRD_개론("20192"); Lecture lecture2 = lectureFixture.영어청해("20192"); - TimetableFrame frame = timetableV2Fixture.시간표4(user, semester, lecture1, lecture2); + CourseType courseType1 = courseTypeFixture.HRD_필수(); + CourseType courseType2 = courseTypeFixture.교양_필수(); + + TimetableFrame frame = timetableV2Fixture.시간표4(user, semester, lecture1, lecture2, courseType1, courseType2); Integer frameId = frame.getId(); Integer lectureId = lecture1.getId(); @@ -343,7 +363,10 @@ void setup() { void 시간표에서_여러개의_강의를_한번에_삭제한다_V2() throws Exception { Lecture lecture1 = lectureFixture.HRD_개론("20192"); Lecture lecture2 = lectureFixture.영어청해("20192"); - TimetableFrame frame = timetableV2Fixture.시간표4(user, semester, lecture1, lecture2); + CourseType courseType1 = courseTypeFixture.HRD_필수(); + CourseType courseType2 = courseTypeFixture.교양_필수(); + + TimetableFrame frame = timetableV2Fixture.시간표4(user, semester, lecture1, lecture2, courseType1, courseType2); List timetableLectureIds = frame.getTimetableLectures().stream() .map(TimetableLecture::getId) @@ -364,7 +387,9 @@ void setup() { void 시간표에서_삭제된_강의를_복구한다_V2() throws Exception { Lecture 건축구조의_이해_및_실습 = lectureFixture.건축구조의_이해_및_실습(semester.getSemester()); Lecture HRD_개론 = lectureFixture.HRD_개론(semester.getSemester()); - TimetableFrame frame = timetableV2Fixture.시간표8(user, semester, 건축구조의_이해_및_실습, HRD_개론); + CourseType courseType1 = courseTypeFixture.전공_필수(); + CourseType courseType2 = courseTypeFixture.교양_필수(); + TimetableFrame frame = timetableV2Fixture.시간표8(user, semester, 건축구조의_이해_및_실습, HRD_개론, courseType1, courseType2); List timetableLecturesId = frame.getTimetableLectures().stream() .map(TimetableLecture::getId) @@ -401,7 +426,8 @@ void setup() { "lecture_class": "01", "target": "디자 1 건축", "professor": "황현식", - "department": "디자인ㆍ건축공학부" + "department": "디자인ㆍ건축공학부", + "course_type": "전공 필수" }, { "id": 2, @@ -421,7 +447,8 @@ void setup() { "lecture_class": "06", "target": "기공1", "professor": "박한수,최준호", - "department": "기계공학부" + "department": "기계공학부", + "course_type": "MSC 필수" } ], "grades": 6, @@ -434,7 +461,9 @@ void setup() { void 삭제된_시간표프레임과_그에_해당하는_강의를_복구한다_V2() throws Exception { Lecture 건축구조의_이해_및_실습 = lectureFixture.건축구조의_이해_및_실습(semester.getSemester()); Lecture HRD_개론 = lectureFixture.HRD_개론(semester.getSemester()); - TimetableFrame frame = timetableV2Fixture.시간표7(user, semester, 건축구조의_이해_및_실습, HRD_개론); + CourseType courseType1 = courseTypeFixture.전공_필수(); + CourseType courseType2 = courseTypeFixture.교양_필수(); + TimetableFrame frame = timetableV2Fixture.시간표7(user, semester, 건축구조의_이해_및_실습, HRD_개론, courseType1, courseType2); mockMvc.perform( post("/v2/timetables/frame/rollback") @@ -465,7 +494,8 @@ void setup() { "lecture_class": "01", "target": "디자 1 건축", "professor": "황현식", - "department": "디자인ㆍ건축공학부" + "department": "디자인ㆍ건축공학부", + "course_type": "전공 필수" }, { "id": 2, @@ -485,7 +515,8 @@ void setup() { "lecture_class": "06", "target": "기공1", "professor": "박한수,최준호", - "department": "기계공학부" + "department": "기계공학부", + "course_type": "MSC 필수" } ], "grades": 6, diff --git a/src/test/java/in/koreatech/koin/fixture/CourseTypeFixture.java b/src/test/java/in/koreatech/koin/fixture/CourseTypeFixture.java new file mode 100644 index 000000000..9f5a42579 --- /dev/null +++ b/src/test/java/in/koreatech/koin/fixture/CourseTypeFixture.java @@ -0,0 +1,41 @@ +package in.koreatech.koin.fixture; + +import org.springframework.stereotype.Component; + +import in.koreatech.koin.domain.graduation.model.CourseType; +import in.koreatech.koin.domain.graduation.repository.CourseTypeRepository; + +@Component +@SuppressWarnings("NonAsciiCharacters") +public class CourseTypeFixture { + + private final CourseTypeRepository courseTypeRepository; + + public CourseTypeFixture(CourseTypeRepository courseTypeRepository) { + this.courseTypeRepository = courseTypeRepository; + } + + public CourseType 전공_필수() { + return courseTypeRepository.save( + CourseType.builder() + .name("전공 필수") + .build() + ); + } + + public CourseType HRD_필수() { + return courseTypeRepository.save( + CourseType.builder() + .name("MSC 필수") + .build() + ); + } + + public CourseType 교양_필수() { + return courseTypeRepository.save( + CourseType.builder() + .name("교양 필수") + .build() + ); + } +} diff --git a/src/test/java/in/koreatech/koin/fixture/TimeTableV2Fixture.java b/src/test/java/in/koreatech/koin/fixture/TimeTableV2Fixture.java index 2564f758f..b1c273dc8 100644 --- a/src/test/java/in/koreatech/koin/fixture/TimeTableV2Fixture.java +++ b/src/test/java/in/koreatech/koin/fixture/TimeTableV2Fixture.java @@ -4,6 +4,7 @@ import org.springframework.stereotype.Component; +import in.koreatech.koin.domain.graduation.model.CourseType; import in.koreatech.koin.domain.timetable.model.Lecture; import in.koreatech.koin.domain.timetable.model.Semester; import in.koreatech.koin.domain.timetableV2.model.TimetableFrame; @@ -81,7 +82,8 @@ public TimeTableV2Fixture( return timetableFrameRepositoryV2.save(frame); } - public TimetableFrame 시간표4(User user, Semester semester, Lecture lecture1, Lecture lecture2) { + public TimetableFrame 시간표4(User user, Semester semester, Lecture lecture1, Lecture lecture2, CourseType courseType1, + CourseType courseType2) { TimetableFrame frame = TimetableFrame.builder() .user(user) .semester(semester) @@ -95,6 +97,7 @@ public TimeTableV2Fixture( .isDeleted(false) .lecture(lecture1) .timetableFrame(frame) + .courseType(courseType1) .build(); TimetableLecture timetableLecture2 = TimetableLecture.builder() @@ -102,6 +105,7 @@ public TimeTableV2Fixture( .isDeleted(false) .lecture(lecture2) .timetableFrame(frame) + .courseType(courseType2) .build(); frame.getTimetableLectures().add(timetableLecture1); @@ -110,7 +114,7 @@ public TimeTableV2Fixture( return timetableFrameRepositoryV2.save(frame); } - public TimetableFrame 시간표5(User user, Semester semester, Lecture lecture1) { + public TimetableFrame 시간표5(User user, Semester semester, Lecture lecture1, CourseType courseType1) { TimetableFrame frame = TimetableFrame.builder() .user(user) .semester(semester) @@ -123,6 +127,7 @@ public TimeTableV2Fixture( .grades("0") .isDeleted(false) .lecture(lecture1) + .courseType(courseType1) .timetableFrame(frame) .build(); @@ -143,7 +148,8 @@ public TimeTableV2Fixture( return timetableFrameRepositoryV2.save(frame); } - public TimetableFrame 시간표6(User user, Semester semester, Lecture lecture1, Lecture lecture2) { + public TimetableFrame 시간표6(User user, Semester semester, Lecture lecture1, Lecture lecture2, CourseType courseType1, + CourseType courseType2) { TimetableFrame frame = TimetableFrame.builder() .user(user) .semester(semester) @@ -156,6 +162,7 @@ public TimeTableV2Fixture( .grades("0") .isDeleted(false) .lecture(lecture1) + .courseType(courseType1) .timetableFrame(frame) .build(); @@ -163,6 +170,7 @@ public TimeTableV2Fixture( .grades("0") .isDeleted(false) .lecture(lecture2) + .courseType(courseType2) .timetableFrame(frame) .build(); @@ -172,7 +180,8 @@ public TimeTableV2Fixture( return timetableFrameRepositoryV2.save(frame); } - public TimetableFrame 시간표7(User user, Semester semester, Lecture lecture1, Lecture lecture2) { + public TimetableFrame 시간표7(User user, Semester semester, Lecture lecture1, Lecture lecture2, CourseType courseType1, + CourseType courseType2) { TimetableFrame frame = TimetableFrame.builder() .user(user) .isDeleted(true) @@ -186,6 +195,7 @@ public TimeTableV2Fixture( .grades("0") .isDeleted(true) .lecture(lecture1) + .courseType(courseType1) .timetableFrame(frame) .build(); @@ -193,6 +203,7 @@ public TimeTableV2Fixture( .grades("0") .isDeleted(true) .lecture(lecture2) + .courseType(courseType2) .timetableFrame(frame) .build(); @@ -202,7 +213,8 @@ public TimeTableV2Fixture( return timetableFrameRepositoryV2.save(frame); } - public TimetableFrame 시간표8(User user, Semester semester, Lecture lecture1, Lecture lecture2) { + public TimetableFrame 시간표8(User user, Semester semester, Lecture lecture1, Lecture lecture2, CourseType courseType1, + CourseType courseType2) { TimetableFrame frame = TimetableFrame.builder() .user(user) .isDeleted(false) @@ -216,6 +228,7 @@ public TimeTableV2Fixture( .grades("0") .isDeleted(true) .lecture(lecture1) + .courseType(courseType1) .timetableFrame(frame) .build(); @@ -223,6 +236,7 @@ public TimeTableV2Fixture( .grades("0") .isDeleted(true) .lecture(lecture2) + .courseType(courseType2) .timetableFrame(frame) .build(); From 7fcac8a913461f8056f7d89ec94bb1be30fdc22c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=A0=EA=B4=80=EA=B7=9C?= Date: Sun, 29 Dec 2024 23:56:08 +0900 Subject: [PATCH 6/6] =?UTF-8?q?chore:=20=EB=A6=AC=EB=B7=B0=20=EB=B0=98?= =?UTF-8?q?=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../in/koreatech/koin/acceptance/TimetableLectureApiTest.java | 2 +- src/test/java/in/koreatech/koin/fixture/CourseTypeFixture.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/in/koreatech/koin/acceptance/TimetableLectureApiTest.java b/src/test/java/in/koreatech/koin/acceptance/TimetableLectureApiTest.java index 0f13e9dcb..cec1d887a 100644 --- a/src/test/java/in/koreatech/koin/acceptance/TimetableLectureApiTest.java +++ b/src/test/java/in/koreatech/koin/acceptance/TimetableLectureApiTest.java @@ -310,7 +310,7 @@ void setup() { "target": "기공1", "professor": "박한수,최준호", "department": "기계공학부", - "course_type": "MSC 필수" + "course_type": "HRD 필수" } ], "grades": 6, diff --git a/src/test/java/in/koreatech/koin/fixture/CourseTypeFixture.java b/src/test/java/in/koreatech/koin/fixture/CourseTypeFixture.java index 9f5a42579..90841e92a 100644 --- a/src/test/java/in/koreatech/koin/fixture/CourseTypeFixture.java +++ b/src/test/java/in/koreatech/koin/fixture/CourseTypeFixture.java @@ -26,7 +26,7 @@ public CourseTypeFixture(CourseTypeRepository courseTypeRepository) { public CourseType HRD_필수() { return courseTypeRepository.save( CourseType.builder() - .name("MSC 필수") + .name("HRD 필수") .build() ); }