-
Notifications
You must be signed in to change notification settings - Fork 2
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
경기 조회 API #151
Merged
Merged
경기 조회 API #151
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
eaaca60
:bug: 잘못된 엔티티 ID 변경
6d2d50e
:sparkles: 경기 조회 API DTO
ace2140
:sparkles: 경기 조회 API Controller
cc2bc69
:sparkles: 경기 조회 API 서비스
16200b2
포인트 계산 로직
7e1dba1
:bug: 개행문자
e265e2a
:bug: 개행문자
743ebeb
:recycle: A -> B
7ecf03e
:recycle: Builder Annotation
bdcf7b0
:recycle: json naming
8bad5a6
:recycle: nullable dto
19e5392
:recycle: 경기 종료 전 경기
581a291
Merge branch 'main' into 150-fetch-match-api
5619910
Update match response
tlsgmltjd 941f571
Update match response dto json property
tlsgmltjd 1aa5161
Update CalculatePoint CRITICAL
tlsgmltjd 8a6c81d
Update refactor
tlsgmltjd 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
25 changes: 25 additions & 0 deletions
25
gsmgogo-api/src/main/java/team/gsmgogo/domain/match/controller/MatchController.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,25 @@ | ||
package team.gsmgogo.domain.match.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import team.gsmgogo.domain.match.controller.dto.response.MatchResponse; | ||
import team.gsmgogo.domain.match.service.MatchService; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/match") | ||
public class MatchController { | ||
private final MatchService matchService; | ||
|
||
@GetMapping | ||
public ResponseEntity<MatchResponse> getMatches( | ||
@RequestParam("m") Integer month, | ||
@RequestParam("d") Integer day | ||
){ | ||
return ResponseEntity.ok(matchService.execute(month, day)); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...ogo-api/src/main/java/team/gsmgogo/domain/match/controller/dto/response/MatchInfoDto.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,69 @@ | ||
package team.gsmgogo.domain.match.controller.dto.response; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import team.gsmgogo.domain.match.enums.MatchLevelType; | ||
import team.gsmgogo.domain.match.enums.TeamClassType; | ||
import team.gsmgogo.domain.team.enums.TeamType; | ||
import team.gsmgogo.domain.user.enums.GradeEnum; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@JsonNaming(value = PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
public class MatchInfoDto { | ||
private Long matchId; | ||
|
||
private TeamType matchType; | ||
|
||
private MatchLevelType matchLevel; | ||
|
||
@JsonProperty("team_a_id") | ||
private Long teamAId; | ||
|
||
@JsonProperty("team_a_name") | ||
private String teamAName; | ||
|
||
@JsonProperty("team_a_grade") | ||
private GradeEnum teamAGrade; | ||
|
||
@JsonProperty("team_a_class_type") | ||
private TeamClassType teamAClassType; | ||
|
||
@JsonProperty("team_b_id") | ||
private Long teamBId; | ||
|
||
@JsonProperty("team_b_name") | ||
private String teamBName; | ||
|
||
@JsonProperty("team_b_grade") | ||
private GradeEnum teamBGrade; | ||
|
||
@JsonProperty("team_b_class_type") | ||
private TeamClassType teamBClassType; | ||
|
||
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") | ||
private LocalDateTime matchStartAt; | ||
|
||
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") | ||
private LocalDateTime matchEndAt; | ||
|
||
@JsonProperty("is_vote") | ||
private boolean isVote; | ||
|
||
@JsonProperty("team_a_bet") | ||
private Long teamABet; | ||
|
||
@JsonProperty("team_b_bet") | ||
private Long teamBBet; | ||
} |
18 changes: 18 additions & 0 deletions
18
...go-api/src/main/java/team/gsmgogo/domain/match/controller/dto/response/MatchResponse.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,18 @@ | ||
package team.gsmgogo.domain.match.controller.dto.response; | ||
|
||
import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@JsonNaming(value = PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
public class MatchResponse { | ||
private List<MatchInfoDto> matches; | ||
private List<MatchResultDto> matchResult; | ||
} |
76 changes: 76 additions & 0 deletions
76
...o-api/src/main/java/team/gsmgogo/domain/match/controller/dto/response/MatchResultDto.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,76 @@ | ||
package team.gsmgogo.domain.match.controller.dto.response; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import team.gsmgogo.domain.match.enums.MatchLevelType; | ||
import team.gsmgogo.domain.match.enums.TeamClassType; | ||
import team.gsmgogo.domain.team.enums.TeamType; | ||
import team.gsmgogo.domain.user.enums.GradeEnum; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@JsonNaming(value = PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
public class MatchResultDto { | ||
private Long matchId; | ||
|
||
private TeamType matchType; | ||
|
||
private MatchLevelType matchLevel; | ||
|
||
@JsonProperty("team_a_id") | ||
private Long teamAId; | ||
|
||
@JsonProperty("team_a_name") | ||
private String teamAName; | ||
|
||
@JsonProperty("team_a_grade") | ||
private GradeEnum teamAGrade; | ||
|
||
@JsonProperty("team_a_class_type") | ||
private TeamClassType teamAClassType; | ||
|
||
@JsonProperty("team_b_id") | ||
private Long teamBId; | ||
|
||
@JsonProperty("team_b_name") | ||
private String teamBName; | ||
|
||
@JsonProperty("team_b_grade") | ||
private GradeEnum teamBGrade; | ||
|
||
@JsonProperty("team_b_class_type") | ||
private TeamClassType teamBClassType; | ||
|
||
@JsonProperty("is_vote") | ||
private boolean isVote; | ||
|
||
@JsonProperty("team_a_bet") | ||
private Long teamABet; | ||
|
||
@JsonProperty("team_b_bet") | ||
private Long teamBBet; | ||
|
||
@JsonProperty("team_a_score") | ||
private Integer teamAScore; | ||
|
||
@JsonProperty("team_b_score") | ||
private Integer teamBScore; | ||
|
||
@JsonProperty("bet_team_a_score") | ||
private Integer betTeamAScore; | ||
|
||
@JsonProperty("bet_team_b_score") | ||
private Integer betTeamBScore; | ||
|
||
private Long earnedPoint; | ||
|
||
private Long losePoint; | ||
} |
7 changes: 7 additions & 0 deletions
7
gsmgogo-api/src/main/java/team/gsmgogo/domain/match/service/MatchService.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,7 @@ | ||
package team.gsmgogo.domain.match.service; | ||
|
||
import team.gsmgogo.domain.match.controller.dto.response.MatchResponse; | ||
|
||
public interface MatchService { | ||
MatchResponse execute(int month, int day); | ||
} |
109 changes: 109 additions & 0 deletions
109
gsmgogo-api/src/main/java/team/gsmgogo/domain/match/service/impl/MatchServiceImpl.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,109 @@ | ||
package team.gsmgogo.domain.match.service.impl; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import team.gsmgogo.domain.bet.entity.BetEntity; | ||
import team.gsmgogo.domain.bet.repository.BetJpaRepository; | ||
import team.gsmgogo.domain.match.controller.dto.response.MatchInfoDto; | ||
import team.gsmgogo.domain.match.controller.dto.response.MatchResponse; | ||
import team.gsmgogo.domain.match.controller.dto.response.MatchResultDto; | ||
import team.gsmgogo.domain.match.entity.MatchEntity; | ||
import team.gsmgogo.domain.match.repository.MatchQueryDslRepository; | ||
import team.gsmgogo.domain.match.service.MatchService; | ||
import team.gsmgogo.domain.matchresult.entity.MatchResultEntity; | ||
import team.gsmgogo.domain.matchresult.repository.MatchResultQueryDslRepository; | ||
import team.gsmgogo.domain.user.entity.UserEntity; | ||
import team.gsmgogo.global.common.CalculatePoint; | ||
import team.gsmgogo.global.common.CalculatePointRequest; | ||
import team.gsmgogo.global.common.CalculatePointResponse; | ||
import team.gsmgogo.global.facade.UserFacade; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class MatchServiceImpl implements MatchService { | ||
private final MatchQueryDslRepository matchQueryDslRepository; | ||
private final MatchResultQueryDslRepository matchResultQueryDslRepository; | ||
private final BetJpaRepository betJpaRepository; | ||
private final UserFacade userFacade; | ||
|
||
@Override | ||
public MatchResponse execute(int month, int day) { | ||
UserEntity currentUser = userFacade.getCurrentUser(); | ||
List<MatchEntity> matches = matchQueryDslRepository.findByMonthAndDay(month, day); | ||
List<MatchResultEntity> matchResults = matchResultQueryDslRepository.findByMonthAndDay(month, 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().getTeamId()) | ||
.teamAName(match.getTeamA().getTeamName()) | ||
.teamAGrade(match.getTeamAGrade()) | ||
.teamAClassType(match.getTeamAClassType()) | ||
.teamBId(match.getTeamB().getTeamId()) | ||
.teamBName(match.getTeamB().getTeamName()) | ||
.teamBGrade(match.getTeamBGrade()) | ||
.teamBClassType(match.getTeamBClassType()) | ||
.matchStartAt(match.getStartAt()) | ||
.matchEndAt(match.getEndAt()) | ||
.isVote(bettings.stream().anyMatch(bet -> bet.getMatch() == match)) | ||
.teamABet(match.getTeamABet()) | ||
.teamBBet(match.getTeamBBet()) | ||
.build()).toList(); | ||
|
||
List<MatchResultDto> endedMatches = matchResults.stream() | ||
.map(matchResult -> { | ||
MatchEntity match = matchResult.getMatch(); | ||
BetEntity betting = bettings.stream() | ||
.filter(bet -> bet.getMatch() == match) | ||
.findFirst().orElse(null); | ||
|
||
CalculatePointResponse calculatePoint = new CalculatePointResponse(); | ||
|
||
if (betting != null){ | ||
CalculatePointRequest request = new CalculatePointRequest( | ||
betting.getBetPoint(), | ||
matchResult.getTeamAScore(), | ||
matchResult.getTeamBScore(), | ||
betting.getBetScoreA(), | ||
betting.getBetScoreB(), | ||
match.getTeamABet(), | ||
match.getTeamBBet() | ||
); | ||
calculatePoint = new CalculatePoint().execute(request); | ||
} | ||
|
||
return MatchResultDto.builder() | ||
.matchId(match.getMatchId()) | ||
.matchType(match.getMatchType()) | ||
.matchLevel(match.getMatchLevel()) | ||
.teamAId(match.getTeamA().getTeamId()) | ||
.teamAName(match.getTeamA().getTeamName()) | ||
.teamAGrade(match.getTeamAGrade()) | ||
.teamAClassType(match.getTeamAClassType()) | ||
.teamBId(match.getTeamB().getTeamId()) | ||
.teamBName(match.getTeamB().getTeamName()) | ||
.teamBGrade(match.getTeamBGrade()) | ||
.teamBClassType(match.getTeamBClassType()) | ||
.isVote(betting != null) | ||
.teamABet(match.getTeamABet()) | ||
.teamBBet(match.getTeamBBet()) | ||
.teamAScore(matchResult.getTeamAScore()) | ||
.teamBScore(matchResult.getTeamBScore()) | ||
.earnedPoint(calculatePoint.getEarnedPoint()) | ||
.losePoint(calculatePoint.getLosePoint()) | ||
.betTeamAScore(betting != null ? betting.getBetScoreA() : null) | ||
.betTeamBScore(betting != null ? betting.getBetScoreB() : null) | ||
.build(); | ||
}).toList(); | ||
|
||
return new MatchResponse(matchList, endedMatches); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
gsmgogo-api/src/main/java/team/gsmgogo/global/common/CalculatePoint.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,30 @@ | ||
package team.gsmgogo.global.common; | ||
|
||
public class CalculatePoint { | ||
public CalculatePointResponse execute(CalculatePointRequest req){ | ||
CalculatePointResponse response = null; | ||
|
||
long winTeamPoint = Math.max(req.getAllAPoint(), req.getAllBPoint()); | ||
long loseTeamPoint = Math.min(req.getAllAPoint(), req.getAllBPoint()); | ||
|
||
// 스코어 예측 성공 | ||
if (req.getAScore() == req.getBetAScore() && req.getBScore() == req.getBetBScore()){ | ||
Long pointResult = (long) Math.ceil(((req.getBetPoint() * ((double) loseTeamPoint / winTeamPoint)) + req.getBetPoint()) * 1.5); | ||
response = new CalculatePointResponse(pointResult, null); | ||
} | ||
|
||
// 승부 예측 성공 | ||
if ((req.getAScore() > req.getBScore() && req.getBetAScore() > req.getBetBScore()) || | ||
(req.getAScore() < req.getBScore() && req.getBetAScore() < req.getBetBScore())){ | ||
Long pointResult = (long) Math.ceil(((req.getBetPoint() * ((double) loseTeamPoint / winTeamPoint)) + req.getBetPoint()) * 0.9); | ||
response = new CalculatePointResponse(pointResult, null); | ||
} | ||
|
||
// 예측 실패 | ||
if (response == null) { | ||
response = new CalculatePointResponse(null, req.getBetPoint()); | ||
} | ||
|
||
return response; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
gsmgogo-api/src/main/java/team/gsmgogo/global/common/CalculatePointRequest.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,18 @@ | ||
package team.gsmgogo.global.common; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CalculatePointRequest { | ||
private Long betPoint; | ||
private int aScore; | ||
private int bScore; | ||
private int betAScore; | ||
private int betBScore; | ||
private Long allAPoint; | ||
private Long allBPoint; | ||
} |
13 changes: 13 additions & 0 deletions
13
gsmgogo-api/src/main/java/team/gsmgogo/global/common/CalculatePointResponse.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,13 @@ | ||
package team.gsmgogo.global.common; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CalculatePointResponse { | ||
private Long earnedPoint = null; | ||
private Long losePoint = null; | ||
} |
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
5 changes: 4 additions & 1 deletion
5
gsmgogo-entity/src/main/java/team/gsmgogo/domain/bet/repository/BetJpaRepository.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 |
---|---|---|
@@ -1,11 +1,14 @@ | ||
package team.gsmgogo.domain.bet.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import team.gsmgogo.domain.bet.entity.BetEntity; | ||
import team.gsmgogo.domain.match.entity.MatchEntity; | ||
import team.gsmgogo.domain.user.entity.UserEntity; | ||
import team.gsmgogo.domain.match.entity.MatchEntity; | ||
|
||
public interface BetJpaRepository extends JpaRepository<BetEntity, Long> { | ||
List<BetEntity> findByUser(UserEntity user); | ||
boolean existsByUserAndMatch(UserEntity user, MatchEntity matchEntity); | ||
} |
Oops, something went wrong.
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.
경시 시작 시간, 끝나는 시간 값을 이용하여
matches: 경기 시작 전 or 경기 중인 경기
matchResults: 경기 시간이 끝난 경기
이렇게 조회되도록 변경 부탁드려요! 현재 상황은 경기 시간이 끝난 경기가 하나 있는데 matchs와 matchResults 모두 하나씩 나옵니다!
시간을 계산하여 한 쪽에서만 나오도록 변경 부탁드려요!