Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,11 +19,19 @@
public class SurveyStatsController {

private final SurveyGlobalStatsService surveyGlobalStatsService;
private final SurveyQuery surveyQuery;

@GetMapping("/global-stats")
@Operation(summary = "전체 설문 전역 통계 조회", description = "전체 설문에 대한 총 목표 수/참여자 수/프로모션 지급자 수/일간 활성 사용자 수를 반환합니다.")
public SuccessResponse<GlobalStatsResponse> getGlobalStats() {
GlobalStats stats = surveyGlobalStatsService.getStats();
return SuccessResponse.ok(GlobalStatsResponse.from(stats));
}

@GetMapping("/open-stats")
@Operation(summary = "열린 설문 통계 조회", description = "현재 진행 중인 설문 수와 가장 높은 참여 보상 코인 금액을 반환합니다.")
public SuccessResponse<OpenSurveyStatsResponse> getOpenStats() {
OpenSurveyStats stats = surveyQuery.getOpenSurveyStats();
return SuccessResponse.ok(OpenSurveyStatsResponse.from(stats));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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 != null ? openSurveyCount : 0L,
maxRewardCoin != null ? maxRewardCoin : 0
);
}
Comment thread
KJaeKwan marked this conversation as resolved.
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -37,4 +38,5 @@ Slice<SurveyWithEligibility> getSurveyListWithEligibility(
List<Long> closeDueSurveys();

List<OngoingSurveyStats> findOngoingSurveys();
OpenSurveyStats findOpenSurveyStats();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -319,4 +320,21 @@ public List<OngoingSurveyStats> 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();

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);
}
Comment thread
KJaeKwan marked this conversation as resolved.
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,6 +48,7 @@ ParticipationScreeningListResponse getScreeningList(
// 외부 PORT
Page<SurveyListView> getPagedSurveyListViewByQuery(Pageable pageable, SurveySearchQuery query);
List<OngoingSurveyStats> getOngoingSurveyStats();
OpenSurveyStats getOpenSurveyStats();
SurveyDetailData getSurveyDetailById(Long surveyId);
ScreeningViewData getScreeningIntroBySurveyId(Long surveyId);
List<SectionDto> getSectionDtoListBySurveyId(Long surveyId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -531,4 +532,9 @@ public List<SectionDto> getSectionDtoListBySurveyId(Long surveyId) {
public List<OngoingSurveyStats> getOngoingSurveyStats() {
return surveyRepository.findOngoingSurveys();
}

@Override
public OpenSurveyStats getOpenSurveyStats() {
return surveyRepository.findOpenSurveyStats();
}
}
Loading