-
Notifications
You must be signed in to change notification settings - Fork 0
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
refactor: 퀴즈게임상태로직개선 #127
The head ref may contain hidden characters: "refactor/#107-\uD034\uC988\uAC8C\uC784\uC0C1\uD0DC\uB85C\uC9C1\uAC1C\uC120"
refactor: 퀴즈게임상태로직개선 #127
Changes from all commits
17e8385
21dff1c
bb10ee7
ae151f2
c6d7576
8b13dd3
a70c63b
938d8b2
3f70171
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,55 @@ | ||
package yjh.cstar.play.application | ||
|
||
import org.springframework.scheduling.annotation.Async | ||
import org.springframework.stereotype.Service | ||
import yjh.cstar.common.BaseException | ||
import yjh.cstar.game.application.GameResultService | ||
import yjh.cstar.play.application.port.AnswerProvider | ||
import yjh.cstar.play.application.port.GameNotifier | ||
import yjh.cstar.play.application.port.RankingHandler | ||
import yjh.cstar.play.application.request.QuizDto | ||
import yjh.cstar.play.application.request.toModel | ||
import yjh.cstar.play.domain.GameConfig | ||
import yjh.cstar.play.domain.QuizGame | ||
import yjh.cstar.play.domain.game.GameInfo | ||
import yjh.cstar.room.application.RoomService | ||
import yjh.cstar.util.Logger | ||
|
||
@Service | ||
class GamePlayService( | ||
private val quizGameService: QuizGameService, | ||
private val answerProvider: AnswerProvider, | ||
private val gameNotifier: GameNotifier, | ||
private val rankingHandler: RankingHandler, | ||
private val gameResultService: GameResultService, | ||
private val roomService: RoomService, | ||
) { | ||
|
||
@Async("GamePlayThreadPool") | ||
fun start(players: Map<Long, String>, quizzes: List<QuizDto>, roomId: Long, categoryId: Long) { | ||
Logger.info("[INFO] 게임 엔진 스레드 시작 - roomId : $roomId") | ||
fun play(players: Map<Long, String>, randomQuizzes: List<QuizDto>, roomId: Long, categoryId: Long) { | ||
try { | ||
val gameInfo = GameInfo.of( | ||
players = players, | ||
quizzes = randomQuizzes.map { it.toModel() }, | ||
roomId = roomId, | ||
categoryId = categoryId | ||
) | ||
|
||
quizGameService.play(players, quizzes, roomId, categoryId) | ||
val gameConfig = GameConfig( | ||
answerProvider, | ||
gameNotifier, | ||
rankingHandler, | ||
gameResultService, | ||
roomService | ||
) | ||
val quizGame = QuizGame.of(gameInfo, gameConfig) | ||
|
||
Logger.info("[INFO] 게임 엔진 스레드 종료 - roomId : $roomId") | ||
quizGame.initialize() | ||
quizGame.run() | ||
quizGame.finishGame() | ||
} catch (e: BaseException) { | ||
Logger.error(e.toString()) | ||
roomService.endGameAndResetRoom(roomId) | ||
} catch (e: Exception) { | ||
Logger.error(e.toString()) | ||
roomService.endGameAndResetRoom(roomId) | ||
} | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,9 @@ interface RankingHandler { | |
|
||
fun initRankingBoard(roomId: Long, players: Players) | ||
|
||
fun assignScoreToPlayer(roomId: Long, playerId: Long) | ||
fun assignScoreToRoundWinner(roomId: Long, roundWinner: Long) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 확실히 의미가 명확해진 것 같습니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 의도를 명확히 전달하기위해 조금 과장해서 적은것도 있고, 실제로 조금 부자연스러워 보이는 것도 있는 것 같습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 의도를 명확히 하기 위해 조금 부자연스럽더라도 길게 적는 게 더 좋아보입니다. 다른 사람의 코드를 읽는 개발자 입장에서 그렇게 하는게 이해하기 더 쉬운 것 같아요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵넵 팀원들이 이해된다면 그걸로 된 것 같아요 |
||
|
||
fun getWinner(roomId: Long): Long | ||
fun getWinnerId(roomId: Long): Long | ||
|
||
fun getRanking(roomId: Long): Ranking | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package yjh.cstar.play.domain | ||
|
||
import yjh.cstar.game.application.GameResultService | ||
import yjh.cstar.play.application.port.AnswerProvider | ||
import yjh.cstar.play.application.port.GameNotifier | ||
import yjh.cstar.play.application.port.RankingHandler | ||
import yjh.cstar.room.application.RoomService | ||
|
||
data class GameConfig( | ||
val answerProvider: AnswerProvider, | ||
val gameNotifier: GameNotifier, | ||
val rankingHandler: RankingHandler, | ||
val gameResultService: GameResultService, | ||
val roomService: RoomService, | ||
) |
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.
제가 이해한 바로는, 다른 패키지와의 통일성을 위해 컨트롤러에서 서비스 단에 요청을 전달하여 게임 진행 로직을 처리하는 방식으로 변경된 것 같습니다. 여기서 특정 패키지의 서비스 단에서 다른 패키지의 컨트롤러 단을 주입받아 사용하는 경우, 계층 간의 방향성이 깨지거나 사이드 이펙트가 발생할 가능성은 없을까요? (계층 간의 방향성은, 컨트롤러 -> 서비스 -> 리포지토리로 이어지는 계층 구조를 의미합니다.)
제가 잘 모르는 부분이라 설명해주시면 큰 도움이 될 것 같습니다. 👍👍
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.
우선 game 패키지와 play 패키지를 서로 다른 두개의 서버라고 가정했습니다.
예를들어 game 서비스는 게임 시작 api 요청을 처리하고, 게임 실행 로직에 대한 이벤트를 외부 서버에 발급한다는 느낌이었습니다.
그래서 이 경우에는 game서버에서 play서버라는 외붕 서버에 요청하는것처럼 구현하였고, 실제 외부 서버의 역할을 하는 play패키는 컨트롤러에서 api요청을 받는방식과 같다고 생각해서 presentation 패키지에 두었습니다.
(물론 현재는 단일 서버이긴 하지만요..!)
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.
네네 이해했습니다. 단일 서버이지만 확장성을 고려해서 두 패키지를 서로 다른 서버라고 가정한거다! ㅎㅎ 이해했습니다. 그 부분을 우리 리드미나 프로젝트 소개할 때 적는 것도 좋을 것 같습니다. 😁😁
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.
추후에 멀티모듈로 분리해서 서버 분리 실습해봐도 재밌을 것 같아요!(학습용..)