From 1a69ff765e0e7a483be422736191ced24449ed0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=A0=EA=B4=80=EA=B7=9C?= Date: Mon, 6 Jan 2025 14:54:50 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20dto=20=EC=B0=B8=EC=A1=B0=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response/TimetableFramesResponseV3.java | 22 ++--- .../acceptance/TimetableFrameApiV3Test.java | 92 +++++++++---------- 2 files changed, 52 insertions(+), 62 deletions(-) diff --git a/src/main/java/in/koreatech/koin/domain/timetableV3/dto/response/TimetableFramesResponseV3.java b/src/main/java/in/koreatech/koin/domain/timetableV3/dto/response/TimetableFramesResponseV3.java index fcacb89d7..c66bc10d6 100644 --- a/src/main/java/in/koreatech/koin/domain/timetableV3/dto/response/TimetableFramesResponseV3.java +++ b/src/main/java/in/koreatech/koin/domain/timetableV3/dto/response/TimetableFramesResponseV3.java @@ -11,7 +11,6 @@ import com.fasterxml.jackson.databind.annotation.JsonNaming; -import in.koreatech.koin.domain.timetableV2.dto.response.TimetableFrameResponse; import in.koreatech.koin.domain.timetableV2.model.TimetableFrame; import in.koreatech.koin.domain.timetableV3.model.Term; import io.swagger.v3.oas.annotations.media.Schema; @@ -30,14 +29,15 @@ public record InnerTimetableFrameResponse( String term, @Schema(description = "timetableFrame 리스트", requiredMode = REQUIRED) - List frames + List frames ) { - + } public static List from(List timetableFrameList) { List responseList = new ArrayList<>(); - Map>> groupedByYearAndTerm = new TreeMap<>(Comparator.reverseOrder()); + Map>> groupedByYearAndTerm = new TreeMap<>( + Comparator.reverseOrder()); // 일차로 Term으로 그룹핑, 이후 year로 그룹핑 for (TimetableFrame timetableFrame : timetableFrameList) { @@ -46,25 +46,25 @@ public static List from(List timetabl groupedByYearAndTerm.computeIfAbsent(year, k -> new TreeMap<>(Comparator.comparing(Term::getPriority))); - Map> termMap = groupedByYearAndTerm.get(year); + Map> termMap = groupedByYearAndTerm.get(year); termMap.computeIfAbsent(term, k -> new ArrayList<>()); - termMap.get(term).add(TimetableFrameResponse.from(timetableFrame)); + termMap.get(term).add(TimetableFrameResponseV3.from(timetableFrame)); } // 메인 시간표가 멘 위로 그 다음은 id로 정렬 groupedByYearAndTerm.values().forEach(termMap -> termMap.values().forEach(frameList -> - frameList.sort(Comparator.comparing(TimetableFrameResponse::isMain).reversed() - .thenComparing(TimetableFrameResponse::id)) + frameList.sort(Comparator.comparing(TimetableFrameResponseV3::isMain).reversed() + .thenComparing(TimetableFrameResponseV3::id)) ) ); - for (Map.Entry>> yearEntry : groupedByYearAndTerm.entrySet()) { + for (Map.Entry>> yearEntry : groupedByYearAndTerm.entrySet()) { List termResponses = new ArrayList<>(); int year = yearEntry.getKey(); - Map> termMap = yearEntry.getValue(); + Map> termMap = yearEntry.getValue(); - for (Map.Entry> termEntry : termMap.entrySet()) { + for (Map.Entry> termEntry : termMap.entrySet()) { Term term = termEntry.getKey(); termResponses.add(new InnerTimetableFrameResponse(term.getDescription(), termEntry.getValue())); } diff --git a/src/test/java/in/koreatech/koin/acceptance/TimetableFrameApiV3Test.java b/src/test/java/in/koreatech/koin/acceptance/TimetableFrameApiV3Test.java index 3100c0347..a0c19ac0d 100644 --- a/src/test/java/in/koreatech/koin/acceptance/TimetableFrameApiV3Test.java +++ b/src/test/java/in/koreatech/koin/acceptance/TimetableFrameApiV3Test.java @@ -51,24 +51,24 @@ void setup() { post("/v3/timetables/frame") .header("Authorization", "Bearer " + token) .content(String.format(""" - { - "year": "%d", - "term": "%s" - } - """, semester.getYear(), semester.getTerm().getDescription() + { + "year": "%d", + "term": "%s" + } + """, semester.getYear(), semester.getTerm().getDescription() )) .contentType(MediaType.APPLICATION_JSON) ) .andExpect(status().isOk()) .andExpect(content().json(""" - [ - { - "id": 1, - "name": "시간표1", - "is_main": true - } - ] - """)); + [ + { + "id": 1, + "name": "시간표1", + "is_main": true + } + ] + """)); } @Test @@ -80,33 +80,33 @@ void setup() { put("/v3/timetables/frame/{id}", frameId) .header("Authorization", "Bearer " + token) .content(""" - { - "name": "새로운 이름", - "is_main": true - } - """ + { + "name": "새로운 이름", + "is_main": true + } + """ ) .contentType(MediaType.APPLICATION_JSON) ) .andExpect(status().isOk()) .andExpect(content().json(""" - [ - { - "id": 1, - "name": "새로운 이름", - "is_main": true - } - ] - """)); + [ + { + "id": 1, + "name": "새로운 이름", + "is_main": true + } + ] + """)); } @Test - void 모든_시간표_frame을_조회한다() throws Exception { + void 특정_학기의_모든_시간표_frame을_조회한다() throws Exception { timetableV2Fixture.시간표1(user, semester); timetableV2Fixture.시간표2(user, semester); mockMvc.perform( - get("/v3/timetables/frames") + get("/v3/timetables/frame") .header("Authorization", "Bearer " + token) .param("year", String.valueOf(semester.getYear())) .param("term", String.valueOf(semester.getTerm().getDescription())) @@ -114,29 +114,19 @@ void setup() { ) .andExpect(status().isOk()) .andExpect(content().json(""" - [ - { - "year": 2019, - "timetable_frames": [ - { - "term": "2학기", - "frames": [ - { - "id": 1, - "name": "시간표1", - "is_main": true - }, - { - "id": 2, - "name": "시간표2", - "is_main": false - } - ] - } - ] - } - ] - """)); + [ + { + "id": 1, + "name": "시간표1", + "is_main": true + }, + { + "id": 2, + "name": "시간표2", + "is_main": false + } + ] + """)); } @Test