Skip to content

Commit

Permalink
refactor : 패키지 명 변경에 따른 네이밍 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
waterricecake committed Aug 20, 2024
1 parent 5c193ad commit 468b7da
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 57 deletions.
24 changes: 12 additions & 12 deletions src/main/java/mafia/mafiatogether/game/application/GameService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import lombok.RequiredArgsConstructor;
import mafia.mafiatogether.config.exception.ExceptionCode;
import mafia.mafiatogether.config.exception.GameException;
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 mafia.mafiatogether.game.domain.Game;
import mafia.mafiatogether.game.domain.GameRepository;
import mafia.mafiatogether.game.domain.status.StatusType;
Expand All @@ -24,13 +24,13 @@ public class GameService {
private final GameRepository gameRepository;

@Transactional
public RoomStatusResponse findStatus(final String code) {
public GameStatusResponse findStatus(final String code) {
final Optional<Game> game = gameRepository.findById(code);
if (game.isPresent()) {
return new RoomStatusResponse(checkStatusChanged(game.get()));
return new GameStatusResponse(checkStatusChanged(game.get()));
}
if (lobbyRepository.existsById(code)) {
return new RoomStatusResponse(StatusType.WAIT);
return new GameStatusResponse(StatusType.WAIT);
}
throw new GameException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE);
}
Expand Down Expand Up @@ -58,27 +58,27 @@ public void modifyStatus(final String code) {
}

@Transactional(readOnly = true)
public RoomInfoResponse findRoomInfo(final String code, final String name) {
public GameInfoResponse findGameInfo(final String code, final String name) {
final Optional<Game> 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) {
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 RoomInfoResponse.ofRoom(lobby, name);
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 GameException(ExceptionCode.INVALID_NOT_FOUND_ROOM_CODE));
if (!game.isEnd()) {
throw new GameException(ExceptionCode.GAME_IS_NOT_FINISHED);
}
return RoomResultResponse.from(game);
return GameResultResponse.from(game);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import mafia.mafiatogether.game.domain.status.StatusType;

public record RoomModifyRequest(
public record GameStartRequest(
StatusType statusType
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import mafia.mafiatogether.lobby.domain.ParticipantCollection;
import mafia.mafiatogether.lobby.domain.Lobby;

public record RoomInfoResponse(
public record GameInfoResponse(
Timestamp startTime,
Timestamp endTime,
Boolean isAlive,
Expand All @@ -19,9 +19,9 @@ public record RoomInfoResponse(
String myName,
List<PlayerResponse> 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(),
Expand All @@ -32,8 +32,8 @@ public static RoomInfoResponse ofGame(final Game game, final String name) {
);
}

public static RoomInfoResponse ofRoom(Lobby lobby, 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<RoomResultPlayerDto> winner,
List<RoomResultPlayerDto> loser
List<GameResultPlayerDto> winner,
List<GameResultPlayerDto> loser
) {
public static RoomResultResponse from(final Game game) {
final List<RoomResultPlayerDto> winner = game.getWinners()
public static GameResultResponse from(final Game game) {
final List<GameResultPlayerDto> winner = game.getWinners()
.stream()
.map(RoomResultPlayerDto::of)
.map(GameResultPlayerDto::of)
.toList();
final List<RoomResultPlayerDto> loser = game.getLosers()
final List<GameResultPlayerDto> loser = game.getLosers()
.stream()
.map(RoomResultPlayerDto::of)
.map(GameResultPlayerDto::of)
.toList();

return new RoomResultResponse(
return new GameResultResponse(
game.getWinnerJob(),
game.getStatus().getEndTime(),
winner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import mafia.mafiatogether.game.domain.status.StatusType;

public record RoomStatusResponse(
public record GameStatusResponse(
StatusType statusType
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class DeletedStatus extends Status{

@Override
public Status getNextStatus(Game room, Long now) {
public Status getNextStatus(Game game, Long now) {
throw new GameException(ExceptionCode.DELETED_STATUS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
18 changes: 9 additions & 9 deletions src/main/java/mafia/mafiatogether/game/ui/GameController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
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.request.GameStartRequest;
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;
Expand All @@ -23,7 +23,7 @@ public class GameController {
private final GameService gameService;

@GetMapping("/status")
public ResponseEntity<RoomStatusResponse> findStatus(
public ResponseEntity<GameStatusResponse> findStatus(
@PlayerInfo final PlayerInfoDto playerInfoDto
) {
return ResponseEntity.ok(gameService.findStatus(playerInfoDto.code()));
Expand All @@ -32,24 +32,24 @@ public ResponseEntity<RoomStatusResponse> findStatus(
@PatchMapping("/status")
public ResponseEntity<Void> modifyStatus(
@PlayerInfo final PlayerInfoDto playerInfoDto,
@RequestBody final RoomModifyRequest request
@RequestBody final GameStartRequest request
) {
gameService.modifyStatus(playerInfoDto.code());
return ResponseEntity.ok().build();
}


@GetMapping("/result")
public ResponseEntity<RoomResultResponse> findResult(
public ResponseEntity<GameResultResponse> findResult(
@PlayerInfo final PlayerInfoDto playerInfoDto
) {
return ResponseEntity.ok(gameService.findResult(playerInfoDto.code()));
}

@GetMapping("/info")
public ResponseEntity<RoomInfoResponse> findRoomInfo(
public ResponseEntity<GameInfoResponse> findGameInfo(
@PlayerInfo PlayerInfoDto playerInfoDto
) {
return ResponseEntity.ok(gameService.findRoomInfo(playerInfoDto.code(), playerInfoDto.name()));
return ResponseEntity.ok(gameService.findGameInfo(playerInfoDto.code(), playerInfoDto.name()));
}
}
30 changes: 15 additions & 15 deletions src/test/java/mafia/mafiatogether/game/ui/GameControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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("/games/status")
.then().log().all()
.statusCode(HttpStatus.OK.value())
.extract()
.as(RoomStatusResponse.class);
.as(GameStatusResponse.class);

//then
Assertions.assertThat(response.statusType()).isEqualTo(StatusType.WAIT);
Expand All @@ -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("/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);
Expand Down Expand Up @@ -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("/games/info")
.then().log().all()
.statusCode(HttpStatus.OK.value())
.extract()
.as(RoomInfoResponse.class);
.as(GameInfoResponse.class);

/// then
assertSoftly(
Expand All @@ -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("/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()))
Expand Down Expand Up @@ -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("/games/info")
.then().log().all()
.statusCode(HttpStatus.OK.value())
.extract()
.as(RoomInfoResponse.class);
.as(GameInfoResponse.class);

assertSoftly(
softly -> {
Expand Down Expand Up @@ -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("/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();
}
Expand Down

0 comments on commit 468b7da

Please sign in to comment.