-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feat] 고급 모의투자 게임 구현 #55
Conversation
Advanced Invest, 즉 게임 시스템 구현이 완료되었습니다. 현재 Stock Record 구현이 완료 되지 않아 오류가 생깁니다. 이는 곧 구현 완료 할 예정입니다 related to: #27
StockRecord 기능을 구현하면서 AdvancedInvest 쪽 기능까지 완전히 구현 완료 하였습니다. related to: #27
몇몇 버그를 픽스 했습니다 close: #27
WebSocket 구현이 완료되었습니다. WebSocket 설정 뿐만이 아니라 실질적인 게임의 모든 기능이 이제 Service 에서 진행됩니다 related to: #51
주식의 구매와 판매 관련하여 handler 구현이 정상적으로 완료되지 않아 수정하였습니다 related to: #51
게임 종료시 WebSocket Session 이 종료되지 않고 영원히 유지되는 이상한 일이 일어나서 이를 고쳤습니다. close: #51
StockRecord Repository 에서 활용되는 advId 가 제대로 매핑이 되지 않아 생기는 오류를 수정하였습니다 related to: #51
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수고하셨습니다!
간단한 URI 변경 입니다. 테스트용으로 만들었던걸 그대로 쓰고 있는걸 확인하여 컨베션에 맞게 변경하였습니다 related to: #51
stock 수치를 보낼때 쓰지 않는 수치들이 상당히 많이 존재하여 AdvStockResponseDto 를 다시 사용하기 시작했습니다 related to: #51
주식 수량을 정하는 quantity 필드가 int 로 되어 있던것을 double 로 변경하였습니다. related to: #51
stockRecord 내부에서 advId 를 받아 조회하면 특정 게임의 내역만 조회가 되어 memberId 로 수정하였습니다 related to: #51
전 refactoring 과 같은 이유로, advId 로 조회하는 주식을 전부 memberId 로 추가적으로 변환하였습니다 related to: #51
@@ -0,0 +1,80 @@ | |||
package com.prgrms.ijuju.domain.stock.adv.advancedinvest.controller; | |||
|
|||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR에는 사용되는 코드를 올리셔야 합니다.
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class AdvancedInvestServiceImpl implements AdvancedInvestService { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
전반적으로 비즈니스 로직이 조금 방대하게 있는 편이어서
- 도메인
- 서비스
쪽으로 로직을 던져보면 좋을 것 같습니다.
단, 서비스는 순환 참조가 발생하지 않도록 막아야 합니다.
#️⃣ 연관된 이슈 번호
closed #51
related to #27
related to #25
✅ PR 유형
코드 확인할떄 StockRecord 부터 확인하고 AdvancedInvest 로 넘어가면 좀 더 이해하기 편합니다/
StockRecord : 유저가 진행한 모든 구매와 판매 관련된 기록을 남기고, 해당 기록들을 통해 보유한 주식을 계산하는 도메인
AdvancedInvest : 게임을 진행하는 도메인으로 WebSocket 으로 구현되어 있음.
StockRecord
1. Stock Record 구성
1.1 Controller
StockRecordController
POST /api/v1/stock-records
: 거래 내역 저장.StockRecordRequestDto
를 사용하여 데이터 전송.StockRecordService
에 전달하여 저장.GET /api/v1/stock-records/{advId}
: 특정 AdvancedInvest ID의 거래 내역 조회.StockRecordResponseDto
반환.GET /api/v1/stock-records/{advId}/{stockSymbol}/quantity
: 특정 주식의 보유량 조회.calculateOwnedStock
메서드로 계산된 보유량 반환.GET /api/v1/stock-records/{advId}/all-quantities
: 모든 주식의 보유량 조회.1.2 DTOs
StockRecordRequestDto
stockSymbol
: 주식 심볼.tradeType
: 거래 유형 (구매/판매).price
: 거래 단가.quantity
: 거래 수량.advId
: AdvancedInvest ID.memberId
: 사용자 ID.toEntity(Member member)
메서드를 통해 엔티티로 변환 가능.StockRecordResponseDto
거래 내역 응답을 위한 DTO.
필드:
tradeId
: 거래 ID.stockSymbol
: 주식 심볼.tradeType
: 거래 유형.price
: 거래 단가.quantity
: 거래 수량.tradeDate
: 거래 날짜.fromEntity(StockRecord stockRecord)
메서드를 통해 엔티티에서 변환 가능.1.3 Entity
StockRecord
member
: 거래를 수행한 사용자.symbol
: 주식 심볼.quantity
: 거래 수량.pricePerUnit
: 단위당 가격.tradeType
: 거래 유형 (BUY/SELL).tradeDate
: 거래 날짜.decreaseQuantity(int soldQuantity)
: 판매 시 수량 감소 메서드.1.4 Enum
TradeType
BUY
: 구매.SELL
: 판매.1.5 Repository
StockRecordRepository
findByAdvId(Long advId)
: 특정 AdvancedInvest ID의 거래 내역 조회.findByAdvIdAndStockSymbol(Long advId, String stockSymbol)
: 특정 주식의 거래 내역 조회.findByMemberIdAndSymbol(Long memberId, String symbol)
: 특정 사용자의 주식 거래 내역 조회.1.6 Service
StockRecordService
(인터페이스)saveRecord(StockRecordRequestDto requestDto, Member member)
: 거래 내역 저장.getRecordsByAdvId(Long advId)
: 특정 AdvancedInvest ID의 거래 내역 조회.getRecordsByStock(Long advId, String stockSymbol)
: 특정 주식의 거래 내역 조회.calculateOwnedStock(Long advId, String stockSymbol)
: 특정 주식의 보유량 계산.calculateAllOwnedStocks(Long advId)
: 모든 주식의 보유량 계산.StockRecordServiceImpl
StockRecordService
구현체.saveRecord
: 거래 내역 저장. DTO를 엔티티로 변환 후 데이터베이스에 저장.getRecordsByAdvId
: AdvancedInvest ID로 거래 내역 조회.getRecordsByStock
: 주식 심볼로 특정 거래 내역 조회.calculateOwnedStock
: 구매 및 판매 수량을 계산하여 최종 보유량 반환.calculateAllOwnedStocks
: Map 형태로 모든 주식의 보유량 반환.핵심 요약
StockRecord
엔티티에 저장.AdvancedInvest
1. 핵심 WebSocket 구성
1.1 WebSocketHandler
AdvancedInvestWebSocketHandler
START_GAME
,PAUSE_GAME
,RESUME_GAME
,END_GAME
,BUY_STOCK
,SELL_STOCK
,GET_REMAINING_TIME
와 같은 요청을 처리.WebSocketRequestDto
)로 변환 후 처리.AdvancedInvestService
의 메서드 호출.1.2 WebSocketConfig
/ws/advanced-invest
경로로 WebSocket 연결을 설정.1.3 WebSocketUtil
2. 게임 상태 및 타이머 관리
2.1 AdvancedInvestService (인터페이스)
startGameTimer
,pauseGame
,resumeGame
,getRemainingTime
.startGame
,endGame
,resetPlayedTodayStatus
.buyStock
,sellStock
.2.2 AdvancedInvestServiceImpl
startGameTimer
: 게임 타이머를 시작하며, 각 단계(장전, 거래, 장후)에 맞는 데이터를 클라이언트로 전송.pauseGame
: 타이머를 멈추고 현재 초를 저장.resumeGame
: 저장된 초부터 타이머를 재개.startGame
: AdvancedInvest 엔티티를 생성하고 타이머 시작.endGame
: 게임을 종료하고 WebSocket 연결을 닫음.resetPlayedTodayStatus
: 매일 오전 7시에 진행 중인 게임을 초기화.sendReferenceData
,sendLiveData
,sendEndSignal
메서드를 통해 데이터를 WebSocket으로 전송.buyStock
,sellStock
: 주식 구매/판매 로직 처리.3. DTO
3.1 WebSocketRequestDto
action
: 요청 액션 (START_GAME
,BUY_STOCK
등).advId
: AdvancedInvest ID.stockSymbol
: 주식 심볼.quantity
: 거래 수량.points
: 거래 금액.memberId
: 사용자 ID.3.2 StockTransactionRequestDto
stockSymbol
: 주식 심볼.quantity
: 거래 수량.points
: 거래 금액.memberId
: 사용자 ID.tradeType
: 거래 유형 (BUY/SELL).4. 엔티티 및 저장소
4.1 AdvancedInvest
member
: 게임을 시작한 사용자.startTime
: 게임 시작 시간.paused
: 게임 일시정지 여부.currentSecond
: 현재 진행 시간 (초 단위).playedToday
: 당일 게임 진행 여부.stockRecords
: 관련 주식 거래 내역.4.2 AdvancedInvestRepository
findByMemberIdAndPlayedTodayTrue
: 당일 게임을 실행한 사용자 조회.resetPlayedToday
: 모든 게임의playedToday
상태 초기화.findAllByPausedTrue
: 정지 상태의 게임 조회.5. 핵심 기능 요약
🔍 테스트 결과
🎈 변경 사항 체크리스트
✨ 피드백 반영사항
💬 리뷰 요구사항