From a7ef565afc31a29775ccdbbfe378202f34cb82d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=A0=EA=B4=80=EA=B7=9C?= Date: Wed, 4 Dec 2024 16:25:40 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=8D=B0=EC=9D=B4=ED=84=B0=EB=B2=A0?= =?UTF-8?q?=EC=9D=B4=EC=8A=A4=20=EB=A1=A4=EB=B0=B1=EC=9D=84=20=EC=9C=84?= =?UTF-8?q?=ED=95=9C=20=EC=9E=91=EC=97=85=20=EC=82=AD=EC=A0=9C=20(#1114)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: flyway 삭제 * fix: 연관관계 삭제 * test: 테스트 수정 * test: 미사용 import 삭제 --- .../koin/domain/timetable/model/Lecture.java | 20 ++++------- .../koin/domain/timetable/model/Semester.java | 6 +--- .../repository/LectureRepository.java | 10 +++--- .../timetable/service/TimetableService.java | 6 ++-- .../repository/LectureRepositoryV2.java | 10 +++--- .../V104__alter_lecture_class_time.sql | 2 -- .../V105__add_semester_id_column.sql | 2 -- .../db/migration/V106__update_semester_id.sql | 4 --- .../V107__alter_fk_lectures_on_semester.sql | 5 --- .../koin/acceptance/TimetableApiTest.java | 36 ++++++++++--------- .../acceptance/TimetableFrameApiTest.java | 3 +- .../acceptance/TimetableLectureApiTest.java | 24 ++++++------- .../koin/fixture/LectureFixture.java | 13 +++---- 13 files changed, 56 insertions(+), 85 deletions(-) delete mode 100644 src/main/resources/db/migration/V104__alter_lecture_class_time.sql delete mode 100644 src/main/resources/db/migration/V105__add_semester_id_column.sql delete mode 100644 src/main/resources/db/migration/V106__update_semester_id.sql delete mode 100644 src/main/resources/db/migration/V107__alter_fk_lectures_on_semester.sql diff --git a/src/main/java/in/koreatech/koin/domain/timetable/model/Lecture.java b/src/main/java/in/koreatech/koin/domain/timetable/model/Lecture.java index aac02d468..a786613af 100644 --- a/src/main/java/in/koreatech/koin/domain/timetable/model/Lecture.java +++ b/src/main/java/in/koreatech/koin/domain/timetable/model/Lecture.java @@ -5,11 +5,8 @@ import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; @@ -27,10 +24,10 @@ public class Lecture { @GeneratedValue(strategy = IDENTITY) private Integer id; - @Size(max = 255) + @Size(max = 100) @NotNull @Column(name = "semester_date", nullable = false) - private String semesterDate; + private String semester; @Size(max = 255) @NotNull @@ -89,12 +86,9 @@ public class Lecture { @Column(name = "class_time", nullable = false) private String classTime; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "semester_id") - private Semester semester; - @Builder - public Lecture(String semesterDate, + public Lecture( + String semester, String code, String name, String grades, @@ -106,10 +100,9 @@ public Lecture(String semesterDate, String isEnglish, String designScore, String isElearning, - String classTime, - Semester semester + String classTime ) { - this.semesterDate = semesterDate; + this.semester = semester; this.code = code; this.name = name; this.grades = grades; @@ -122,6 +115,5 @@ public Lecture(String semesterDate, this.designScore = designScore; this.isElearning = isElearning; this.classTime = classTime; - this.semester = semester; } } diff --git a/src/main/java/in/koreatech/koin/domain/timetable/model/Semester.java b/src/main/java/in/koreatech/koin/domain/timetable/model/Semester.java index 012e2c2c9..e53120c47 100644 --- a/src/main/java/in/koreatech/koin/domain/timetable/model/Semester.java +++ b/src/main/java/in/koreatech/koin/domain/timetable/model/Semester.java @@ -33,12 +33,8 @@ public class Semester { @Column(name = "semester", nullable = false, unique = true) private String semester; - @OneToMany(mappedBy = "semester") - private List lectures = new ArrayList<>(); - @Builder - private Semester(String semester, List lectures) { + public Semester(String semester) { this.semester = semester; - this.lectures = lectures; } } diff --git a/src/main/java/in/koreatech/koin/domain/timetable/repository/LectureRepository.java b/src/main/java/in/koreatech/koin/domain/timetable/repository/LectureRepository.java index 8525b4e9b..b88ed96dd 100644 --- a/src/main/java/in/koreatech/koin/domain/timetable/repository/LectureRepository.java +++ b/src/main/java/in/koreatech/koin/domain/timetable/repository/LectureRepository.java @@ -12,17 +12,17 @@ public interface LectureRepository extends Repository { - List findBySemester(Semester semester); + List findBySemester(String semesterDate); Lecture save(Lecture lecture); Optional findById(Integer id); - Optional findBySemesterAndCodeAndLectureClass(Semester semester, String code, String classLecture); + Optional findBySemesterAndCodeAndLectureClass(String semesterDate, String code, String classLecture); - default Lecture getBySemesterAndCodeAndLectureClass(Semester semester, String code, String classLecture) { - return findBySemesterAndCodeAndLectureClass(semester, code, classLecture) - .orElseThrow(() -> SemesterNotFoundException.withDetail("semester: " + semester.getSemester() + " code: " + code + " classLecture: " + classLecture)); + default Lecture getBySemesterAndCodeAndLectureClass(String semesterDate, String code, String classLecture) { + return findBySemesterAndCodeAndLectureClass(semesterDate, code, classLecture) + .orElseThrow(() -> SemesterNotFoundException.withDetail("semester: " + semesterDate + " code: " + code + " classLecture: " + classLecture)); } default Lecture getLectureById(Integer id) { diff --git a/src/main/java/in/koreatech/koin/domain/timetable/service/TimetableService.java b/src/main/java/in/koreatech/koin/domain/timetable/service/TimetableService.java index 58211f04b..d8a4f9f20 100644 --- a/src/main/java/in/koreatech/koin/domain/timetable/service/TimetableService.java +++ b/src/main/java/in/koreatech/koin/domain/timetable/service/TimetableService.java @@ -41,8 +41,8 @@ public class TimetableService { private final UserRepository userRepository; private final EntityManager entityManager; - public List getLecturesBySemester(String requestSemester) { - Semester semester = semesterRepositoryV2.getBySemester(requestSemester); + public List getLecturesBySemester(String semester) { + semesterRepositoryV2.getBySemester(semester); List lectures = lectureRepositoryV2.findBySemester(semester); return lectures.stream() .map(LectureResponse::from) @@ -57,7 +57,7 @@ public TimetableResponse createTimetables(Integer userId, TimetableCreateRequest semester.getId()); for (TimetableCreateRequest.InnerTimetableRequest timeTable : request.timetable()) { - Lecture lecture = lectureRepositoryV2.getBySemesterAndCodeAndLectureClass(semester, + Lecture lecture = lectureRepositoryV2.getBySemesterAndCodeAndLectureClass(request.semester(), timeTable.code(), timeTable.lectureClass()); TimetableLecture timetableLecture = TimetableLecture.builder() .classPlace(timeTable.classPlace()) diff --git a/src/main/java/in/koreatech/koin/domain/timetableV2/repository/LectureRepositoryV2.java b/src/main/java/in/koreatech/koin/domain/timetableV2/repository/LectureRepositoryV2.java index 5a3d3c0a9..0bcf1fb76 100644 --- a/src/main/java/in/koreatech/koin/domain/timetableV2/repository/LectureRepositoryV2.java +++ b/src/main/java/in/koreatech/koin/domain/timetableV2/repository/LectureRepositoryV2.java @@ -12,18 +12,18 @@ public interface LectureRepositoryV2 extends Repository { - List findBySemester(Semester semester); + List findBySemester(String semesterDate); Lecture save(Lecture lecture); Optional findById(Integer id); - Optional findBySemesterAndCodeAndLectureClass(Semester semester, String code, String classLecture); + Optional findBySemesterAndCodeAndLectureClass(String semesterDate, String code, String classLecture); - default Lecture getBySemesterAndCodeAndLectureClass(Semester semester, String code, String classLecture) { - return findBySemesterAndCodeAndLectureClass(semester, code, classLecture) + default Lecture getBySemesterAndCodeAndLectureClass(String semesterDate, String code, String classLecture) { + return findBySemesterAndCodeAndLectureClass(semesterDate, code, classLecture) .orElseThrow(() -> SemesterNotFoundException.withDetail( - "semester: " + semester.getSemester() + " code: " + code + " classLecture: " + classLecture)); + "semester: " + semesterDate + " code: " + code + " classLecture: " + classLecture)); } default Lecture getLectureById(Integer id) { diff --git a/src/main/resources/db/migration/V104__alter_lecture_class_time.sql b/src/main/resources/db/migration/V104__alter_lecture_class_time.sql deleted file mode 100644 index eba35ad70..000000000 --- a/src/main/resources/db/migration/V104__alter_lecture_class_time.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE `koin`.`lectures` -MODIFY COLUMN `class_time` VARCHAR(255) NOT NULL; diff --git a/src/main/resources/db/migration/V105__add_semester_id_column.sql b/src/main/resources/db/migration/V105__add_semester_id_column.sql deleted file mode 100644 index a40959db7..000000000 --- a/src/main/resources/db/migration/V105__add_semester_id_column.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE `koin`.`lectures` - ADD COLUMN `semester_id` INT UNSIGNED NOT NULL; diff --git a/src/main/resources/db/migration/V106__update_semester_id.sql b/src/main/resources/db/migration/V106__update_semester_id.sql deleted file mode 100644 index 6a5d81e4a..000000000 --- a/src/main/resources/db/migration/V106__update_semester_id.sql +++ /dev/null @@ -1,4 +0,0 @@ -UPDATE `koin`.`lectures` l -SET `semester_id` = (SELECT `id` - FROM `koin`.`semester` s - WHERE l.`semester_date` = s.`semester`); diff --git a/src/main/resources/db/migration/V107__alter_fk_lectures_on_semester.sql b/src/main/resources/db/migration/V107__alter_fk_lectures_on_semester.sql deleted file mode 100644 index ea3bb8fcb..000000000 --- a/src/main/resources/db/migration/V107__alter_fk_lectures_on_semester.sql +++ /dev/null @@ -1,5 +0,0 @@ -ALTER TABLE `koin`.`lectures` - ADD CONSTRAINT `FK_LECTURES_ON_SEMESTER` - FOREIGN KEY (`semester_id`) - REFERENCES `koin`.`semester` (`id`) - ON UPDATE CASCADE; diff --git a/src/test/java/in/koreatech/koin/acceptance/TimetableApiTest.java b/src/test/java/in/koreatech/koin/acceptance/TimetableApiTest.java index 2b923f23f..125f4de22 100644 --- a/src/test/java/in/koreatech/koin/acceptance/TimetableApiTest.java +++ b/src/test/java/in/koreatech/koin/acceptance/TimetableApiTest.java @@ -48,14 +48,15 @@ void setup() { @Test void 특정_학기_강의를_조회한다() throws Exception { - Semester semester1 = semesterFixture.semester("20192"); - Semester semester = semesterFixture.semester("20201"); + semesterFixture.semester("20192"); + semesterFixture.semester("20201"); + String semester = "20201"; lectureFixture.HRD_개론(semester); - lectureFixture.건축구조의_이해_및_실습(semester1); + lectureFixture.건축구조의_이해_및_실습("20192"); mockMvc.perform( get("/lectures") - .param("semester_date", semester.getSemester()) + .param("semester_date", semester) .contentType(MediaType.APPLICATION_JSON) ) .andExpect(status().isOk()) @@ -84,14 +85,15 @@ void setup() { @Test void 특정_학기_강의들을_조회한다() throws Exception { - Semester semester = semesterFixture.semester("20201"); + semesterFixture.semester("20201"); + String semester = "20201"; lectureFixture.HRD_개론(semester); lectureFixture.건축구조의_이해_및_실습(semester); lectureFixture.재료역학(semester); mockMvc.perform( get("/lectures") - .param("semester_date", semester.getSemester()) + .param("semester_date", semester) .contentType(MediaType.APPLICATION_JSON) ) .andExpect(status().isOk()) @@ -154,7 +156,7 @@ void setup() { @Test void 존재하지_않는_학기를_조회하면_404() throws Exception { - Semester semester = semesterFixture.semester("20201"); + String semester = "20201"; lectureFixture.HRD_개론(semester); lectureFixture.건축구조의_이해_및_실습(semester); @@ -237,8 +239,8 @@ void setup() { String token = userFixture.getToken(user); Semester semester = semesterFixture.semester("20192"); - Lecture 건축구조의_이해_및_실습 = lectureFixture.건축구조의_이해_및_실습(semester); - Lecture HRD_개론 = lectureFixture.HRD_개론(semester); + Lecture 건축구조의_이해_및_실습 = lectureFixture.건축구조의_이해_및_실습(semester.getSemester()); + Lecture HRD_개론 = lectureFixture.HRD_개론(semester.getSemester()); timetableV2Fixture.시간표6(user, semester, 건축구조의_이해_및_실습, HRD_개론); @@ -320,8 +322,8 @@ void setup() { String token = userFixture.getToken(user); Semester semester1 = semesterFixture.semester("20192"); Semester semester2 = semesterFixture.semester("20201"); - Lecture HRD_개론 = lectureFixture.HRD_개론(semester1); - Lecture 건축구조의_이해_및_실습 = lectureFixture.건축구조의_이해_및_실습(semester2); + Lecture HRD_개론 = lectureFixture.HRD_개론(semester1.getSemester()); + Lecture 건축구조의_이해_및_실습 = lectureFixture.건축구조의_이해_및_실습(semester2.getSemester()); timetableV2Fixture.시간표6(user, semester1, HRD_개론, null); timetableV2Fixture.시간표6(user, semester2, 건축구조의_이해_및_실습, null); @@ -348,8 +350,8 @@ void setup() { String token = userFixture.getToken(user); Semester semester = semesterFixture.semester("20192"); - lectureFixture.건축구조의_이해_및_실습(semester); - lectureFixture.HRD_개론(semester); + lectureFixture.건축구조의_이해_및_실습(semester.getSemester()); + lectureFixture.HRD_개론(semester.getSemester()); timetableV2Fixture.시간표1(user, semester); @@ -441,8 +443,8 @@ void setup() { String token = userFixture.getToken(user); Semester semester = semesterFixture.semester("20192"); - lectureFixture.건축구조의_이해_및_실습(semester); - lectureFixture.HRD_개론(semester); + lectureFixture.건축구조의_이해_및_실습(semester.getSemester()); + lectureFixture.HRD_개론(semester.getSemester()); timetableV2Fixture.시간표1(user, semester); @@ -548,8 +550,8 @@ void setup() { String token = userFixture.getToken(user); Semester semester = semesterFixture.semester("20192"); - Lecture 건축구조의_이해_및_실습 = lectureFixture.건축구조의_이해_및_실습(semester); - Lecture HRD_개론 = lectureFixture.HRD_개론(semester); + Lecture 건축구조의_이해_및_실습 = lectureFixture.건축구조의_이해_및_실습(semester.getSemester()); + Lecture HRD_개론 = lectureFixture.HRD_개론(semester.getSemester()); timetableV2Fixture.시간표6(user, semester, 건축구조의_이해_및_실습, HRD_개론); diff --git a/src/test/java/in/koreatech/koin/acceptance/TimetableFrameApiTest.java b/src/test/java/in/koreatech/koin/acceptance/TimetableFrameApiTest.java index 1449eeb96..0a66b6e6f 100644 --- a/src/test/java/in/koreatech/koin/acceptance/TimetableFrameApiTest.java +++ b/src/test/java/in/koreatech/koin/acceptance/TimetableFrameApiTest.java @@ -3,7 +3,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.TestInstance.Lifecycle; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -165,7 +164,7 @@ void setup() { @Test void 강의를_담고_있는_특정_시간표_frame을_삭제한다() throws Exception { - Lecture lecture = lectureFixture.HRD_개론(semester); + Lecture lecture = lectureFixture.HRD_개론(semester.getSemester()); TimetableFrame frame1 = timetableV2Fixture.시간표5(user, semester, lecture); diff --git a/src/test/java/in/koreatech/koin/acceptance/TimetableLectureApiTest.java b/src/test/java/in/koreatech/koin/acceptance/TimetableLectureApiTest.java index f7c501baa..8f8883f8f 100644 --- a/src/test/java/in/koreatech/koin/acceptance/TimetableLectureApiTest.java +++ b/src/test/java/in/koreatech/koin/acceptance/TimetableLectureApiTest.java @@ -242,8 +242,8 @@ void setup() { @Test void 시간표를_조회한다_TimetableLecture() throws Exception { - Lecture 건축구조의_이해_및_실습 = lectureFixture.건축구조의_이해_및_실습(semester); - Lecture HRD_개론 = lectureFixture.HRD_개론(semester); + Lecture 건축구조의_이해_및_실습 = lectureFixture.건축구조의_이해_및_실습(semester.getSemester()); + Lecture HRD_개론 = lectureFixture.HRD_개론(semester.getSemester()); TimetableFrame frame = timetableV2Fixture.시간표6(user, semester, 건축구조의_이해_및_실습, HRD_개론); @@ -307,8 +307,8 @@ void setup() { @Test void 시간표에서_특정_강의를_삭제한다() throws Exception { - Lecture lecture1 = lectureFixture.HRD_개론(semester); - Lecture lecture2 = lectureFixture.영어청해(semester); + Lecture lecture1 = lectureFixture.HRD_개론("20192"); + Lecture lecture2 = lectureFixture.영어청해("20192"); TimetableFrame frame = timetableV2Fixture.시간표4(user, semester, lecture1, lecture2); Integer lectureId = lecture1.getId(); @@ -324,8 +324,8 @@ void setup() { @Test void 시간표에서_특정_강의를_삭제한다_V2() throws Exception { - Lecture lecture1 = lectureFixture.HRD_개론(semester); - Lecture lecture2 = lectureFixture.영어청해(semester); + Lecture lecture1 = lectureFixture.HRD_개론("20192"); + Lecture lecture2 = lectureFixture.영어청해("20192"); TimetableFrame frame = timetableV2Fixture.시간표4(user, semester, lecture1, lecture2); Integer frameId = frame.getId(); @@ -341,8 +341,8 @@ void setup() { @Test void 시간표에서_여러개의_강의를_한번에_삭제한다_V2() throws Exception { - Lecture lecture1 = lectureFixture.HRD_개론(semester); - Lecture lecture2 = lectureFixture.영어청해(semester); + Lecture lecture1 = lectureFixture.HRD_개론("20192"); + Lecture lecture2 = lectureFixture.영어청해("20192"); TimetableFrame frame = timetableV2Fixture.시간표4(user, semester, lecture1, lecture2); List timetableLectureIds = frame.getTimetableLectures().stream() @@ -362,8 +362,8 @@ void setup() { @Test void 시간표에서_삭제된_강의를_복구한다_V2() throws Exception { - Lecture 건축구조의_이해_및_실습 = lectureFixture.건축구조의_이해_및_실습(semester); - Lecture HRD_개론 = lectureFixture.HRD_개론(semester); + Lecture 건축구조의_이해_및_실습 = lectureFixture.건축구조의_이해_및_실습(semester.getSemester()); + Lecture HRD_개론 = lectureFixture.HRD_개론(semester.getSemester()); TimetableFrame frame = timetableV2Fixture.시간표8(user, semester, 건축구조의_이해_및_실습, HRD_개론); List timetableLecturesId = frame.getTimetableLectures().stream() @@ -432,8 +432,8 @@ void setup() { @Test void 삭제된_시간표프레임과_그에_해당하는_강의를_복구한다_V2() throws Exception { - Lecture 건축구조의_이해_및_실습 = lectureFixture.건축구조의_이해_및_실습(semester); - Lecture HRD_개론 = lectureFixture.HRD_개론(semester); + Lecture 건축구조의_이해_및_실습 = lectureFixture.건축구조의_이해_및_실습(semester.getSemester()); + Lecture HRD_개론 = lectureFixture.HRD_개론(semester.getSemester()); TimetableFrame frame = timetableV2Fixture.시간표7(user, semester, 건축구조의_이해_및_실습, HRD_개론); mockMvc.perform( diff --git a/src/test/java/in/koreatech/koin/fixture/LectureFixture.java b/src/test/java/in/koreatech/koin/fixture/LectureFixture.java index 54dc7d999..172d9ffd4 100644 --- a/src/test/java/in/koreatech/koin/fixture/LectureFixture.java +++ b/src/test/java/in/koreatech/koin/fixture/LectureFixture.java @@ -3,7 +3,6 @@ import org.springframework.stereotype.Component; import in.koreatech.koin.domain.timetable.model.Lecture; -import in.koreatech.koin.domain.timetable.model.Semester; import in.koreatech.koin.domain.timetable.repository.LectureRepository; @Component @@ -16,11 +15,10 @@ public LectureFixture(LectureRepository lectureRepository) { this.lectureRepository = lectureRepository; } - public Lecture 건축구조의_이해_및_실습(Semester semester) { + public Lecture 건축구조의_이해_및_실습(String semester) { return lectureRepository.save( Lecture.builder() .code("ARB244") - .semesterDate(semester.getSemester()) .semester(semester) .name("건축구조의 이해 및 실습") .grades("3") @@ -37,11 +35,10 @@ public LectureFixture(LectureRepository lectureRepository) { ); } - public Lecture HRD_개론(Semester semester) { + public Lecture HRD_개론(String semester) { return lectureRepository.save( Lecture.builder() .code("BSM590") - .semesterDate(semester.getSemester()) .semester(semester) .name("컴퓨팅사고") .grades("3") @@ -58,11 +55,10 @@ public LectureFixture(LectureRepository lectureRepository) { ); } - public Lecture 재료역학(Semester semester) { + public Lecture 재료역학(String semester) { return lectureRepository.save( Lecture.builder() .code("MEB311") - .semesterDate(semester.getSemester()) .semester(semester) .name("재료역학") .grades("3") @@ -79,11 +75,10 @@ public LectureFixture(LectureRepository lectureRepository) { ); } - public Lecture 영어청해(Semester semester) { + public Lecture 영어청해(String semester) { return lectureRepository.save( Lecture.builder() .code("LAN324") - .semesterDate(semester.getSemester()) .semester(semester) .name("영어청해") .grades("1")