diff --git a/build.gradle b/build.gradle index 15edf87e..e06502e3 100644 --- a/build.gradle +++ b/build.gradle @@ -52,6 +52,9 @@ dependencies { // Json implementation 'org.json:json:20210307' + // Actuator + implementation 'org.springframework.boot:spring-boot-starter-actuator' + testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'junit:junit:4.13.1' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' diff --git a/src/main/java/com/hyundai/softeer/backend/domain/firstcome/dto/WaitingEnqueueBodyRequest.java b/src/main/java/com/hyundai/softeer/backend/domain/firstcome/dto/WaitingEnqueueBodyRequest.java index deab7b16..a84683a8 100644 --- a/src/main/java/com/hyundai/softeer/backend/domain/firstcome/dto/WaitingEnqueueBodyRequest.java +++ b/src/main/java/com/hyundai/softeer/backend/domain/firstcome/dto/WaitingEnqueueBodyRequest.java @@ -1,10 +1,14 @@ package com.hyundai.softeer.backend.domain.firstcome.dto; +import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; import lombok.Data; +import lombok.NoArgsConstructor; @Data -@NotNull +@NoArgsConstructor public class WaitingEnqueueBodyRequest { + @NotNull + @Schema(example = "1") Long subEventId; } diff --git a/src/main/java/com/hyundai/softeer/backend/domain/firstcome/dto/WaitingQueueRequest.java b/src/main/java/com/hyundai/softeer/backend/domain/firstcome/dto/WaitingQueueRequest.java index c8bb147b..ce5fd0f8 100644 --- a/src/main/java/com/hyundai/softeer/backend/domain/firstcome/dto/WaitingQueueRequest.java +++ b/src/main/java/com/hyundai/softeer/backend/domain/firstcome/dto/WaitingQueueRequest.java @@ -1,11 +1,18 @@ package com.hyundai.softeer.backend.domain.firstcome.dto; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; import lombok.Data; import lombok.NoArgsConstructor; @Data @NoArgsConstructor public class WaitingQueueRequest { + @NotNull + @Schema(example = "1") private Long subEventId; + + @NotNull + @Schema(example = "MToxOmMwMzA0ODhjLTA0ZGYtNDcwMS1hOGU5LTA1YmUzNmJlMmM2MA") private String token; } diff --git a/src/main/java/com/hyundai/softeer/backend/domain/firstcome/quiz/controller/QuizFirstComeController.java b/src/main/java/com/hyundai/softeer/backend/domain/firstcome/quiz/controller/QuizFirstComeController.java index 41445802..43b8a8c0 100644 --- a/src/main/java/com/hyundai/softeer/backend/domain/firstcome/quiz/controller/QuizFirstComeController.java +++ b/src/main/java/com/hyundai/softeer/backend/domain/firstcome/quiz/controller/QuizFirstComeController.java @@ -240,7 +240,7 @@ public BaseResponse deleteQuizEvent( }) @SecurityRequirement(name = "access-token") public BaseResponse enqueueQuiz( - @RequestBody WaitingEnqueueBodyRequest waitingEnqueueBodyRequest, + @RequestBody @Validated WaitingEnqueueBodyRequest waitingEnqueueBodyRequest, @Parameter(hidden = true) @CurrentUser User authenticatedUser ) { return new BaseResponse<>(quizFirstComeService.enqueueQuiz(authenticatedUser, waitingEnqueueBodyRequest)); @@ -261,9 +261,9 @@ public BaseResponse enqueueQuiz( @ApiResponse(responseCode = "200", description = "퀴즈 이벤트 대기열 진입 성공", useReturnTypeSchema = true), }) @SecurityRequirement(name = "access-token") - public WaitingQueueStatusDto getQueueStatus( - WaitingQueueRequest waitingQueueRequest + public BaseResponse getQueueStatus( + @Validated WaitingQueueRequest waitingQueueRequest ) { - return quizFirstComeService.getQueueStatus(waitingQueueRequest); + return new BaseResponse<>(quizFirstComeService.getQueueStatus(waitingQueueRequest)); } } diff --git a/src/main/java/com/hyundai/softeer/backend/domain/firstcome/quiz/service/CounterService.java b/src/main/java/com/hyundai/softeer/backend/domain/firstcome/quiz/service/CounterService.java index 153e3960..e1482d40 100644 --- a/src/main/java/com/hyundai/softeer/backend/domain/firstcome/quiz/service/CounterService.java +++ b/src/main/java/com/hyundai/softeer/backend/domain/firstcome/quiz/service/CounterService.java @@ -1,5 +1,6 @@ package com.hyundai.softeer.backend.domain.firstcome.quiz.service; +import com.hyundai.softeer.backend.global.aop.LogExecutionTime; import lombok.RequiredArgsConstructor; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; @@ -12,14 +13,17 @@ public class CounterService { private final RedisTemplate redisTemplate; + @LogExecutionTime public Long incrementCounter(String key) { return redisTemplate.opsForValue().increment(key); } + @LogExecutionTime public Long decrementCounter(String key) { return redisTemplate.opsForValue().decrement(key); } + @LogExecutionTime public Long getCounterValue(String key) { String value = redisTemplate.opsForValue().get(key); return (value != null) ? Long.parseLong(value) : 0L; 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 b9610e68..f8dda485 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 @@ -27,6 +27,7 @@ import com.hyundai.softeer.backend.domain.subevent.exception.SubEventNotWithinPeriodException; import com.hyundai.softeer.backend.domain.subevent.repository.SubEventRepository; import com.hyundai.softeer.backend.domain.user.entity.User; +import com.hyundai.softeer.backend.global.aop.LogExecutionTime; import com.hyundai.softeer.backend.global.utils.DateUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -215,6 +216,7 @@ private QuizFirstComeLandResponseDto getPrizesWithEventEnd(List subEve * @return */ @Transactional + @LogExecutionTime public QuizFirstComeSubmitResponseDto quizSubmit(QuizFirstComeSubmitRequest quizFirstComeSubmitRequest, User authenticatedUser) { queueService.validateToken(quizFirstComeSubmitRequest.getToken(), authenticatedUser.getId(), quizFirstComeSubmitRequest.getSubEventId()); @@ -326,8 +328,6 @@ public EnqueueDto enqueueQuiz(User authenticatedUser, WaitingEnqueueBodyRequest long currentUserCount = queueService.getCurrentUserInWaitingQueue(subEventId); - log.info("현재 대기열에 {}명이 있습니다.", currentUserCount); - return EnqueueDto.builder() .token(token) .currentWaitingUsers(currentUserCount) @@ -337,8 +337,6 @@ public EnqueueDto enqueueQuiz(User authenticatedUser, WaitingEnqueueBodyRequest public WaitingQueueStatusDto getQueueStatus(WaitingQueueRequest waitingQueueRequest) { long lowerUserCountInWaitingQueue = queueService.getUserCountWithLowerTimestamp(waitingQueueRequest.getSubEventId(), waitingQueueRequest.getToken()); - log.info("대기열에서 {}번째 입니다.", lowerUserCountInWaitingQueue); - return WaitingQueueStatusDto.builder() .waitingUsers(lowerUserCountInWaitingQueue) .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 25821fc2..a1be019c 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 @@ -10,6 +10,7 @@ import com.hyundai.softeer.backend.domain.winner.entity.Winner; import com.hyundai.softeer.backend.domain.winner.repository.WinnerRepository; import com.hyundai.softeer.backend.domain.winner.utils.WinnerUtil; +import com.hyundai.softeer.backend.global.aop.LogExecutionTime; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -21,7 +22,9 @@ public class QuizWinnerDrawRedis implements QuizWinnerDraw { private final WinnerRepository winnerRepository; private final CounterService counterService; + @Override + @LogExecutionTime public synchronized QuizFirstComeSubmitResponseDto winnerDraw(EventUser eventUser, QuizFirstCome quizFirstCome, SubEvent subEvent, User authenticatedUser) { if (!winnerUtil.isParticipanted(authenticatedUser.getId(), subEvent.getId()).isEmpty()) { return QuizFirstComeSubmitResponseDto.alreadyParticipant(); 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 5e19d034..6ad96bf2 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 @@ -12,6 +12,7 @@ import com.hyundai.softeer.backend.domain.winner.entity.Winner; import com.hyundai.softeer.backend.domain.winner.repository.WinnerRepository; import com.hyundai.softeer.backend.domain.winner.utils.WinnerUtil; +import com.hyundai.softeer.backend.global.aop.LogExecutionTime; import lombok.RequiredArgsConstructor; @RequiredArgsConstructor @@ -23,6 +24,7 @@ public class QuizWinnerDrawSync implements QuizWinnerDraw { private final EventUserRepository eventUserRepository; @Override + @LogExecutionTime public synchronized QuizFirstComeSubmitResponseDto winnerDraw( EventUser eventUser, QuizFirstCome quizFirstCome, diff --git a/src/main/java/com/hyundai/softeer/backend/domain/firstcome/service/QueueService.java b/src/main/java/com/hyundai/softeer/backend/domain/firstcome/service/QueueService.java index 71d382fc..aea88d77 100644 --- a/src/main/java/com/hyundai/softeer/backend/domain/firstcome/service/QueueService.java +++ b/src/main/java/com/hyundai/softeer/backend/domain/firstcome/service/QueueService.java @@ -42,7 +42,7 @@ public long getCurrentUserInWaitingQueue(long subEventId) { public long getUserCountWithLowerTimestamp(long subEventId, String token) { Long rank = redisTemplate.opsForZSet().rank(WAIT_QUEUE_KEY + subEventId, token); - return rank != null ? rank : 0; + return rank != null ? rank + 1 : 0; } public Set popTokensFromWaitingQueue(long subEventId, long count) { 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 1ee8d0e2..5df005a2 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 @@ -12,7 +12,6 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.ZSetOperations; -import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; @@ -20,7 +19,6 @@ import java.util.Map; import java.util.Set; -@Service @RequiredArgsConstructor public class DrawingRankRedis implements DrawingRank { private final EventUserRepository eventUserRepository; 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 22735a1b..2add7a80 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 @@ -10,11 +10,13 @@ import lombok.RequiredArgsConstructor; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.Map; +@Service @RequiredArgsConstructor public class DrawingRankSync implements DrawingRank { private final EventUserRepository eventUserRepository;