diff --git a/src/main/java/OneQ/OnSurvey/domain/survey/controller/ParticipationController.java b/src/main/java/OneQ/OnSurvey/domain/survey/controller/ParticipationController.java index b2d09ff1..36eddc13 100644 --- a/src/main/java/OneQ/OnSurvey/domain/survey/controller/ParticipationController.java +++ b/src/main/java/OneQ/OnSurvey/domain/survey/controller/ParticipationController.java @@ -4,23 +4,16 @@ import OneQ.OnSurvey.domain.participation.entity.ScreeningAnswer; import OneQ.OnSurvey.domain.participation.model.dto.AnswerInsertDto; import OneQ.OnSurvey.domain.participation.model.dto.ParticipationCompletionDto; -import OneQ.OnSurvey.domain.participation.model.dto.ParticipationStatus; import OneQ.OnSurvey.domain.participation.service.answer.AnswerCommand; import OneQ.OnSurvey.domain.participation.service.response.ResponseCommand; -import OneQ.OnSurvey.domain.question.model.dto.type.DefaultQuestionDto; -import OneQ.OnSurvey.domain.question.service.QuestionQueryService; -import OneQ.OnSurvey.domain.survey.SurveyErrorCode; -import OneQ.OnSurvey.domain.survey.entity.Survey; import OneQ.OnSurvey.domain.survey.model.SurveyStatus; import OneQ.OnSurvey.domain.survey.model.request.InsertQuestionAnswerRequest; import OneQ.OnSurvey.domain.survey.model.request.InsertScreeningAnswerRequest; import OneQ.OnSurvey.domain.survey.model.request.SurveyParticipationCompletionRequest; import OneQ.OnSurvey.domain.survey.model.response.*; -import OneQ.OnSurvey.domain.survey.repository.SurveyRepository; import OneQ.OnSurvey.domain.survey.service.command.SurveyCommandService; import OneQ.OnSurvey.domain.survey.service.query.SurveyQuery; import OneQ.OnSurvey.global.auth.custom.CustomUserDetails; -import OneQ.OnSurvey.global.common.exception.CustomException; import OneQ.OnSurvey.global.common.response.SuccessResponse; import io.swagger.v3.oas.annotations.Operation; import jakarta.validation.Valid; @@ -32,9 +25,6 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; -import java.time.LocalDateTime; -import java.util.List; - @Slf4j @RestController @RequestMapping("/v1/survey-participation") @@ -47,9 +37,6 @@ public class ParticipationController { private final ResponseCommand responseCommand; private final SurveyCommandService surveyCommandService; - private final QuestionQueryService questionQueryService; - private final SurveyRepository surveyRepository; - @GetMapping("surveys/ongoing/all") @Operation(summary = "열려있는 설문을 모두 조회합니다.") public SuccessResponse getOngoingSurveyList( @@ -68,89 +55,6 @@ public SuccessResponse getOngoingSurveyList( return SuccessResponse.ok(results); } - @Deprecated(forRemoval = true) - @GetMapping("surveys/ongoing") - @Operation(summary = "노출 중인 설문을 조회합니다.") - public SuccessResponse getSurveyListOnGoing( - @AuthenticationPrincipal CustomUserDetails principal, - @RequestParam(required = false, defaultValue = "0") Long lastSurveyId, - @RequestParam(defaultValue = "15") Integer size - ) { - log.info("[PARTICIPATION] 노출 중 설문 조회 - lastSurveyId: {}, size: {}", lastSurveyId, size); - - Pageable recommendedPageable = PageRequest.of(0, size, Sort.by("id")); - Pageable impendingPageable = PageRequest.of(0, size, Sort.by( - Sort.Order.asc("deadline"), - Sort.Order.asc("id") - )); - - SurveyParticipationResponse.SliceSurveyData recommended = surveyQueryService.getParticipationSurveyList( - lastSurveyId, recommendedPageable, SurveyStatus.ONGOING, principal.getMemberId(), principal.getUserKey() - ); - SurveyParticipationResponse.SliceSurveyData impending = surveyQueryService.getParticipationSurveyList( - lastSurveyId, LocalDateTime.now(), impendingPageable, SurveyStatus.ONGOING, principal.getMemberId(), principal.getUserKey() - ); - - SurveyParticipationResponse response = SurveyParticipationResponse.builder() - .recommended(recommended.getSurveyDataList()) - .impending(impending.getSurveyDataList()) - .recommendedHasNext(recommended.getHasNext()) - .impendingHasNext(impending.getHasNext()) - .build(); - - return SuccessResponse.ok(response); - } - - @Deprecated(forRemoval = true) - @GetMapping("surveys/ongoing/recommended") - @Operation(summary = "사용자 추천 설문을 조회합니다.") - public SuccessResponse getRecommendedSurveyList( - @AuthenticationPrincipal CustomUserDetails principal, - @RequestParam(required = false, defaultValue = "0") Long lastSurveyId, - @RequestParam(defaultValue = "15") Integer size - ) { - log.info("[PARTICIPATION] 사용자 추천 설문 조회 - lastSurveyId: {}, size: {}", lastSurveyId, size); - - Pageable pageable = PageRequest.of(0, size, Sort.by("id")); - SurveyParticipationResponse.SliceSurveyData recommended = - surveyQueryService.getParticipationSurveyList(lastSurveyId, pageable, SurveyStatus.ONGOING, principal.getMemberId(), principal.getUserKey() - ); - - SurveyParticipationResponse response = SurveyParticipationResponse.builder() - .recommended(recommended.getSurveyDataList()) - .recommendedHasNext(recommended.getHasNext()) - .build(); - - return SuccessResponse.ok(response); - } - - @Deprecated(forRemoval = true) - @GetMapping("surveys/ongoing/impending") - @Operation(summary = "마감 임박 설문을 조회합니다.") - public SuccessResponse getImpendingSurveyList( - @AuthenticationPrincipal CustomUserDetails principal, - @RequestParam(required = false, defaultValue = "0") Long lastSurveyId, - @RequestParam(required = false) LocalDateTime lastDeadline, - @RequestParam(defaultValue = "15") Integer size - ) { - log.info("[PARTICIPATION] 마감 임박 설문 조회 - lastSurveyId: {}, lastDeadline: {}, size: {}", lastSurveyId, lastDeadline, size); - - Pageable pageable = PageRequest.of(0, size, Sort.by( - Sort.Order.asc("deadline"), - Sort.Order.asc("id") - )); - SurveyParticipationResponse.SliceSurveyData impending = - surveyQueryService.getParticipationSurveyList(lastSurveyId, lastDeadline, pageable, SurveyStatus.ONGOING, principal.getMemberId(), principal.getUserKey() - ); - - SurveyParticipationResponse response = SurveyParticipationResponse.builder() - .impending(impending.getSurveyDataList()) - .impendingHasNext(impending.getHasNext()) - .build(); - - return SuccessResponse.ok(response); - } - @GetMapping("surveys/info") @Operation(summary = "선택한 설문의 기본 정보를 조회합니다.") public SuccessResponse getSurveyInfo( @@ -174,36 +78,6 @@ public SuccessResponse getQuestionsOfSurveyId( return SuccessResponse.ok(surveyQueryService.getParticipationQuestionInfo(surveyId, section, principal.getUserKey())); } - /** - * @deprecated - * @code GET /surveys/info - * @code GET /surveys/questions - */ - @Deprecated(forRemoval = true) - @GetMapping("surveys") - @Operation(summary = "선택한 설문을 조회합니다.") - public SuccessResponse getTotalSurveyInfoOfSurveyId( - @RequestParam Long surveyId, - @AuthenticationPrincipal CustomUserDetails principal - ) { - log.info("[PARTICIPATION] 응답하고자 하는 설문 문항조회 - surveyId: {}", surveyId); - - Survey survey = surveyQueryService.getSurveyById(surveyId); - - if (surveyQueryService.checkValidSegmentation(surveyId, principal.getUserKey())) { - log.warn("[PARTICIPATION] 세그먼트 불일치로 인한 설문 응답 불가 - surveyId: {}, userKey: {}", surveyId, principal.getUserKey()); - throw new CustomException(SurveyErrorCode.SURVEY_WRONG_SEGMENTATION); - } - - List questionDtoList = questionQueryService.getQuestionDtoListBySurveyId(surveyId); - ParticipationStatus participationStatus = surveyRepository.getParticipationStatus(surveyId, principal.getMemberId()); - - DeprecatedQuestionResponse body = - DeprecatedQuestionResponse.of(survey, questionDtoList, participationStatus); - - return SuccessResponse.ok(body); - } - @GetMapping("surveys/screenings") @Operation(summary = "세그멘테이션에 일치하는 설문의 스크리닝 문항을 조회합니다.") public SuccessResponse getRecommendedScreenings( diff --git a/src/main/java/OneQ/OnSurvey/domain/survey/model/dto/ParticipationInfoVO.java b/src/main/java/OneQ/OnSurvey/domain/survey/model/dto/ParticipationInfoVO.java new file mode 100644 index 00000000..0ac0db40 --- /dev/null +++ b/src/main/java/OneQ/OnSurvey/domain/survey/model/dto/ParticipationInfoVO.java @@ -0,0 +1,37 @@ +package OneQ.OnSurvey.domain.survey.model.dto; + +import OneQ.OnSurvey.domain.member.value.Interest; +import OneQ.OnSurvey.domain.participation.model.dto.ParticipationStatus; + +import java.time.LocalDateTime; +import java.util.Set; + +public record ParticipationInfoVO( + Long surveyId, + String title, + String description, + Integer totalSections, + LocalDateTime deadline, + Set interests, + ParticipationStatus participationStatus, + Boolean isFree +) { + public ParticipationInfoVO( + Long surveyId, + String title, + String description, + Integer totalSections, + LocalDateTime deadline, + Set interests, + Long screeningId, + Boolean eIsScreened, + Boolean eIsResponded, + Boolean isFree + ) { + this( + surveyId, title, description, totalSections, deadline, interests, + ParticipationStatus.generateStatus(screeningId, eIsScreened, eIsResponded), + isFree + ); + } +} diff --git a/src/main/java/OneQ/OnSurvey/domain/survey/model/response/DeprecatedQuestionResponse.java b/src/main/java/OneQ/OnSurvey/domain/survey/model/response/DeprecatedQuestionResponse.java deleted file mode 100644 index 67c7d6f2..00000000 --- a/src/main/java/OneQ/OnSurvey/domain/survey/model/response/DeprecatedQuestionResponse.java +++ /dev/null @@ -1,49 +0,0 @@ -package OneQ.OnSurvey.domain.survey.model.response; - -import OneQ.OnSurvey.domain.member.value.Interest; -import OneQ.OnSurvey.domain.participation.model.dto.ParticipationStatus; -import OneQ.OnSurvey.domain.question.model.dto.type.DefaultQuestionDto; -import OneQ.OnSurvey.domain.survey.entity.Survey; - -import java.time.LocalDateTime; -import java.util.List; -import java.util.Set; - -public record DeprecatedQuestionResponse( - Long surveyId, - Long memberId, - String title, - String description, - Boolean isFree, - Set interests, - LocalDateTime deadline, - List info, - boolean isScreenRequired, - boolean isScreened, - boolean isSurveyResponded -) { - - public static DeprecatedQuestionResponse of( - Survey survey, - List info, - ParticipationStatus participationStatus - ) { - Set interestsSet = survey.getInterests() != null - ? new java.util.HashSet<>(survey.getInterests()) - : java.util.Collections.emptySet(); - - return new DeprecatedQuestionResponse( - survey.getId(), - survey.getMemberId(), - survey.getTitle(), - survey.getDescription(), - survey.getIsFree(), - interestsSet, - survey.getDeadline(), - info, - participationStatus.isScreenRequired(), - participationStatus.isScreened(), - participationStatus.isSurveyResponded() - ); - } -} diff --git a/src/main/java/OneQ/OnSurvey/domain/survey/model/response/ParticipationInfoResponse.java b/src/main/java/OneQ/OnSurvey/domain/survey/model/response/ParticipationInfoResponse.java index 4d4e7bac..9c1d9f89 100644 --- a/src/main/java/OneQ/OnSurvey/domain/survey/model/response/ParticipationInfoResponse.java +++ b/src/main/java/OneQ/OnSurvey/domain/survey/model/response/ParticipationInfoResponse.java @@ -1,8 +1,7 @@ package OneQ.OnSurvey.domain.survey.model.response; import OneQ.OnSurvey.domain.member.value.Interest; -import OneQ.OnSurvey.domain.participation.model.dto.ParticipationStatus; -import OneQ.OnSurvey.domain.survey.entity.Survey; +import OneQ.OnSurvey.domain.survey.model.dto.ParticipationInfoVO; import java.time.LocalDateTime; import java.util.Set; @@ -11,6 +10,7 @@ public record ParticipationInfoResponse( Long surveyId, String title, String description, + Integer totalSections, LocalDateTime deadline, Set interests, Integer responseCount, @@ -20,19 +20,12 @@ public record ParticipationInfoResponse( Boolean isFree ) { public static ParticipationInfoResponse from( - Survey survey, int responseCount, ParticipationStatus participationStatus + ParticipationInfoVO vo, int responseCount ) { return new ParticipationInfoResponse( - survey.getId(), - survey.getTitle(), - survey.getDescription(), - survey.getDeadline(), - survey.getInterests(), - responseCount, - participationStatus.isScreenRequired(), - participationStatus.isScreened(), - participationStatus.isSurveyResponded(), - survey.getIsFree() + vo.surveyId(), vo.title(), vo.description(), vo.totalSections(), vo.deadline(), vo.interests(), responseCount, + vo.participationStatus().isScreenRequired(), vo.participationStatus().isScreened(), vo.participationStatus().isSurveyResponded(), + vo.isFree() ); } } 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 621e0cfe..8279fdf1 100644 --- a/src/main/java/OneQ/OnSurvey/domain/survey/repository/SurveyRepository.java +++ b/src/main/java/OneQ/OnSurvey/domain/survey/repository/SurveyRepository.java @@ -1,12 +1,12 @@ package OneQ.OnSurvey.domain.survey.repository; import OneQ.OnSurvey.domain.member.dto.MemberSegmentation; -import OneQ.OnSurvey.domain.participation.model.dto.ParticipationStatus; 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.ParticipationInfoVO; import OneQ.OnSurvey.domain.survey.model.dto.SurveyListView; import OneQ.OnSurvey.domain.survey.model.dto.SurveySearchQuery; import OneQ.OnSurvey.domain.survey.model.dto.SurveyWithEligibility; @@ -30,13 +30,10 @@ List getSurveyIdListByFilters( Slice getSurveyListWithEligibility( Long lastSurveyId, LocalDateTime lastDeadline, Pageable pageable, SurveyStatus status, Long creatorId, Collection excludedIds, MemberSegmentation memberSegmentation); - Survey save(Survey survey); - SurveyStatus getSurveyStatusById(Long surveyId); - ParticipationStatus getParticipationStatus(Long surveyId, Long memberId); List closeDueSurveys(); - List findOngoingSurveys(); OpenSurveyStats findOpenSurveyStats(); + ParticipationInfoVO getParticipationInfoVO(Long surveyId, Long memberId); } 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 42a6935c..7c4d03a9 100644 --- a/src/main/java/OneQ/OnSurvey/domain/survey/repository/SurveyRepositoryImpl.java +++ b/src/main/java/OneQ/OnSurvey/domain/survey/repository/SurveyRepositoryImpl.java @@ -2,7 +2,6 @@ import OneQ.OnSurvey.domain.member.dto.MemberSegmentation; import OneQ.OnSurvey.domain.member.value.Interest; -import OneQ.OnSurvey.domain.participation.model.dto.ParticipationStatus; import OneQ.OnSurvey.domain.survey.entity.Survey; import OneQ.OnSurvey.domain.survey.model.AgeRange; import OneQ.OnSurvey.domain.survey.model.Gender; @@ -10,6 +9,7 @@ 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.ParticipationInfoVO; import OneQ.OnSurvey.domain.survey.model.dto.SurveyDetailData; import OneQ.OnSurvey.domain.survey.model.dto.SurveyListView; import OneQ.OnSurvey.domain.survey.model.dto.SurveySearchQuery; @@ -40,6 +40,7 @@ import static OneQ.OnSurvey.domain.survey.entity.QScreening.screening; import static OneQ.OnSurvey.domain.survey.entity.QSurvey.survey; import static OneQ.OnSurvey.domain.survey.entity.QSurveyInfo.surveyInfo; +import static OneQ.OnSurvey.domain.question.entity.QSection.section; import static com.querydsl.core.group.GroupBy.groupBy; import static com.querydsl.core.group.GroupBy.set; @@ -198,36 +199,6 @@ public SurveyStatus getSurveyStatusById(Long surveyId) { .fetchOne(); } - @Override - public ParticipationStatus getParticipationStatus(Long surveyId, Long memberId) { - Tuple statusResult = jpaQueryFactory - .select( - screening.id, // 스크리닝 존재 여부 - response.isScreened, // 스크리닝 응답 여부 - response.isResponded // 설문 응답 여부 - ) - .from(survey) - .leftJoin(screening).on( - survey.id.eq(screening.surveyId) - ) - .leftJoin(response).on( - survey.id.eq(response.surveyId), - response.memberId.eq(memberId) - ) - .where(survey.id.eq(surveyId)) - .fetchOne(); - - if (statusResult == null) { - return ParticipationStatus.defaultStatus(false); - } - - Long screeningId = statusResult.get(screening.id); - Boolean isScreened = statusResult.get(response.isScreened); - Boolean isResponded = statusResult.get(response.isResponded); - - return ParticipationStatus.generateStatus(screeningId, isScreened, isResponded); - } - @Override public List getSurveyIdListByFilters( Long lastSurveyId, LocalDateTime lastDeadline, Pageable pageable, @@ -337,4 +308,41 @@ public OpenSurveyStats findOpenSurveyStats() { Integer maxCoin = result.get(surveyInfo.promotionAmount.max()); return OpenSurveyStats.of(count, maxCoin); } + + @Override + public ParticipationInfoVO getParticipationInfoVO(Long surveyId, Long memberId) { + EnumPath interestAlias = Expressions.enumPath(Interest.class, "interestAlias"); + + return jpaQueryFactory + .from(survey) + .leftJoin(section).on(survey.id.eq(section.surveyId)) + .leftJoin(survey.interests, interestAlias) + .leftJoin(screening).on( + survey.id.eq(screening.surveyId) + ) + .leftJoin(response).on( + survey.id.eq(response.surveyId), + response.memberId.eq(memberId) + ) + .where( + survey.id.eq(surveyId), + survey.status.eq(SurveyStatus.ONGOING) + ) + .groupBy(survey.id, survey.title, survey.description, survey.deadline, interestAlias, + screening.id, response.isScreened, response.isResponded, survey.isFree + ) + .transform( + groupBy(survey.id).as(Projections.constructor(ParticipationInfoVO.class, + survey.id, + survey.title, + survey.description, + section.sectionId.coalesce(1L).countDistinct().intValue(), // 최소 하나의 섹션 개수를 가지도록 coalesce 처리 + survey.deadline, + set(interestAlias), + screening.id, // 스크리닝 존재 여부 + response.isScreened, // 스크리닝 응답 여부 + response.isResponded, // 설문 응답 여부 + survey.isFree + ))).get(surveyId); + } } 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 ad53bf23..2f530d62 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 @@ -13,7 +13,6 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import java.time.LocalDateTime; import java.util.List; public interface SurveyQuery { @@ -22,13 +21,6 @@ public interface SurveyQuery { SurveyParticipationResponse getParticipationSurveySlice( Long lastSurveyId, Pageable pageable, SurveyStatus status, Long memberId, Long userKey ); - - SurveyParticipationResponse.SliceSurveyData getParticipationSurveyList( - Long lastSurveyId, Pageable pageable, SurveyStatus status, Long memberId, Long userKey - ); - SurveyParticipationResponse.SliceSurveyData getParticipationSurveyList( - Long lastSurveyId, LocalDateTime lastDeadline, Pageable pageable, SurveyStatus status, Long memberId, Long userKey - ); ParticipationScreeningListResponse getScreeningList( Long lastSurveyId, Pageable pageable, Long memberId, Long userKey ); 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 2daa19ee..efc75d0f 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 @@ -3,7 +3,6 @@ import OneQ.OnSurvey.domain.member.dto.MemberSegmentation; import OneQ.OnSurvey.domain.member.repository.MemberRepository; import OneQ.OnSurvey.domain.member.value.Interest; -import OneQ.OnSurvey.domain.participation.model.dto.ParticipationStatus; import OneQ.OnSurvey.domain.participation.repository.response.ResponseRepository; import OneQ.OnSurvey.domain.question.model.dto.SectionDto; import OneQ.OnSurvey.domain.question.model.dto.type.DefaultQuestionDto; @@ -143,54 +142,6 @@ public SurveyParticipationResponse getParticipationSurveySlice( .build(); } - @Override - public SurveyParticipationResponse.SliceSurveyData getParticipationSurveyList( - Long lastSurveyId, Pageable pageable, SurveyStatus status, Long memberId, Long userKey - ) { - log.info("[SURVEY:QUERY:getParticipationSurveyList] 본인 제작 제외 설문 조회 - " - + "lastSurveyId: {}, size: {}, status: {}, userKey: {}", - lastSurveyId, pageable.getPageSize(), status.name(), userKey - ); - - List excludedIdList = responseRepository.getExcludedSurveyIdList(memberId, true); - MemberSegmentation memberSegmentation = memberRepository.findMemberSegmentByUserKey(userKey); - log.info("[SURVEY:QUERY:getParticipationSurveyList] 사용자 세그멘테이션 - userKey: {}, memberSegmentation: {}, excludedIdList: {}", - userKey, memberSegmentation, excludedIdList); - - Slice recommendedList = surveyRepository.getSurveyListWithEligibility( - lastSurveyId, null, pageable, status, memberId, excludedIdList, memberSegmentation - ); - log.info("[SURVEY:QUERY:getParticipationSurveyList] 추천 설문 조회 결과 - recommended: {}", recommendedList); - - return new SurveyParticipationResponse.SliceSurveyData( - recommendedList.stream().map(SurveyParticipationResponse::from).toList(), recommendedList.hasNext() - ); - } - - @Override - public SurveyParticipationResponse.SliceSurveyData getParticipationSurveyList( - Long lastSurveyId, LocalDateTime lastDeadline, Pageable pageable, SurveyStatus status, Long memberId, Long userKey - ) { - log.info("[SURVEY:QUERY:getParticipationSurveyList] 본인 제작 제외 마감기한 기반 설문 조회 - " - + "lastSurveyId: {}, lastDateTime: {}, size: {}, status: {}, userKey: {}", - lastSurveyId, lastDeadline, pageable.getPageSize(), status.name(), userKey - ); - - List excludedIdList = responseRepository.getExcludedSurveyIdList(memberId, true); - MemberSegmentation memberSegmentation = memberRepository.findMemberSegmentByUserKey(userKey); - log.info("[SURVEY:QUERY:getParticipationSurveyList] 사용자 세그멘테이션 - userKey: {}, memberSegmentation: {}, excludedIdList: {}", - userKey, memberSegmentation, excludedIdList); - - Slice impendingList = surveyRepository.getSurveyListWithEligibility( - lastSurveyId, lastDeadline, pageable, status, memberId, excludedIdList, memberSegmentation - ); - log.info("[SURVEY:QUERY:getParticipationSurveyList] 마감임박 설문 조회 결과 - impending: {}", impendingList); - - return new SurveyParticipationResponse.SliceSurveyData( - impendingList.stream().map(SurveyParticipationResponse::from).toList(), impendingList.hasNext() - ); - } - @Override public ParticipationScreeningListResponse getScreeningList( Long lastSurveyId, Pageable pageable, Long memberId, Long userKey @@ -228,27 +179,26 @@ public ParticipationInfoResponse getParticipationInfo(Long surveyId, Long userKe throw new CustomException(SurveyErrorCode.SURVEY_WRONG_SEGMENTATION); } - Survey survey = surveyRepository.getSurveyById(surveyId) - .orElseThrow(() -> new CustomException(SurveyErrorCode.SURVEY_NOT_FOUND)); + ParticipationInfoVO vo = surveyRepository.getParticipationInfoVO(surveyId, memberId); - if (!isSurveyAccessible(survey.getStatus())) { - log.warn("[SURVEY:QUERY] 마감된 설문 참여 불가 - surveyId: {}, status: {}", surveyId, survey.getStatus()); + // surveyId에 해당하는 설문이 없거나 상태가 ONGOING이 아닌 경우 + if (vo == null) { + log.warn("[SURVEY:QUERY] 마감된 설문 참여 불가 - surveyId: {}", surveyId); throw new CustomException(SurveyErrorCode.SURVEY_INCORRECT_STATUS); } - int completedCount = redisAgent.getIntValue(this.completedKey + surveyId); - ParticipationStatus participationStatus = surveyRepository.getParticipationStatus(surveyId, memberId); - if (participationStatus.isScreenRequired()) { + + if (vo.participationStatus().isScreenRequired()) { log.warn("[SURVEY:QUERY] 스크리닝 퀴즈 응답이 필요합니다. - surveyId: {}, memberId: {}", surveyId, memberId); } - if (participationStatus.isScreened()) { + if (vo.participationStatus().isScreened()) { log.warn("[SURVEY:QUERY] 스크리닝 퀴즈에 의해 필터링되었습니다. - surveyId: {}, memberId: {}", surveyId, memberId); } - if (participationStatus.isSurveyResponded()) { + if (vo.participationStatus().isSurveyResponded()) { log.warn("[SURVEY:QUERY] 이미 참여한 설문입니다. - surveyId: {}, memberId: {}", surveyId, memberId); } - return ParticipationInfoResponse.from(survey, completedCount, participationStatus); + return ParticipationInfoResponse.from(vo, completedCount); } @Override