-
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] 선택지별 투표 결과 API 호출 시, 기권자 정보도 함께 조회 #211
Changes from 6 commits
05e4257
fe405a1
74f35d1
e7e2040
ef75936
bf05ee6
ed93b12
52275a6
d2d4366
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package ddangkong.facade.balance.vote.dto; | ||
|
||
import ddangkong.domain.room.member.Member; | ||
import java.util.List; | ||
|
||
public record GiveUpVoteMemberResponse( | ||
List<String> members, | ||
int memberCount) { | ||
|
||
public static GiveUpVoteMemberResponse create(List<Member> giveUpMembers) { | ||
List<String> members = giveUpMembers.stream() | ||
.map(Member::getNickname) | ||
.toList(); | ||
int memberCount = giveUpMembers.size(); | ||
|
||
return new GiveUpVoteMemberResponse(members, memberCount); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,22 +66,44 @@ private boolean isVoteFinished(Room room, BalanceContent balanceContent) { | |
public RoomBalanceVoteResultResponse getAllVoteResult(Long roomId, Long balanceContentId) { | ||
Room room = roomService.getRoom(roomId); | ||
BalanceContent balanceContent = balanceContentService.getBalanceContent(balanceContentId); | ||
if (isVoteFinished(room, balanceContent)) { | ||
BalanceOptions balanceOptions = balanceOptionService.getBalanceOptions(balanceContent); | ||
// todo 기권 추가 | ||
ContentRoomBalanceVoteResponse group = getContentRoomBalanceVoteResponse(room, balanceOptions); | ||
ContentTotalBalanceVoteResponse total = getContentTotalBalanceVoteResponse(balanceOptions); | ||
return new RoomBalanceVoteResultResponse(group, total); | ||
|
||
if (!isVoteFinished(room, balanceContent)) { | ||
throw new BadRequestException("투표가 끝나지 않아 투표 결과를 조회할 수 없습니다."); | ||
} | ||
throw new BadRequestException("투표가 끝나지 않아 투표 결과를 조회할 수 없습니다."); | ||
|
||
BalanceOptions balanceOptions = balanceOptionService.getBalanceOptions(balanceContent); | ||
|
||
ContentRoomBalanceVoteResponse group = getContentRoomBalanceVoteResponse(room, balanceOptions, balanceContent); | ||
ContentTotalBalanceVoteResponse total = getContentTotalBalanceVoteResponse(balanceOptions); | ||
|
||
return new RoomBalanceVoteResultResponse(group, total); | ||
} | ||
|
||
private ContentRoomBalanceVoteResponse getContentRoomBalanceVoteResponse(Room room, BalanceOptions balanceOptions) { | ||
private List<Member> getGiveUpVoteMemberResponse(Room room, BalanceContent balanceContent) { | ||
List<Member> roomMembers = memberService.findRoomMembers(room); | ||
List<RoomBalanceVote> votesInRoomByContent = roomBalanceVoteService.getVotesInRoomByContent(room, | ||
balanceContent); | ||
|
||
List<Member> voteMembers = votesInRoomByContent.stream() | ||
.map(RoomBalanceVote::getMember) | ||
.toList(); | ||
|
||
return roomMembers.stream() | ||
.filter(roomMember -> !voteMembers.contains(roomMember)) | ||
.toList(); | ||
} | ||
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. 사소한 의견) 밑에 메서드랑 위치를 바꿔주시면 더 가독성이 좋을것 같아요~ |
||
|
||
private ContentRoomBalanceVoteResponse getContentRoomBalanceVoteResponse(Room room, | ||
BalanceOptions balanceOptions, | ||
BalanceContent balanceContent) { | ||
List<Member> giveUpMembers = getGiveUpVoteMemberResponse(room, balanceContent); | ||
List<RoomBalanceVote> firstOptionVotes = roomBalanceVoteService | ||
.getVotesInRoom(room, balanceOptions.getFirstOption()); | ||
.getVotesInRoomByOption(room, balanceOptions.getFirstOption()); | ||
List<RoomBalanceVote> secondOptionVotes = roomBalanceVoteService | ||
.getVotesInRoom(room, balanceOptions.getSecondOption()); | ||
return ContentRoomBalanceVoteResponse.create(balanceOptions, firstOptionVotes, secondOptionVotes); | ||
.getVotesInRoomByOption(room, balanceOptions.getSecondOption()); | ||
|
||
return ContentRoomBalanceVoteResponse.create(balanceOptions, firstOptionVotes, secondOptionVotes, | ||
giveUpMembers); | ||
} | ||
|
||
private ContentTotalBalanceVoteResponse getContentTotalBalanceVoteResponse(BalanceOptions balanceOptions) { | ||
|
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. 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. 위 테스크를 '마루' 의견 반영해서 "투표자가 0명인 경우, 그룹 결과 퍼센트를 0, 0으로 반환"하도록 하는 것 확인했습니다~ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package ddangkong.service.room.balance.roomvote; | ||
|
||
import ddangkong.domain.balance.content.BalanceContent; | ||
import ddangkong.domain.balance.option.BalanceOption; | ||
import ddangkong.domain.balance.option.BalanceOptions; | ||
import ddangkong.domain.room.Room; | ||
|
@@ -47,7 +48,12 @@ public boolean isVoteFinished(List<Member> roomMembers, BalanceOptions balanceOp | |
} | ||
|
||
@Transactional(readOnly = true) | ||
public List<RoomBalanceVote> getVotesInRoom(Room room, BalanceOption balanceOption) { | ||
public List<RoomBalanceVote> getVotesInRoomByOption(Room room, BalanceOption balanceOption) { | ||
return roomVoteRepository.findByMemberRoomAndBalanceOption(room, balanceOption); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public List<RoomBalanceVote> getVotesInRoomByContent(Room room, BalanceContent balanceContent) { | ||
return roomVoteRepository.findByMemberRoomAndBalanceOptionBalanceContent(room, balanceContent); | ||
} | ||
Comment on lines
50
to
+58
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. 사소한 의견) 해당 메서드 내부에서 한 번만 조회하는데, |
||
} |
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.
사소한 의견) 이 부분은 따로 메서드 분리하면 더 좋을 것 같아요!