-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…put-output-추상화-하기 refactor: 퀴즈게임 도메인로직의 input output 추상화 하기
- Loading branch information
Showing
21 changed files
with
195 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 9 additions & 12 deletions
21
src/main/kotlin/yjh/cstar/engine/application/QuizGameService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,29 @@ | ||
package yjh.cstar.engine.application | ||
|
||
import org.springframework.stereotype.Service | ||
import yjh.cstar.engine.application.port.AnswerProvider | ||
import yjh.cstar.engine.application.port.GameNotifier | ||
import yjh.cstar.engine.application.port.RankingHandler | ||
import yjh.cstar.engine.domain.game.GameInfo | ||
import yjh.cstar.engine.domain.game.QuizGame | ||
import yjh.cstar.engine.domain.io.InputHandler | ||
import yjh.cstar.engine.domain.io.OutputHandler | ||
import yjh.cstar.engine.domain.io.RankingHandler | ||
import yjh.cstar.engine.domain.quiz.QuizDto | ||
import yjh.cstar.game.application.GameResultService | ||
|
||
@Service | ||
class QuizGameService( | ||
private val inputHandler: InputHandler, | ||
private val outputHandler: OutputHandler, | ||
private val answerProvider: AnswerProvider, | ||
private val gameNotifier: GameNotifier, | ||
private val rankingHandler: RankingHandler, | ||
private val gameResultService: GameResultService, | ||
) { | ||
|
||
fun play( | ||
players: Map<Long, String>, | ||
quizzes: List<QuizDto>, | ||
roomId: Long, | ||
categoryId: Long, | ||
) { | ||
fun play(players: Map<Long, String>, quizzes: List<QuizDto>, roomId: Long, categoryId: Long) { | ||
val gameInfo = GameInfo.of(players, quizzes, roomId, categoryId) | ||
val quizGame = QuizGame(gameInfo, inputHandler, outputHandler, rankingHandler, gameResultService) | ||
|
||
val quizGame = QuizGame(gameInfo, answerProvider, gameNotifier, rankingHandler, gameResultService) | ||
|
||
quizGame.initialize() | ||
|
||
quizGame.run() | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/yjh/cstar/engine/application/port/AnswerProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package yjh.cstar.engine.application.port | ||
|
||
import yjh.cstar.engine.domain.quiz.PlayerAnswer | ||
|
||
interface AnswerProvider { | ||
|
||
fun receivePlayerAnswer(roomId: Long, quizId: Long): PlayerAnswer? | ||
|
||
fun initializePlayerAnswerToReceive(roomId: Long, quizId: Long) | ||
} |
7 changes: 0 additions & 7 deletions
7
src/main/kotlin/yjh/cstar/engine/application/port/GameAnswerPollRepository.kt
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
src/main/kotlin/yjh/cstar/engine/application/port/GameNotifier.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package yjh.cstar.engine.application.port | ||
|
||
import yjh.cstar.engine.domain.player.Players | ||
import yjh.cstar.engine.domain.quiz.Quiz | ||
import yjh.cstar.engine.domain.ranking.Ranking | ||
|
||
interface GameNotifier { | ||
|
||
fun notifyGameStartComments(destination: String, roomId: Long) | ||
|
||
fun notifyQuizQuestion(destination: String, quizNo: Int, quiz: Quiz) | ||
|
||
fun notifyRoundResult(destination: String, playerId: Long, nickname: String) | ||
|
||
fun notifyRanking(destination: String, players: Players, ranking: Ranking) | ||
|
||
fun notifyGameResult(destination: String, playerId: Long, nickname: String) | ||
|
||
fun notifyTimeOut(destination: String) | ||
|
||
fun notifyCountdown(destination: String) | ||
} |
6 changes: 3 additions & 3 deletions
6
.../cstar/engine/domain/io/RankingHandler.kt → ...engine/application/port/RankingHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
src/main/kotlin/yjh/cstar/engine/domain/io/ExternalInputHandler.kt
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
src/main/kotlin/yjh/cstar/engine/domain/io/OutputHandler.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
package yjh.cstar.engine.domain.quiz | ||
|
||
data class QuizDto(val id: Long, val question: String, val answer: String) | ||
|
||
class Quiz(val id: Long, val question: String, private val answer: String) { | ||
|
||
companion object { | ||
fun of(id: Long, question: String, answer: String) = Quiz(id, question, answer) | ||
} | ||
|
||
fun isCorrectAnswer(playerAnswer: PlayerAnswer) = playerAnswer.isMatch(answer) | ||
fun isSameAnswer(answer: String) = this.answer == answer | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package yjh.cstar.engine.domain.quiz | ||
|
||
data class QuizDto(val id: Long, val question: String, val answer: String) | ||
|
||
fun QuizDto.toModel(): Quiz = Quiz( | ||
id = this.id, | ||
question = this.question, | ||
answer = this.answer | ||
) |
Oops, something went wrong.