Skip to content

Commit

Permalink
Merge pull request #173 from GSM-GOGO/feature/matchResponseDto
Browse files Browse the repository at this point in the history
경기 조회 API 필드 추가
  • Loading branch information
tlsgmltjd authored May 5, 2024
2 parents f423cf5 + 9fed580 commit 35a7be6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,14 @@ public class MatchInfoDto {

@JsonProperty("team_b_bet")
private Long teamBBet;

@JsonProperty("bet_team_a_score")
private Long betTeamAScore;

@JsonProperty("bet_team_b_score")
private Long betTeamBScore;

@JsonProperty("bet_point")
private Long betPoint;

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package team.gsmgogo.domain.match.service.impl;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -40,36 +39,45 @@ public MatchResponse execute(int month, int day) {
List<BetEntity> bettings = betJpaRepository.findByUser(currentUser);

List<MatchInfoDto> matchList = matches.stream()
.map(match -> MatchInfoDto.builder()
.matchId(match.getMatchId())
.matchType(match.getMatchType())
.matchLevel(match.getMatchLevel())
.teamAId(match.getTeamA() != null ? match.getTeamA().getTeamId() : null)
.teamAName(match.getTeamA() != null ? match.getTeamA().getTeamName() : "TBD")
.teamAGrade(match.getTeamAGrade())
.teamAClassType(match.getTeamAClassType())
.teamBId(match.getTeamB() != null ? match.getTeamB().getTeamId() : null)
.teamBName(match.getTeamB() != null ? match.getTeamB().getTeamName() : "TBD")
.teamBGrade(match.getTeamBGrade())
.teamBClassType(match.getTeamBClassType())
.badmintonRank(
match.getTeamA() != null && match.getTeamA().getTeamType() == TeamType.BADMINTON ? match.getTeamA().getBadmintonRank() : null)
.badmintonAParticipateNames(
match.getTeamA() != null && match.getTeamA().getTeamType() == TeamType.BADMINTON ?
match.getTeamA().getTeamParticipates().get(0).getUser().getUserName() + "/" + match.getTeamA().getTeamParticipates().get(1).getUser().getUserName()
: null
)
.badmintonBParticipateNames(
match.getTeamB() != null && match.getTeamB().getTeamType() == TeamType.BADMINTON ?
match.getTeamB().getTeamParticipates().get(0).getUser().getUserName() + "/" + match.getTeamB().getTeamParticipates().get(1).getUser().getUserName()
: null
)
.matchStartAt(match.getStartAt())
.matchEndAt(match.getEndAt())
.isVote(bettings.stream().anyMatch(bet -> bet.getMatch() == match))
.teamABet(match.getTeamABet())
.teamBBet(match.getTeamBBet())
.build()).toList();
.map(match -> {

Optional<BetEntity> currentBetting = bettings.stream()
.findFirst().filter(bet -> bet.getMatch() == match);

return MatchInfoDto.builder()
.matchId(match.getMatchId())
.matchType(match.getMatchType())
.matchLevel(match.getMatchLevel())
.teamAId(match.getTeamA() != null ? match.getTeamA().getTeamId() : null)
.teamAName(match.getTeamA() != null ? match.getTeamA().getTeamName() : "TBD")
.teamAGrade(match.getTeamAGrade())
.teamAClassType(match.getTeamAClassType())
.teamBId(match.getTeamB() != null ? match.getTeamB().getTeamId() : null)
.teamBName(match.getTeamB() != null ? match.getTeamB().getTeamName() : "TBD")
.teamBGrade(match.getTeamBGrade())
.teamBClassType(match.getTeamBClassType())
.badmintonRank(
match.getTeamA() != null && match.getTeamA().getTeamType() == TeamType.BADMINTON ? match.getTeamA().getBadmintonRank() : null)
.badmintonAParticipateNames(
match.getTeamA() != null && match.getTeamA().getTeamType() == TeamType.BADMINTON ?
match.getTeamA().getTeamParticipates().get(0).getUser().getUserName() + "/" + match.getTeamA().getTeamParticipates().get(1).getUser().getUserName()
: null
)
.badmintonBParticipateNames(
match.getTeamB() != null && match.getTeamB().getTeamType() == TeamType.BADMINTON ?
match.getTeamB().getTeamParticipates().get(0).getUser().getUserName() + "/" + match.getTeamB().getTeamParticipates().get(1).getUser().getUserName()
: null
)
.matchStartAt(match.getStartAt())
.matchEndAt(match.getEndAt())
.isVote(currentBetting.isPresent())
.teamABet(match.getTeamABet())
.teamBBet(match.getTeamBBet())
.betTeamAScore(currentBetting.map(entity -> Long.valueOf(entity.getBetScoreA())).orElse(null))
.betTeamBScore(currentBetting.map(betEntity -> Long.valueOf(betEntity.getBetScoreB())).orElse(null))
.betPoint(currentBetting.map(BetEntity::getBetPoint).orElse(null))
.build();
}).toList();

List<MatchResultDto> endedMatches = matchResults.stream()
.map(matchResult -> {
Expand Down

0 comments on commit 35a7be6

Please sign in to comment.