Skip to content

feat: LoL 커스텀 매치 결과 DB 저장 기능 구현 #86

@Sunja-An

Description

@Sunja-An

개요

로그인된 사용자가 LoL 팀 밸런싱 API를 호출할 때, 팀 구성 결과와 승부 결과를 DB에 저장할 수 있도록 기능을 추가한다.

배경

기존 /api/lol/temporal 엔드포인트는 Stateless 연산만 수행하여 팀 밸런싱 결과가 응답 이후 휘발됐다. 로그인된 사용자가 커스텀 매치 기록을 남기고, 이후 승패 결과까지 저장할 수 있도록 영속성 레이어가 필요하다.

구현 범위

DB (Migration #26)

  • lol_custom_matches — 커스텀 매치 세션 (creator_user_id FK, status, winner)
  • lol_custom_match_players — 10명 플레이어 배치 정보 (team, username, tag, rank, position, position_preference)

도메인 레이어

  • LolCustomMatch 엔티티 (상태: PENDING → FINISHED/CANCELLED)
  • LolCustomMatchPlayer 엔티티

애플리케이션 레이어

  • LolCustomMatchRepositoryPort 인터페이스
  • LolTeamBalanceService.BalanceAndSave(creatorUserID, req) — 팀 밸런싱 + DB 저장
  • LolTeamBalanceService.RecordMatchResult(matchID, creatorUserID, winner) — 승패 기록 (생성자 권한 검증)

인프라 레이어

  • LolCustomMatchDatabaseAdapter — GORM 트랜잭션 기반 저장

API 변경

POST /api/lol/temporal (기존 변경)

팀 밸런싱 결과를 DB에 저장하고 match_id를 함께 반환한다.

Response (변경 전)

{
  "status": 201,
  "data": {
    "team_a": [...],
    "team_b": [...]
  }
}

Response (변경 후)

{
  "status": 201,
  "data": {
    "match_id": 1,
    "team_a": [...],
    "team_b": [...]
  }
}

PATCH /api/lol/temporal/:matchId/result (신규)

커스텀 매치의 승리 팀을 기록한다. 매치를 생성한 사용자만 호출 가능.

Request

{ "winner": "TEAM_A" }

Response

{ "status": 200, "message": "match result recorded" }

Error cases

상태코드 설명
403 매치 생성자가 아닌 경우
404 매치가 존재하지 않는 경우
400 이미 결과가 기록된 경우, 잘못된 winner 값

에러 코드 추가

코드 메시지
LOL001 lol custom match not found
LOL002 you are not the creator of this match
LOL003 match result has already been recorded
LOL004 winner must be TEAM_A or TEAM_B

체크리스트

  • DB 마이그레이션 파일 작성
  • Domain 엔티티 구현
  • Repository Port 인터페이스 정의
  • GORM DB 어댑터 구현
  • 서비스 메서드 추가 (BalanceAndSave, RecordMatchResult)
  • 컨트롤러 엔드포인트 추가
  • 에러 상수 추가
  • 기존 단위 테스트 호환성 유지

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions