From a7f4ce05385bdb36a9854248d135f639926fb9ca Mon Sep 17 00:00:00 2001 From: jaekwan Date: Sun, 10 May 2026 14:07:48 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=EC=97=B4=EB=A0=A4=EC=9E=88?= =?UTF-8?q?=EB=8A=94=20=EC=84=A4=EB=AC=B8=20=EC=88=98=20=EB=B0=8F=20?= =?UTF-8?q?=EC=B5=9C=EA=B3=A0=20=EC=B0=B8=EC=97=AC=20=EB=B3=B4=EC=83=81=20?= =?UTF-8?q?=EC=BD=94=EC=9D=B8=20=EC=A1=B0=ED=9A=8C=20API=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../survey/controller/SurveyStatsController.java | 11 +++++++++++ .../domain/survey/model/dto/OpenSurveyStats.java | 10 ++++++++++ .../model/response/OpenSurveyStatsResponse.java | 12 ++++++++++++ .../survey/repository/SurveyRepository.java | 2 ++ .../survey/repository/SurveyRepositoryImpl.java | 15 +++++++++++++++ .../domain/survey/service/query/SurveyQuery.java | 2 ++ .../survey/service/query/SurveyQueryService.java | 6 ++++++ 7 files changed, 58 insertions(+) create mode 100644 src/main/java/OneQ/OnSurvey/domain/survey/model/dto/OpenSurveyStats.java create mode 100644 src/main/java/OneQ/OnSurvey/domain/survey/model/response/OpenSurveyStatsResponse.java diff --git a/src/main/java/OneQ/OnSurvey/domain/survey/controller/SurveyStatsController.java b/src/main/java/OneQ/OnSurvey/domain/survey/controller/SurveyStatsController.java index e7f12677..ebcb6e38 100644 --- a/src/main/java/OneQ/OnSurvey/domain/survey/controller/SurveyStatsController.java +++ b/src/main/java/OneQ/OnSurvey/domain/survey/controller/SurveyStatsController.java @@ -1,8 +1,11 @@ package OneQ.OnSurvey.domain.survey.controller; import OneQ.OnSurvey.domain.survey.model.dto.GlobalStats; +import OneQ.OnSurvey.domain.survey.model.dto.OpenSurveyStats; import OneQ.OnSurvey.domain.survey.model.response.GlobalStatsResponse; +import OneQ.OnSurvey.domain.survey.model.response.OpenSurveyStatsResponse; import OneQ.OnSurvey.domain.survey.service.SurveyGlobalStatsService; +import OneQ.OnSurvey.domain.survey.service.query.SurveyQuery; import OneQ.OnSurvey.global.common.response.SuccessResponse; import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; @@ -16,6 +19,7 @@ public class SurveyStatsController { private final SurveyGlobalStatsService surveyGlobalStatsService; + private final SurveyQuery surveyQuery; @GetMapping("/global-stats") @Operation(summary = "전체 설문 전역 통계 조회", description = "전체 설문에 대한 총 목표 수/참여자 수/프로모션 지급자 수/일간 활성 사용자 수를 반환합니다.") @@ -23,4 +27,11 @@ public SuccessResponse getGlobalStats() { GlobalStats stats = surveyGlobalStatsService.getStats(); return SuccessResponse.ok(GlobalStatsResponse.from(stats)); } + + @GetMapping("/open-stats") + @Operation(summary = "열린 설문 통계 조회", description = "현재 진행 중인 설문 수와 가장 높은 참여 보상 코인 금액을 반환합니다.") + public SuccessResponse getOpenStats() { + OpenSurveyStats stats = surveyQuery.getOpenSurveyStats(); + return SuccessResponse.ok(OpenSurveyStatsResponse.from(stats)); + } } diff --git a/src/main/java/OneQ/OnSurvey/domain/survey/model/dto/OpenSurveyStats.java b/src/main/java/OneQ/OnSurvey/domain/survey/model/dto/OpenSurveyStats.java new file mode 100644 index 00000000..dc3069fe --- /dev/null +++ b/src/main/java/OneQ/OnSurvey/domain/survey/model/dto/OpenSurveyStats.java @@ -0,0 +1,10 @@ +package OneQ.OnSurvey.domain.survey.model.dto; + +public record OpenSurveyStats( + Long openSurveyCount, + Integer maxRewardCoin +) { + public static OpenSurveyStats of(Long openSurveyCount, Integer maxRewardCoin) { + return new OpenSurveyStats(openSurveyCount, maxRewardCoin != null ? maxRewardCoin : 0); + } +} diff --git a/src/main/java/OneQ/OnSurvey/domain/survey/model/response/OpenSurveyStatsResponse.java b/src/main/java/OneQ/OnSurvey/domain/survey/model/response/OpenSurveyStatsResponse.java new file mode 100644 index 00000000..cf0af95f --- /dev/null +++ b/src/main/java/OneQ/OnSurvey/domain/survey/model/response/OpenSurveyStatsResponse.java @@ -0,0 +1,12 @@ +package OneQ.OnSurvey.domain.survey.model.response; + +import OneQ.OnSurvey.domain.survey.model.dto.OpenSurveyStats; + +public record OpenSurveyStatsResponse( + Long openSurveyCount, + Integer maxRewardCoin +) { + public static OpenSurveyStatsResponse from(OpenSurveyStats stats) { + return new OpenSurveyStatsResponse(stats.openSurveyCount(), stats.maxRewardCoin()); + } +} diff --git a/src/main/java/OneQ/OnSurvey/domain/survey/repository/SurveyRepository.java b/src/main/java/OneQ/OnSurvey/domain/survey/repository/SurveyRepository.java index cc83e59d..621e0cfe 100644 --- a/src/main/java/OneQ/OnSurvey/domain/survey/repository/SurveyRepository.java +++ b/src/main/java/OneQ/OnSurvey/domain/survey/repository/SurveyRepository.java @@ -5,6 +5,7 @@ import OneQ.OnSurvey.domain.survey.entity.Survey; import OneQ.OnSurvey.domain.survey.model.SurveyStatus; import OneQ.OnSurvey.domain.survey.model.dto.OngoingSurveyStats; +import OneQ.OnSurvey.domain.survey.model.dto.OpenSurveyStats; import OneQ.OnSurvey.domain.survey.model.dto.SurveyDetailData; import OneQ.OnSurvey.domain.survey.model.dto.SurveyListView; import OneQ.OnSurvey.domain.survey.model.dto.SurveySearchQuery; @@ -37,4 +38,5 @@ Slice getSurveyListWithEligibility( List closeDueSurveys(); List findOngoingSurveys(); + OpenSurveyStats findOpenSurveyStats(); } diff --git a/src/main/java/OneQ/OnSurvey/domain/survey/repository/SurveyRepositoryImpl.java b/src/main/java/OneQ/OnSurvey/domain/survey/repository/SurveyRepositoryImpl.java index fe1a13ac..21b753d0 100644 --- a/src/main/java/OneQ/OnSurvey/domain/survey/repository/SurveyRepositoryImpl.java +++ b/src/main/java/OneQ/OnSurvey/domain/survey/repository/SurveyRepositoryImpl.java @@ -9,6 +9,7 @@ import OneQ.OnSurvey.domain.survey.model.Residence; import OneQ.OnSurvey.domain.survey.model.SurveyStatus; import OneQ.OnSurvey.domain.survey.model.dto.OngoingSurveyStats; +import OneQ.OnSurvey.domain.survey.model.dto.OpenSurveyStats; import OneQ.OnSurvey.domain.survey.model.dto.SurveyDetailData; import OneQ.OnSurvey.domain.survey.model.dto.SurveyListView; import OneQ.OnSurvey.domain.survey.model.dto.SurveySearchQuery; @@ -319,4 +320,18 @@ public List findOngoingSurveys() { .orderBy(survey.id.desc()) .fetch(); } + + @Override + public OpenSurveyStats findOpenSurveyStats() { + Tuple result = jpaQueryFactory + .select(survey.count(), surveyInfo.promotionAmount.max()) + .from(survey) + .leftJoin(surveyInfo).on(survey.id.eq(surveyInfo.surveyId)) + .where(survey.status.eq(SurveyStatus.ONGOING)) + .fetchOne(); + + Long count = result != null ? result.get(survey.count()) : 0L; + Integer maxCoin = result != null ? result.get(surveyInfo.promotionAmount.max()) : null; + return OpenSurveyStats.of(count != null ? count : 0L, maxCoin); + } } diff --git a/src/main/java/OneQ/OnSurvey/domain/survey/service/query/SurveyQuery.java b/src/main/java/OneQ/OnSurvey/domain/survey/service/query/SurveyQuery.java index ea3f5614..ad53bf23 100644 --- a/src/main/java/OneQ/OnSurvey/domain/survey/service/query/SurveyQuery.java +++ b/src/main/java/OneQ/OnSurvey/domain/survey/service/query/SurveyQuery.java @@ -4,6 +4,7 @@ import OneQ.OnSurvey.domain.survey.entity.Survey; import OneQ.OnSurvey.domain.survey.model.SurveyStatus; import OneQ.OnSurvey.domain.survey.model.dto.OngoingSurveyStats; +import OneQ.OnSurvey.domain.survey.model.dto.OpenSurveyStats; import OneQ.OnSurvey.domain.survey.model.dto.ScreeningViewData; import OneQ.OnSurvey.domain.survey.model.dto.SurveyDetailData; import OneQ.OnSurvey.domain.survey.model.dto.SurveyListView; @@ -47,6 +48,7 @@ ParticipationScreeningListResponse getScreeningList( // 외부 PORT Page getPagedSurveyListViewByQuery(Pageable pageable, SurveySearchQuery query); List getOngoingSurveyStats(); + OpenSurveyStats getOpenSurveyStats(); SurveyDetailData getSurveyDetailById(Long surveyId); ScreeningViewData getScreeningIntroBySurveyId(Long surveyId); List getSectionDtoListBySurveyId(Long surveyId); diff --git a/src/main/java/OneQ/OnSurvey/domain/survey/service/query/SurveyQueryService.java b/src/main/java/OneQ/OnSurvey/domain/survey/service/query/SurveyQueryService.java index 3dec0a24..2daa19ee 100644 --- a/src/main/java/OneQ/OnSurvey/domain/survey/service/query/SurveyQueryService.java +++ b/src/main/java/OneQ/OnSurvey/domain/survey/service/query/SurveyQueryService.java @@ -17,6 +17,7 @@ import OneQ.OnSurvey.domain.survey.model.Residence; import OneQ.OnSurvey.domain.survey.model.SurveyStatus; import OneQ.OnSurvey.domain.survey.model.dto.OngoingSurveyStats; +import OneQ.OnSurvey.domain.survey.model.dto.OpenSurveyStats; import OneQ.OnSurvey.domain.survey.model.dto.ScreeningIntroData; import OneQ.OnSurvey.domain.survey.model.dto.ScreeningViewData; import OneQ.OnSurvey.domain.survey.model.dto.SurveyDetailData; @@ -531,4 +532,9 @@ public List getSectionDtoListBySurveyId(Long surveyId) { public List getOngoingSurveyStats() { return surveyRepository.findOngoingSurveys(); } + + @Override + public OpenSurveyStats getOpenSurveyStats() { + return surveyRepository.findOpenSurveyStats(); + } } From 5a2028f8d783221cfb08366c7854972335be2463 Mon Sep 17 00:00:00 2001 From: jaekwan Date: Sun, 10 May 2026 14:14:47 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20=EC=BD=94=EB=93=9C=20=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/survey/model/dto/OpenSurveyStats.java | 5 ++++- .../domain/survey/repository/SurveyRepositoryImpl.java | 9 ++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/OneQ/OnSurvey/domain/survey/model/dto/OpenSurveyStats.java b/src/main/java/OneQ/OnSurvey/domain/survey/model/dto/OpenSurveyStats.java index dc3069fe..d7c83b30 100644 --- a/src/main/java/OneQ/OnSurvey/domain/survey/model/dto/OpenSurveyStats.java +++ b/src/main/java/OneQ/OnSurvey/domain/survey/model/dto/OpenSurveyStats.java @@ -5,6 +5,9 @@ public record OpenSurveyStats( Integer maxRewardCoin ) { public static OpenSurveyStats of(Long openSurveyCount, Integer maxRewardCoin) { - return new OpenSurveyStats(openSurveyCount, maxRewardCoin != null ? maxRewardCoin : 0); + return new OpenSurveyStats( + openSurveyCount != null ? openSurveyCount : 0L, + maxRewardCoin != null ? maxRewardCoin : 0 + ); } } diff --git a/src/main/java/OneQ/OnSurvey/domain/survey/repository/SurveyRepositoryImpl.java b/src/main/java/OneQ/OnSurvey/domain/survey/repository/SurveyRepositoryImpl.java index 21b753d0..42a6935c 100644 --- a/src/main/java/OneQ/OnSurvey/domain/survey/repository/SurveyRepositoryImpl.java +++ b/src/main/java/OneQ/OnSurvey/domain/survey/repository/SurveyRepositoryImpl.java @@ -330,8 +330,11 @@ public OpenSurveyStats findOpenSurveyStats() { .where(survey.status.eq(SurveyStatus.ONGOING)) .fetchOne(); - Long count = result != null ? result.get(survey.count()) : 0L; - Integer maxCoin = result != null ? result.get(surveyInfo.promotionAmount.max()) : null; - return OpenSurveyStats.of(count != null ? count : 0L, maxCoin); + if (result == null) { + return OpenSurveyStats.of(0L, null); + } + Long count = result.get(survey.count()); + Integer maxCoin = result.get(surveyInfo.promotionAmount.max()); + return OpenSurveyStats.of(count, maxCoin); } }