Skip to content

Commit

Permalink
chore: dto 참조 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Soundbar91 committed Jan 6, 2025
1 parent 263439c commit 1a69ff7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,14 +29,15 @@ public record InnerTimetableFrameResponse(
String term,

@Schema(description = "timetableFrame 리스트", requiredMode = REQUIRED)
List<TimetableFrameResponse> frames
List<TimetableFrameResponseV3> frames
) {

}

public static List<TimetableFramesResponseV3> from(List<TimetableFrame> timetableFrameList) {
List<TimetableFramesResponseV3> responseList = new ArrayList<>();
Map<Integer, Map<Term, List<TimetableFrameResponse>>> groupedByYearAndTerm = new TreeMap<>(Comparator.reverseOrder());
Map<Integer, Map<Term, List<TimetableFrameResponseV3>>> groupedByYearAndTerm = new TreeMap<>(
Comparator.reverseOrder());

// 일차로 Term으로 그룹핑, 이후 year로 그룹핑
for (TimetableFrame timetableFrame : timetableFrameList) {
Expand All @@ -46,25 +46,25 @@ public static List<TimetableFramesResponseV3> from(List<TimetableFrame> timetabl

groupedByYearAndTerm.computeIfAbsent(year, k -> new TreeMap<>(Comparator.comparing(Term::getPriority)));

Map<Term, List<TimetableFrameResponse>> termMap = groupedByYearAndTerm.get(year);
Map<Term, List<TimetableFrameResponseV3>> 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<Integer, Map<Term, List<TimetableFrameResponse>>> yearEntry : groupedByYearAndTerm.entrySet()) {
for (Map.Entry<Integer, Map<Term, List<TimetableFrameResponseV3>>> yearEntry : groupedByYearAndTerm.entrySet()) {
List<InnerTimetableFrameResponse> termResponses = new ArrayList<>();
int year = yearEntry.getKey();
Map<Term, List<TimetableFrameResponse>> termMap = yearEntry.getValue();
Map<Term, List<TimetableFrameResponseV3>> termMap = yearEntry.getValue();

for (Map.Entry<Term, List<TimetableFrameResponse>> termEntry : termMap.entrySet()) {
for (Map.Entry<Term, List<TimetableFrameResponseV3>> termEntry : termMap.entrySet()) {
Term term = termEntry.getKey();
termResponses.add(new InnerTimetableFrameResponse(term.getDescription(), termEntry.getValue()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -80,63 +80,53 @@ 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()))
.contentType(MediaType.APPLICATION_JSON)
)
.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
Expand Down

0 comments on commit 1a69ff7

Please sign in to comment.