Skip to content

Sisc1 be 베팅게임 수정#134

Merged
discipline24 merged 4 commits intomainfrom
SISC1-BE-베팅게임-수정
Nov 24, 2025

Hidden character warning

The head ref may contain hidden characters: "SISC1-BE-\ubca0\ud305\uac8c\uc784-\uc218\uc815"
Merged

Sisc1 be 베팅게임 수정#134
discipline24 merged 4 commits intomainfrom
SISC1-BE-베팅게임-수정

Conversation

@cksdid202
Copy link
Contributor

@cksdid202 cksdid202 commented Nov 24, 2025

Summary by CodeRabbit

  • 기능 개선

    • 베팅 취소 시 포인트 환불과 함께 베팅은 삭제되지 않고 취소 상태로 남아 감사 이력이 유지됩니다.
    • 취소 시 라운드 통계(상승/하락 카운트 및 합계 포인트)가 안전하게 감소하도록 처리되고 동시 취소는 중복 처리 오류(BET_ALREADY_PROCESSED)를 반환합니다.
  • 새로운 기능

    • 사용자 베팅 상세에 이전 종가·결산 종가 및 상승/하락 베팅 수가 표시됩니다.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Nov 24, 2025

Walkthrough

UserBet 취소 흐름을 ACTIVE → CANCELED로 원자적 전환하도록 변경하고, 취소 시 포인트 환불(타겟: BetRound ID) 및 BetRound 통계(업/다운 카운트·합계 포인트) 감소를 수행하도록 로직을 변경했으며, UserBetResponse DTO에 BetRound 관련 4개 필드를 추가했습니다.

Changes

응집군 / 파일(s) 변경 요약
DTO 필드 확장
backend/src/main/java/org/sejongisc/backend/betting/dto/UserBetResponse.java
BigDecimalBetRound 임포트 추가. previousClosePrice, settleClosePrice, upBetCount, downBetCount 필드 추가 및 from(UserBet)에서 BetRound로부터 매핑.
BetRound 통계 감소 메서드 추가
backend/src/main/java/org/sejongisc/backend/betting/repository/BetRoundRepository.java
decrementUpStats(UUID id, long points)decrementDownStats(UUID id, long points) 메서드 추가(각각 up/down 카운트 및 합계 포인트 감소). @Modifying(clearAutomatically = true)@Query 사용.
UserBet 상태 전환(취소) 및 취소 로직 변경
backend/src/main/java/org/sejongisc/backend/betting/service/BettingService.java
backend/src/main/java/org/sejongisc/backend/betting/repository/UserBetRepository.java
취소 로직을 삭제에서 상태 원자적 전환(ACTIVE → CANCELED)으로 변경(새 리포지토리 메서드 updateStatusToCanceled 추가). 취소 성공 시 포인트 환불 이력 생성(대상: BetRound ID) 및 BetRound 통계 감소 호출(옵션에 따라 decrementUpStats / decrementDownStats). 동시성 시 처리(업데이트된 행 수로 이미 처리 여부 판별).
상태 및 에러 코드 추가
backend/src/main/java/org/sejongisc/backend/betting/entity/BetStatus.java
backend/src/main/java/org/sejongisc/backend/common/exception/ErrorCode.java
BetStatusCANCELED 상수 추가. ErrorCodeBET_ALREADY_PROCESSED(HttpStatus.CONFLICT, "이미 취소 되거나 처리된 베팅입니다.") 추가.

Sequence Diagram(s)

sequenceDiagram
    participant U as 사용자
    participant S as BettingService
    participant UR as UserBetRepository
    participant BR as BetRoundRepository
    participant PH as PointHistoryRepository

    U->>S: cancelUserBet(userBetId)
    S->>UR: updateStatusToCanceled(userBetId, userId, ACTIVE, CANCELED)
    alt 업데이트된 행 = 0
        S-->>U: 에러 (BET_ALREADY_PROCESSED)
    else 업데이트된 행 = 1
        S->>S: bet 정보 조회 (amount, option, round)
        alt 유료 베팅인 경우
            S->>PH: 포인트 환불 이력 생성 (targetId = roundId)
        end
        alt option == RISE
            S->>BR: decrementUpStats(roundId, points)
        else
            S->>BR: decrementDownStats(roundId, points)
        end
        S-->>U: 취소 완료 (CANCELED)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • 주의점:
    • BettingService.cancelUserBet의 트랜잭션 경계와 동시성(원자적 업데이트 이후 보상 작업의 일관성)
    • BetRound 통계 감소로 인해 음수 카운트·합계가 발생하지 않는지 경계 검사
    • PointHistory의 targetId 변경(BetRound ID)로 인한 조회/감사 영향

Possibly related PRs

Suggested reviewers

  • discipline24

Poem

🐇 나는 작은 토끼, 코드밭을 뛰네
취소된 내기는 조용히 돌아오고,
포인트는 다시 손에, 통계는 정리돼,
라운드는 숨 고르고 다음을 기다리네,
토끼가 전하는 작은 축하의 점프 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 77.78% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive PR 제목이 베팅 게임 수정이라는 매우 포괄적이고 모호한 표현으로, 실제 변경사항의 핵심인 베팅 취소 기능 구현과 통계 처리 로직을 구체적으로 설명하지 못하고 있습니다. 제목을 '베팅 취소 기능 구현 및 통계 감소 처리' 또는 '베팅 취소 시 자동 환불 및 통계 업데이트 기능 추가' 같이 구체적으로 수정하여 변경사항의 주요 목적을 명확히 하시기 바랍니다.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch SISC1-BE-베팅게임-수정

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6bb0763 and 74aa751.

