Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 결과 조회 기능 구현 #46

Merged
merged 2 commits into from
May 20, 2024
Merged

feat: 결과 조회 기능 구현 #46

merged 2 commits into from
May 20, 2024

Conversation

thdwoqor
Copy link
Contributor

EndStatus에서 결과를 반환할수있게 구현했고 처음에는 Room을 상태로 가지고있었다가 Room 전체를 필요로하지않고 테스트가 매우 힘들어져서 List를 가지는 방향으로 변경함...
더좋은 방법있으면 리뷰 부탁...

Copy link
Contributor

@waterricecake waterricecake left a comment

Choose a reason for hiding this comment

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

다 좋은데 다운캐스팅 한게 조금 아쉽긴 하네.. 물론 어쩔수 없는 상황에 쓰는거지만 이것때문에 추상화한 의미가 조금 퇴색되는 느낌..
근데 지금 막 뭐 바꿀려면 대공사니까 나는 어프루브....
지금 떠오르는 차선책은

  1. endStatus의 getWinner, getLoser메서드를 satatus로 옮긴다
  2. Room의 players를 레퍼 클래스로 감싸 players 중 무언가 세는 역할을 부여한다
    라고 생각하는데 솔직히 1도 별로고 2는 뭔가 대공사 인거 같네

if(!room.isEnd()){
throw new RoomException(ExceptionCode.GAME_IS_NOT_FINISHED);
}
return RoomResultResponse.of((EndStatus) room.getStatus());
Copy link
Contributor

Choose a reason for hiding this comment

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

다운캐스팅 조금 아쉽긴한데 그렇지 않으면 내부의 함수를 room으로 빼야해서 또 room의 역할이 너무 커지네;;;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😭

Comment on lines +21 to +53
public static EndStatus create(final List<Player> players, final Long now) {
return new EndStatus(players, now, now + ONE_MINUTE);
}

public JobType getWinnerJob() {
if(getAliveMafia()==0){
return JobType.CITIZEN;
}
return JobType.MAFIA;
}

private Map<Boolean, List<Player>> partitionPlayersByRole() {
return players
.stream()
.collect(Collectors.partitioningBy(Player::isMafia));
}

public List<Player> getWinner() {
Map<Boolean, List<Player>> players = partitionPlayersByRole();

if (getAliveMafia() == 0) {
return players.get(Boolean.FALSE);
}
return players.get(Boolean.TRUE);
}

public List<Player> getLoser() {
Map<Boolean, List<Player>> players = partitionPlayersByRole();

if (getAliveMafia() == 0) {
return players.get(Boolean.TRUE);
}
return players.get(Boolean.FALSE);
Copy link
Contributor

Choose a reason for hiding this comment

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

room에서 이 역할들을 해주면 room의 역할이 너무 커지니까 status내부로 옮긴건가? room 역할 줄인건 좋은데 다운캐스팅을 하면 추상화한게 좀 아쉬워지는 느낌이라 지양하고 싶긴한데

@thdwoqor thdwoqor merged commit 238c4f5 into dev May 20, 2024
1 check passed
waterricecake pushed a commit that referenced this pull request May 20, 2024
* feat: 게임이 끝나지않았을때 예외 추가

* feat: 게임 결과 반환 기능 구현
waterricecake pushed a commit that referenced this pull request Oct 14, 2024
* feat: 게임이 끝나지않았을때 예외 추가

* feat: 게임 결과 반환 기능 구현
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants