Skip to content

Commit

Permalink
Hotfix button game
Browse files Browse the repository at this point in the history
  • Loading branch information
tlsgmltjd committed May 12, 2024
1 parent 0db7a0e commit ef4e4a1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@
@JsonNaming(value = PropertyNamingStrategies.SnakeCaseStrategy.class)
public class ButtonGameRequest {
@NotNull
@Enumerated(EnumType.STRING)
private ButtonType buttonType;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import team.gsmgogo.domain.bet.entity.BetEntity;
import team.gsmgogo.domain.bet.repository.BetJpaRepository;
import team.gsmgogo.domain.buttongame.entity.ButtonGameEntity;
import team.gsmgogo.domain.buttongame.enums.ButtonType;
import team.gsmgogo.domain.buttongame.repository.ButtonGameRepository;
import team.gsmgogo.domain.buttongameparticipate.entity.ButtonGameParticipate;
import team.gsmgogo.domain.buttongameparticipate.repository.ButtonGameParticipateRepository;
Expand Down Expand Up @@ -43,6 +44,16 @@ public void execute(ButtonGameRequest request) {
if (buttonGameParticipateRepository.existsByButtonGameAndUser(buttonGame, currentUser))
throw new ExpectedException("이미 버튼을 눌렀습니다.", HttpStatus.BAD_REQUEST);

List<ButtonType> typeList = List.of(
ButtonType.ONE,
ButtonType.TWO,
ButtonType.THREE,
ButtonType.FOUR,
ButtonType.FIVE);

if (request.getButtonType() == null || !typeList.stream().anyMatch(type -> type.equals(request.getButtonType())))
throw new ExpectedException("올바른 버튼 종류를 입력해주세요.", HttpStatus.BAD_REQUEST);

AtomicInteger betPoint = new AtomicInteger();
buttonGameParticipate.findByUser(currentUser)
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@ public ButtonGameResponse execute(int month, int day) {
.filter(p -> p.getUser().getUserId().equals(currentUser.getUserId()))
.findAny().orElse(null);

if (myButtonGameParticipate == null)
return ButtonGameResponse.builder()
.buttonType(null)
.date(findButtonGame.getCreateDate())
.isActive(findButtonGame.getIsActive())
.results(null)
.isWin(null)
.winType(null)
.earnedPoint(null)
.build();

Map<ButtonType, Integer> typeMap = Map.of(
ButtonType.ONE, 0,
ButtonType.TWO, 0,
Expand All @@ -66,17 +55,18 @@ public ButtonGameResponse execute(int month, int day) {
}
);

boolean isWin = findButtonGame.getWinType() == myButtonGameParticipate.getButtonType();
Boolean isWin = (myButtonGameParticipate == null) ? null :
findButtonGame.getWinType() == myButtonGameParticipate.getButtonType();

return ButtonGameResponse.builder()
.buttonType(myButtonGameParticipate.getButtonType())
.buttonType(myButtonGameParticipate != null ? myButtonGameParticipate.getButtonType() : null)
.date(findButtonGame.getCreateDate())
.isActive(findButtonGame.getIsActive())
.results(!findButtonGame.getIsActive() ? updatedTypeMap : null)
.winType(findButtonGame.getWinType())
.isWin(findButtonGame.getWinType() == null ? null : isWin)
.earnedPoint(isWin ?
(int) Math.ceil((double) 2_000_000 / updatedTypeMap.get(findButtonGame.getWinType())) : null
.winType(findButtonGame.getWinType() != null ? findButtonGame.getWinType() : null)
.isWin(isWin)
.earnedPoint(isWin != null ? (isWin ?
(int) Math.ceil((double) 2_000_000 / updatedTypeMap.get(findButtonGame.getWinType())) : null) : null
)
.build();
}
Expand Down

0 comments on commit ef4e4a1

Please sign in to comment.