diff --git a/src/main/java/mafia/mafiatogether/chat/application/ChatService.java b/src/main/java/mafia/mafiatogether/chat/application/ChatService.java index c77d6674..d78c63e0 100644 --- a/src/main/java/mafia/mafiatogether/chat/application/ChatService.java +++ b/src/main/java/mafia/mafiatogether/chat/application/ChatService.java @@ -9,7 +9,7 @@ import mafia.mafiatogether.chat.domain.ChatRepository; import mafia.mafiatogether.chat.domain.Message; import mafia.mafiatogether.config.exception.ExceptionCode; -import mafia.mafiatogether.config.exception.RoomException; +import mafia.mafiatogether.config.exception.GameException; import mafia.mafiatogether.job.domain.PlayerJob; import mafia.mafiatogether.job.domain.PlayerJobRepository; import org.springframework.stereotype.Service; @@ -25,9 +25,9 @@ public class ChatService { @Transactional(readOnly = true) public List findAllChat(final String code, final String name) { final PlayerJob playerJobs = playerJobRepository.findById(code) - .orElseThrow(() -> new RoomException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); + .orElseThrow(() -> new GameException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); final Chat chat = chatRepository.findById(code) - .orElseThrow(() -> new RoomException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); + .orElseThrow(() -> new GameException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); final boolean isMafia = playerJobs.isMafia(name); return chat.getMessages().stream() .map(message -> ChatResponse.of( @@ -42,7 +42,7 @@ public List findAllChat(final String code, final String name) { @Transactional public void saveChat(final String code, final String name, final ChatRequest chatRequest) { final Chat chat = chatRepository.findById(code) - .orElseThrow(() -> new RoomException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); + .orElseThrow(() -> new GameException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); final Message message = new Message(name, chatRequest.contents(), Clock.systemDefaultZone().millis()); chat.saveMessage(message); chatRepository.save(chat); diff --git a/src/main/java/mafia/mafiatogether/config/exception/RoomException.java b/src/main/java/mafia/mafiatogether/config/exception/GameException.java similarity index 50% rename from src/main/java/mafia/mafiatogether/config/exception/RoomException.java rename to src/main/java/mafia/mafiatogether/config/exception/GameException.java index c5e78a62..318726aa 100644 --- a/src/main/java/mafia/mafiatogether/config/exception/RoomException.java +++ b/src/main/java/mafia/mafiatogether/config/exception/GameException.java @@ -1,8 +1,8 @@ package mafia.mafiatogether.config.exception; -public class RoomException extends GlobalException{ +public class GameException extends GlobalException{ - public RoomException(final ExceptionCode code) { + public GameException(final ExceptionCode code) { super(code.getCode(),code.getMessage()); } } diff --git a/src/main/java/mafia/mafiatogether/game/application/GameEventListener.java b/src/main/java/mafia/mafiatogether/game/application/GameEventListener.java index cb6463cb..837940bb 100644 --- a/src/main/java/mafia/mafiatogether/game/application/GameEventListener.java +++ b/src/main/java/mafia/mafiatogether/game/application/GameEventListener.java @@ -7,7 +7,7 @@ import mafia.mafiatogether.chat.domain.Chat; import mafia.mafiatogether.chat.domain.ChatRepository; import mafia.mafiatogether.config.exception.ExceptionCode; -import mafia.mafiatogether.config.exception.RoomException; +import mafia.mafiatogether.config.exception.GameException; import mafia.mafiatogether.game.application.dto.event.ClearJobTargetEvent; import mafia.mafiatogether.game.application.dto.event.ClearVoteEvent; import mafia.mafiatogether.game.application.dto.event.DeleteGameEvent; @@ -41,9 +41,9 @@ public class GameEventListener { @EventListener public void listenVoteExecuteEvent(final VoteExecuteEvent voteExecuteEvent) { final Game game = gameRepository.findById(voteExecuteEvent.getCode()) - .orElseThrow(() -> new RoomException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); + .orElseThrow(() -> new GameException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); final Vote vote = voteRepository.findById(voteExecuteEvent.getCode()) - .orElseThrow(() -> new RoomException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); + .orElseThrow(() -> new GameException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); final String target = vote.countVotes(); game.executeTarget(target); gameRepository.save(game); @@ -52,7 +52,7 @@ public void listenVoteExecuteEvent(final VoteExecuteEvent voteExecuteEvent) { @EventListener public void listenClearVoteEvent(final ClearVoteEvent clearVoteEvent) { final Vote vote = voteRepository.findById(clearVoteEvent.getCode()) - .orElseThrow(() -> new RoomException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); + .orElseThrow(() -> new GameException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); vote.clearVoteTargets(); voteRepository.save(vote); } @@ -60,9 +60,9 @@ public void listenClearVoteEvent(final ClearVoteEvent clearVoteEvent) { @EventListener public void listenJobExecuteEvent(final JobExecuteEvent jobExecuteEvent) { final Game game = gameRepository.findById(jobExecuteEvent.getCode()) - .orElseThrow(() -> new RoomException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); + .orElseThrow(() -> new GameException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); final JobTarget jobTarget = jobTargetRepository.findById(jobExecuteEvent.getCode()) - .orElseThrow(() -> new RoomException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); + .orElseThrow(() -> new GameException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); final String target = jobTarget.findTarget(); game.executeTarget(target); gameRepository.save(game); @@ -71,7 +71,7 @@ public void listenJobExecuteEvent(final JobExecuteEvent jobExecuteEvent) { @EventListener public void listenClearJobTargetEvent(final ClearJobTargetEvent clearJobTargetEvent) { final JobTarget jobTarget = jobTargetRepository.findById(clearJobTargetEvent.getCode()) - .orElseThrow(() -> new RoomException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); + .orElseThrow(() -> new GameException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); jobTarget.clearJobTargets(); jobTargetRepository.save(jobTarget); } @@ -103,12 +103,12 @@ public void listenDeleteGameEvent(final DeleteGameEvent deleteGameEvent) { @EventListener public void listenAllPlayerVoteEvent(final AllPlayerVotedEvent allPlayerVotedEvent) { final Game game = gameRepository.findById(allPlayerVotedEvent.getCode()) - .orElseThrow(() -> new RoomException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); + .orElseThrow(() -> new GameException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); if (!game.getStatus().getType().equals(StatusType.DAY)) { return; } final Vote vote = voteRepository.findById(allPlayerVotedEvent.getCode()) - .orElseThrow(() -> new RoomException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); + .orElseThrow(() -> new GameException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); if (game.getAlivePlayerCount() == vote.getVotedCount()) { game.skipStatus(Clock.systemDefaultZone().millis()); gameRepository.save(game); diff --git a/src/main/java/mafia/mafiatogether/game/application/GameService.java b/src/main/java/mafia/mafiatogether/game/application/GameService.java index 797a8461..b7cdd57b 100644 --- a/src/main/java/mafia/mafiatogether/game/application/GameService.java +++ b/src/main/java/mafia/mafiatogether/game/application/GameService.java @@ -4,15 +4,15 @@ import java.util.Optional; import lombok.RequiredArgsConstructor; import mafia.mafiatogether.config.exception.ExceptionCode; -import mafia.mafiatogether.config.exception.RoomException; -import mafia.mafiatogether.game.application.dto.response.RoomInfoResponse; -import mafia.mafiatogether.game.application.dto.response.RoomResultResponse; -import mafia.mafiatogether.game.application.dto.response.RoomStatusResponse; +import mafia.mafiatogether.config.exception.GameException; +import mafia.mafiatogether.game.application.dto.response.GameInfoResponse; +import mafia.mafiatogether.game.application.dto.response.GameResultResponse; +import mafia.mafiatogether.game.application.dto.response.GameStatusResponse; import mafia.mafiatogether.game.domain.Game; import mafia.mafiatogether.game.domain.GameRepository; import mafia.mafiatogether.game.domain.status.StatusType; -import mafia.mafiatogether.room.domain.Room; -import mafia.mafiatogether.room.domain.RoomRepository; +import mafia.mafiatogether.lobby.domain.Lobby; +import mafia.mafiatogether.lobby.domain.LobbyRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -20,19 +20,19 @@ @RequiredArgsConstructor public class GameService { - private final RoomRepository roomRepository; + private final LobbyRepository lobbyRepository; private final GameRepository gameRepository; @Transactional - public RoomStatusResponse findStatus(final String code) { + public GameStatusResponse findStatus(final String code) { final Optional game = gameRepository.findById(code); if (game.isPresent()) { - return new RoomStatusResponse(checkStatusChanged(game.get())); + return new GameStatusResponse(checkStatusChanged(game.get())); } - if (roomRepository.existsById(code)) { - return new RoomStatusResponse(StatusType.WAIT); + if (lobbyRepository.existsById(code)) { + return new GameStatusResponse(StatusType.WAIT); } - throw new RoomException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE); + throw new GameException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE); } private StatusType checkStatusChanged(final Game game) { @@ -49,36 +49,36 @@ private StatusType checkStatusChanged(final Game game) { } @Transactional - public void modifyStatus(final String code) { - final Room room = roomRepository.findById(code) - .orElseThrow(() -> new RoomException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); - Game game = Game.create(room, Clock.systemDefaultZone().millis()); + public void startGame(final String code) { + final Lobby lobby = lobbyRepository.findById(code) + .orElseThrow(() -> new GameException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); + final Game game = Game.create(lobby, Clock.systemDefaultZone().millis()); game.distributeRole(); gameRepository.save(game); } @Transactional(readOnly = true) - public RoomInfoResponse findRoomInfo(final String code, final String name) { + public GameInfoResponse findGameInfo(final String code, final String name) { final Optional game = gameRepository.findById(code); if (!game.isPresent()) { return getLobbyInfo(code, name); } - return RoomInfoResponse.ofGame(game.get(), name); + return GameInfoResponse.ofGame(game.get(), name); } - private RoomInfoResponse getLobbyInfo(final String code, final String name) { - final Room room = roomRepository.findById(code) - .orElseThrow(() -> new RoomException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); - return RoomInfoResponse.ofRoom(room, name); + private GameInfoResponse getLobbyInfo(final String code, final String name) { + final Lobby lobby = lobbyRepository.findById(code) + .orElseThrow(() -> new GameException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); + return GameInfoResponse.ofLobby(lobby, name); } @Transactional(readOnly = true) - public RoomResultResponse findResult(final String code) { + public GameResultResponse findResult(final String code) { final Game game = gameRepository.findById(code) - .orElseThrow(() -> new RoomException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); + .orElseThrow(() -> new GameException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); if (!game.isEnd()) { - throw new RoomException(ExceptionCode.GAME_IS_NOT_FINISHED); + throw new GameException(ExceptionCode.GAME_IS_NOT_FINISHED); } - return RoomResultResponse.from(game); + return GameResultResponse.from(game); } } diff --git a/src/main/java/mafia/mafiatogether/game/application/dto/request/RoomModifyRequest.java b/src/main/java/mafia/mafiatogether/game/application/dto/request/RoomModifyRequest.java deleted file mode 100644 index 6aee6c29..00000000 --- a/src/main/java/mafia/mafiatogether/game/application/dto/request/RoomModifyRequest.java +++ /dev/null @@ -1,8 +0,0 @@ -package mafia.mafiatogether.game.application.dto.request; - -import mafia.mafiatogether.game.domain.status.StatusType; - -public record RoomModifyRequest( - StatusType statusType -) { -} diff --git a/src/main/java/mafia/mafiatogether/game/application/dto/response/RoomInfoResponse.java b/src/main/java/mafia/mafiatogether/game/application/dto/response/GameInfoResponse.java similarity index 81% rename from src/main/java/mafia/mafiatogether/game/application/dto/response/RoomInfoResponse.java rename to src/main/java/mafia/mafiatogether/game/application/dto/response/GameInfoResponse.java index c75309db..34e8427b 100644 --- a/src/main/java/mafia/mafiatogether/game/application/dto/response/RoomInfoResponse.java +++ b/src/main/java/mafia/mafiatogether/game/application/dto/response/GameInfoResponse.java @@ -7,10 +7,10 @@ import mafia.mafiatogether.game.domain.Game; import mafia.mafiatogether.game.domain.Player; import mafia.mafiatogether.game.domain.PlayerCollection; -import mafia.mafiatogether.room.domain.ParticipantCollection; -import mafia.mafiatogether.room.domain.Room; +import mafia.mafiatogether.lobby.domain.ParticipantCollection; +import mafia.mafiatogether.lobby.domain.Lobby; -public record RoomInfoResponse( +public record GameInfoResponse( Timestamp startTime, Timestamp endTime, Boolean isAlive, @@ -19,9 +19,9 @@ public record RoomInfoResponse( String myName, List players ) { - public static RoomInfoResponse ofGame(final Game game, final String name) { + public static GameInfoResponse ofGame(final Game game, final String name) { final Player player = game.getPlayer(name); - return new RoomInfoResponse( + return new GameInfoResponse( game.getStatus().getStartTime(), game.getStatus().getEndTime(), player.isAlive(), @@ -32,15 +32,15 @@ public static RoomInfoResponse ofGame(final Game game, final String name) { ); } - public static RoomInfoResponse ofRoom(Room room, String name) { - return new RoomInfoResponse( + public static GameInfoResponse ofLobby(Lobby lobby, String name) { + return new GameInfoResponse( new Timestamp(Clock.systemDefaultZone().millis()), new Timestamp(Clock.systemDefaultZone().millis()), true, - room.getRoomInfo().getTotal(), - room.getMaster().getName().equals(name), + lobby.getLobbyInfo().getTotal(), + lobby.getMaster().getName().equals(name), name, - convertFrom(room.getParticipants()) + convertFrom(lobby.getParticipants()) ); } diff --git a/src/main/java/mafia/mafiatogether/game/application/dto/response/RoomResultPlayerDto.java b/src/main/java/mafia/mafiatogether/game/application/dto/response/GameResultPlayerDto.java similarity index 74% rename from src/main/java/mafia/mafiatogether/game/application/dto/response/RoomResultPlayerDto.java rename to src/main/java/mafia/mafiatogether/game/application/dto/response/GameResultPlayerDto.java index 51b7933b..e2f4b990 100644 --- a/src/main/java/mafia/mafiatogether/game/application/dto/response/RoomResultPlayerDto.java +++ b/src/main/java/mafia/mafiatogether/game/application/dto/response/GameResultPlayerDto.java @@ -2,15 +2,15 @@ import mafia.mafiatogether.game.domain.Player; -public record RoomResultPlayerDto( +public record GameResultPlayerDto( String name, Boolean isAlive, String job ) { - public static RoomResultPlayerDto of( + public static GameResultPlayerDto of( final Player player ) { - return new RoomResultPlayerDto( + return new GameResultPlayerDto( player.getName(), player.isAlive(), player.getJobType().name() diff --git a/src/main/java/mafia/mafiatogether/game/application/dto/response/RoomResultResponse.java b/src/main/java/mafia/mafiatogether/game/application/dto/response/GameResultResponse.java similarity index 52% rename from src/main/java/mafia/mafiatogether/game/application/dto/response/RoomResultResponse.java rename to src/main/java/mafia/mafiatogether/game/application/dto/response/GameResultResponse.java index 388f32ab..e5f9d34d 100644 --- a/src/main/java/mafia/mafiatogether/game/application/dto/response/RoomResultResponse.java +++ b/src/main/java/mafia/mafiatogether/game/application/dto/response/GameResultResponse.java @@ -4,23 +4,23 @@ import java.util.List; import mafia.mafiatogether.game.domain.Game; -public record RoomResultResponse( +public record GameResultResponse( String winnerJob, Timestamp endTime, - List winner, - List loser + List winner, + List loser ) { - public static RoomResultResponse from(final Game game) { - final List winner = game.getWinners() + public static GameResultResponse from(final Game game) { + final List winner = game.getWinners() .stream() - .map(RoomResultPlayerDto::of) + .map(GameResultPlayerDto::of) .toList(); - final List loser = game.getLosers() + final List loser = game.getLosers() .stream() - .map(RoomResultPlayerDto::of) + .map(GameResultPlayerDto::of) .toList(); - return new RoomResultResponse( + return new GameResultResponse( game.getWinnerJob(), game.getStatus().getEndTime(), winner, diff --git a/src/main/java/mafia/mafiatogether/game/application/dto/response/RoomStatusResponse.java b/src/main/java/mafia/mafiatogether/game/application/dto/response/GameStatusResponse.java similarity index 82% rename from src/main/java/mafia/mafiatogether/game/application/dto/response/RoomStatusResponse.java rename to src/main/java/mafia/mafiatogether/game/application/dto/response/GameStatusResponse.java index 0c0d4f92..04fed1ba 100644 --- a/src/main/java/mafia/mafiatogether/game/application/dto/response/RoomStatusResponse.java +++ b/src/main/java/mafia/mafiatogether/game/application/dto/response/GameStatusResponse.java @@ -2,7 +2,7 @@ import mafia.mafiatogether.game.domain.status.StatusType; -public record RoomStatusResponse( +public record GameStatusResponse( StatusType statusType ) { } diff --git a/src/main/java/mafia/mafiatogether/game/domain/Game.java b/src/main/java/mafia/mafiatogether/game/domain/Game.java index 156a0cb1..9f825209 100644 --- a/src/main/java/mafia/mafiatogether/game/domain/Game.java +++ b/src/main/java/mafia/mafiatogether/game/domain/Game.java @@ -15,8 +15,8 @@ import mafia.mafiatogether.game.domain.status.StatusType; import mafia.mafiatogether.job.domain.jobtype.Job; import mafia.mafiatogether.job.domain.jobtype.JobType; -import mafia.mafiatogether.room.domain.Room; -import mafia.mafiatogether.room.domain.RoomInfo; +import mafia.mafiatogether.lobby.domain.Lobby; +import mafia.mafiatogether.lobby.domain.LobbyInfo; import org.springframework.data.annotation.Id; import org.springframework.data.domain.AbstractAggregateRoot; import org.springframework.data.redis.core.RedisHash; @@ -29,21 +29,21 @@ public class Game extends AbstractAggregateRoot { @Id private String code; private Status status; - private RoomInfo roomInfo; + private LobbyInfo lobbyInfo; private String master; private PlayerCollection players; private transient Status statusSnapshot; - public static Game create(final Room room, final Long now) { - room.validateToStart(); + public static Game create(final Lobby lobby, final Long now) { + lobby.validateToStart(); final Status status = DayIntroStatus.create(now); return new Game( - room.getCode(), + lobby.getCode(), status, - room.getRoomInfo(), - room.getMaster().getName(), - PlayerCollection.create(room.getParticipants()), + lobby.getLobbyInfo(), + lobby.getMaster().getName(), + PlayerCollection.create(lobby.getParticipants()), status ); } @@ -53,7 +53,7 @@ public Game() { } public void distributeRole() { - final Queue jobs = roomInfo.getRandomJobQueue(); + final Queue jobs = lobbyInfo.getRandomJobQueue(); for (Player player : players.getPlayers()) { if (jobs.isEmpty()) { break; diff --git a/src/main/java/mafia/mafiatogether/game/domain/PlayerCollection.java b/src/main/java/mafia/mafiatogether/game/domain/PlayerCollection.java index 448b1316..1e92ac13 100644 --- a/src/main/java/mafia/mafiatogether/game/domain/PlayerCollection.java +++ b/src/main/java/mafia/mafiatogether/game/domain/PlayerCollection.java @@ -7,8 +7,8 @@ import mafia.mafiatogether.config.exception.ExceptionCode; import mafia.mafiatogether.config.exception.PlayerException; import mafia.mafiatogether.job.domain.jobtype.JobType; -import mafia.mafiatogether.room.domain.Participant; -import mafia.mafiatogether.room.domain.ParticipantCollection; +import mafia.mafiatogether.lobby.domain.Participant; +import mafia.mafiatogether.lobby.domain.ParticipantCollection; @Getter @AllArgsConstructor diff --git a/src/main/java/mafia/mafiatogether/game/domain/status/DeletedStatus.java b/src/main/java/mafia/mafiatogether/game/domain/status/DeletedStatus.java index 3c4bd5ef..9ace7124 100644 --- a/src/main/java/mafia/mafiatogether/game/domain/status/DeletedStatus.java +++ b/src/main/java/mafia/mafiatogether/game/domain/status/DeletedStatus.java @@ -2,15 +2,15 @@ import lombok.NoArgsConstructor; import mafia.mafiatogether.config.exception.ExceptionCode; -import mafia.mafiatogether.config.exception.RoomException; +import mafia.mafiatogether.config.exception.GameException; import mafia.mafiatogether.game.domain.Game; @NoArgsConstructor public class DeletedStatus extends Status{ @Override - public Status getNextStatus(Game room, Long now) { - throw new RoomException(ExceptionCode.DELETED_STATUS); + public Status getNextStatus(Game game, Long now) { + throw new GameException(ExceptionCode.DELETED_STATUS); } @Override diff --git a/src/main/java/mafia/mafiatogether/game/domain/status/Status.java b/src/main/java/mafia/mafiatogether/game/domain/status/Status.java index c429ae26..55acb73c 100644 --- a/src/main/java/mafia/mafiatogether/game/domain/status/Status.java +++ b/src/main/java/mafia/mafiatogether/game/domain/status/Status.java @@ -12,7 +12,7 @@ public abstract class Status { protected Long startTime; protected Long endTime; - public abstract Status getNextStatus(final Game room, final Long now); + public abstract Status getNextStatus(final Game game, final Long now); public abstract StatusType getType(); diff --git a/src/main/java/mafia/mafiatogether/game/ui/GameController.java b/src/main/java/mafia/mafiatogether/game/ui/GameController.java index 0abb85fe..bb1405c4 100644 --- a/src/main/java/mafia/mafiatogether/game/ui/GameController.java +++ b/src/main/java/mafia/mafiatogether/game/ui/GameController.java @@ -4,50 +4,48 @@ import mafia.mafiatogether.config.PlayerInfo; import mafia.mafiatogether.game.application.GameService; import mafia.mafiatogether.config.PlayerInfoDto; -import mafia.mafiatogether.game.application.dto.request.RoomModifyRequest; -import mafia.mafiatogether.game.application.dto.response.RoomInfoResponse; -import mafia.mafiatogether.game.application.dto.response.RoomResultResponse; -import mafia.mafiatogether.game.application.dto.response.RoomStatusResponse; +import mafia.mafiatogether.game.application.dto.response.GameInfoResponse; +import mafia.mafiatogether.game.application.dto.response.GameResultResponse; +import mafia.mafiatogether.game.application.dto.response.GameStatusResponse; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PatchMapping; -import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequiredArgsConstructor +@RequestMapping("/games") public class GameController { private final GameService gameService; - @GetMapping("/rooms/status") - public ResponseEntity findStatus( + @GetMapping("/status") + public ResponseEntity findStatus( @PlayerInfo final PlayerInfoDto playerInfoDto ) { return ResponseEntity.ok(gameService.findStatus(playerInfoDto.code())); } - @PatchMapping("/rooms/status") - public ResponseEntity modifyStatus( - @PlayerInfo final PlayerInfoDto playerInfoDto, - @RequestBody final RoomModifyRequest request + @PostMapping("/start") + public ResponseEntity startGame( + @PlayerInfo final PlayerInfoDto playerInfoDto ) { - gameService.modifyStatus(playerInfoDto.code()); + gameService.startGame(playerInfoDto.code()); return ResponseEntity.ok().build(); } - - @GetMapping("/rooms/result") - public ResponseEntity findResult( + @GetMapping("/result") + public ResponseEntity findResult( @PlayerInfo final PlayerInfoDto playerInfoDto ) { return ResponseEntity.ok(gameService.findResult(playerInfoDto.code())); } - @GetMapping("/rooms/info") - public ResponseEntity findRoomInfo( + @GetMapping("/info") + public ResponseEntity findGameInfo( @PlayerInfo PlayerInfoDto playerInfoDto ) { - return ResponseEntity.ok(gameService.findRoomInfo(playerInfoDto.code(), playerInfoDto.name())); + return ResponseEntity.ok(gameService.findGameInfo(playerInfoDto.code(), playerInfoDto.name())); } } diff --git a/src/main/java/mafia/mafiatogether/job/application/PlayerService.java b/src/main/java/mafia/mafiatogether/job/application/JobService.java similarity index 74% rename from src/main/java/mafia/mafiatogether/job/application/PlayerService.java rename to src/main/java/mafia/mafiatogether/job/application/JobService.java index b62715c7..837e8e4f 100644 --- a/src/main/java/mafia/mafiatogether/job/application/PlayerService.java +++ b/src/main/java/mafia/mafiatogether/job/application/JobService.java @@ -3,12 +3,12 @@ import lombok.RequiredArgsConstructor; import mafia.mafiatogether.config.exception.ExceptionCode; import mafia.mafiatogether.config.exception.PlayerException; -import mafia.mafiatogether.config.exception.RoomException; -import mafia.mafiatogether.job.application.dto.request.PlayerExecuteAbilityRequest; +import mafia.mafiatogether.config.exception.GameException; +import mafia.mafiatogether.job.application.dto.request.JobExecuteAbilityRequest; import mafia.mafiatogether.job.application.dto.response.JobResponse; import mafia.mafiatogether.job.application.dto.response.MafiaTargetResponse; -import mafia.mafiatogether.job.application.dto.response.PlayerExecuteAbilityResponse; -import mafia.mafiatogether.job.application.dto.response.RoomNightResultResponse; +import mafia.mafiatogether.job.application.dto.response.JobExecuteAbilityResponse; +import mafia.mafiatogether.job.application.dto.response.JobResultResponse; import mafia.mafiatogether.job.domain.JobTarget; import mafia.mafiatogether.job.domain.JobTargetRepository; import mafia.mafiatogether.job.domain.PlayerJob; @@ -19,7 +19,7 @@ @Service @RequiredArgsConstructor -public class PlayerService { +public class JobService { private final JobTargetRepository jobTargetRepository; private final PlayerJobRepository playerJobRepository; @@ -27,27 +27,27 @@ public class PlayerService { @Transactional(readOnly = true) public JobResponse getPlayerJob(final String code, final String name) { final PlayerJob playerJob = playerJobRepository.findById(code) - .orElseThrow(() -> new RoomException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); + .orElseThrow(() -> new GameException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); return new JobResponse(playerJob.findJobByName(name).getJobType().name()); } @Transactional - public PlayerExecuteAbilityResponse executeSkill( + public JobExecuteAbilityResponse executeSkill( final String code, final String name, - final PlayerExecuteAbilityRequest request + final JobExecuteAbilityRequest request ) { final JobTarget jobTarget = jobTargetRepository.findById(code) - .orElseThrow(() -> new RoomException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); + .orElseThrow(() -> new GameException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); final PlayerJob playerJob = playerJobRepository.findById(code) - .orElseThrow(() -> new RoomException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); + .orElseThrow(() -> new GameException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); validateTarget(playerJob, request.target()); final Job requestJob = playerJob.findJobByName(name); final String result = requestJob.applySkill(jobTarget.getJobTargets(), playerJob.getPlayerJobs(), request.target()); jobTarget.addJobTarget(requestJob.getJobType(), request.target()); jobTargetRepository.save(jobTarget); - return new PlayerExecuteAbilityResponse(requestJob.getJobType().name(), result); + return new JobExecuteAbilityResponse(requestJob.getJobType().name(), result); } private void validateTarget(final PlayerJob playerJob, String target) { @@ -66,16 +66,16 @@ public MafiaTargetResponse getTarget( .orElseThrow(() -> new PlayerException(ExceptionCode.INVALID_PLAYER)) .findJobByName(name); final JobTarget jobTarget = jobTargetRepository.findById(code) - .orElseThrow(() -> new RoomException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); + .orElseThrow(() -> new GameException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); final String mafiaJobTarget = jobTarget.findJobTargetBy(playerJob.getJobType()); return new MafiaTargetResponse(mafiaJobTarget); } @Transactional(readOnly = true) - public RoomNightResultResponse findJobResult(final String code) { + public JobResultResponse findJobResult(final String code) { final JobTarget jobTarget = jobTargetRepository.findById(code) - .orElseThrow(() -> new RoomException(ExceptionCode.INVALID_PLAYER)); + .orElseThrow(() -> new GameException(ExceptionCode.INVALID_PLAYER)); final String target = jobTarget.findTarget(); - return new RoomNightResultResponse(target); + return new JobResultResponse(target); } } diff --git a/src/main/java/mafia/mafiatogether/job/application/dto/request/PlayerExecuteAbilityRequest.java b/src/main/java/mafia/mafiatogether/job/application/dto/request/JobExecuteAbilityRequest.java similarity index 66% rename from src/main/java/mafia/mafiatogether/job/application/dto/request/PlayerExecuteAbilityRequest.java rename to src/main/java/mafia/mafiatogether/job/application/dto/request/JobExecuteAbilityRequest.java index b26503f7..f4084ad4 100644 --- a/src/main/java/mafia/mafiatogether/job/application/dto/request/PlayerExecuteAbilityRequest.java +++ b/src/main/java/mafia/mafiatogether/job/application/dto/request/JobExecuteAbilityRequest.java @@ -1,6 +1,6 @@ package mafia.mafiatogether.job.application.dto.request; -public record PlayerExecuteAbilityRequest( +public record JobExecuteAbilityRequest( String target ) { } diff --git a/src/main/java/mafia/mafiatogether/job/application/dto/response/PlayerExecuteAbilityResponse.java b/src/main/java/mafia/mafiatogether/job/application/dto/response/JobExecuteAbilityResponse.java similarity index 70% rename from src/main/java/mafia/mafiatogether/job/application/dto/response/PlayerExecuteAbilityResponse.java rename to src/main/java/mafia/mafiatogether/job/application/dto/response/JobExecuteAbilityResponse.java index db2cc173..7d7950a7 100644 --- a/src/main/java/mafia/mafiatogether/job/application/dto/response/PlayerExecuteAbilityResponse.java +++ b/src/main/java/mafia/mafiatogether/job/application/dto/response/JobExecuteAbilityResponse.java @@ -1,6 +1,6 @@ package mafia.mafiatogether.job.application.dto.response; -public record PlayerExecuteAbilityResponse( +public record JobExecuteAbilityResponse( String job, String result ) { diff --git a/src/main/java/mafia/mafiatogether/job/application/dto/response/RoomNightResultResponse.java b/src/main/java/mafia/mafiatogether/job/application/dto/response/JobResultResponse.java similarity index 67% rename from src/main/java/mafia/mafiatogether/job/application/dto/response/RoomNightResultResponse.java rename to src/main/java/mafia/mafiatogether/job/application/dto/response/JobResultResponse.java index f0b10c20..cd56d417 100644 --- a/src/main/java/mafia/mafiatogether/job/application/dto/response/RoomNightResultResponse.java +++ b/src/main/java/mafia/mafiatogether/job/application/dto/response/JobResultResponse.java @@ -1,6 +1,6 @@ package mafia.mafiatogether.job.application.dto.response; -public record RoomNightResultResponse( +public record JobResultResponse( String dead ) { } diff --git a/src/main/java/mafia/mafiatogether/job/ui/PlayerController.java b/src/main/java/mafia/mafiatogether/job/ui/JobController.java similarity index 53% rename from src/main/java/mafia/mafiatogether/job/ui/PlayerController.java rename to src/main/java/mafia/mafiatogether/job/ui/JobController.java index d4f277a8..3bd09386 100644 --- a/src/main/java/mafia/mafiatogether/job/ui/PlayerController.java +++ b/src/main/java/mafia/mafiatogether/job/ui/JobController.java @@ -3,57 +3,57 @@ import lombok.RequiredArgsConstructor; import mafia.mafiatogether.config.PlayerInfo; import mafia.mafiatogether.config.PlayerInfoDto; -import mafia.mafiatogether.job.application.PlayerService; -import mafia.mafiatogether.job.application.dto.request.PlayerExecuteAbilityRequest; +import mafia.mafiatogether.job.application.JobService; +import mafia.mafiatogether.job.application.dto.request.JobExecuteAbilityRequest; import mafia.mafiatogether.job.application.dto.response.JobResponse; import mafia.mafiatogether.job.application.dto.response.MafiaTargetResponse; -import mafia.mafiatogether.job.application.dto.response.PlayerExecuteAbilityResponse; -import mafia.mafiatogether.job.application.dto.response.RoomNightResultResponse; +import mafia.mafiatogether.job.application.dto.response.JobExecuteAbilityResponse; +import mafia.mafiatogether.job.application.dto.response.JobResultResponse; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequiredArgsConstructor -public class PlayerController { +@RequestMapping("/jobs") +public class JobController { - private final PlayerService playerService; + private final JobService jobService; - @GetMapping("/players/my/job") + @GetMapping("/my") public ResponseEntity getJob(@PlayerInfo PlayerInfoDto playerInfoDto) { - return ResponseEntity.ok(playerService.getPlayerJob(playerInfoDto.code(), playerInfoDto.name())); + return ResponseEntity.ok(jobService.getPlayerJob(playerInfoDto.code(), playerInfoDto.name())); } - @PostMapping("/players/skill") - public ResponseEntity executeSkill( + @PostMapping("/skill") + public ResponseEntity executeSkill( @PlayerInfo PlayerInfoDto playerInfoDto, - @RequestBody PlayerExecuteAbilityRequest request + @RequestBody JobExecuteAbilityRequest request ) { - return ResponseEntity.ok(playerService.executeSkill( + return ResponseEntity.ok(jobService.executeSkill( playerInfoDto.code(), playerInfoDto.name(), request )); } - @GetMapping("/players/skill") + @GetMapping("/skill") public ResponseEntity getTarget( @PlayerInfo PlayerInfoDto playerInfoDto ) { - return ResponseEntity.ok(playerService.getTarget( + return ResponseEntity.ok(jobService.getTarget( playerInfoDto.code(), playerInfoDto.name() )); } - - // job - @GetMapping("/rooms/night/result") - public ResponseEntity findNightResult( + @GetMapping("/skill/result") + public ResponseEntity findNightResult( @PlayerInfo final PlayerInfoDto playerInfoDto ) { - return ResponseEntity.ok(playerService.findJobResult(playerInfoDto.code())); + return ResponseEntity.ok(jobService.findJobResult(playerInfoDto.code())); } } diff --git a/src/main/java/mafia/mafiatogether/lobby/application/LobbyService.java b/src/main/java/mafia/mafiatogether/lobby/application/LobbyService.java new file mode 100644 index 00000000..538dcd27 --- /dev/null +++ b/src/main/java/mafia/mafiatogether/lobby/application/LobbyService.java @@ -0,0 +1,46 @@ +package mafia.mafiatogether.lobby.application; + +import lombok.RequiredArgsConstructor; +import mafia.mafiatogether.config.exception.ExceptionCode; +import mafia.mafiatogether.config.exception.GameException; +import mafia.mafiatogether.lobby.application.dto.request.LobbyCreateRequest; +import mafia.mafiatogether.lobby.application.dto.response.LobbyCodeResponse; +import mafia.mafiatogether.lobby.application.dto.response.LobbyValidateResponse; +import mafia.mafiatogether.lobby.domain.CodeGenerator; +import mafia.mafiatogether.lobby.domain.Lobby; +import mafia.mafiatogether.lobby.domain.LobbyInfo; +import mafia.mafiatogether.lobby.domain.LobbyRepository; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class LobbyService { + + private final LobbyRepository lobbyRepository; + + @Transactional + public LobbyCodeResponse create(final LobbyCreateRequest request) { + String code = CodeGenerator.generate(); + while (lobbyRepository.existsById(code)){ + code = CodeGenerator.generate(); + } + final LobbyInfo lobbyInfo = LobbyInfo.of(request.total(), request.mafia(), request.doctor(), request.police()); + final Lobby lobby = Lobby.create(code, lobbyInfo); + lobbyRepository.save(lobby); + return new LobbyCodeResponse(code); + } + + @Transactional + public void join(final String code, final String name) { + final Lobby lobby = lobbyRepository.findById(code) + .orElseThrow(() -> new GameException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); + lobby.joinPlayer(name); + lobbyRepository.save(lobby); + } + + @Transactional(readOnly = true) + public LobbyValidateResponse validateCode(final String code) { + return new LobbyValidateResponse(lobbyRepository.existsById(code)); + } +} diff --git a/src/main/java/mafia/mafiatogether/lobby/application/dto/request/LobbyCreateRequest.java b/src/main/java/mafia/mafiatogether/lobby/application/dto/request/LobbyCreateRequest.java new file mode 100644 index 00000000..0ec051a1 --- /dev/null +++ b/src/main/java/mafia/mafiatogether/lobby/application/dto/request/LobbyCreateRequest.java @@ -0,0 +1,9 @@ +package mafia.mafiatogether.lobby.application.dto.request; + +public record LobbyCreateRequest( + Integer total, + Integer mafia, + Integer doctor, + Integer police +) { +} diff --git a/src/main/java/mafia/mafiatogether/lobby/application/dto/response/LobbyAuthResponse.java b/src/main/java/mafia/mafiatogether/lobby/application/dto/response/LobbyAuthResponse.java new file mode 100644 index 00000000..03265b77 --- /dev/null +++ b/src/main/java/mafia/mafiatogether/lobby/application/dto/response/LobbyAuthResponse.java @@ -0,0 +1,6 @@ +package mafia.mafiatogether.lobby.application.dto.response; + +public record LobbyAuthResponse( + String auth +) { +} diff --git a/src/main/java/mafia/mafiatogether/lobby/application/dto/response/LobbyCodeResponse.java b/src/main/java/mafia/mafiatogether/lobby/application/dto/response/LobbyCodeResponse.java new file mode 100644 index 00000000..8e45d386 --- /dev/null +++ b/src/main/java/mafia/mafiatogether/lobby/application/dto/response/LobbyCodeResponse.java @@ -0,0 +1,6 @@ +package mafia.mafiatogether.lobby.application.dto.response; + +public record LobbyCodeResponse( + String code +) { +} diff --git a/src/main/java/mafia/mafiatogether/lobby/application/dto/response/LobbyValidateResponse.java b/src/main/java/mafia/mafiatogether/lobby/application/dto/response/LobbyValidateResponse.java new file mode 100644 index 00000000..f8d2c3e6 --- /dev/null +++ b/src/main/java/mafia/mafiatogether/lobby/application/dto/response/LobbyValidateResponse.java @@ -0,0 +1,6 @@ +package mafia.mafiatogether.lobby.application.dto.response; + +public record LobbyValidateResponse( + Boolean exist +) { +} diff --git a/src/main/java/mafia/mafiatogether/room/domain/CodeGenerator.java b/src/main/java/mafia/mafiatogether/lobby/domain/CodeGenerator.java similarity index 93% rename from src/main/java/mafia/mafiatogether/room/domain/CodeGenerator.java rename to src/main/java/mafia/mafiatogether/lobby/domain/CodeGenerator.java index cdc9eec7..f88bb986 100644 --- a/src/main/java/mafia/mafiatogether/room/domain/CodeGenerator.java +++ b/src/main/java/mafia/mafiatogether/lobby/domain/CodeGenerator.java @@ -1,4 +1,4 @@ -package mafia.mafiatogether.room.domain; +package mafia.mafiatogether.lobby.domain; import java.util.Random; diff --git a/src/main/java/mafia/mafiatogether/room/domain/Room.java b/src/main/java/mafia/mafiatogether/lobby/domain/Lobby.java similarity index 61% rename from src/main/java/mafia/mafiatogether/room/domain/Room.java rename to src/main/java/mafia/mafiatogether/lobby/domain/Lobby.java index 8752179f..b439346e 100644 --- a/src/main/java/mafia/mafiatogether/room/domain/Room.java +++ b/src/main/java/mafia/mafiatogether/lobby/domain/Lobby.java @@ -1,57 +1,57 @@ -package mafia.mafiatogether.room.domain; +package mafia.mafiatogether.lobby.domain; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Getter; import mafia.mafiatogether.config.exception.ExceptionCode; -import mafia.mafiatogether.config.exception.RoomException; +import mafia.mafiatogether.config.exception.GameException; import org.springframework.data.annotation.Id; import org.springframework.data.redis.core.RedisHash; @Getter -@RedisHash("room") +@RedisHash("lobby") @AllArgsConstructor(access = AccessLevel.PRIVATE) -public class Room { +public class Lobby { @Id private String code; private ParticipantCollection participants; - private RoomInfo roomInfo; + private LobbyInfo lobbyInfo; private Participant master; - public Room(){ + public Lobby(){ this.participants = new ParticipantCollection(); } - public static Room create(final String code, final RoomInfo roomInfo) { - return new Room( + public static Lobby create(final String code, final LobbyInfo lobbyInfo) { + return new Lobby( code, new ParticipantCollection(), - roomInfo, + lobbyInfo, Participant.NONE ); } - public static Room create(final RoomInfo roomInfo) { - return new Room( + public static Lobby create(final LobbyInfo lobbyInfo) { + return new Lobby( null, new ParticipantCollection(), - roomInfo, + lobbyInfo, Participant.NONE ); } public void joinPlayer(final String name) { final Participant participant = new Participant(name); - participants.put(participant, roomInfo.getTotal()); + participants.put(participant, lobbyInfo.getTotal()); if (master.equals(Participant.NONE)) { master = participant; } } public void validateToStart() { - if (roomInfo.getTotal() != participants.size()) { - throw new RoomException(ExceptionCode.NOT_ENOUGH_PLAYER); + if (lobbyInfo.getTotal() != participants.size()) { + throw new GameException(ExceptionCode.NOT_ENOUGH_PLAYER); } } } diff --git a/src/main/java/mafia/mafiatogether/room/domain/RoomInfo.java b/src/main/java/mafia/mafiatogether/lobby/domain/LobbyInfo.java similarity index 67% rename from src/main/java/mafia/mafiatogether/room/domain/RoomInfo.java rename to src/main/java/mafia/mafiatogether/lobby/domain/LobbyInfo.java index 7a7e5bfd..d3e2321a 100644 --- a/src/main/java/mafia/mafiatogether/room/domain/RoomInfo.java +++ b/src/main/java/mafia/mafiatogether/lobby/domain/LobbyInfo.java @@ -1,4 +1,4 @@ -package mafia.mafiatogether.room.domain; +package mafia.mafiatogether.lobby.domain; import java.util.ArrayList; import java.util.Collections; @@ -8,7 +8,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import mafia.mafiatogether.config.exception.ExceptionCode; -import mafia.mafiatogether.config.exception.RoomException; +import mafia.mafiatogether.config.exception.GameException; import mafia.mafiatogether.job.domain.jobtype.Doctor; import mafia.mafiatogether.job.domain.jobtype.Job; import mafia.mafiatogether.job.domain.jobtype.Mafia; @@ -16,18 +16,22 @@ @Getter @RequiredArgsConstructor -public class RoomInfo { +public class LobbyInfo { private final int total; private final int mafia; private final int doctor; private final int police; - public static RoomInfo of(final int total, final int mafia, final int doctor, final int police) { - if (total / 2 < mafia || total < 3 || mafia == 0) { - throw new RoomException(ExceptionCode.INVALID_ROOM_INFORMATION); + public static LobbyInfo of(final int total, final int mafia, final int doctor, final int police) { + if (isInvalidJobBalance(total, mafia)) { + throw new GameException(ExceptionCode.INVALID_ROOM_INFORMATION); } - return new RoomInfo(total, mafia, doctor, police); + return new LobbyInfo(total, mafia, doctor, police); + } + + private static boolean isInvalidJobBalance(int total, int mafia) { + return total / 2 < mafia || total < 3 || mafia == 0; } public Queue getRandomJobQueue() { diff --git a/src/main/java/mafia/mafiatogether/lobby/domain/LobbyRepository.java b/src/main/java/mafia/mafiatogether/lobby/domain/LobbyRepository.java new file mode 100644 index 00000000..78743ac9 --- /dev/null +++ b/src/main/java/mafia/mafiatogether/lobby/domain/LobbyRepository.java @@ -0,0 +1,6 @@ +package mafia.mafiatogether.lobby.domain; + +import org.springframework.data.repository.CrudRepository; + +public interface LobbyRepository extends CrudRepository { +} diff --git a/src/main/java/mafia/mafiatogether/room/domain/Participant.java b/src/main/java/mafia/mafiatogether/lobby/domain/Participant.java similarity index 89% rename from src/main/java/mafia/mafiatogether/room/domain/Participant.java rename to src/main/java/mafia/mafiatogether/lobby/domain/Participant.java index bf64e6e6..7d533e17 100644 --- a/src/main/java/mafia/mafiatogether/room/domain/Participant.java +++ b/src/main/java/mafia/mafiatogether/lobby/domain/Participant.java @@ -1,4 +1,4 @@ -package mafia.mafiatogether.room.domain; +package mafia.mafiatogether.lobby.domain; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; diff --git a/src/main/java/mafia/mafiatogether/room/domain/ParticipantCollection.java b/src/main/java/mafia/mafiatogether/lobby/domain/ParticipantCollection.java similarity index 79% rename from src/main/java/mafia/mafiatogether/room/domain/ParticipantCollection.java rename to src/main/java/mafia/mafiatogether/lobby/domain/ParticipantCollection.java index fa053c39..7ff88ac0 100644 --- a/src/main/java/mafia/mafiatogether/room/domain/ParticipantCollection.java +++ b/src/main/java/mafia/mafiatogether/lobby/domain/ParticipantCollection.java @@ -1,11 +1,11 @@ -package mafia.mafiatogether.room.domain; +package mafia.mafiatogether.lobby.domain; import java.util.ArrayList; import java.util.List; import java.util.Optional; import lombok.Getter; import mafia.mafiatogether.config.exception.ExceptionCode; -import mafia.mafiatogether.config.exception.RoomException; +import mafia.mafiatogether.config.exception.GameException; @Getter public class ParticipantCollection { @@ -27,13 +27,13 @@ public void put(Participant participant, int total) { private void validateParticipant(Participant participant, int total) { if (participants.size() >= total) { - throw new RoomException(ExceptionCode.ROOM_FULL); + throw new GameException(ExceptionCode.ROOM_FULL); } Optional sameName = participants.stream() .filter(p -> p.getName().equals(participant.getName())) .findFirst(); if (sameName.isPresent()){ - throw new RoomException(ExceptionCode.INVALID_NAMES); + throw new GameException(ExceptionCode.INVALID_NAMES); } } } diff --git a/src/main/java/mafia/mafiatogether/lobby/ui/LobbyController.java b/src/main/java/mafia/mafiatogether/lobby/ui/LobbyController.java new file mode 100644 index 00000000..aafeadb3 --- /dev/null +++ b/src/main/java/mafia/mafiatogether/lobby/ui/LobbyController.java @@ -0,0 +1,55 @@ +package mafia.mafiatogether.lobby.ui; + +import java.util.Base64; +import lombok.RequiredArgsConstructor; +import mafia.mafiatogether.config.PlayerInfo; +import mafia.mafiatogether.config.PlayerInfoDto; +import mafia.mafiatogether.lobby.application.LobbyService; +import mafia.mafiatogether.lobby.application.dto.request.LobbyCreateRequest; +import mafia.mafiatogether.lobby.application.dto.response.LobbyAuthResponse; +import mafia.mafiatogether.lobby.application.dto.response.LobbyCodeResponse; +import mafia.mafiatogether.lobby.application.dto.response.LobbyValidateResponse; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/lobbies") +public class LobbyController { + + private final LobbyService lobbyService; + + @PostMapping + public ResponseEntity create(@RequestBody final LobbyCreateRequest request) { + return ResponseEntity.ok(lobbyService.create(request)); + } + + @GetMapping + public ResponseEntity join( + @RequestParam("code") final String code, + @RequestParam("name") final String name + ) { + lobbyService.join(code, name); + String encodedStr = Base64.getEncoder().encodeToString((code + ":" + name).getBytes()); + return ResponseEntity.ok(new LobbyAuthResponse(encodedStr)); + } + + @GetMapping("/code") + public ResponseEntity findCode( + @PlayerInfo PlayerInfoDto playerInfoDto + ) { + return ResponseEntity.ok(new LobbyCodeResponse(playerInfoDto.code())); + } + + @GetMapping("/code/exist") + public ResponseEntity validateCode( + @RequestParam("code") final String code + ) { + return ResponseEntity.ok(lobbyService.validateCode(code)); + } +} diff --git a/src/main/java/mafia/mafiatogether/room/application/RoomService.java b/src/main/java/mafia/mafiatogether/room/application/RoomService.java deleted file mode 100644 index 2b81ca06..00000000 --- a/src/main/java/mafia/mafiatogether/room/application/RoomService.java +++ /dev/null @@ -1,46 +0,0 @@ -package mafia.mafiatogether.room.application; - -import lombok.RequiredArgsConstructor; -import mafia.mafiatogether.config.exception.ExceptionCode; -import mafia.mafiatogether.config.exception.RoomException; -import mafia.mafiatogether.room.application.dto.request.RoomCreateRequest; -import mafia.mafiatogether.room.application.dto.response.RoomCodeResponse; -import mafia.mafiatogether.room.application.dto.response.RoomValidateResponse; -import mafia.mafiatogether.room.domain.CodeGenerator; -import mafia.mafiatogether.room.domain.Room; -import mafia.mafiatogether.room.domain.RoomInfo; -import mafia.mafiatogether.room.domain.RoomRepository; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -@RequiredArgsConstructor -public class RoomService { - - private final RoomRepository roomRepository; - - @Transactional - public RoomCodeResponse create(final RoomCreateRequest request) { - String code = CodeGenerator.generate(); - while (roomRepository.existsById(code)){ - code = CodeGenerator.generate(); - } - final RoomInfo roomInfo = RoomInfo.of(request.total(), request.mafia(), request.doctor(), request.police()); - final Room room = Room.create(code, roomInfo); - roomRepository.save(room); - return new RoomCodeResponse(code); - } - - @Transactional - public void join(final String code, final String name) { - final Room room = roomRepository.findById(code) - .orElseThrow(() -> new RoomException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); - room.joinPlayer(name); - roomRepository.save(room); - } - - @Transactional(readOnly = true) - public RoomValidateResponse validateCode(final String code) { - return new RoomValidateResponse(roomRepository.existsById(code)); - } -} diff --git a/src/main/java/mafia/mafiatogether/room/application/dto/request/RoomCreateRequest.java b/src/main/java/mafia/mafiatogether/room/application/dto/request/RoomCreateRequest.java deleted file mode 100644 index d1591c36..00000000 --- a/src/main/java/mafia/mafiatogether/room/application/dto/request/RoomCreateRequest.java +++ /dev/null @@ -1,15 +0,0 @@ -package mafia.mafiatogether.room.application.dto.request; - -import mafia.mafiatogether.room.domain.RoomInfo; - -public record RoomCreateRequest( - Integer total, - Integer mafia, - Integer doctor, - Integer police -) { - - public RoomInfo toDomain() { - return RoomInfo.of(total, mafia, doctor, police); - } -} diff --git a/src/main/java/mafia/mafiatogether/room/application/dto/response/RoomAuthResponse.java b/src/main/java/mafia/mafiatogether/room/application/dto/response/RoomAuthResponse.java deleted file mode 100644 index 84019105..00000000 --- a/src/main/java/mafia/mafiatogether/room/application/dto/response/RoomAuthResponse.java +++ /dev/null @@ -1,6 +0,0 @@ -package mafia.mafiatogether.room.application.dto.response; - -public record RoomAuthResponse( - String auth -) { -} diff --git a/src/main/java/mafia/mafiatogether/room/application/dto/response/RoomCodeResponse.java b/src/main/java/mafia/mafiatogether/room/application/dto/response/RoomCodeResponse.java deleted file mode 100644 index 43d820c8..00000000 --- a/src/main/java/mafia/mafiatogether/room/application/dto/response/RoomCodeResponse.java +++ /dev/null @@ -1,6 +0,0 @@ -package mafia.mafiatogether.room.application.dto.response; - -public record RoomCodeResponse( - String code -) { -} diff --git a/src/main/java/mafia/mafiatogether/room/application/dto/response/RoomValidateResponse.java b/src/main/java/mafia/mafiatogether/room/application/dto/response/RoomValidateResponse.java deleted file mode 100644 index 424da62b..00000000 --- a/src/main/java/mafia/mafiatogether/room/application/dto/response/RoomValidateResponse.java +++ /dev/null @@ -1,6 +0,0 @@ -package mafia.mafiatogether.room.application.dto.response; - -public record RoomValidateResponse( - Boolean exist -) { -} diff --git a/src/main/java/mafia/mafiatogether/room/domain/RoomRepository.java b/src/main/java/mafia/mafiatogether/room/domain/RoomRepository.java deleted file mode 100644 index eb6b8ab7..00000000 --- a/src/main/java/mafia/mafiatogether/room/domain/RoomRepository.java +++ /dev/null @@ -1,6 +0,0 @@ -package mafia.mafiatogether.room.domain; - -import org.springframework.data.repository.CrudRepository; - -public interface RoomRepository extends CrudRepository { -} diff --git a/src/main/java/mafia/mafiatogether/room/ui/RoomController.java b/src/main/java/mafia/mafiatogether/room/ui/RoomController.java deleted file mode 100644 index fcdf5da2..00000000 --- a/src/main/java/mafia/mafiatogether/room/ui/RoomController.java +++ /dev/null @@ -1,56 +0,0 @@ -package mafia.mafiatogether.room.ui; - -import java.util.Base64; -import lombok.RequiredArgsConstructor; -import mafia.mafiatogether.config.PlayerInfo; -import mafia.mafiatogether.config.PlayerInfoDto; -import mafia.mafiatogether.room.application.RoomService; -import mafia.mafiatogether.room.application.dto.request.RoomCreateRequest; -import mafia.mafiatogether.room.application.dto.response.RoomAuthResponse; -import mafia.mafiatogether.room.application.dto.response.RoomCodeResponse; -import mafia.mafiatogether.room.application.dto.response.RoomValidateResponse; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequiredArgsConstructor -@RequestMapping("/rooms") -public class RoomController { - - private final RoomService roomService; - - @PostMapping - public ResponseEntity create(@RequestBody final RoomCreateRequest request) { - return ResponseEntity.ok(roomService.create(request)); - } - - @GetMapping - public ResponseEntity join( - @RequestParam("code") final String code, - @RequestParam("name") final String name - ) { - roomService.join(code, name); - String encodedStr = Base64.getEncoder().encodeToString((code + ":" + name).getBytes()); - return ResponseEntity.ok(new RoomAuthResponse(encodedStr)); - } - - @GetMapping("/code") - public ResponseEntity findCode( - @PlayerInfo PlayerInfoDto playerInfoDto - ) { - return ResponseEntity.ok(new RoomCodeResponse(playerInfoDto.code())); - } - - @GetMapping("/code/exist") - public ResponseEntity validateCode( - @RequestParam("code") final String code - ) { - return ResponseEntity.ok(roomService.validateCode(code)); - } - -} diff --git a/src/main/java/mafia/mafiatogether/vote/application/VoteService.java b/src/main/java/mafia/mafiatogether/vote/application/VoteService.java index e2056b6d..290f0dc2 100644 --- a/src/main/java/mafia/mafiatogether/vote/application/VoteService.java +++ b/src/main/java/mafia/mafiatogether/vote/application/VoteService.java @@ -2,7 +2,7 @@ import lombok.RequiredArgsConstructor; import mafia.mafiatogether.config.exception.ExceptionCode; -import mafia.mafiatogether.config.exception.RoomException; +import mafia.mafiatogether.config.exception.GameException; import mafia.mafiatogether.vote.application.dto.event.AllPlayerVotedEvent; import mafia.mafiatogether.vote.application.dto.response.VoteResultResponse; import mafia.mafiatogether.vote.domain.Vote; @@ -21,7 +21,7 @@ public class VoteService { @Transactional public void votePlayer(final String code, final String name, final String targetName) { final Vote vote = voteRepository.findById(code) - .orElseThrow(() -> new RoomException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); + .orElseThrow(() -> new GameException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); vote.addVoteTarget(name, targetName); voteRepository.save(vote); eventPublisher.publishEvent(new AllPlayerVotedEvent(code)); @@ -30,7 +30,7 @@ public void votePlayer(final String code, final String name, final String target @Transactional(readOnly = true) public VoteResultResponse getResult(final String code) { final Vote vote = voteRepository.findById(code) - .orElseThrow(() -> new RoomException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); + .orElseThrow(() -> new GameException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE)); return new VoteResultResponse(vote.countVotes()); } } diff --git a/src/main/java/mafia/mafiatogether/vote/ui/VoteController.java b/src/main/java/mafia/mafiatogether/vote/ui/VoteController.java index b71b9aa5..1c46df3d 100644 --- a/src/main/java/mafia/mafiatogether/vote/ui/VoteController.java +++ b/src/main/java/mafia/mafiatogether/vote/ui/VoteController.java @@ -15,7 +15,7 @@ @RestController @RequiredArgsConstructor -@RequestMapping("/vote") +@RequestMapping("/votes") public class VoteController { private final VoteService voteService; diff --git a/src/test/java/mafia/mafiatogether/game/application/GameEventListenerTest.java b/src/test/java/mafia/mafiatogether/game/application/GameEventListenerTest.java index f55905f6..49b7109d 100644 --- a/src/test/java/mafia/mafiatogether/game/application/GameEventListenerTest.java +++ b/src/test/java/mafia/mafiatogether/game/application/GameEventListenerTest.java @@ -9,16 +9,16 @@ import mafia.mafiatogether.game.domain.Player; import mafia.mafiatogether.game.domain.status.StatusType; import mafia.mafiatogether.global.ControllerTest; -import mafia.mafiatogether.job.application.PlayerService; -import mafia.mafiatogether.job.application.dto.request.PlayerExecuteAbilityRequest; +import mafia.mafiatogether.job.application.JobService; +import mafia.mafiatogether.job.application.dto.request.JobExecuteAbilityRequest; import mafia.mafiatogether.job.domain.JobTarget; import mafia.mafiatogether.job.domain.JobTargetRepository; import mafia.mafiatogether.job.domain.PlayerJob; import mafia.mafiatogether.job.domain.PlayerJobRepository; import mafia.mafiatogether.job.domain.jobtype.JobType; -import mafia.mafiatogether.room.domain.Room; -import mafia.mafiatogether.room.domain.RoomInfo; -import mafia.mafiatogether.room.domain.RoomRepository; +import mafia.mafiatogether.lobby.domain.Lobby; +import mafia.mafiatogether.lobby.domain.LobbyInfo; +import mafia.mafiatogether.lobby.domain.LobbyRepository; import mafia.mafiatogether.vote.application.VoteService; import mafia.mafiatogether.vote.domain.VoteRepository; import org.assertj.core.api.Assertions; @@ -39,10 +39,10 @@ class GameEventListenerTest extends ControllerTest { private VoteRepository voteRepository; @Autowired - private RoomRepository roomRepository; + private LobbyRepository lobbyRepository; @Autowired - private PlayerService playerService; + private JobService jobService; @Autowired private JobTargetRepository jobTargetRepository; @@ -64,14 +64,14 @@ class GameEventListenerTest extends ControllerTest { @BeforeEach void setTest() { - Room room = Room.create(CODE, RoomInfo.of(5, 2, 1, 1)); - room.joinPlayer(PLAYER1_NAME); - room.joinPlayer(PLAYER2_NAME); - room.joinPlayer(PLAYER3_NAME); - room.joinPlayer(PLAYER4_NAME); - room.joinPlayer(PLAYER5_NAME); - roomRepository.save(room); - game = Game.create(room, Clock.systemDefaultZone().millis()); + Lobby lobby = Lobby.create(CODE, LobbyInfo.of(5, 2, 1, 1)); + lobby.joinPlayer(PLAYER1_NAME); + lobby.joinPlayer(PLAYER2_NAME); + lobby.joinPlayer(PLAYER3_NAME); + lobby.joinPlayer(PLAYER4_NAME); + lobby.joinPlayer(PLAYER5_NAME); + lobbyRepository.save(lobby); + game = Game.create(lobby, Clock.systemDefaultZone().millis()); game.distributeRole(); gameRepository.save(game); } @@ -114,7 +114,7 @@ void setTest() { gameRepository.save(game); // when - playerService.executeSkill(CODE, mafia, new PlayerExecuteAbilityRequest(target)); + jobService.executeSkill(CODE, mafia, new JobExecuteAbilityRequest(target)); game = gameRepository.findById(CODE).get(); game.skipStatus(Clock.systemDefaultZone().millis()); // DAY_INTRO gameRepository.save(game); @@ -144,8 +144,8 @@ void setTest() { gameRepository.save(game); // when - playerService.executeSkill(CODE, mafia, new PlayerExecuteAbilityRequest(target)); - playerService.executeSkill(CODE, doctor, new PlayerExecuteAbilityRequest(target)); + jobService.executeSkill(CODE, mafia, new JobExecuteAbilityRequest(target)); + jobService.executeSkill(CODE, doctor, new JobExecuteAbilityRequest(target)); game = gameRepository.findById(CODE).get(); game.skipStatus(Clock.systemDefaultZone().millis()); // DAY_INTRO gameRepository.save(game); @@ -167,7 +167,7 @@ void setTest() { game.skipStatus(Clock.systemDefaultZone().millis());// NIGHT_INTRO game.skipStatus(Clock.systemDefaultZone().millis());// NIGHT gameRepository.save(game); - playerService.executeSkill(CODE, mafia, new PlayerExecuteAbilityRequest(PLAYER1_NAME)); + jobService.executeSkill(CODE, mafia, new JobExecuteAbilityRequest(PLAYER1_NAME)); game.skipStatus(Clock.systemDefaultZone().millis());// DAY_INTRO game.skipStatus(Clock.systemDefaultZone().millis());// NOTICE gameRepository.save(game); diff --git a/src/test/java/mafia/mafiatogether/game/domain/GameTest.java b/src/test/java/mafia/mafiatogether/game/domain/GameTest.java index c5ddef2f..16d6b463 100644 --- a/src/test/java/mafia/mafiatogether/game/domain/GameTest.java +++ b/src/test/java/mafia/mafiatogether/game/domain/GameTest.java @@ -7,8 +7,8 @@ import java.util.ArrayList; import java.util.List; import mafia.mafiatogether.job.domain.jobtype.JobType; -import mafia.mafiatogether.room.domain.Room; -import mafia.mafiatogether.room.domain.RoomInfo; +import mafia.mafiatogether.lobby.domain.Lobby; +import mafia.mafiatogether.lobby.domain.LobbyInfo; import org.junit.jupiter.api.Test; @SuppressWarnings("NonAsciiCharacters") @@ -17,13 +17,13 @@ class GameTest { @Test void 직업을_배정할_수_있다() { //given - Room room = Room.create(new RoomInfo(5, 2, 0, 1)); - room.joinPlayer("A"); - room.joinPlayer("B"); - room.joinPlayer("C"); - room.joinPlayer("D"); - room.joinPlayer("E"); - Game game = Game.create(room, Clock.systemDefaultZone().millis()); + Lobby lobby = Lobby.create(new LobbyInfo(5, 2, 0, 1)); + lobby.joinPlayer("A"); + lobby.joinPlayer("B"); + lobby.joinPlayer("C"); + lobby.joinPlayer("D"); + lobby.joinPlayer("E"); + Game game = Game.create(lobby, Clock.systemDefaultZone().millis()); Player a = game.getPlayer("A"); Player b = game.getPlayer("B"); diff --git a/src/test/java/mafia/mafiatogether/game/domain/status/StatusTest.java b/src/test/java/mafia/mafiatogether/game/domain/status/StatusTest.java index 2e96ff5a..1a1ec343 100644 --- a/src/test/java/mafia/mafiatogether/game/domain/status/StatusTest.java +++ b/src/test/java/mafia/mafiatogether/game/domain/status/StatusTest.java @@ -18,8 +18,8 @@ import static org.assertj.core.api.SoftAssertions.assertSoftly; import mafia.mafiatogether.game.domain.Game; -import mafia.mafiatogether.room.domain.Room; -import mafia.mafiatogether.room.domain.RoomInfo; +import mafia.mafiatogether.lobby.domain.Lobby; +import mafia.mafiatogether.lobby.domain.LobbyInfo; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -35,11 +35,11 @@ class StatusTest { @BeforeEach void setRoom() { - Room room = Room.create(new RoomInfo(3, 1, 0, 1)); - room.joinPlayer(PLAYER1); - room.joinPlayer(PLAYER2); - room.joinPlayer(PLAYER3); - game = Game.create(room, dayIntroTime); + Lobby lobby = Lobby.create(new LobbyInfo(3, 1, 0, 1)); + lobby.joinPlayer(PLAYER1); + lobby.joinPlayer(PLAYER2); + lobby.joinPlayer(PLAYER3); + game = Game.create(lobby, dayIntroTime); game.distributeRole(); } diff --git a/src/test/java/mafia/mafiatogether/game/ui/GameControllerTest.java b/src/test/java/mafia/mafiatogether/game/ui/GameControllerTest.java index ffd2c59b..4522a7e0 100644 --- a/src/test/java/mafia/mafiatogether/game/ui/GameControllerTest.java +++ b/src/test/java/mafia/mafiatogether/game/ui/GameControllerTest.java @@ -14,8 +14,8 @@ import mafia.mafiatogether.global.ControllerTest; import mafia.mafiatogether.game.application.dto.response.PlayerResponse; import mafia.mafiatogether.job.domain.jobtype.JobType; -import mafia.mafiatogether.game.application.dto.response.RoomInfoResponse; -import mafia.mafiatogether.game.application.dto.response.RoomStatusResponse; +import mafia.mafiatogether.game.application.dto.response.GameInfoResponse; +import mafia.mafiatogether.game.application.dto.response.GameStatusResponse; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -35,14 +35,14 @@ void setTest(){ final String basic = Base64.getEncoder().encodeToString((CODE + ":" + PLAYER1_NAME).getBytes()); //when - final RoomStatusResponse response = RestAssured.given().log().all() + final GameStatusResponse response = RestAssured.given().log().all() .contentType(ContentType.JSON) .header("Authorization", "Basic " + basic) - .when().get("/rooms/status") + .when().get("/games/status") .then().log().all() .statusCode(HttpStatus.OK.value()) .extract() - .as(RoomStatusResponse.class); + .as(GameStatusResponse.class); //then Assertions.assertThat(response.statusType()).isEqualTo(StatusType.WAIT); @@ -55,14 +55,14 @@ void setTest(){ setGame(); //when - final RoomStatusResponse response = RestAssured.given().log().all() + final GameStatusResponse response = RestAssured.given().log().all() .contentType(ContentType.JSON) .header("Authorization", "Basic " + basic) - .when().get("/rooms/status") + .when().get("/games/status") .then().log().all() .statusCode(HttpStatus.OK.value()) .extract() - .as(RoomStatusResponse.class); + .as(GameStatusResponse.class); //then Assertions.assertThat(response.statusType()).isEqualTo(StatusType.DAY_INTRO); @@ -88,7 +88,7 @@ void setTest(){ .contentType(ContentType.JSON) .body(Map.of("statusType", StatusType.DAY_INTRO)) .header("Authorization", "Basic " + basic) - .when().patch("/rooms/status") + .when().post("/games/start") .then().log().all() .statusCode(HttpStatus.BAD_REQUEST.value()) .extract() @@ -104,14 +104,14 @@ void setTest(){ final String basic = Base64.getEncoder().encodeToString((CODE + ":" + PLAYER1_NAME).getBytes()); // when - final RoomInfoResponse response = RestAssured.given().log().all() + final GameInfoResponse response = RestAssured.given().log().all() .contentType(ContentType.JSON) .header("Authorization", "Basic " + basic) - .when().get("/rooms/info") + .when().get("/games/info") .then().log().all() .statusCode(HttpStatus.OK.value()) .extract() - .as(RoomInfoResponse.class); + .as(GameInfoResponse.class); /// then assertSoftly( @@ -131,14 +131,14 @@ void setTest(){ final String basic = Base64.getEncoder().encodeToString((CODE + ":" + citizen.getName()).getBytes()); // when & then - final RoomInfoResponse response = RestAssured.given().log().all() + final GameInfoResponse response = RestAssured.given().log().all() .contentType(ContentType.JSON) .header("Authorization", "Basic " + basic) - .when().get("/rooms/info") + .when().get("/games/info") .then().log().all() .statusCode(HttpStatus.OK.value()) .extract() - .as(RoomInfoResponse.class); + .as(GameInfoResponse.class); PlayerResponse power = response.players() .stream().filter(player -> player.name().equals(citizen.getName())) @@ -173,14 +173,14 @@ void setTest(){ final String basic = Base64.getEncoder().encodeToString((CODE + ":" + citizen.getName()).getBytes()); // when & then - final RoomInfoResponse response = RestAssured.given().log().all() + final GameInfoResponse response = RestAssured.given().log().all() .contentType(ContentType.JSON) .header("Authorization", "Basic " + basic) - .when().get("/rooms/info") + .when().get("/games/info") .then().log().all() .statusCode(HttpStatus.OK.value()) .extract() - .as(RoomInfoResponse.class); + .as(GameInfoResponse.class); assertSoftly( softly -> { @@ -225,16 +225,16 @@ private Player findPlayer(Game game, JobType jobType) { } private long countMafiaResponse(final String basic) { - final RoomInfoResponse roomInfoResponse = RestAssured.given().log().all() + final GameInfoResponse gameInfoResponse = RestAssured.given().log().all() .contentType(ContentType.JSON) .header("Authorization", "Basic " + basic) - .when().get("/rooms/info") + .when().get("/games/info") .then().log().all() .statusCode(HttpStatus.OK.value()) .extract() - .as(RoomInfoResponse.class); + .as(GameInfoResponse.class); - return roomInfoResponse.players().stream() + return gameInfoResponse.players().stream() .filter(response -> response.job() != null && response.job().equals(JobType.MAFIA)) .count(); } diff --git a/src/test/java/mafia/mafiatogether/global/ControllerTest.java b/src/test/java/mafia/mafiatogether/global/ControllerTest.java index 678987f9..d16cde39 100644 --- a/src/test/java/mafia/mafiatogether/global/ControllerTest.java +++ b/src/test/java/mafia/mafiatogether/global/ControllerTest.java @@ -8,9 +8,9 @@ import mafia.mafiatogether.game.domain.PlayerCollection; import mafia.mafiatogether.game.domain.status.StatusType; import mafia.mafiatogether.job.domain.jobtype.JobType; -import mafia.mafiatogether.room.domain.Room; -import mafia.mafiatogether.room.domain.RoomInfo; -import mafia.mafiatogether.room.domain.RoomRepository; +import mafia.mafiatogether.lobby.domain.Lobby; +import mafia.mafiatogether.lobby.domain.LobbyInfo; +import mafia.mafiatogether.lobby.domain.LobbyRepository; import mafia.mafiatogether.vote.domain.VoteRepository; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -29,7 +29,7 @@ public abstract class ControllerTest { private int port; @Autowired - protected RoomRepository roomRepository; + protected LobbyRepository lobbyRepository; @Autowired protected GameRepository gameRepository; @@ -55,24 +55,24 @@ void setPort() { } protected void setRoom() { - final Room room = Room.create(CODE, RoomInfo.of(5, 2, 1, 1)); - room.joinPlayer(PLAYER1_NAME); - room.joinPlayer(PLAYER2_NAME); - room.joinPlayer(PLAYER3_NAME); - room.joinPlayer(PLAYER4_NAME); - roomRepository.save(room); + final Lobby lobby = Lobby.create(CODE, LobbyInfo.of(5, 2, 1, 1)); + lobby.joinPlayer(PLAYER1_NAME); + lobby.joinPlayer(PLAYER2_NAME); + lobby.joinPlayer(PLAYER3_NAME); + lobby.joinPlayer(PLAYER4_NAME); + lobbyRepository.save(lobby); } protected void setGame() { - Room room = roomRepository.findById(CODE).get(); - room.joinPlayer(PLAYER5_NAME); - roomRepository.save(room); + Lobby lobby = lobbyRepository.findById(CODE).get(); + lobby.joinPlayer(PLAYER5_NAME); + lobbyRepository.save(lobby); String basic = Base64.getEncoder().encodeToString((CODE + ":" + "player1").getBytes()); RestAssured.given().log().all() .contentType(ContentType.JSON) .body(Map.of("statusType", StatusType.DAY_INTRO)) .header("Authorization", "Basic " + basic) - .when().patch("/rooms/status") + .when().post("/games/start") .then().log().all() .statusCode(HttpStatus.OK.value()); final PlayerCollection players = gameRepository.findById(CODE).get().getPlayers(); diff --git a/src/test/java/mafia/mafiatogether/job/ui/PlayerControllerTest.java b/src/test/java/mafia/mafiatogether/job/ui/JobControllerTest.java similarity index 93% rename from src/test/java/mafia/mafiatogether/job/ui/PlayerControllerTest.java rename to src/test/java/mafia/mafiatogether/job/ui/JobControllerTest.java index 8476ffa3..dba27545 100644 --- a/src/test/java/mafia/mafiatogether/job/ui/PlayerControllerTest.java +++ b/src/test/java/mafia/mafiatogether/job/ui/JobControllerTest.java @@ -19,7 +19,7 @@ import org.springframework.http.HttpStatus; @SuppressWarnings("NonAsciiCharacters") -class PlayerControllerTest extends ControllerTest { +class JobControllerTest extends ControllerTest { @Autowired private JobTargetRepository jobTargetRepository; @@ -50,7 +50,7 @@ void clearTest() { .contentType(ContentType.JSON) .body(Map.of("target", CITIZEN)) .header("Authorization", "Basic " + basic) - .when().post("/players/skill") + .when().post("/jobs/skill") .then().log().all() .statusCode(HttpStatus.OK.value()); @@ -67,7 +67,7 @@ void clearTest() { final String actual = RestAssured.given().log().all() .contentType(ContentType.JSON) .header("Authorization", "Basic " + basic) - .when().get("/players/skill") + .when().get("/jobs/skill") .then().log().all() .statusCode(HttpStatus.OK.value()) .extract() @@ -98,7 +98,7 @@ private void executeSkill(final String name, final String target) { .contentType(ContentType.JSON) .body(Map.of("target", target)) .header("Authorization", "Basic " + basic) - .when().post("/players/skill") + .when().post("/jobs/skill") .then().log().all(); } @@ -113,7 +113,7 @@ private void executeSkill(final String name, final String target) { .contentType(ContentType.JSON) .body(Map.of("target", target)) .header("Authorization", "Basic " + basic) - .when().post("/players/skill") + .when().post("/jobs/skill") .then().log().all() .statusCode(HttpStatus.BAD_REQUEST.value()) .body("errorCode", equalTo(ExceptionCode.INVALID_PLAYER.getCode())); @@ -128,7 +128,7 @@ private void executeSkill(final String name, final String target) { RestAssured.given().log().all() .contentType(ContentType.JSON) .header("Authorization", "Basic " + basic) - .when().get("/players/my/job") + .when().get("/jobs/my") .then().log().all() .statusCode(HttpStatus.OK.value()) .body("job", equalTo("CITIZEN")); diff --git a/src/test/java/mafia/mafiatogether/room/ui/RoomControllerTest.java b/src/test/java/mafia/mafiatogether/lobby/ui/LobbyControllerTest.java similarity index 72% rename from src/test/java/mafia/mafiatogether/room/ui/RoomControllerTest.java rename to src/test/java/mafia/mafiatogether/lobby/ui/LobbyControllerTest.java index 61a385ee..195e1090 100644 --- a/src/test/java/mafia/mafiatogether/room/ui/RoomControllerTest.java +++ b/src/test/java/mafia/mafiatogether/lobby/ui/LobbyControllerTest.java @@ -1,4 +1,4 @@ -package mafia.mafiatogether.room.ui; +package mafia.mafiatogether.lobby.ui; import io.restassured.RestAssured; import io.restassured.http.ContentType; @@ -8,11 +8,11 @@ import mafia.mafiatogether.config.exception.ErrorResponse; import mafia.mafiatogether.config.exception.ExceptionCode; import mafia.mafiatogether.global.ControllerTest; -import mafia.mafiatogether.room.application.dto.request.RoomCreateRequest; -import mafia.mafiatogether.room.application.dto.response.RoomCodeResponse; -import mafia.mafiatogether.room.domain.Room; -import mafia.mafiatogether.room.domain.RoomInfo; -import mafia.mafiatogether.room.domain.RoomRepository; +import mafia.mafiatogether.lobby.application.dto.request.LobbyCreateRequest; +import mafia.mafiatogether.lobby.application.dto.response.LobbyCodeResponse; +import mafia.mafiatogether.lobby.domain.Lobby; +import mafia.mafiatogether.lobby.domain.LobbyInfo; +import mafia.mafiatogether.lobby.domain.LobbyRepository; import org.assertj.core.api.Assertions; import org.hamcrest.Matchers; import org.junit.jupiter.api.AfterEach; @@ -25,36 +25,36 @@ import org.springframework.http.HttpStatus; @SuppressWarnings("NonAsciiCharacters") -class RoomControllerTest extends ControllerTest { +class LobbyControllerTest extends ControllerTest { @Autowired - private RoomRepository roomRepository; + private LobbyRepository lobbyRepository; @BeforeEach void setTest(){ - final Room room = Room.create(CODE, RoomInfo.of(3,1,1,1)); - roomRepository.save(room); + final Lobby lobby = Lobby.create(CODE, LobbyInfo.of(3,1,1,1)); + lobbyRepository.save(lobby); } @AfterEach void clearTest(){ - roomRepository.deleteById(CODE); + lobbyRepository.deleteById(CODE); } @Test void 방을_생성할_수_있다() { //given - final RoomCreateRequest request = new RoomCreateRequest(5, 1, 1, 1); + final LobbyCreateRequest request = new LobbyCreateRequest(5, 1, 1, 1); //when - final RoomCodeResponse response = RestAssured.given().log().all() + final LobbyCodeResponse response = RestAssured.given().log().all() .contentType(ContentType.JSON) .body(request) - .when().post("/rooms") + .when().post("/lobbies") .then().log().all() .statusCode(HttpStatus.OK.value()) .extract() - .as(RoomCodeResponse.class); + .as(LobbyCodeResponse.class); //then Assertions.assertThat(response.code()).isNotBlank(); @@ -68,13 +68,13 @@ void clearTest(){ final int mafia ) { //given - final RoomCreateRequest request = new RoomCreateRequest(total, mafia, 1, 1); + final LobbyCreateRequest request = new LobbyCreateRequest(total, mafia, 1, 1); //when final ErrorResponse response = RestAssured.given().log().all() .contentType(ContentType.JSON) .body(request) - .when().post("/rooms") + .when().post("/lobbies") .then().log().all() .statusCode(HttpStatus.BAD_REQUEST.value()) .extract() @@ -97,13 +97,13 @@ static Stream provideRoomCreateFailCase() { //when RestAssured.given().log().all() .contentType(ContentType.JSON) - .when().get("/rooms?code=" + CODE + "&name=power") + .when().get("/lobbies?code=" + CODE + "&name=power") .then().log().all() .statusCode(HttpStatus.OK.value()); //then - Room room = roomRepository.findById(CODE).get(); - List actual = room.getParticipants().getParticipants().stream() + Lobby lobby = lobbyRepository.findById(CODE).get(); + List actual = lobby.getParticipants().getParticipants().stream() .map(participant -> participant.getName()) .toList(); Assertions.assertThat(actual).contains("power"); @@ -117,32 +117,32 @@ static Stream provideRoomCreateFailCase() { //when RestAssured.given().log().all() .contentType(ContentType.JSON) - .when().get("/rooms?code=" + CODE + "&name=" + expect) + .when().get("/lobbies?code=" + CODE + "&name=" + expect) .then().log().all() .statusCode(HttpStatus.OK.value()); RestAssured.given().log().all() .contentType(ContentType.JSON) - .when().get("/rooms?code=" + CODE + "&name=not_master") + .when().get("/lobbies?code=" + CODE + "&name=not_master") .then().log().all() .statusCode(HttpStatus.OK.value()); //then - String actual = roomRepository.findById(CODE).get().getMaster().getName(); + String actual = lobbyRepository.findById(CODE).get().getMaster().getName(); Assertions.assertThat(actual).isEqualTo(expect); } @Test void 방이_꽉_차_있을때_참가에_실패한다() { //given - final Room room = roomRepository.findById(CODE).get(); - room.joinPlayer("A"); - room.joinPlayer("C"); - room.joinPlayer("D"); - roomRepository.save(room); + final Lobby lobby = lobbyRepository.findById(CODE).get(); + lobby.joinPlayer("A"); + lobby.joinPlayer("C"); + lobby.joinPlayer("D"); + lobbyRepository.save(lobby); //when final ErrorResponse response = RestAssured.given().log().all() .contentType(ContentType.JSON) - .when().get("/rooms?code=" + CODE + "&name=E") + .when().get("/lobbies?code=" + CODE + "&name=E") .then().log().all() .statusCode(HttpStatus.BAD_REQUEST.value()) .extract() @@ -155,13 +155,13 @@ static Stream provideRoomCreateFailCase() { @Test void 방에_이미_존재한느_이름으로_참가할때_참가에_실패한다() { //given - final Room room = roomRepository.findById(CODE).get(); - room.joinPlayer("A"); - roomRepository.save(room); + final Lobby lobby = lobbyRepository.findById(CODE).get(); + lobby.joinPlayer("A"); + lobbyRepository.save(lobby); //when final ErrorResponse response = RestAssured.given().log().all() .contentType(ContentType.JSON) - .when().get("/rooms?code=" + CODE + "&name=A") + .when().get("/lobbies?code=" + CODE + "&name=A") .then().log().all() .statusCode(HttpStatus.BAD_REQUEST.value()) .extract() @@ -180,7 +180,7 @@ static Stream provideRoomCreateFailCase() { RestAssured.given().log().all() .contentType(ContentType.JSON) .header("Authorization", "Basic " + basic) - .when().get("/rooms/code") + .when().get("/lobbies/code") .then().log().all() .statusCode(HttpStatus.OK.value()) .body("code", Matchers.equalTo(CODE)); @@ -191,7 +191,7 @@ static Stream provideRoomCreateFailCase() { // when & then RestAssured.given().log().all() .contentType(ContentType.JSON) - .when().get("/rooms/code/exist?code=" + CODE) + .when().get("/lobbies/code/exist?code=" + CODE) .then().log().all() .statusCode(HttpStatus.OK.value()) .body("exist", Matchers.equalTo(true)); diff --git a/src/test/java/mafia/mafiatogether/room/util/CodeGeneratorTest.java b/src/test/java/mafia/mafiatogether/lobby/util/CodeGeneratorTest.java similarity index 76% rename from src/test/java/mafia/mafiatogether/room/util/CodeGeneratorTest.java rename to src/test/java/mafia/mafiatogether/lobby/util/CodeGeneratorTest.java index 323bb571..5499375b 100644 --- a/src/test/java/mafia/mafiatogether/room/util/CodeGeneratorTest.java +++ b/src/test/java/mafia/mafiatogether/lobby/util/CodeGeneratorTest.java @@ -1,6 +1,6 @@ -package mafia.mafiatogether.room.util; +package mafia.mafiatogether.lobby.util; -import mafia.mafiatogether.room.domain.CodeGenerator; +import mafia.mafiatogether.lobby.domain.CodeGenerator; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/src/test/java/mafia/mafiatogether/vote/ui/VoteControllerTest.java b/src/test/java/mafia/mafiatogether/vote/ui/VoteControllerTest.java index 62e39482..8b5ae6af 100644 --- a/src/test/java/mafia/mafiatogether/vote/ui/VoteControllerTest.java +++ b/src/test/java/mafia/mafiatogether/vote/ui/VoteControllerTest.java @@ -31,7 +31,7 @@ void setTest(){ .contentType(ContentType.JSON) .header("Authorization", "Basic " + basic) .body(Map.of("target", expect)) - .when().post("/vote") + .when().post("/votes") .then().log().all() .statusCode(HttpStatus.NO_CONTENT.value()); @@ -49,7 +49,7 @@ void setTest(){ .contentType(ContentType.JSON) .header("Authorization", "Basic " + basic) .body(Map.of("target", "")) - .when().post("/vote") + .when().post("/votes") .then().log().all() .statusCode(HttpStatus.NO_CONTENT.value()); @@ -72,7 +72,7 @@ void setTest(){ final VoteResultResponse voteResultResponse = RestAssured.given().log().all() .contentType(ContentType.JSON) .header("Authorization", "Basic " + basic) - .when().get("/vote") + .when().get("/votes") .then().log().all() .statusCode(HttpStatus.OK.value()) .extract() @@ -88,7 +88,7 @@ private void voteTarget(final String name, final String target) { .contentType(ContentType.JSON) .header("Authorization", "Basic " + basic) .body(Map.of("target", target)) - .when().post("/vote") + .when().post("/votes") .then().log().all() .statusCode(HttpStatus.NO_CONTENT.value()); }