Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public GameStartRes startGame(Long userId, Long fairytaleId) {
GameSession session = new GameSession(userId, fairytaleId, nodes, edges);
sessionManager.save(session);

return GameStartRes.of(session.getSessionId(), session.getNodes());
return GameStartRes.of(session.getSessionId(), fairytale, session.getNodes());
}

@Override
Expand All @@ -108,7 +108,8 @@ public ClassifyRes classify(String sessionId, Long nodeId, String category) {

// 모든 노드 분류 완료 → 1단계 종료, 2단계 데이터 반환
if (session.isClassifyComplete()) {
return ClassifyRes.stageComplete(session.getNodes(), session.getTotalEdges());
Fairytale fairytale = entityManager.find(Fairytale.class, session.getFairytaleId());
return ClassifyRes.stageComplete(fairytale, session.getNodes(), session.getTotalEdges());
}

return ClassifyRes.correct(false);
Expand Down Expand Up @@ -171,7 +172,8 @@ public QuizAnswerRes answerQuiz(String sessionId, String quizId, Long selectedCh
saveGameResult(session);
// 세션 제거
sessionManager.remove(sessionId);
return QuizAnswerRes.stageComplete(edge.getDescription(), session.getNodes(), session.getEdges());
Fairytale fairytale = entityManager.find(Fairytale.class, session.getFairytaleId());
return QuizAnswerRes.stageComplete(fairytale, edge.getDescription(), session.getNodes(), session.getEdges());
}

return QuizAnswerRes.correct(edge.getDescription());
Expand All @@ -192,10 +194,15 @@ public EdgeDetailRes getEdgeDetail(Long userId, Long edgeId) {
public GraphDetailRes getGraph(Long userId, Long fairytaleId) {
validateGraphCompleted(userId, fairytaleId);

Fairytale fairytale = entityManager.find(Fairytale.class, fairytaleId);
if (fairytale == null) {
throw new FairytaleNotFoundException();
}

List<GraphNode> nodes = graphNodeRepository.findByFairytaleId(fairytaleId);
List<GraphEdge> edges = graphEdgeRepository.findByFairytaleId(fairytaleId);

return GraphDetailRes.of(fairytaleId, nodes, edges);
return GraphDetailRes.of(fairytale, nodes, edges);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.capstone.kkumteul.domain.game.web.dto;

import com.capstone.kkumteul.domain.fairytale.entity.Fairytale;
import com.capstone.kkumteul.domain.game.service.GameSession.SessionNode;
import com.fasterxml.jackson.annotation.JsonInclude;

Expand All @@ -16,25 +17,35 @@ public record ClassifyRes(
boolean stageComplete,
String hint,
String nextStage,
String selectedCharSpecies,
String selectedBackground,
AssembleQuestionRes question
) {

/** 정답 — stageComplete 여부만 전달 */
public static ClassifyRes correct(boolean stageComplete) {
return new ClassifyRes(true, stageComplete, null, null, null);
return new ClassifyRes(true, stageComplete, null, null, null, null, null);
}

/** 오답 — 힌트 메시지 포함 */
public static ClassifyRes incorrect() {
return new ClassifyRes(false, false, "다시 시도해보세요!", null, null);
return new ClassifyRes(false, false, "다시 시도해보세요!", null, null, null, null);
}

public static ClassifyRes stageComplete(Collection<SessionNode> nodes, int totalEdges) {
public static ClassifyRes stageComplete(Fairytale fairytale, Collection<SessionNode> nodes, int totalEdges) {
List<NodeWithCategoryRes> nodeResList = nodes.stream()
.map(NodeWithCategoryRes::from)
.toList();
AssembleQuestionRes question = new AssembleQuestionRes(nodeResList, totalEdges);
return new ClassifyRes(true, true, null, "ASSEMBLE", question);
return new ClassifyRes(
true,
true,
null,
"ASSEMBLE",
fairytale.getCharSpecies().name(),
fairytale.getBackground().name(),
question
);
}

public record AssembleQuestionRes(List<NodeWithCategoryRes> nodes, int totalEdges) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.capstone.kkumteul.domain.game.web.dto;

import com.capstone.kkumteul.domain.fairytale.entity.Fairytale;
import com.capstone.kkumteul.domain.game.entity.NodeCategory;
import com.capstone.kkumteul.domain.game.service.GameSession.SessionNode;

Expand All @@ -14,18 +15,26 @@
public record GameStartRes(
String sessionId,
String stage,
String selectedCharSpecies,
String selectedBackground,
ClassifyQuestionRes question
) {

public static GameStartRes of(String sessionId, Collection<SessionNode> nodes) {
List<NodeRes> nodeResList = nodes.stream()
.map(NodeRes::from)
public static GameStartRes of(String sessionId, Fairytale fairytale, Collection<SessionNode> nodes) {
List<NodeWithCategoryRes> nodeResList = nodes.stream()
.map(NodeWithCategoryRes::from)
.toList();
List<String> categories = Arrays.stream(NodeCategory.values())
.map(NodeCategory::getLabel)
.toList();
return new GameStartRes(sessionId, "CLASSIFY", new ClassifyQuestionRes(nodeResList, categories));
return new GameStartRes(
sessionId,
"CLASSIFY",
fairytale.getCharSpecies().name(),
fairytale.getBackground().name(),
new ClassifyQuestionRes(nodeResList, categories)
);
}

public record ClassifyQuestionRes(List<NodeRes> nodes, List<String> categories) {}
public record ClassifyQuestionRes(List<NodeWithCategoryRes> nodes, List<String> categories) {}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.capstone.kkumteul.domain.game.web.dto;

import com.capstone.kkumteul.domain.fairytale.entity.Fairytale;
import com.capstone.kkumteul.domain.game.entity.GraphEdge;
import com.capstone.kkumteul.domain.game.entity.GraphNode;

Expand All @@ -11,18 +12,26 @@
*/
public record GraphDetailRes(
Long fairytaleId,
String selectedCharSpecies,
String selectedBackground,
List<NodeWithCategoryRes> nodes,
List<EdgeRes> edges
) {

public static GraphDetailRes of(Long fairytaleId, List<GraphNode> nodes, List<GraphEdge> edges) {
public static GraphDetailRes of(Fairytale fairytale, List<GraphNode> nodes, List<GraphEdge> edges) {
List<NodeWithCategoryRes> nodeResList = nodes.stream()
.map(n -> new NodeWithCategoryRes(n.getId(), n.getWord(), n.getCategory().getLabel()))
.toList();
List<EdgeRes> edgeResList = edges.stream()
.map(e -> new EdgeRes(e.getId(), e.getFromNode().getId(), e.getToNode().getId()))
.toList();
return new GraphDetailRes(fairytaleId, nodeResList, edgeResList);
return new GraphDetailRes(
fairytale.getId(),
fairytale.getCharSpecies().name(),
fairytale.getBackground().name(),
nodeResList,
edgeResList
);
}

public record EdgeRes(Long edgeId, Long from, Long to) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.capstone.kkumteul.domain.game.web.dto;

import com.capstone.kkumteul.domain.fairytale.entity.Fairytale;
import com.capstone.kkumteul.domain.game.service.GameSession.SessionEdge;
import com.capstone.kkumteul.domain.game.service.GameSession.SessionNode;
import com.fasterxml.jackson.annotation.JsonInclude;
Expand All @@ -19,28 +20,39 @@ public record QuizAnswerRes(
String description,
String hint,
String nextStage,
String selectedCharSpecies,
String selectedBackground,
GraphRes graph
) {

/** 정답 — 엣지 설명 포함 */
public static QuizAnswerRes correct(String description) {
return new QuizAnswerRes(true, false, description, null, null, null);
return new QuizAnswerRes(true, false, description, null, null, null, null, null);
}

/** 오답 — 힌트 메시지 포함 */
public static QuizAnswerRes incorrect() {
return new QuizAnswerRes(false, false, null, "틀렸어요! 다시 한번 생각해볼까요?", null, null);
return new QuizAnswerRes(false, false, null, "틀렸어요! 다시 한번 생각해볼까요?", null, null, null, null);
}

public static QuizAnswerRes stageComplete(String description, Collection<SessionNode> nodes, List<SessionEdge> edges) {
public static QuizAnswerRes stageComplete(Fairytale fairytale, String description, Collection<SessionNode> nodes, List<SessionEdge> edges) {
List<NodeWithCategoryRes> nodeResList = nodes.stream()
.map(NodeWithCategoryRes::from)
.toList();
List<EdgeRes> edgeResList = edges.stream()
.map(e -> new EdgeRes(e.getId(), e.getFromNodeId(), e.getToNodeId()))
.toList();
GraphRes graph = new GraphRes(nodeResList, edgeResList);
return new QuizAnswerRes(true, true, description, null, "RELATION", graph);
return new QuizAnswerRes(
true,
true,
description,
null,
"RELATION",
fairytale.getCharSpecies().name(),
fairytale.getBackground().name(),
graph
);
}

public record GraphRes(List<NodeWithCategoryRes> nodes, List<EdgeRes> edges) {}
Expand Down
Loading