Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ ext {
test {
outputs.dir snippetsDir
useJUnitPlatform()
jvmArgs '-Dnet.bytebuddy.experimental=true'
testLogging {
events "failed" // 실패한 테스트만 로그 출력
exceptionFormat "full" // Expected vs Actual 포함
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,25 @@ public void updateGame(Long leagueId, Long gameId, GameRequest.Update request, M
league.validateRoundWithinLimit(request.round());

Game game = entityUtils.getEntity(gameId, Game.class);
GameState state = GameState.from(request.state());

game.updateName(request.name());
game.updateStartTime(request.startTime());
game.updateVideoId(request.videoId());
game.updateGameQuarter(request.quarter());
game.updateState(GameState.from(request.state()));
game.updateState(state);
game.updateRound(Round.from(request.round()));
updateResultIfFinished(game, state);
}

private void updateResultIfFinished(Game game, GameState state) {
if (!GameState.FINISHED.equals(state)) {
return;
}
if (game.getGameTeams().size() != Game.MINIMUM_TEAMS) {
return;
}
game.determineResult();
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

경기 결과를 계산할 수 있는지 판단하는 로직(참여 팀이 2개인지 확인)은 애플리케이션 서비스 레이어보다는 Game 도메인 엔티티에 속하는 것이 더 적절해 보입니다.

도메인 주도 설계(DDD) 원칙에 따라 도메인 객체의 캡슐화를 강화하고 책임 분리를 명확히 하기 위해, 이 로직을 Game 엔티티 내부로 옮기는 것을 제안합니다.

Game 클래스에 tryDetermineResult()와 같은 새로운 메서드를 만들어 관련 로직을 포함시키고, GameService에서는 이 메서드를 호출만 하도록 변경하면 좋을 것 같습니다.

Game.java에 추가할 메서드:

public void tryDetermineResult() {
    if (getGameTeams().size() == MINIMUM_TEAMS) {
        determineResult();
    }
}

이렇게 변경하면 Game 엔티티가 자신의 비즈니스 규칙을 스스로 책임지게 되어, 코드가 더 유지보수하기 좋고 견고해질 것입니다.

    private void updateResultIfFinished(Game game, GameState state) {
        if (GameState.FINISHED.equals(state)) {
            game.tryDetermineResult();
        }
    }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 이건 Game 내부로 들어가도 될 것 같아요!
그리고 updateResult 로 둬서 캡슐화를 지켜도 될 것 같은데 어떠세요?

Game 이 업데이트 할 수 있는 상태인지 아닌지는 서비스 레이어에서는 관여하지 말고, 도메인 레이어에서만 알고 있는 게 더 적절할 것 같다는 생각이 들어요.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TAEW00KIM 요거 반영 안된 것 같아요~

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하 넵넵

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jin409 반영 후에 충돌 해결해서 올려뒀습니다! 머지할까요?


@Transactional
Expand Down Expand Up @@ -182,4 +195,4 @@ private void validateGameTeamsInLeague(League league, GameRequest.TeamLineupRequ
}
}

}
}
Binary file added src/main/resources/.DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions src/main/resources/static/docs/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -6429,7 +6429,7 @@ <h4 id="_사용자_로그인_http_response"><a class="link" href="#_사용자_
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Set-Cookie: HCC_SES=testAccessToken; Path=/; Max-Age=604800; Expires=Tue, 17 Feb 2026 15:11:52 GMT; Secure; HttpOnly; SameSite=Strict</code></pre>
Set-Cookie: HCC_SES=testAccessToken; Path=/; Max-Age=604800; Expires=Fri, 20 Feb 2026 14:03:47 GMT; Secure; HttpOnly; SameSite=Strict</code></pre>
</div>
</div>
</div>
Expand Down Expand Up @@ -8421,7 +8421,7 @@ <h4 id="_팀별보기_데이터_조회_response_fields"><a class="link" href="#_
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2026-02-10 15:21:15 +0900
Last updated 2026-02-12 11:49:57 +0900
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.3/highlight.min.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static org.mockito.Mockito.when;

import com.sports.server.command.game.domain.Game;
import com.sports.server.command.game.domain.GameResult;
import com.sports.server.command.game.domain.GameState;
import com.sports.server.command.game.domain.GameTeam;
import com.sports.server.command.game.domain.LineupPlayerState;
Expand Down Expand Up @@ -206,6 +207,28 @@ void setUp() {
() -> assertThat(game.getVideoId()).isEqualTo(updateDto.videoId()));
}

@Test
void 게임을_직접_종료하면_결과가_저장된다() {
// given
GameRequest.Update finishRequest = new GameRequest.Update(
nameOfGame, 4, "경기후", "FINISHED", LocalDateTime.of(2024, 9, 11, 12, 0, 0), "videoId"
);

// when
gameService.updateGame(leagueId, gameId, finishRequest, manager);

// then
Game game = entityUtils.getEntity(gameId, Game.class);
GameTeam firstGameTeam = entityUtils.getEntity(1L, GameTeam.class);
GameTeam secondGameTeam = entityUtils.getEntity(2L, GameTeam.class);

assertAll(
() -> assertThat(game.getState()).isEqualTo(GameState.FINISHED),
() -> assertThat(firstGameTeam.getResult()).isEqualTo(GameResult.LOSE),
() -> assertThat(secondGameTeam.getResult()).isEqualTo(GameResult.WIN)
);
}

@Test
void 게임이_속한_리그의_매니저가_아닌_회원이_게임을_수정하려고_하면_예외가_발생한다() {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ class GameTest {
public void setUp() {
game = entityBuilder(Game.class)
.set("id", 1L)
.set("teams", new ArrayList<>())
.set("gameTeams", new ArrayList<>())
.sample();

game2 = entityBuilder(Game.class)
.set("id", 2L)
.set("teams", new ArrayList<>())
.set("gameTeams", new ArrayList<>())
.sample();

team1 = entityBuilder(GameTeam.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class GameProgressTimelineTest {
@BeforeEach
void setUp() {
game = entityBuilder(Game.class)
.set("teams", new ArrayList<>())
.set("gameTeams", new ArrayList<>())
.set("gameQuarter", Quarter.PRE_GAME.getName())
.set("state", GameState.SCHEDULED)
.set("is_pk_taken", false)
.set("isPkTaken", false)
.sample();
}

Expand Down Expand Up @@ -290,4 +290,4 @@ class RollbackTest {
GameProgressType.GAME_END
);
}
}
}
Loading