Skip to content

Commit

Permalink
feat: domain 의 game 을 gameId 를 통해서 관리
Browse files Browse the repository at this point in the history
  • Loading branch information
be-student committed Apr 21, 2023
1 parent 40a329e commit c03a82a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private RacingGameMapper() {
}

public static GameEntity toGameEntity(final RacingGame racingGame) {
return new GameEntity(racingGame.getGameId(), racingGame.getCount().getTargetCount());
return new GameEntity(racingGame.getGameId().getValue(), racingGame.getCount().getTargetCount());
}

public static List<CarEntity> toCarEntities(final List<Car> cars, final GameId gameId) {
Expand All @@ -28,7 +28,7 @@ public static List<CarEntity> toCarEntities(final List<Car> cars, final GameId g
public static List<WinnerEntity> toWinnerEntity(final RacingGame racingGame) {
return racingGame.findWinner()
.stream()
.map(car -> WinnerEntity.fromDomain(car, racingGame.getGameId()))
.map(car -> WinnerEntity.fromDomain(car, racingGame.getGameId().getValue()))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class RacingGameMapperTest {
List.of(new CarEntity(1, "ㅁㄴㅇㄹ", 3, 3)));

assertAll(
() -> assertThat(result.getGameId()).isEqualTo(3),
() -> assertThat(result.getGameId().getValue()).isEqualTo(3),
() -> assertThat(result.getCount().getTargetCount()).isEqualTo(5),
() -> assertThat(result.getCars()).hasSize(1),
() -> assertThat(result.getCars().get(0).getCarName()).isEqualTo("ㅁㄴㅇㄹ"),
Expand All @@ -85,7 +85,7 @@ class RacingGameMapperTest {

assertAll(
() -> assertThat(result).hasSize(2),
() -> assertThat(result.get(0).getGameId()).isEqualTo(1),
() -> assertThat(result.get(0).getGameId().getValue()).isEqualTo(1),
() -> assertThat(result.get(0).getCount().getTargetCount()).isEqualTo(5),
() -> assertThat(result.get(0).getCars()).hasSize(2),
() -> assertThat(result.get(0).getCars().get(0).getCarName()).isEqualTo("ㅁㄴㅇㄹ"),
Expand All @@ -94,7 +94,7 @@ class RacingGameMapperTest {
() -> assertThat(result.get(0).getCars().get(1).getCarName()).isEqualTo("asdf"),
() -> assertThat(result.get(0).getCars().get(1).getPosition()).isEqualTo(4),
() -> assertThat(result.get(0).getCars().get(1).getCarId().getValue()).isEqualTo(2),
() -> assertThat(result.get(1).getGameId()).isEqualTo(2),
() -> assertThat(result.get(1).getGameId().getValue()).isEqualTo(2),
() -> assertThat(result.get(1).getCount().getTargetCount()).isEqualTo(5),
() -> assertThat(result.get(1).getCars()).hasSize(2),
() -> assertThat(result.get(1).getCars().get(0).getCarName()).isEqualTo("ㅁㄴㅇㄹ"),
Expand Down
14 changes: 14 additions & 0 deletions domain/src/main/java/racingcar/domain/GameId.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package racingcar.domain;

public class GameId {

private final Integer value;

public GameId(final Integer value) {
this.value = value;
}

public Integer getValue() {
return value;
}
}
6 changes: 3 additions & 3 deletions domain/src/main/java/racingcar/domain/RacingGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ public class RacingGame {

private final Cars cars;
private final Count count;
private Integer gameId;
private GameId gameId;

public RacingGame(final List<String> carsName, final int count) {
cars = Cars.from(carsName);
this.count = new Count(count);
}

public RacingGame(final Integer gameId, final List<Car> cars, final int count) {
this.gameId = gameId;
this.gameId = new GameId(gameId);
this.cars = new Cars(cars);
this.count = new Count(count);
}
Expand All @@ -35,7 +35,7 @@ public List<Car> getCars() {
return cars.getCars();
}

public Integer getGameId() {
public GameId getGameId() {
return gameId;
}
}

0 comments on commit c03a82a

Please sign in to comment.