Skip to content

[Feature] 배틀 결과 조회 API 구현#175

Merged
U-S-jun merged 8 commits intodevfrom
feature/#174-result-api
Jan 16, 2026
Merged

[Feature] 배틀 결과 조회 API 구현#175
U-S-jun merged 8 commits intodevfrom
feature/#174-result-api

Conversation

@U-S-jun
Copy link
Copy Markdown
Collaborator

@U-S-jun U-S-jun commented Jan 16, 2026

🔗 관련 이슈

Closes #174

✅ 작업 내용

배틀 종료 후 결과를 목데이터가 아닌 종료 스냅샷으로 반환하도록 백엔드 로직을 전환했고 metrics.totalChats를 추가해 채팅 총 개수을 제공하도록 확장했습니다. DTO/타입, 테스트 수정 반영했습니다.

  • backend/src/battles/service/battles.service.ts

    • finishBattle에서 종료 시점 스냅샷을 생성해 finishedBattles 맵에 저장하도록 변경.
    • buildFinishedBattleState: 결과/메트릭/투표 타임라인/타임라인/MVP를 ActiveBattle 기반으로 계산해 FinishedBattleState 구성.
    • buildTimeline: 타임라인 변환 후 시간순 정렬.
    • metrics.totalChats 계산: all + teamA + teamB 채팅 수 합산.
  • backend/src/battles/types/battleResult.types.ts

    • Metrics에 totalChats: number 필드 추가
  • backend/src/battles/dto/battleResult.dto.ts

    • res 변환 타입을 FinishedBattleState로 변경해 스냅샷에 맞춤.
  • backend/src/battles/dto/closedBattleResponse.dto.ts

    • 종료 배틀 목록 메서드를 FinishedBattleState 기반으로 변경.

💡개선 사항


📸 참고 사항

Get /battles/:8/result

{
    "battleId": "8",
    "authorId": "user-8",
    "title": "Functional vs OOP",
    "description": "Paradigm discussion",
    "status": "CLOSED",
    "language": "TS",
    "category": "IMPLEMENT",
    "playTime": 15,
    "createdAt": "2026-01-16T00:14:39.173Z",
    "finishedAt": "2026-01-16T00:18:09.277Z",
    "codeA": "function add(a, b) { return a + b; }",
    "codeB": "class Calculator { add(a, b) { return a + b; } }",
    "result": {
        "winner": "DRAW",
        "teamA": {
            "votes": 1,
            "percentage": 50
        },
        "teamB": {
            "votes": 1,
            "percentage": 50
        },
        "neutral": {
            "votes": 0,
            "percentage": 0
        }
    },
    "metrics": {
        "totalParticipants": 2,
        "totalViews": 2,
        "strategiesCount": 8
    },
    "voteTimeline": [
        {
            "turn": 1,
            "teamAVotes": 1,
            "teamBVotes": 1,
            "neutralVotes": 0,
            "timestamp": "2026-01-16T00:18:09.277Z"
        }
    ],
    "timeline": [
        {
            "id": "019bc428-6701-7019-861e-ecc7453f0e24",
            "type": "ATTACK",
            "author": {
                "id": "user-grd6v7wfg",
                "nickname": "user-grd6v7wfg"
            },
            "team": "A",
            "content": "afds",
            "turn": 1,
            "upvotes": 1,
            "createdAt": "2026-01-16T00:16:09.271Z"
        },
        {
            "id": "019bc428-6e38-735a-aa5e-8e9e7c526975",
            "type": "ATTACK",
            "author": {
                "id": "user-57enp9p55",
                "nickname": "user-57enp9p55"
            },
            "team": "B",
            "content": "fads",
            "turn": 1,
            "upvotes": 1,
            "createdAt": "2026-01-16T00:16:09.271Z"
        },
        {
            "id": "019bc428-f3ba-73d3-8b2a-287f8e2d5eaf",
            "type": "DEFENSE",
            "author": {
                "id": "user-grd6v7wfg",
                "nickname": "user-grd6v7wfg"
            },
            "team": "A",
            "content": "ㅎㅇㅎㅇ",
            "turn": 1,
            "upvotes": 1,
            "createdAt": "2026-01-16T00:16:49.271Z"
        },
        {
            "id": "null-B-DEFENSE-1768522609271",
            "type": "DEFENSE",
            "author": {
                "id": "unknown",
                "nickname": "unknown"
            },
            "team": "B",
            "content": "투표로 선정된 의견이 없습니다",
            "turn": 1,
            "upvotes": 0,
            "createdAt": "2026-01-16T00:16:49.271Z"
        },
        {
            "id": "019bc429-93ac-75d9-a1e7-7739f61577db",
            "type": "ATTACK",
            "author": {
                "id": "user-grd6v7wfg",
                "nickname": "user-grd6v7wfg"
            },
            "team": "A",
            "content": "bb",
            "turn": 2,
            "upvotes": 1,
            "createdAt": "2026-01-16T00:17:19.271Z"
        },
        {
            "id": "019bc429-a0dc-715f-9475-2715503e571b",
            "type": "ATTACK",
            "author": {
                "id": "user-57enp9p55",
                "nickname": "user-57enp9p55"
            },
            "team": "B",
            "content": "bb",
            "turn": 2,
            "upvotes": 1,
            "createdAt": "2026-01-16T00:17:19.271Z"
        },
        {
            "id": "019bc429-f172-7006-9503-e895c8514d85",
            "type": "DEFENSE",
            "author": {
                "id": "user-grd6v7wfg",
                "nickname": "user-grd6v7wfg"
            },
            "team": "A",
            "content": "ss",
            "turn": 2,
            "upvotes": 1,
            "createdAt": "2026-01-16T00:17:59.273Z"
        },
        {
            "id": "019bc429-f9ab-720a-a7ae-669ee4ba8ff1",
            "type": "DEFENSE",
            "author": {
                "id": "user-57enp9p55",
                "nickname": "user-57enp9p55"
            },
            "team": "B",
            "content": "nn",
            "turn": 2,
            "upvotes": 1,
            "createdAt": "2026-01-16T00:17:59.273Z"
        }
    ],
    "mvp": {
        "userId": "user-grd6v7wfg",
        "nickname": "user-grd6v7wfg",
        "team": "A",
        "totalVotes": 4
    }
}

💬 질문사항 (고민했던 부분)

buildFinishedBattleState 추가 : 결과/메트릭/투표 타임라인/타임라인/MVP를 Active 배틀을 기반으로 계산해 finishedBattleState 구성
buildTimeline 추가: 공격/방어 기록을 타임라인을 변환 후 시간순 정렬
getBattleResult에서 finishedBattles에 없을 경우 badRequest 반환
totalChats 계산 : all + teamA + teamB
Copy link
Copy Markdown
Collaborator

@rhxfkg rhxfkg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다!

Copy link
Copy Markdown
Member

@jjjjjinseo jjjjjinseo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다!

@U-S-jun U-S-jun merged commit 7235aa0 into dev Jan 16, 2026
1 check passed
@U-S-jun U-S-jun deleted the feature/#174-result-api branch January 16, 2026 01:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🛠️ BE Extra attention is needed 🎯 task

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] 배틀 결과 페이지 조회 API 구현

4 participants