diff --git a/src/main/java/com/hyundai/softeer/backend/domain/eventuser/controller/SharedUrlController.java b/src/main/java/com/hyundai/softeer/backend/domain/eventuser/controller/SharedUrlController.java index f446b5a6..0556a1fb 100644 --- a/src/main/java/com/hyundai/softeer/backend/domain/eventuser/controller/SharedUrlController.java +++ b/src/main/java/com/hyundai/softeer/backend/domain/eventuser/controller/SharedUrlController.java @@ -1,7 +1,6 @@ package com.hyundai.softeer.backend.domain.eventuser.controller; import com.hyundai.softeer.backend.domain.eventuser.dto.RedirectUrlDto; -import com.hyundai.softeer.backend.domain.eventuser.dto.SharedUrlRequest; import com.hyundai.softeer.backend.domain.eventuser.service.EventUserService; import com.hyundai.softeer.backend.global.dto.BaseResponse; import io.swagger.v3.oas.annotations.Operation; @@ -13,7 +12,6 @@ import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.http.MediaType; -import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @@ -42,7 +40,7 @@ public class SharedUrlController { @ApiResponse(responseCode = "404", description = "존재하지 않는 이벤트 참가자", content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = BaseResponse.class), examples = @ExampleObject("{\"message\":\"잘못된 공유 주소입니다.\",\"status\":404}"))}), }) public BaseResponse getSharedUrl( - @PathVariable @Validated SharedUrlRequest sharedUrl + @PathVariable String sharedUrl ) { return new BaseResponse<>(eventUserService.getRedirectUrl(sharedUrl)); } diff --git a/src/main/java/com/hyundai/softeer/backend/domain/eventuser/service/EventUserService.java b/src/main/java/com/hyundai/softeer/backend/domain/eventuser/service/EventUserService.java index 55f35ffc..5a9118a0 100644 --- a/src/main/java/com/hyundai/softeer/backend/domain/eventuser/service/EventUserService.java +++ b/src/main/java/com/hyundai/softeer/backend/domain/eventuser/service/EventUserService.java @@ -34,7 +34,7 @@ public class EventUserService { public EventUserInfoDto getEventUserInfo(User user, Long subEventId) { EventUser eventUser = eventUserRepository.findByUserIdAndSubEventId(user.getId(), subEventId) .orElseThrow(() -> new EventUserNotFoundException()); - + return EventUserInfoDto.fromEntity(eventUser); } @@ -101,8 +101,8 @@ public EventUserPageResponseDto getUserPage(EventUserPageRequest eventUserPageRe .build(); } - public RedirectUrlDto getRedirectUrl(SharedUrlRequest sharedUrlRequest) { - EventUser eventUser = eventUserRepository.findBySharedUrl(sharedUrlRequest.getSharedUrl()) + public RedirectUrlDto getRedirectUrl(String sharedUrl) { + EventUser eventUser = eventUserRepository.findBySharedUrl(sharedUrl) .orElseThrow(() -> new SharedUrlNotFoundException()); eventUser.scoreSharedScore(); diff --git a/src/main/java/com/hyundai/softeer/backend/domain/firstcome/quiz/dto/QuizFirstComeLandResponseDto.java b/src/main/java/com/hyundai/softeer/backend/domain/firstcome/quiz/dto/QuizFirstComeLandResponseDto.java index 8f5028f0..2e4496d6 100644 --- a/src/main/java/com/hyundai/softeer/backend/domain/firstcome/quiz/dto/QuizFirstComeLandResponseDto.java +++ b/src/main/java/com/hyundai/softeer/backend/domain/firstcome/quiz/dto/QuizFirstComeLandResponseDto.java @@ -12,6 +12,9 @@ @Getter public class QuizFirstComeLandResponseDto { + @Schema(description = "퀴즈 번호", example = "1") + private Integer quizSequence; + @Schema(description = "이벤트 유효 여부", example = "true") private boolean valid; diff --git a/src/main/java/com/hyundai/softeer/backend/domain/firstcome/quiz/service/QuizFirstComeService.java b/src/main/java/com/hyundai/softeer/backend/domain/firstcome/quiz/service/QuizFirstComeService.java index c6941b2f..4d646db4 100644 --- a/src/main/java/com/hyundai/softeer/backend/domain/firstcome/quiz/service/QuizFirstComeService.java +++ b/src/main/java/com/hyundai/softeer/backend/domain/firstcome/quiz/service/QuizFirstComeService.java @@ -132,6 +132,7 @@ public QuizFirstComeLandResponseDto getQuizLand(Long eventId) { .startAt(subEvent.getStartAt()) .endAt(subEvent.getEndAt()) .lastQuizNumber(subEvents.size()) + .quizSequence(quizFirstCome.getSequence()) .build(); } diff --git a/src/main/java/com/hyundai/softeer/backend/domain/firstcome/quiz/service/winnerdraw/QuizWinnerDrawRedis.java b/src/main/java/com/hyundai/softeer/backend/domain/firstcome/quiz/service/winnerdraw/QuizWinnerDrawRedis.java index c8661bd5..761ec1e4 100644 --- a/src/main/java/com/hyundai/softeer/backend/domain/firstcome/quiz/service/winnerdraw/QuizWinnerDrawRedis.java +++ b/src/main/java/com/hyundai/softeer/backend/domain/firstcome/quiz/service/winnerdraw/QuizWinnerDrawRedis.java @@ -42,8 +42,6 @@ public synchronized QuizFirstComeSubmitResponseDto winnerDraw(EventUser eventUse winner.setUser(authenticatedUser); winnerRepository.save(winner); - counterService.incrementCounter(CounterService.COUNTER_KEY); - - return QuizFirstComeSubmitResponseDto.winner(prize.getPrizeWinningImgUrl()); + return QuizFirstComeSubmitResponseDto.winner(prize.getPrizeResultImgUrl()); } } diff --git a/src/main/java/com/hyundai/softeer/backend/domain/firstcome/quiz/service/winnerdraw/QuizWinnerDrawSync.java b/src/main/java/com/hyundai/softeer/backend/domain/firstcome/quiz/service/winnerdraw/QuizWinnerDrawSync.java index ac348deb..c0357c64 100644 --- a/src/main/java/com/hyundai/softeer/backend/domain/firstcome/quiz/service/winnerdraw/QuizWinnerDrawSync.java +++ b/src/main/java/com/hyundai/softeer/backend/domain/firstcome/quiz/service/winnerdraw/QuizWinnerDrawSync.java @@ -55,6 +55,6 @@ public synchronized QuizFirstComeSubmitResponseDto winnerDraw( eventUser.updateWinner(); eventUserRepository.save(eventUser); - return QuizFirstComeSubmitResponseDto.winner(prize.getPrizeWinningImgUrl()); + return QuizFirstComeSubmitResponseDto.winner(prize.getPrizeResultImgUrl()); } } diff --git a/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/controller/DrawingLotteryController.java b/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/controller/DrawingLotteryController.java index f0d8a8cc..73578595 100644 --- a/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/controller/DrawingLotteryController.java +++ b/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/controller/DrawingLotteryController.java @@ -30,8 +30,6 @@ @Slf4j @RequestMapping("/api/v1/lottery/drawing") public class DrawingLotteryController { - public static final int RANK_COUNT = 20; - private final DrawingLotteryService drawingLotteryService; @Value("${properties.event-id}") @@ -78,7 +76,7 @@ public BaseResponse getDrawingLandingPage() { public BaseResponse> getRankList( @Validated SubEventRequest subEventRequest ) { - return new BaseResponse<>(drawingLotteryService.getRankList(subEventRequest, RANK_COUNT)); + return new BaseResponse<>(drawingLotteryService.getRankList(subEventRequest)); } @GetMapping("") diff --git a/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/DrawingLotteryService.java b/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/DrawingLotteryService.java index afb5241d..753e0e87 100644 --- a/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/DrawingLotteryService.java +++ b/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/DrawingLotteryService.java @@ -39,17 +39,19 @@ public class DrawingLotteryService implements LotteryService { private final ScoreCalculator scoreCalculator; private final DrawingRank drawingRank; + public static final int RANK_COUNT = 20; + @Value("${properties.event-id}") private Long eventId; @PostConstruct public void init() { - SubEvent rankingSubEvent = subEventRepository.findByEventId(eventId) + subEventRepository.findByEventId(eventId) .stream() .filter(subEvent -> subEvent.getEventType().equals(SubEventType.DRAWING)) .findFirst().get(); - drawingRank.updateRankingData(rankingSubEvent.getId(), 20); + drawingRank.updateRankingData(rankingSubEvent.getId(), RANK_COUNT); } @Transactional(readOnly = true) @@ -64,8 +66,8 @@ public DrawingLotteryLandDto getDrawingLotteryLand(long eventId) { return DrawingLotteryLandDto.fromEntity(drawing); } - public List getRankList(SubEventRequest subEventRequest, int rankCount) { - return drawingRank.getRankList(subEventRequest, rankCount); + public List getRankList(SubEventRequest subEventRequest) { + return drawingRank.getRankList(subEventRequest, RANK_COUNT); } private SubEvent findDrawingEvent(List subEvents) { @@ -177,6 +179,6 @@ public DrawingScoreDto getDrawingScore(User authenticatedUser, DrawingScoreReque @Transactional public DrawingTotalScoreDto getDrawingTotalScore(User authenticatedUser, SubEventRequest subEventRequest) { - return drawingRank.getDrawingTotalScore(authenticatedUser, subEventRequest); + return drawingRank.getDrawingTotalScore(authenticatedUser, subEventRequest, RANK_COUNT); } } diff --git a/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/rank/DrawingRank.java b/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/rank/DrawingRank.java index 9ae54c1c..ac57d187 100644 --- a/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/rank/DrawingRank.java +++ b/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/rank/DrawingRank.java @@ -10,7 +10,7 @@ public interface DrawingRank { List getRankList(SubEventRequest subEventRequest, int rankCount); - DrawingTotalScoreDto getDrawingTotalScore(User authenticatedUser, SubEventRequest subEventRequest); + DrawingTotalScoreDto getDrawingTotalScore(User authenticatedUser, SubEventRequest subEventRequest, int rankCount); void updateRankingData(long subEventId, int rankCount); } diff --git a/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/rank/DrawingRankRedis.java b/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/rank/DrawingRankRedis.java index 117d1334..1ee8d0e2 100644 --- a/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/rank/DrawingRankRedis.java +++ b/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/rank/DrawingRankRedis.java @@ -54,7 +54,7 @@ public List getRankList(SubEventRequest subEventRequest, int rankCount) @Transactional @Override - public DrawingTotalScoreDto getDrawingTotalScore(User authenticatedUser, SubEventRequest subEventRequest) { + public DrawingTotalScoreDto getDrawingTotalScore(User authenticatedUser, SubEventRequest subEventRequest, int rankCount) { EventUser eventUser = eventUserRepository.findByUserIdAndSubEventId(authenticatedUser.getId(), subEventRequest.getSubEventId()) .orElseThrow(() -> new EventUserNotFoundException()); @@ -73,6 +73,25 @@ public DrawingTotalScoreDto getDrawingTotalScore(User authenticatedUser, SubEven eventUser.updateGameScore(totalScore); eventUserRepository.save(eventUser); redisTemplate.opsForZSet().add(RANKING_KEY, authenticatedUser.getName(), totalScore); + Long rankSize = redisTemplate.opsForZSet().zCard(RANKING_KEY); + + if (rankSize != null && rankSize < rankCount) { + redisTemplate.opsForZSet().add(RANKING_KEY, authenticatedUser.getName(), totalScore); + } else if (rankSize != null) { + // ZSet의 크기가 20이라면, 20번째 순위의 값을 가져옴 + Set> range = redisTemplate.opsForZSet().rangeWithScores(RANKING_KEY, -1, -1); + if (range != null && !range.isEmpty()) { + ZSetOperations.TypedTuple lastRank = range.iterator().next(); + double lastRankScore = lastRank.getScore(); + + // 새로운 값이 20위의 값보다 크다면 추가 + if (totalScore > lastRankScore) { + redisTemplate.opsForZSet().add(RANKING_KEY, authenticatedUser.getName(), totalScore); + // 최하위 랭크 제거 (21번째 항목 제거) + redisTemplate.opsForZSet().removeRange(RANKING_KEY, 0, 0); + } + } + } } return DrawingTotalScoreDto.builder() diff --git a/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/rank/DrawingRankSync.java b/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/rank/DrawingRankSync.java index e44a35ee..22735a1b 100644 --- a/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/rank/DrawingRankSync.java +++ b/src/main/java/com/hyundai/softeer/backend/domain/lottery/drawing/service/rank/DrawingRankSync.java @@ -40,7 +40,7 @@ public List getRankList(SubEventRequest subEventRequest, int rankCount) @Transactional @Override - public DrawingTotalScoreDto getDrawingTotalScore(User authenticatedUser, SubEventRequest subEventRequest) { + public DrawingTotalScoreDto getDrawingTotalScore(User authenticatedUser, SubEventRequest subEventRequest, int rankCount) { EventUser eventUser = eventUserRepository.findByUserIdAndSubEventId(authenticatedUser.getId(), subEventRequest.getSubEventId()) .orElseThrow(() -> new EventUserNotFoundException()); diff --git a/src/main/java/com/hyundai/softeer/backend/domain/prize/entity/Prize.java b/src/main/java/com/hyundai/softeer/backend/domain/prize/entity/Prize.java index bfd179d4..72f5e7c4 100644 --- a/src/main/java/com/hyundai/softeer/backend/domain/prize/entity/Prize.java +++ b/src/main/java/com/hyundai/softeer/backend/domain/prize/entity/Prize.java @@ -25,4 +25,6 @@ public class Prize { private String prizeImgUrl; private String prizeWinningImgUrl; + + private String prizeResultImgUrl; }