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 e53120c47..ef9dc1eee 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 @@ -6,8 +6,11 @@ import java.util.ArrayList; import java.util.List; +import in.koreatech.koin.domain.timetableV3.model.Term; import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.OneToMany; @@ -33,8 +36,18 @@ public class Semester { @Column(name = "semester", nullable = false, unique = true) private String semester; + @NotNull + @Column(name = "year", nullable = false) + private Integer year; + + @Enumerated(EnumType.STRING) + @Column(name = "term", nullable = false, length = 20) + private Term term; + @Builder - public Semester(String semester) { + public Semester(String semester, Integer year, Term term) { this.semester = semester; + this.year = year; + this.term = term; } } diff --git a/src/main/java/in/koreatech/koin/domain/timetableV3/controller/SemesterApiV3.java b/src/main/java/in/koreatech/koin/domain/timetableV3/controller/SemesterApiV3.java new file mode 100644 index 000000000..ce0612999 --- /dev/null +++ b/src/main/java/in/koreatech/koin/domain/timetableV3/controller/SemesterApiV3.java @@ -0,0 +1,47 @@ +package in.koreatech.koin.domain.timetableV3.controller; + +import static in.koreatech.koin.domain.user.model.UserType.STUDENT; + +import java.util.List; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; + +import in.koreatech.koin.domain.timetableV3.dto.response.SemesterCheckResponseV3; +import in.koreatech.koin.domain.timetableV3.dto.response.SemesterResponseV3; +import in.koreatech.koin.global.auth.Auth; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; + +@Tag(name = "(Normal) V3-Semester", description = "학기 정보를 관리한다") +public interface SemesterApiV3 { + @ApiResponses( + value = { + @ApiResponse(responseCode = "200"), + @ApiResponse(responseCode = "401", content = @Content(schema = @Schema(hidden = true))), + @ApiResponse(responseCode = "403", content = @Content(schema = @Schema(hidden = true))), + @ApiResponse(responseCode = "404", content = @Content(schema = @Schema(hidden = true))) + } + ) + @Operation(summary = "학기 정보 조회") + @GetMapping("/v3/semesters") + ResponseEntity> getSemesters(); + + @ApiResponses( + value = { + @ApiResponse(responseCode = "200"), + @ApiResponse(responseCode = "401", content = @Content(schema = @Schema(hidden = true))) + } + ) + @Operation(summary = "학생 학기 정보 조회") + @SecurityRequirement(name = "Jwt Authentication") + @GetMapping("/v3/semesters/check") + ResponseEntity getStudentSemesters( + @Auth(permit = {STUDENT}) Integer userId + ); +} diff --git a/src/main/java/in/koreatech/koin/domain/timetableV3/controller/SemesterControllerV3.java b/src/main/java/in/koreatech/koin/domain/timetableV3/controller/SemesterControllerV3.java new file mode 100644 index 000000000..ea6c0ba0d --- /dev/null +++ b/src/main/java/in/koreatech/koin/domain/timetableV3/controller/SemesterControllerV3.java @@ -0,0 +1,36 @@ +package in.koreatech.koin.domain.timetableV3.controller; + +import static in.koreatech.koin.domain.user.model.UserType.STUDENT; + +import java.util.List; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import in.koreatech.koin.domain.timetableV3.dto.response.SemesterCheckResponseV3; +import in.koreatech.koin.domain.timetableV3.dto.response.SemesterResponseV3; +import in.koreatech.koin.domain.timetableV3.service.SemesterServiceV3; +import in.koreatech.koin.global.auth.Auth; +import lombok.RequiredArgsConstructor; + +@RestController +@RequiredArgsConstructor +public class SemesterControllerV3 { + + private final SemesterServiceV3 semesterServiceV3; + + @GetMapping("/v3/semesters") + public ResponseEntity> getSemesters() { + List semesterResponseV3 = semesterServiceV3.getSemesters(); + return ResponseEntity.ok(semesterResponseV3); + } + + @GetMapping("/v3/semesters/check") + public ResponseEntity getStudentSemesters( + @Auth(permit = {STUDENT}) Integer userId + ) { + SemesterCheckResponseV3 semesterCheckResponseV3 = semesterServiceV3.getStudentSemesters(userId); + return ResponseEntity.ok(semesterCheckResponseV3); + } +} diff --git a/src/main/java/in/koreatech/koin/domain/timetableV3/dto/response/SemesterCheckResponseV3.java b/src/main/java/in/koreatech/koin/domain/timetableV3/dto/response/SemesterCheckResponseV3.java new file mode 100644 index 000000000..2cd239a05 --- /dev/null +++ b/src/main/java/in/koreatech/koin/domain/timetableV3/dto/response/SemesterCheckResponseV3.java @@ -0,0 +1,45 @@ +package in.koreatech.koin.domain.timetableV3.dto.response; + +import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; + +import java.util.List; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +import in.koreatech.koin.domain.timetable.model.Semester; +import io.swagger.v3.oas.annotations.media.Schema; + +@JsonNaming(value = SnakeCaseStrategy.class) +public record SemesterCheckResponseV3( + @Schema(description = "유저 id", example = "1", requiredMode = REQUIRED) + Integer userId, + + @Schema(description = "유저 학기", requiredMode = REQUIRED) + List semesters +) { + @JsonNaming(value = SnakeCaseStrategy.class) + public record InnerSemesterCheckResponse( + @Schema(description = "year", example = "2024", requiredMode = REQUIRED) + Integer year, + + @Schema(description = "term", example = "1학기", requiredMode = REQUIRED) + String term + ) { + public static InnerSemesterCheckResponse of(Semester semester) { + return new InnerSemesterCheckResponse( + semester.getYear(), + semester.getTerm().getDescription() + ); + } + } + + public static SemesterCheckResponseV3 of(Integer userId, List semester) { + return new SemesterCheckResponseV3( + userId, + semester.stream() + .map(InnerSemesterCheckResponse::of) + .toList() + ); + } +} diff --git a/src/main/java/in/koreatech/koin/domain/timetableV3/dto/response/SemesterResponseV3.java b/src/main/java/in/koreatech/koin/domain/timetableV3/dto/response/SemesterResponseV3.java new file mode 100644 index 000000000..1bdc3bbef --- /dev/null +++ b/src/main/java/in/koreatech/koin/domain/timetableV3/dto/response/SemesterResponseV3.java @@ -0,0 +1,25 @@ +package in.koreatech.koin.domain.timetableV3.dto.response; + +import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +import in.koreatech.koin.domain.timetable.model.Semester; +import io.swagger.v3.oas.annotations.media.Schema; + +@JsonNaming(value = PropertyNamingStrategies.SnakeCaseStrategy.class) +public record SemesterResponseV3( + @Schema(description = "year", example = "2024", requiredMode = REQUIRED) + Integer year, + + @Schema(description = "term", example = "1학기", requiredMode = REQUIRED) + String term +) { + public static SemesterResponseV3 of(Semester semester) { + return new SemesterResponseV3( + semester.getYear(), + semester.getTerm().getDescription() + ); + } +} diff --git a/src/main/java/in/koreatech/koin/domain/timetableV3/model/Term.java b/src/main/java/in/koreatech/koin/domain/timetableV3/model/Term.java new file mode 100644 index 000000000..6f65b2280 --- /dev/null +++ b/src/main/java/in/koreatech/koin/domain/timetableV3/model/Term.java @@ -0,0 +1,19 @@ +package in.koreatech.koin.domain.timetableV3.model; + +import lombok.Getter; + +@Getter +public enum Term { + WINTER("겨울학기", 1), + SECOND("2학기", 2), + SUMMER("여름학기", 3), + FIRST("1학기", 4); + + private final String description; + private final int priority; + + Term(String description, int priority) { + this.description = description; + this.priority = priority; + } +} diff --git a/src/main/java/in/koreatech/koin/domain/timetableV3/repository/SemesterRepositoryV3.java b/src/main/java/in/koreatech/koin/domain/timetableV3/repository/SemesterRepositoryV3.java new file mode 100644 index 000000000..dd8454dae --- /dev/null +++ b/src/main/java/in/koreatech/koin/domain/timetableV3/repository/SemesterRepositoryV3.java @@ -0,0 +1,14 @@ +package in.koreatech.koin.domain.timetableV3.repository; + +import java.util.List; + +import org.springframework.data.repository.Repository; + +import in.koreatech.koin.domain.timetable.model.Semester; + +public interface SemesterRepositoryV3 extends Repository { + + List findAll(); + + Semester save(Semester semester); +} diff --git a/src/main/java/in/koreatech/koin/domain/timetableV3/repository/TimetableFrameRepositoryV3.java b/src/main/java/in/koreatech/koin/domain/timetableV3/repository/TimetableFrameRepositoryV3.java new file mode 100644 index 000000000..c860bd18f --- /dev/null +++ b/src/main/java/in/koreatech/koin/domain/timetableV3/repository/TimetableFrameRepositoryV3.java @@ -0,0 +1,12 @@ +package in.koreatech.koin.domain.timetableV3.repository; + +import org.springframework.data.repository.Repository; + +import java.util.List; + +import in.koreatech.koin.domain.timetableV2.model.TimetableFrame; + +public interface TimetableFrameRepositoryV3 extends Repository { + + List findByUserIdAndIsMainTrue(Integer userId); +} diff --git a/src/main/java/in/koreatech/koin/domain/timetableV3/service/SemesterServiceV3.java b/src/main/java/in/koreatech/koin/domain/timetableV3/service/SemesterServiceV3.java new file mode 100644 index 000000000..f342cbb62 --- /dev/null +++ b/src/main/java/in/koreatech/koin/domain/timetableV3/service/SemesterServiceV3.java @@ -0,0 +1,42 @@ +package in.koreatech.koin.domain.timetableV3.service; + +import java.util.Comparator; +import java.util.List; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import in.koreatech.koin.domain.timetable.model.Semester; +import in.koreatech.koin.domain.timetableV2.model.TimetableFrame; +import in.koreatech.koin.domain.timetableV3.dto.response.SemesterCheckResponseV3; +import in.koreatech.koin.domain.timetableV3.dto.response.SemesterResponseV3; +import in.koreatech.koin.domain.timetableV3.repository.SemesterRepositoryV3; +import in.koreatech.koin.domain.timetableV3.repository.TimetableFrameRepositoryV3; +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class SemesterServiceV3 { + + private final TimetableFrameRepositoryV3 timetableFrameRepository; + private final SemesterRepositoryV3 semesterRepository; + + public List getSemesters() { + return semesterRepository.findAll().stream() + .sorted(Comparator.comparing(Semester::getYear).reversed() + .thenComparing(semester -> semester.getTerm().getPriority())) + .map(SemesterResponseV3::of) + .toList(); + } + + public SemesterCheckResponseV3 getStudentSemesters(Integer userId) { + List semesters = timetableFrameRepository.findByUserIdAndIsMainTrue(userId).stream() + .map(TimetableFrame::getSemester) + .distinct() + .sorted(Comparator.comparing(Semester::getYear).reversed() + .thenComparing(semester -> semester.getTerm().getPriority())) + .toList(); + return SemesterCheckResponseV3.of(userId, semesters); + } +} diff --git a/src/main/resources/db/migration/V108__alter__semester.sql b/src/main/resources/db/migration/V108__alter__semester.sql new file mode 100644 index 000000000..49e89123a --- /dev/null +++ b/src/main/resources/db/migration/V108__alter__semester.sql @@ -0,0 +1,30 @@ +alter table semester + add column year int unsigned, + add column term varchar(20); + +update semester set year = 2019, term = 'SECOND' where semester = '20192'; +update semester set year = 2019, term = 'SUMMER' where semester = '2019-여름'; +update semester set year = 2019, term = 'WINTER' where semester = '2019-겨울'; +update semester set year = 2020, term = 'FIRST' where semester = '20201'; +update semester set year = 2020, term = 'SECOND' where semester = '20202'; +update semester set year = 2020, term = 'SUMMER' where semester = '2020-여름'; +update semester set year = 2020, term = 'WINTER' where semester = '2020-겨울'; +update semester set year = 2021, term = 'FIRST' where semester = '20211'; +update semester set year = 2021, term = 'SECOND' where semester = '20212'; +update semester set year = 2021, term = 'SUMMER' where semester = '2021-여름'; +update semester set year = 2021, term = 'WINTER' where semester = '2021-겨울'; +update semester set year = 2022, term = 'FIRST' where semester = '20221'; +update semester set year = 2022, term = 'SECOND' where semester = '20222'; +update semester set year = 2022, term = 'SUMMER' where semester = '2022-여름'; +update semester set year = 2022, term = 'WINTER' where semester = '2022-겨울'; +update semester set year = 2023, term = 'FIRST' where semester = '20231'; +update semester set year = 2023, term = 'SECOND' where semester = '20232'; +update semester set year = 2023, term = 'SUMMER' where semester = '2023-여름'; +update semester set year = 2023, term = 'WINTER' where semester = '2023-겨울'; +update semester set year = 2024, term = 'FIRST' where semester = '20241'; +update semester set year = 2024, term = 'SECOND' where semester = '20242'; +update semester set year = 2024, term = 'SUMMER' where semester = '2024-여름'; + +ALTER TABLE semester + MODIFY COLUMN year INT UNSIGNED NOT NULL, + MODIFY COLUMN term VARCHAR(20) NOT NULL; \ No newline at end of file diff --git a/src/test/java/in/koreatech/koin/acceptance/SemesterApiTest.java b/src/test/java/in/koreatech/koin/acceptance/SemesterApiTest.java new file mode 100644 index 000000000..5ae89e051 --- /dev/null +++ b/src/test/java/in/koreatech/koin/acceptance/SemesterApiTest.java @@ -0,0 +1,209 @@ +package in.koreatech.koin.acceptance; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.transaction.annotation.Transactional; + +import in.koreatech.koin.AcceptanceTest; +import in.koreatech.koin.domain.timetable.model.Lecture; +import in.koreatech.koin.domain.timetable.model.Semester; +import in.koreatech.koin.domain.user.model.User; +import in.koreatech.koin.fixture.LectureFixture; +import in.koreatech.koin.fixture.SemesterFixture; +import in.koreatech.koin.fixture.TimeTableV2Fixture; +import in.koreatech.koin.fixture.UserFixture; + +@SuppressWarnings("NonAsciiCharacters") +@Transactional +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class SemesterApiTest extends AcceptanceTest { + + @Autowired + private LectureFixture lectureFixture; + + @Autowired + private UserFixture userFixture; + + @Autowired + private SemesterFixture semesterFixture; + + @Autowired + private TimeTableV2Fixture timetableV2Fixture; + + @BeforeAll + void setup() { + clear(); + } + + @Test + void 모든_학기를_조회한다() throws Exception { + semesterFixture.semester_2024년도_1학기(); + semesterFixture.semester_2024년도_2학기(); + semesterFixture.semester_2024년도_여름(); + semesterFixture.semester_2023년도_1학기(); + semesterFixture.semester_2023년도_2학기(); + semesterFixture.semester_2023년도_여름(); + semesterFixture.semester_2023년도_겨울(); + + mockMvc.perform( + get("/semesters") + .contentType(MediaType.APPLICATION_JSON) + ) + .andExpect(status().isOk()) + .andExpect(content().json(""" + [ + { + "id": 2, + "semester": "20242" + }, + { + "id": 3, + "semester": "2024-여름" + }, + { + "id": 1, + "semester": "20241" + }, + { + "id": 7, + "semester": "2023-겨울" + }, + { + "id": 5, + "semester": "20232" + }, + { + "id": 6, + "semester": "2023-여름" + }, + { + "id": 4, + "semester": "20231" + } + ] + """)); + } + + @Test + void 학생이_가진_시간표의_학기를_조회한다() throws Exception { + User user = userFixture.준호_학생().getUser(); + String token = userFixture.getToken(user); + Semester semester1 = semesterFixture.semester_2019년도_2학기(); + Semester semester2 = semesterFixture.semester_2020년도_1학기(); + Lecture HRD_개론 = lectureFixture.HRD_개론(semester1.getSemester()); + Lecture 건축구조의_이해_및_실습 = lectureFixture.건축구조의_이해_및_실습(semester2.getSemester()); + timetableV2Fixture.시간표6(user, semester1, HRD_개론, null); + timetableV2Fixture.시간표6(user, semester2, 건축구조의_이해_및_실습, null); + + mockMvc.perform( + get("/semesters/check") + .header("Authorization", "Bearer " + token) + .contentType(MediaType.APPLICATION_JSON) + ) + .andExpect(status().isOk()) + .andExpect(content().json(""" + { + "user_id": 1, + "semesters": [ + "20201", + "20192" + ] + } + """)); + } + + @Test + void 모든_학기를_조회한다_V3() throws Exception { + semesterFixture.semester_2019년도_1학기(); + semesterFixture.semester_2019년도_2학기(); + semesterFixture.semester_2019년도_여름(); + semesterFixture.semester_2019년도_겨울(); + semesterFixture.semester_2020년도_1학기(); + semesterFixture.semester_2020년도_2학기(); + semesterFixture.semester_2020년도_여름(); + semesterFixture.semester_2020년도_겨울(); + + mockMvc.perform( + get("/v3/semesters") + .contentType(MediaType.APPLICATION_JSON) + ) + .andExpect(status().isOk()) + .andExpect(content().json(""" + [ + { + "year": 2020, + "term": "겨울학기" + }, + { + "year": 2020, + "term": "2학기" + }, + { + "year": 2020, + "term": "여름학기" + }, + { + "year": 2020, + "term": "1학기" + }, + { + "year": 2019, + "term": "겨울학기" + }, + { + "year": 2019, + "term": "2학기" + }, + { + "year": 2019, + "term": "여름학기" + }, + { + "year": 2019, + "term": "1학기" + } + ] + """)); + } + + @Test + void 학생이_가진_시간표의_학기를_조회한다_V3() throws Exception { + User user = userFixture.준호_학생().getUser(); + String token = userFixture.getToken(user); + Semester semester1 = semesterFixture.semester_2019년도_2학기(); + Semester semester2 = semesterFixture.semester_2020년도_1학기(); + Lecture HRD_개론 = lectureFixture.HRD_개론(semester1.getSemester()); + Lecture 건축구조의_이해_및_실습 = lectureFixture.건축구조의_이해_및_실습(semester2.getSemester()); + timetableV2Fixture.시간표6(user, semester1, HRD_개론, null); + timetableV2Fixture.시간표6(user, semester2, 건축구조의_이해_및_실습, null); + + mockMvc.perform( + get("/v3/semesters/check") + .header("Authorization", "Bearer " + token) + .contentType(MediaType.APPLICATION_JSON) + ) + .andExpect(status().isOk()) + .andExpect(content().json(""" + { + "user_id": 1, + "semesters": [ + { + "year": 2019, + "term": "2학기" + }, + { + "year": 2020, + "term": "1학기" + } + ] + } + """)); + } +} diff --git a/src/test/java/in/koreatech/koin/acceptance/TimetableApiTest.java b/src/test/java/in/koreatech/koin/acceptance/TimetableApiTest.java index 125f4de22..45c1ddfc4 100644 --- a/src/test/java/in/koreatech/koin/acceptance/TimetableApiTest.java +++ b/src/test/java/in/koreatech/koin/acceptance/TimetableApiTest.java @@ -48,8 +48,8 @@ void setup() { @Test void 특정_학기_강의를_조회한다() throws Exception { - semesterFixture.semester("20192"); - semesterFixture.semester("20201"); + semesterFixture.semester_2019년도_2학기(); + semesterFixture.semester_2020년도_1학기(); String semester = "20201"; lectureFixture.HRD_개론(semester); lectureFixture.건축구조의_이해_및_실습("20192"); @@ -85,7 +85,7 @@ void setup() { @Test void 특정_학기_강의들을_조회한다() throws Exception { - semesterFixture.semester("20201"); + semesterFixture.semester_2020년도_1학기(); String semester = "20201"; lectureFixture.HRD_개론(semester); lectureFixture.건축구조의_이해_및_실습(semester); @@ -170,10 +170,10 @@ void setup() { @Test void 계절학기를_조회하면_빈_리스트로_반환한다() throws Exception { - semesterFixture.semester("20241"); - semesterFixture.semester("20242"); - semesterFixture.semester("2024-여름"); - semesterFixture.semester("2024-겨울"); + semesterFixture.semester_2024년도_1학기(); + semesterFixture.semester_2024년도_2학기(); + semesterFixture.semester_2024년도_여름(); + semesterFixture.semester_2024년도_겨울(); mockMvc.perform( get("/lectures") @@ -184,60 +184,11 @@ void setup() { .andExpect(content().json("[]")); } - @Test - void 모든_학기를_조회한다() throws Exception { - semesterFixture.semester("20241"); - semesterFixture.semester("20242"); - semesterFixture.semester("2024-여름"); - semesterFixture.semester("20231"); - semesterFixture.semester("20232"); - semesterFixture.semester("2023-여름"); - semesterFixture.semester("2023-겨울"); - - mockMvc.perform( - get("/semesters") - .contentType(MediaType.APPLICATION_JSON) - ) - .andExpect(status().isOk()) - .andExpect(content().json(""" - [ - { - "id": 2, - "semester": "20242" - }, - { - "id": 3, - "semester": "2024-여름" - }, - { - "id": 1, - "semester": "20241" - }, - { - "id": 7, - "semester": "2023-겨울" - }, - { - "id": 5, - "semester": "20232" - }, - { - "id": 6, - "semester": "2023-여름" - }, - { - "id": 4, - "semester": "20231" - } - ] - """)); - } - @Test void 시간표를_조회한다() throws Exception { User user = userFixture.준호_학생().getUser(); String token = userFixture.getToken(user); - Semester semester = semesterFixture.semester("20192"); + Semester semester = semesterFixture.semester_2019년도_2학기(); Lecture 건축구조의_이해_및_실습 = lectureFixture.건축구조의_이해_및_실습(semester.getSemester()); Lecture HRD_개론 = lectureFixture.HRD_개론(semester.getSemester()); @@ -296,7 +247,7 @@ void setup() { void 시간표를_조회한다_시간표_프레임_없으면_생성() throws Exception { User user = userFixture.준호_학생().getUser(); String token = userFixture.getToken(user); - Semester semester = semesterFixture.semester("20192"); + Semester semester = semesterFixture.semester_2019년도_2학기(); mockMvc.perform( get("/timetables") @@ -316,39 +267,11 @@ void setup() { """)); } - @Test - void 학생이_가진_시간표의_학기를_조회한다() throws Exception { - User user = userFixture.준호_학생().getUser(); - String token = userFixture.getToken(user); - Semester semester1 = semesterFixture.semester("20192"); - 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); - - mockMvc.perform( - get("/semesters/check") - .header("Authorization", "Bearer " + token) - .contentType(MediaType.APPLICATION_JSON) - ) - .andExpect(status().isOk()) - .andExpect(content().json(""" - { - "user_id": 1, - "semesters": [ - "20201", - "20192" - ] - } - """)); - } - @Test void 시간표를_생성한다() throws Exception { User user = userFixture.준호_학생().getUser(); String token = userFixture.getToken(user); - Semester semester = semesterFixture.semester("20192"); + Semester semester = semesterFixture.semester_2019년도_2학기(); lectureFixture.건축구조의_이해_및_실습(semester.getSemester()); lectureFixture.HRD_개론(semester.getSemester()); @@ -441,7 +364,7 @@ void setup() { void 시간표를_단일_생성한다_전체_반환() throws Exception { User user = userFixture.준호_학생().getUser(); String token = userFixture.getToken(user); - Semester semester = semesterFixture.semester("20192"); + Semester semester = semesterFixture.semester_2019년도_2학기(); lectureFixture.건축구조의_이해_및_실습(semester.getSemester()); lectureFixture.HRD_개론(semester.getSemester()); @@ -548,7 +471,7 @@ void setup() { void 시간표를_삭제한다() throws Exception { User user = userFixture.준호_학생().getUser(); String token = userFixture.getToken(user); - Semester semester = semesterFixture.semester("20192"); + Semester semester = semesterFixture.semester_2019년도_2학기(); Lecture 건축구조의_이해_및_실습 = lectureFixture.건축구조의_이해_및_실습(semester.getSemester()); Lecture HRD_개론 = lectureFixture.HRD_개론(semester.getSemester()); diff --git a/src/test/java/in/koreatech/koin/acceptance/TimetableFrameApiTest.java b/src/test/java/in/koreatech/koin/acceptance/TimetableFrameApiTest.java index 0a66b6e6f..8eacc566c 100644 --- a/src/test/java/in/koreatech/koin/acceptance/TimetableFrameApiTest.java +++ b/src/test/java/in/koreatech/koin/acceptance/TimetableFrameApiTest.java @@ -57,7 +57,7 @@ void setup() { clear(); user = userFixture.준호_학생().getUser(); token = userFixture.getToken(user); - semester = semesterFixture.semester("20192"); + semester = semesterFixture.semester_2019년도_2학기(); } @Test @@ -236,8 +236,8 @@ void setup() { @Test void 모든_학기의_시간표_프레임을_조회한다() throws Exception { - Semester semester1 = semesterFixture.semester("20241"); - Semester semester2 = semesterFixture.semester("20242"); + Semester semester1 = semesterFixture.semester_2024년도_1학기(); + Semester semester2 = semesterFixture.semester_2024년도_2학기(); timetableV2Fixture.시간표1(user, semester1); timetableV2Fixture.시간표2(user, semester1); diff --git a/src/test/java/in/koreatech/koin/acceptance/TimetableLectureApiTest.java b/src/test/java/in/koreatech/koin/acceptance/TimetableLectureApiTest.java index 8f8883f8f..2fae83d8e 100644 --- a/src/test/java/in/koreatech/koin/acceptance/TimetableLectureApiTest.java +++ b/src/test/java/in/koreatech/koin/acceptance/TimetableLectureApiTest.java @@ -51,7 +51,7 @@ void setup() { clear(); user = userFixture.준호_학생().getUser(); token = userFixture.getToken(user); - semester = semesterFixture.semester("20192"); + semester = semesterFixture.semester_2019년도_2학기(); } @Test diff --git a/src/test/java/in/koreatech/koin/fixture/SemesterFixture.java b/src/test/java/in/koreatech/koin/fixture/SemesterFixture.java index 5533d4bdf..8098e8210 100644 --- a/src/test/java/in/koreatech/koin/fixture/SemesterFixture.java +++ b/src/test/java/in/koreatech/koin/fixture/SemesterFixture.java @@ -4,22 +4,256 @@ import in.koreatech.koin.domain.timetable.model.Semester; import in.koreatech.koin.domain.timetable.repository.SemesterRepository; +import in.koreatech.koin.domain.timetableV3.model.Term; +import in.koreatech.koin.domain.timetableV3.repository.SemesterRepositoryV3; @Component @SuppressWarnings("NonAsciiCharacters") public class SemesterFixture { - private final SemesterRepository semesterRepository; + private final SemesterRepositoryV3 semesterRepositoryV3; - public SemesterFixture(SemesterRepository semesterRepository) { - this.semesterRepository = semesterRepository; + public SemesterFixture(SemesterRepositoryV3 semesterRepositoryV3) { + this.semesterRepositoryV3 = semesterRepositoryV3; } - public Semester semester(String semester) { - return semesterRepository.save( + public Semester semester_2019년도_1학기() { + return semesterRepositoryV3.save( Semester.builder() - .semester(semester) - .build() + .semester("20191") + .year(2019) + .term(Term.FIRST) + .build() + ); + } + + public Semester semester_2019년도_2학기() { + return semesterRepositoryV3.save( + Semester.builder() + .semester("20192") + .year(2019) + .term(Term.SECOND) + .build() + ); + } + + public Semester semester_2019년도_여름() { + return semesterRepositoryV3.save( + Semester.builder() + .semester("2019-여름") + .year(2019) + .term(Term.SUMMER) + .build() + ); + } + + public Semester semester_2019년도_겨울() { + return semesterRepositoryV3.save( + Semester.builder() + .semester("2019-겨울") + .year(2019) + .term(Term.WINTER) + .build() + ); + } + + public Semester semester_2020년도_1학기() { + return semesterRepositoryV3.save( + Semester.builder() + .semester("20201") + .year(2020) + .term(Term.FIRST) + .build() + ); + } + + public Semester semester_2020년도_2학기() { + return semesterRepositoryV3.save( + Semester.builder() + .semester("20202") + .year(2020) + .term(Term.SECOND) + .build() + ); + } + + public Semester semester_2020년도_여름() { + return semesterRepositoryV3.save( + Semester.builder() + .semester("2020-여름") + .year(2020) + .term(Term.SUMMER) + .build() + ); + } + + public Semester semester_2020년도_겨울() { + return semesterRepositoryV3.save( + Semester.builder() + .semester("2020-겨울") + .year(2020) + .term(Term.WINTER) + .build() + ); + } + + public Semester semester_2021년도_1학기() { + return semesterRepositoryV3.save( + Semester.builder() + .semester("20211") + .year(2021) + .term(Term.FIRST) + .build() + ); + } + + public Semester semester_2021년도_2학기() { + return semesterRepositoryV3.save( + Semester.builder() + .semester("20212") + .year(2021) + .term(Term.SECOND) + .build() + ); + } + + public Semester semester_2021년도_여름() { + return semesterRepositoryV3.save( + Semester.builder() + .semester("2021-여름") + .year(2021) + .term(Term.SUMMER) + .build() + ); + } + + public Semester semester_2021년도_겨울() { + return semesterRepositoryV3.save( + Semester.builder() + .semester("2021-겨울") + .year(2021) + .term(Term.WINTER) + .build() + ); + } + + public Semester semester_2022년도_1학기() { + return semesterRepositoryV3.save( + Semester.builder() + .semester("20221") + .year(2022) + .term(Term.FIRST) + .build() + ); + } + + public Semester semester_2022년도_2학기() { + return semesterRepositoryV3.save( + Semester.builder() + .semester("20222") + .year(2022) + .term(Term.SECOND) + .build() + ); + } + + public Semester semester_2022년도_여름() { + return semesterRepositoryV3.save( + Semester.builder() + .semester("2022-여름") + .year(2022) + .term(Term.SUMMER) + .build() + ); + } + + public Semester semester_2022년도_겨울() { + return semesterRepositoryV3.save( + Semester.builder() + .semester("2022-겨울") + .year(2022) + .term(Term.WINTER) + .build() + ); + } + + public Semester semester_2023년도_1학기() { + return semesterRepositoryV3.save( + Semester.builder() + .semester("20231") + .year(2023) + .term(Term.FIRST) + .build() + ); + } + + public Semester semester_2023년도_2학기() { + return semesterRepositoryV3.save( + Semester.builder() + .semester("20232") + .year(2023) + .term(Term.SECOND) + .build() + ); + } + + public Semester semester_2023년도_여름() { + return semesterRepositoryV3.save( + Semester.builder() + .semester("2023-여름") + .year(2023) + .term(Term.SUMMER) + .build() + ); + } + + public Semester semester_2023년도_겨울() { + return semesterRepositoryV3.save( + Semester.builder() + .semester("2023-겨울") + .year(2023) + .term(Term.WINTER) + .build() + ); + } + + public Semester semester_2024년도_1학기() { + return semesterRepositoryV3.save( + Semester.builder() + .semester("20241") + .year(2024) + .term(Term.FIRST) + .build() + ); + } + + public Semester semester_2024년도_2학기() { + return semesterRepositoryV3.save( + Semester.builder() + .semester("20242") + .year(2024) + .term(Term.SECOND) + .build() + ); + } + + public Semester semester_2024년도_여름() { + return semesterRepositoryV3.save( + Semester.builder() + .semester("2024-여름") + .year(2024) + .term(Term.SUMMER) + .build() + ); + } + + public Semester semester_2024년도_겨울() { + return semesterRepositoryV3.save( + Semester.builder() + .semester("2024-겨울") + .year(2024) + .term(Term.WINTER) + .build() ); } }