📒 Files selected for processing (1)
  • backend/src/main/java/org/sejongisc/backend/betting/repository/UserBetRepository.java (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • backend/src/main/java/org/sejongisc/backend/betting/repository/UserBetRepository.java

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
backend/src/main/java/org/sejongisc/backend/betting/repository/BetRoundRepository.java (1)

34-42: 증가 쿼리와 대칭적인 통계 감소 쿼리 구현은 좋습니다. 다만 음수로 내려가는 경우를 DB에서 한 번 더 막을 수 있습니다.

현재 구현은 incrementUp/DownStats와 완전히 대칭이라 기본 동작은 문제 없습니다. 다만 서비스 레이어에서 중복 취소나 잘못된 파라미터로 이 메서드가 여러 번 호출될 가능성을 완전히 배제하기 어렵다면,

  • upBetCount >= 1 AND upTotalPoints >= :points
  • downBetCount >= 1 AND downTotalPoints >= :points

와 같은 조건을 WHERE 절에 추가해 통계 값이 0 아래로 내려가지 않도록 DB 차원의 방어 로직을 두는 것도 고려해 볼 만합니다.

backend/src/main/java/org/sejongisc/backend/betting/dto/UserBetResponse.java (1)

6-53: 라운드 가격·통계 필드 추가 및 매핑은 일관되고 올바르게 보입니다.

previousClosePrice / settleClosePrice / upBetCount / downBetCountBetRound에서 끌어와 함께 내려주는 구조는 클라이언트 입장에서 필요한 정보들을 잘 묶어준 것 같습니다(Line 28-32, 50-53).

사소한 부분이지만, 이미 BetRound round = bet.getRound();(Line 36)를 선언하셨으니 아래의 .betRoundId(...), .roundTitle(...), .symbol(...)round.get…를 사용하도록 통일하면 NPE 디버깅이나 필드 추가 시 읽기성이 조금 더 좋아질 것 같습니다. 그 외에는 DTO 설계·매핑 모두 무난합니다.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 17223f1 and b07cac1.

📒 Files selected for processing (3)
  • backend/src/main/java/org/sejongisc/backend/betting/dto/UserBetResponse.java (3 hunks)
  • backend/src/main/java/org/sejongisc/backend/betting/repository/BetRoundRepository.java (1 hunks)
  • backend/src/main/java/org/sejongisc/backend/betting/service/BettingService.java (1 hunks)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b07cac1 and 6bb0763.

📒 Files selected for processing (4)
  • backend/src/main/java/org/sejongisc/backend/betting/entity/BetStatus.java (1 hunks)
  • backend/src/main/java/org/sejongisc/backend/betting/repository/UserBetRepository.java (2 hunks)
  • backend/src/main/java/org/sejongisc/backend/betting/service/BettingService.java (1 hunks)
  • backend/src/main/java/org/sejongisc/backend/common/exception/ErrorCode.java (1 hunks)
🔇 Additional comments (6)
backend/src/main/java/org/sejongisc/backend/betting/entity/BetStatus.java (1)

6-7: LGTM!

CANCELED 상태 추가가 적절합니다. 취소 흐름을 명확하게 표현하고 있습니다.

backend/src/main/java/org/sejongisc/backend/common/exception/ErrorCode.java (1)

84-84: LGTM!

중복 취소 시도를 처리하기 위한 에러 코드가 적절합니다. HttpStatus.CONFLICT와 명확한 메시지가 잘 정의되어 있습니다.

backend/src/main/java/org/sejongisc/backend/betting/repository/UserBetRepository.java (1)

24-27: 원자적 상태 전환 로직이 잘 구현되어 있습니다.

@Modifying과 조건부 UPDATE를 사용한 원자적 상태 전환이 적절합니다. updatedCount를 반환하여 서비스 레이어에서 동시성 제어를 할 수 있도록 설계되었습니다. 다만 Line 3의 임포트 오류를 먼저 수정해야 합니다.

backend/src/main/java/org/sejongisc/backend/betting/service/BettingService.java (3)

215-227: 이전 리뷰의 멱등성 문제가 해결되었습니다.

원자적 상태 전환(updateStatusToCanceled)과 updatedCount 체크를 통해 동시 취소 요청 시 중복 처리를 방지하는 로직이 잘 구현되었습니다. 이전 리뷰에서 제기된 포인트 이중 환불 및 통계 이중 감소 문제가 해결되었습니다.

Based on learnings, the past review comment raised concerns about idempotency which are now properly addressed.


233-242: 포인트 환불 로직이 적절합니다.

Line 240에서 betRound.getBetRoundID()targetId로 사용하는 것이 베팅 생성(Line 176) 및 정산(Line 291)과 일관성 있게 처리되고 있습니다.


244-250: 검증 완료: 메서드가 올바르게 구현되어 있습니다.

BetRoundRepository에서 두 메서드 모두 다음과 같이 올바르게 구현되어 있습니다:

  • decrementUpStats (line 37): @Modifying(clearAutomatically = true)@Query로 원자적 UPDATE 구문 포함
  • decrementDownStats (line 42): @Modifying(clearAutomatically = true)@Query로 원자적 UPDATE 구문 포함

두 메서드 모두 데이터베이스 수준의 원자적 연산을 통해 통계를 감소시키므로 코드가 안전합니다.

@discipline24 discipline24 merged commit 921e364 into main Nov 24, 2025
1 check passed
@discipline24 discipline24 deleted the SISC1-BE-베팅게임-수정 branch November 24, 2025 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants