Skip to content

Commit

Permalink
[FIX] 퀴즈 생성 및 응답 형식을 Json에서 List로 변경 (#104)
Browse files Browse the repository at this point in the history
* feat: add map to list converter in dto

* feat: add list to map converter in request dto

* feat: change quiz request/response in talk controller test

* chore: copy documents
  • Loading branch information
2tle authored Oct 4, 2024
1 parent 48bd0e0 commit 823ef5b
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 247 deletions.
12 changes: 8 additions & 4 deletions src/main/java/com/scg/stop/video/dto/request/QuizRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

Expand All @@ -19,16 +21,18 @@ public class QuizRequest {
//@NotNull(message = "퀴즈를 입력해주세요.")
@Size(min=1, message = "퀴즈는 1개 이상이어야 합니다.")
@Valid
public Map<String,
@Valid QuizInfoRequest> quiz;
public List<@Valid QuizInfoRequest> quiz;

public Quiz toEntity() { return Quiz.from(
this.toQuizInfoMap()
); }

public Map<String, QuizInfo> toQuizInfoMap() {
return quiz.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().toQuizInfo()));
Map<String, QuizInfo> quizInfoMap = new HashMap<>();
for(int i = 0; i < quiz.size(); i++) {
quizInfoMap.put(Integer.toString(i), quiz.get(i).toQuizInfo());
}
return quizInfoMap;
}

}
16 changes: 11 additions & 5 deletions src/main/java/com/scg/stop/video/dto/response/QuizResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class QuizResponse {
public Map<String, QuizInfo> quiz;

public List<QuizInfo> quiz;
public static QuizResponse from(Quiz quiz) {
return new QuizResponse(
quiz.getQuiz()
);
List<String> keys = new ArrayList<>(quiz.getQuiz().keySet());
Collections.sort(keys);
List<QuizInfo> tmp = new ArrayList<>();
for(String key : keys) {
tmp.add(quiz.getQuiz().get(key));
}
return new QuizResponse(tmp);
}
}
Loading

0 comments on commit 823ef5b

Please sign in to comment.