Skip to content

Commit

Permalink
fix: 데이터베이스 롤백을 위한 작업 삭제 (#1114)
Browse files Browse the repository at this point in the history
* fix: flyway 삭제

* fix: 연관관계 삭제

* test: 테스트 수정

* test: 미사용 import 삭제
  • Loading branch information
Soundbar91 authored Dec 4, 2024
1 parent 598ea50 commit a7ef565
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -122,6 +115,5 @@ public Lecture(String semesterDate,
this.designScore = designScore;
this.isElearning = isElearning;
this.classTime = classTime;
this.semester = semester;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@ public class Semester {
@Column(name = "semester", nullable = false, unique = true)
private String semester;

@OneToMany(mappedBy = "semester")
private List<Lecture> lectures = new ArrayList<>();

@Builder
private Semester(String semester, List<Lecture> lectures) {
public Semester(String semester) {
this.semester = semester;
this.lectures = lectures;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@

public interface LectureRepository extends Repository<Lecture, Integer> {

List<Lecture> findBySemester(Semester semester);
List<Lecture> findBySemester(String semesterDate);

Lecture save(Lecture lecture);

Optional<Lecture> findById(Integer id);

Optional<Lecture> findBySemesterAndCodeAndLectureClass(Semester semester, String code, String classLecture);
Optional<Lecture> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public class TimetableService {
private final UserRepository userRepository;
private final EntityManager entityManager;

public List<LectureResponse> getLecturesBySemester(String requestSemester) {
Semester semester = semesterRepositoryV2.getBySemester(requestSemester);
public List<LectureResponse> getLecturesBySemester(String semester) {
semesterRepositoryV2.getBySemester(semester);
List<Lecture> lectures = lectureRepositoryV2.findBySemester(semester);
return lectures.stream()
.map(LectureResponse::from)
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@

public interface LectureRepositoryV2 extends Repository<Lecture, Integer> {

List<Lecture> findBySemester(Semester semester);
List<Lecture> findBySemester(String semesterDate);

Lecture save(Lecture lecture);

Optional<Lecture> findById(Integer id);

Optional<Lecture> findBySemesterAndCodeAndLectureClass(Semester semester, String code, String classLecture);
Optional<Lecture> 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) {
Expand Down

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions src/main/resources/db/migration/V106__update_semester_id.sql

This file was deleted.

This file was deleted.

36 changes: 19 additions & 17 deletions src/test/java/in/koreatech/koin/acceptance/TimetableApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -154,7 +156,7 @@ void setup() {

@Test
void 존재하지_않는_학기를_조회하면_404() throws Exception {
Semester semester = semesterFixture.semester("20201");
String semester = "20201";
lectureFixture.HRD_개론(semester);
lectureFixture.건축구조의_이해_및_실습(semester);

Expand Down Expand Up @@ -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_개론);

Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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_개론);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_개론);

Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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<Integer> timetableLectureIds = frame.getTimetableLectures().stream()
Expand All @@ -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<Integer> timetableLecturesId = frame.getTimetableLectures().stream()
Expand Down Expand Up @@ -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(
Expand Down
Loading

0 comments on commit a7ef565

Please sign in to comment.