Skip to content

Commit

Permalink
[REFACTOR] 타임라인이 경기에 주는 영향을 apply 메서드로 명시적으로 호출 #206
Browse files Browse the repository at this point in the history
  • Loading branch information
ldk980130 committed Aug 18, 2024
1 parent a1042e1 commit 469036d
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public void register(Member member, Long gameId, TimelineRequest request) {
Game game = checkPermissionAndGet(gameId, member);

Timeline timeline = timelineMapper.toEntity(game, request);
timeline.apply();

timelineRepository.save(timeline);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public String getType() {
return "GAME_PROGRESS";
}

@Override
public void apply() {
// TODO Game 상태 변경
}

@Override
public void rollback() {
// TODO 게임 상태 변경 타임라인 생성 로직 구현 이후 구현 예정
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public String getType() {
return "PK";
}

@Override
public void apply() {
}

@Override
public void rollback() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ private void validatePlayers(LineupPlayer originLineupPlayer, LineupPlayer repla
}
}

@Override
public void apply() {

}

@Override
public void rollback() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ public static ScoreTimeline score(
Integer recordedAt,
LineupPlayer scorer
) {
game.score(scorer);

GameTeam team1 = game.getTeam1();
GameTeam team2 = game.getTeam2();

Expand Down Expand Up @@ -87,6 +85,14 @@ private ScoreTimeline(
this.snapshotScore2 = snapshotScore2;
}

@Override
public void apply() {
game.score(scorer);

snapshotScore1 = gameTeam1.getScore();
snapshotScore2 = gameTeam2.getScore();
}

@Override
public void rollback() {
game.cancelScore(scorer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@ private void validateRecordedAt(Integer recordedAt) {
}
}

public abstract void apply();

public abstract void rollback();
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class CreateTest {
scorer
);

timeline.apply();

// then
assertThat(timeline.getScorer()).isEqualTo(scorer);
assertThat(timeline.getSnapshotScore1()).isEqualTo(2);
Expand All @@ -76,6 +78,8 @@ class CreateTest {
scorer
);

timeline.apply();

// then
assertThat(timeline.getScorer()).isEqualTo(scorer);
assertThat(timeline.getSnapshotScore1()).isEqualTo(1);
Expand Down

0 comments on commit 469036d

Please sign in to comment.