-
Notifications
You must be signed in to change notification settings - Fork 0
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
+206
−8
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 49 additions & 3 deletions
52
src/main/java/mafia/mafiatogether/domain/status/EndStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,17 @@ | |
|
||
import java.time.Clock; | ||
import lombok.RequiredArgsConstructor; | ||
import mafia.mafiatogether.config.exception.ExceptionCode; | ||
import mafia.mafiatogether.config.exception.RoomException; | ||
import mafia.mafiatogether.domain.Player; | ||
import mafia.mafiatogether.domain.Room; | ||
import mafia.mafiatogether.domain.RoomManager; | ||
import mafia.mafiatogether.domain.status.EndStatus; | ||
import mafia.mafiatogether.service.dto.RoomCodeResponse; | ||
import mafia.mafiatogether.service.dto.RoomCreateRequest; | ||
import mafia.mafiatogether.service.dto.RoomInfoResponse; | ||
import mafia.mafiatogether.service.dto.RoomModifyRequest; | ||
import mafia.mafiatogether.service.dto.RoomResultResponse; | ||
import mafia.mafiatogether.service.dto.RoomStatusResponse; | ||
import mafia.mafiatogether.service.dto.RoomValidateResponse; | ||
import org.springframework.stereotype.Service; | ||
|
@@ -50,4 +54,12 @@ public RoomInfoResponse findRoomInfo(final String code, final String name) { | |
public RoomValidateResponse validateCode(final String code) { | ||
return new RoomValidateResponse(roomManager.validateCode(code)); | ||
} | ||
|
||
public RoomResultResponse findResult(final String code) { | ||
final Room room = roomManager.findByCode(code); | ||
if(!room.isEnd()){ | ||
throw new RoomException(ExceptionCode.GAME_IS_NOT_FINISHED); | ||
} | ||
return RoomResultResponse.of((EndStatus) room.getStatus()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 다운캐스팅 조금 아쉽긴한데 그렇지 않으면 내부의 함수를 room으로 빼야해서 또 room의 역할이 너무 커지네;;; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😭 |
||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/mafia/mafiatogether/service/dto/RoomResultPlayerDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package mafia.mafiatogether.service.dto; | ||
|
||
import mafia.mafiatogether.domain.Player; | ||
|
||
public record RoomResultPlayerDto( | ||
String name, | ||
Boolean isAlive, | ||
String job | ||
) { | ||
public static RoomResultPlayerDto of( | ||
final Player player | ||
) { | ||
return new RoomResultPlayerDto( | ||
player.getName(), | ||
player.isAlive(), | ||
player.getJobType().name() | ||
); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/mafia/mafiatogether/service/dto/RoomResultResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package mafia.mafiatogether.service.dto; | ||
|
||
import java.sql.Timestamp; | ||
import java.util.List; | ||
import mafia.mafiatogether.domain.status.EndStatus; | ||
|
||
public record RoomResultResponse( | ||
String winnerJob, | ||
Timestamp endTime, | ||
List<RoomResultPlayerDto> winner, | ||
List<RoomResultPlayerDto> loser | ||
) { | ||
public static RoomResultResponse of( | ||
final EndStatus endStatus | ||
) { | ||
final List<RoomResultPlayerDto> winner = endStatus.getWinner() | ||
.stream() | ||
.map(RoomResultPlayerDto::of) | ||
.toList(); | ||
|
||
final List<RoomResultPlayerDto> loser = endStatus.getLoser() | ||
.stream() | ||
.map(RoomResultPlayerDto::of) | ||
.toList(); | ||
|
||
return new RoomResultResponse( | ||
endStatus.getWinnerJob().name(), | ||
endStatus.getEndTime(), | ||
winner, | ||
loser | ||
); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/test/java/mafia/mafiatogether/domain/status/EndStatusTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package mafia.mafiatogether.domain.status; | ||
|
||
import java.time.Clock; | ||
import java.util.List; | ||
import mafia.mafiatogether.domain.Player; | ||
import mafia.mafiatogether.domain.job.JobType; | ||
import mafia.mafiatogether.domain.job.Mafia; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class EndStatusTest { | ||
|
||
@Test | ||
void 시민_승리_결과_반환() { | ||
Mafia mafia = new Mafia(); | ||
Player A = Player.create("A"); | ||
A.modifyJob(mafia); | ||
A.kill(); | ||
Player B = Player.create("B"); | ||
B.modifyJob(mafia); | ||
B.kill(); | ||
Player C = Player.create("C"); | ||
Player D = Player.create("D"); | ||
Player E = Player.create("E"); | ||
|
||
List<Player> players = List.of(A, B, C, D, E); | ||
|
||
EndStatus endStatus = EndStatus.create(players, Clock.systemUTC().millis()); | ||
|
||
Assertions.assertThat(endStatus.getWinnerJob()).isEqualTo(JobType.CITIZEN); | ||
Assertions.assertThat(endStatus.getWinner()).containsAll(List.of(C, D, E)); | ||
Assertions.assertThat(endStatus.getLoser()).containsAll(List.of(A, B)); | ||
} | ||
|
||
@Test | ||
void 마피아_승리_결과_반환() { | ||
Mafia mafia = new Mafia(); | ||
Player A = Player.create("A"); | ||
A.modifyJob(mafia); | ||
Player B = Player.create("B"); | ||
B.modifyJob(mafia); | ||
Player C = Player.create("C"); | ||
C.kill(); | ||
Player D = Player.create("D"); | ||
Player E = Player.create("E"); | ||
|
||
List<Player> players = List.of(A, B, C, D, E); | ||
|
||
EndStatus endStatus = EndStatus.create(players, Clock.systemUTC().millis()); | ||
|
||
Assertions.assertThat(endStatus.getWinnerJob()).isEqualTo(JobType.MAFIA); | ||
Assertions.assertThat(endStatus.getLoser()).containsAll(List.of(C, D, E)); | ||
Assertions.assertThat(endStatus.getWinner()).containsAll(List.of(A, B)); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
room에서 이 역할들을 해주면 room의 역할이 너무 커지니까 status내부로 옮긴건가? room 역할 줄인건 좋은데 다운캐스팅을 하면 추상화한게 좀 아쉬워지는 느낌이라 지양하고 싶긴한데