Skip to content

Commit

Permalink
refactor: 진행중인 게임 찾는 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
chaewon121 committed Nov 6, 2023
1 parent dce0561 commit 39e1e7c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public Game findGameById(final FindGameByIdCommand findGameByIdCommand) {

@Transactional(readOnly = true)
public List<Game> findGamesByStatus(final FindGameByStatusCommand findGameByStatusCommand) {
Player player = playerService.findPlayerById(findGameByStatusCommand.playerId());
final Player player = playerService.findPlayerById(findGameByStatusCommand.playerId());
return gameRepository.findByPlayerIdAndGameStatus(player.getId(), findGameByStatusCommand.gameStatus());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.now.naaga.letter.application;

import com.now.naaga.game.application.GameService;
import com.now.naaga.game.application.dto.FindGameByStatusCommand;
import com.now.naaga.game.application.dto.FindGameInProgressCommand;
import com.now.naaga.game.domain.Game;
import com.now.naaga.game.exception.GameException;
import com.now.naaga.game.exception.GameExceptionType;
import com.now.naaga.letter.application.dto.CreateLetterCommand;
import com.now.naaga.letter.domain.Letter;
import com.now.naaga.letter.domain.letterlog.ReadLetterLog;
Expand All @@ -23,7 +21,6 @@

import java.util.List;

import static com.now.naaga.game.domain.GameStatus.IN_PROGRESS;
import static com.now.naaga.letter.exception.LetterExceptionType.NO_EXIST;

@Transactional
Expand Down Expand Up @@ -79,7 +76,7 @@ public Letter findLetter(final LetterReadCommand letterReadCommand) {
}

private void logReadLetter(final Player player,
final Letter letter) {
final Letter letter) {
final Game gameInProgress = getGameInProgress(player.getId());
final ReadLetterLog readLetterLog = new ReadLetterLog(gameInProgress, letter);
readLetterLogRepository.save(readLetterLog);
Expand All @@ -105,12 +102,8 @@ public List<Letter> findLetterLogInGame(final FindLetterLogByGameCommand findLet
}

private Game getGameInProgress(final Long playerId) {
final FindGameByStatusCommand findGameByStatusCommand = new FindGameByStatusCommand(playerId, IN_PROGRESS);
final List<Game> gamesInProgress = gameService.findGamesByStatus(findGameByStatusCommand);
if (gamesInProgress.isEmpty()) {
throw new GameException(GameExceptionType.NOT_EXIST_IN_PROGRESS);
}
return gamesInProgress.get(0);
final FindGameInProgressCommand findGameByStatusCommand = new FindGameInProgressCommand(playerId);
return gameService.findGameInProgress(findGameByStatusCommand);
}
}

0 comments on commit 39e1e7c

Please sign in to comment.