diff --git a/src/main/java/com/cmc/zenefitserver/domain/userpolicy/api/UserPolicyController.java b/src/main/java/com/cmc/zenefitserver/domain/userpolicy/api/UserPolicyController.java index 47479a1..6bf2b40 100644 --- a/src/main/java/com/cmc/zenefitserver/domain/userpolicy/api/UserPolicyController.java +++ b/src/main/java/com/cmc/zenefitserver/domain/userpolicy/api/UserPolicyController.java @@ -2,8 +2,7 @@ import com.cmc.zenefitserver.domain.user.domain.User; import com.cmc.zenefitserver.domain.userpolicy.application.UserPolicyService; -import com.cmc.zenefitserver.domain.userpolicy.dto.ApplyPolicyListResponseDto; -import com.cmc.zenefitserver.domain.userpolicy.dto.InterestPolicyListResponseDto; +import com.cmc.zenefitserver.domain.userpolicy.dto.InterestAndApplyPolicyListResponseDto; import com.cmc.zenefitserver.domain.userpolicy.dto.PolicySizeResponseDto; import com.cmc.zenefitserver.global.annotation.AuthUser; import com.cmc.zenefitserver.global.common.CommonResponse; @@ -11,8 +10,6 @@ import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Slice; import org.springframework.web.bind.annotation.*; @RequiredArgsConstructor @@ -53,15 +50,15 @@ public CommonResponse saveApplyPolicy(@AuthUser User user, @PathVariable @GetMapping @Operation(summary = "관심 정책 리스트 조회 API", description = "유저의 관심 정책 리스트를 보여줄 때 사용합니다.") - public CommonResponse> getInterestPolicesByPaging(@AuthUser User user, @RequestParam int page, @RequestParam int size) { - Page result = userPolicyService.getUserPoliciesByInterestFlag(user, true, page, size); + public CommonResponse> getInterestPolicesByPaging(@AuthUser User user, @RequestParam int page, @RequestParam int size) { + Page result = userPolicyService.getUserPoliciesByInterestFlag(user, true, page, size); return CommonResponse.success(result); } @GetMapping("/apply") @Operation(summary = "수혜(신청) 정책 리스트 조회 API", description = "유저의 수혜(신청) 정책 리스트를 보여줄 때 사용합니다.") - public CommonResponse> getApplyPolicesByPaging(@AuthUser User user, @RequestParam int page, @RequestParam int size) { - Page result = userPolicyService.getUserPoliciesByApplyFlag(user, true, page, size); + public CommonResponse> getApplyPolicesByPaging(@AuthUser User user, @RequestParam int page, @RequestParam int size) { + Page result = userPolicyService.getUserPoliciesByApplyFlag(user, true, page, size); return CommonResponse.success(result); } diff --git a/src/main/java/com/cmc/zenefitserver/domain/userpolicy/application/UserPolicyService.java b/src/main/java/com/cmc/zenefitserver/domain/userpolicy/application/UserPolicyService.java index 9080146..cb2578a 100644 --- a/src/main/java/com/cmc/zenefitserver/domain/userpolicy/application/UserPolicyService.java +++ b/src/main/java/com/cmc/zenefitserver/domain/userpolicy/application/UserPolicyService.java @@ -2,28 +2,20 @@ import com.cmc.zenefitserver.domain.policy.dao.PolicyRepository; import com.cmc.zenefitserver.domain.policy.domain.Policy; -import com.cmc.zenefitserver.domain.policy.domain.enums.AreaCode; import com.cmc.zenefitserver.domain.user.dao.UserRepository; import com.cmc.zenefitserver.domain.user.domain.User; -import com.cmc.zenefitserver.domain.userpolicy.dao.UserPolicyQueryRepository; import com.cmc.zenefitserver.domain.userpolicy.dao.UserPolicyRepository; import com.cmc.zenefitserver.domain.userpolicy.domain.UserPolicy; -import com.cmc.zenefitserver.domain.userpolicy.dto.ApplyPolicyListResponseDto; -import com.cmc.zenefitserver.domain.userpolicy.dto.InterestPolicyListResponseDto; +import com.cmc.zenefitserver.domain.userpolicy.dto.InterestAndApplyPolicyListResponseDto; import com.cmc.zenefitserver.domain.userpolicy.dto.PolicySizeResponseDto; import com.cmc.zenefitserver.global.error.ErrorCode; import com.cmc.zenefitserver.global.error.exception.BusinessException; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Slice; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.List; -import java.util.stream.Collectors; - @RequiredArgsConstructor @Service public class UserPolicyService { @@ -31,7 +23,18 @@ public class UserPolicyService { private final UserRepository userRepository; private final PolicyRepository policyRepository; private final UserPolicyRepository userPolicyRepository; - private final UserPolicyQueryRepository userPolicyQueryRepository; + + public Page getUserPoliciesByInterestFlag(User user, boolean interestFlag, int page, int size) { + PageRequest pageable = PageRequest.of(page, size); + return userPolicyRepository.findUserPoliciesByUserAndInterestFlag(user, interestFlag, pageable) + .map(userPolicy -> InterestAndApplyPolicyListResponseDto.of(userPolicy.getPolicy())); + } + + public Page getUserPoliciesByApplyFlag(User user, boolean applyFlag, int page, int size) { + PageRequest pageable = PageRequest.of(page, size); + return userPolicyRepository.findUserPoliciesByUserAndApplyFlag(user, applyFlag, pageable) + .map(userPolicy -> InterestAndApplyPolicyListResponseDto.of(userPolicy.getPolicy())); + } @Transactional public void saveInterestPolicy(User user, Long policyId) { @@ -93,47 +96,6 @@ public void saveApplyPolicy(User user, Long policyId) { userPolicyRepository.save(findUserPolicy); } - public Slice getInterestPolicyListByPaging(User user, Long lastPolicyId, Pageable pageable) { - return userPolicyQueryRepository.searchInterestPolicyBySlice(user, lastPolicyId, pageable); - } - - public Slice getApplyPolicyListByPaging(User user, Long lastPolicyId, Pageable pageable) { - return userPolicyQueryRepository.searchApplyPolicyBySlice(user, lastPolicyId, pageable); - } - - public List getInterestPolicyList(User user) { - return userPolicyRepository.findAllByUser_userIdAndInterestFlag(user.getUserId(), true) - .stream() - .map(entity -> { - Policy policy = entity.getPolicy(); - InterestPolicyListResponseDto dto = InterestPolicyListResponseDto.builder() - .policyId(policy.getId()) - .policyName(policy.getPolicyName()) - .policyIntroduction(policy.getPolicyIntroduction()) - .policyLogo(policy.getPolicyLogo()) - .build(); - return dto; - }) - .collect(Collectors.toList()); - } - - public List getApplyPolicyList(User user) { - return userPolicyRepository.findAllByUser_userIdAndApplyFlag(user.getUserId(), true) - .stream() - .map(entity -> { - Policy policy = entity.getPolicy(); - ApplyPolicyListResponseDto dto = ApplyPolicyListResponseDto.builder() - .policyId(policy.getId()) - .policyName(policy.getPolicyName()) - .policyIntroduction(policy.getPolicyIntroduction()) - .policyLogo(policy.getPolicyLogo()) - .build(); - return dto; - }) - .collect(Collectors.toList()); - - } - @Transactional public void deleteInterestPolicy(User user, Long policyId) { UserPolicy findUserPolicy = userPolicyRepository.findByUser_userIdAndPolicy_Id(user.getUserId(), policyId) @@ -188,16 +150,46 @@ public PolicySizeResponseDto getAllApplyPolicySize(User user) { .build(); } - public Page getUserPoliciesByInterestFlag(User user, boolean interestFlag, int page, int size) { - PageRequest pageable = PageRequest.of(page, size); - return userPolicyRepository.findUserPoliciesByUserAndInterestFlag(user, interestFlag, pageable) - .map(userPolicy -> InterestPolicyListResponseDto.of(userPolicy.getPolicy())); - } - public Page getUserPoliciesByApplyFlag(User user, boolean applyFlag, int page, int size) { - PageRequest pageable = PageRequest.of(page, size); - return userPolicyRepository.findUserPoliciesByUserAndApplyFlag(user, applyFlag, pageable) - .map(userPolicy -> ApplyPolicyListResponseDto.of(userPolicy.getPolicy())); - } +// public Slice getInterestPolicyListByPaging(User user, Long lastPolicyId, Pageable pageable) { +// return userPolicyQueryRepository.searchInterestPolicyBySlice(user, lastPolicyId, pageable); +// } +// +// public Slice getApplyPolicyListByPaging(User user, Long lastPolicyId, Pageable pageable) { +// return userPolicyQueryRepository.searchApplyPolicyBySlice(user, lastPolicyId, pageable); +// } +// +// public List getInterestPolicyList(User user) { +// return userPolicyRepository.findAllByUser_userIdAndInterestFlag(user.getUserId(), true) +// .stream() +// .map(entity -> { +// Policy policy = entity.getPolicy(); +// InterestAndApplyPolicyListResponseDto dto = InterestAndApplyPolicyListResponseDto.builder() +// .policyId(policy.getId()) +// .policyName(policy.getPolicyName()) +// .policyIntroduction(policy.getPolicyIntroduction()) +// .policyLogo(policy.getPolicyLogo()) +// .build(); +// return dto; +// }) +// .collect(Collectors.toList()); +// } +// +// public List getApplyPolicyList(User user) { +// return userPolicyRepository.findAllByUser_userIdAndApplyFlag(user.getUserId(), true) +// .stream() +// .map(entity -> { +// Policy policy = entity.getPolicy(); +// ApplyPolicyListResponseDto dto = ApplyPolicyListResponseDto.builder() +// .policyId(policy.getId()) +// .policyName(policy.getPolicyName()) +// .policyIntroduction(policy.getPolicyIntroduction()) +// .policyLogo(policy.getPolicyLogo()) +// .build(); +// return dto; +// }) +// .collect(Collectors.toList()); +// +// } } diff --git a/src/main/java/com/cmc/zenefitserver/domain/userpolicy/dao/UserPolicyQueryRepository.java b/src/main/java/com/cmc/zenefitserver/domain/userpolicy/dao/UserPolicyQueryRepository.java index e0cc4ea..5c585c5 100644 --- a/src/main/java/com/cmc/zenefitserver/domain/userpolicy/dao/UserPolicyQueryRepository.java +++ b/src/main/java/com/cmc/zenefitserver/domain/userpolicy/dao/UserPolicyQueryRepository.java @@ -1,8 +1,7 @@ package com.cmc.zenefitserver.domain.userpolicy.dao; import com.cmc.zenefitserver.domain.user.domain.User; -import com.cmc.zenefitserver.domain.userpolicy.dto.ApplyPolicyListResponseDto; -import com.cmc.zenefitserver.domain.userpolicy.dto.InterestPolicyListResponseDto; +import com.cmc.zenefitserver.domain.userpolicy.dto.InterestAndApplyPolicyListResponseDto; import com.querydsl.core.types.Projections; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; @@ -24,9 +23,9 @@ public class UserPolicyQueryRepository { private final JPAQueryFactory jpaQueryFactory; - public Slice searchInterestPolicyBySlice(User user, Long lastPolicyId, Pageable pageable) { - List results = jpaQueryFactory.select( - Projections.constructor(InterestPolicyListResponseDto.class, + public Slice searchInterestPolicyBySlice(User user, Long lastPolicyId, Pageable pageable) { + List results = jpaQueryFactory.select( + Projections.constructor(InterestAndApplyPolicyListResponseDto.class, userPolicy.policy.id, userPolicy.policy.policyName, userPolicy.policy.policyIntroduction, @@ -47,28 +46,28 @@ public Slice searchInterestPolicyBySlice(User use return checkLastPage(pageable, results); } - public Slice searchApplyPolicyBySlice(User user, Long lastPolicyId, Pageable pageable) { - List results = jpaQueryFactory.select( - Projections.constructor(ApplyPolicyListResponseDto.class, - userPolicy.policy.id, - userPolicy.policy.policyName, - userPolicy.policy.policyIntroduction, - userPolicy.policy.benefit, - userPolicy.policy.policyLogo - ) - ) - .from(userPolicy) - .where( - ltPolicyId(lastPolicyId), - userPolicy.user.userId.eq(user.getUserId()), - userPolicy.applyFlag.eq(true) - ) - .orderBy(userPolicy.policy.id.desc()) - .limit(pageable.getPageSize() + 1) - .fetch(); - - return checkLastPageApply(pageable, results); - } +// public Slice searchApplyPolicyBySlice(User user, Long lastPolicyId, Pageable pageable) { +// List results = jpaQueryFactory.select( +// Projections.constructor(ApplyPolicyListResponseDto.class, +// userPolicy.policy.id, +// userPolicy.policy.policyName, +// userPolicy.policy.policyIntroduction, +// userPolicy.policy.benefit, +// userPolicy.policy.policyLogo +// ) +// ) +// .from(userPolicy) +// .where( +// ltPolicyId(lastPolicyId), +// userPolicy.user.userId.eq(user.getUserId()), +// userPolicy.applyFlag.eq(true) +// ) +// .orderBy(userPolicy.policy.id.desc()) +// .limit(pageable.getPageSize() + 1) +// .fetch(); +// +// return checkLastPageApply(pageable, results); +// } private BooleanExpression ltPolicyId(Long policyId) { if (policyId == null) { @@ -78,7 +77,7 @@ private BooleanExpression ltPolicyId(Long policyId) { } // 무한 스크롤 방식 처리하는 메서드 - private Slice checkLastPage(Pageable pageable, List results) { + private Slice checkLastPage(Pageable pageable, List results) { boolean hasNext = false; @@ -91,16 +90,16 @@ private Slice checkLastPage(Pageable pageable, Li return new SliceImpl<>(results, pageable, hasNext); } - private Slice checkLastPageApply(Pageable pageable, List results) { - - boolean hasNext = false; - - // 조회한 결과 개수가 요청한 페이지 사이즈보다 크면 뒤에 더 있음, next = true - if (results.size() > pageable.getPageSize()) { - hasNext = true; - results.remove(pageable.getPageSize()); - } - - return new SliceImpl<>(results, pageable, hasNext); - } +// private Slice checkLastPageApply(Pageable pageable, List results) { +// +// boolean hasNext = false; +// +// // 조회한 결과 개수가 요청한 페이지 사이즈보다 크면 뒤에 더 있음, next = true +// if (results.size() > pageable.getPageSize()) { +// hasNext = true; +// results.remove(pageable.getPageSize()); +// } +// +// return new SliceImpl<>(results, pageable, hasNext); +// } } diff --git a/src/main/java/com/cmc/zenefitserver/domain/userpolicy/dto/ApplyPolicyListResponseDto.java b/src/main/java/com/cmc/zenefitserver/domain/userpolicy/dto/ApplyPolicyListResponseDto.java deleted file mode 100644 index 7463fb8..0000000 --- a/src/main/java/com/cmc/zenefitserver/domain/userpolicy/dto/ApplyPolicyListResponseDto.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.cmc.zenefitserver.domain.userpolicy.dto; - -import com.cmc.zenefitserver.domain.policy.domain.Policy; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.ToString; - -@ToString -@Getter -@NoArgsConstructor -@ApiModel(description = "수혜(신청) 정책 리스트 정보 조회 API response") -public class ApplyPolicyListResponseDto { - @ApiModelProperty(notes = "정책 ID", example = "12") - private Long policyId; - - @ApiModelProperty(notes = "정책 이름", example = "청년도약계좌") - private String policyName; - - @ApiModelProperty(notes = "정책 소개", example = "월 70만원을 5년 납입하면 약 5,000만원을 적립할 수 있는 청년도약계좌") - private String policyIntroduction; - - @ApiModelProperty(notes = "정책 로고", example = "기관 로고 url") - private String policyLogo; - - @Builder - private ApplyPolicyListResponseDto(Long policyId, String policyName, String policyIntroduction, String policyLogo) { - this.policyId = policyId; - this.policyName = policyName; - this.policyIntroduction = policyIntroduction; - this.policyLogo = policyLogo; - } - - public static ApplyPolicyListResponseDto of(Policy policy){ - return ApplyPolicyListResponseDto.builder() - .policyId(policy.getId()) - .policyName(policy.getPolicyName()) - .policyLogo(policy.getPolicyLogo()) - .policyIntroduction(policy.getPolicyIntroduction()) - .build(); - } - - -} diff --git a/src/main/java/com/cmc/zenefitserver/domain/userpolicy/dto/InterestPolicyListResponseDto.java b/src/main/java/com/cmc/zenefitserver/domain/userpolicy/dto/InterestAndApplyPolicyListResponseDto.java similarity index 80% rename from src/main/java/com/cmc/zenefitserver/domain/userpolicy/dto/InterestPolicyListResponseDto.java rename to src/main/java/com/cmc/zenefitserver/domain/userpolicy/dto/InterestAndApplyPolicyListResponseDto.java index 3ca8613..c7d1a39 100644 --- a/src/main/java/com/cmc/zenefitserver/domain/userpolicy/dto/InterestPolicyListResponseDto.java +++ b/src/main/java/com/cmc/zenefitserver/domain/userpolicy/dto/InterestAndApplyPolicyListResponseDto.java @@ -12,7 +12,7 @@ @Getter @NoArgsConstructor @ApiModel(description = "관심 정책 리스트 정보 조회 API response") -public class InterestPolicyListResponseDto { +public class InterestAndApplyPolicyListResponseDto { @ApiModelProperty(notes = "정책 ID", example = "12") private Long policyId; @@ -27,15 +27,15 @@ public class InterestPolicyListResponseDto { private String policyLogo; @Builder - private InterestPolicyListResponseDto(Long policyId, String policyName, String policyIntroduction, String policyLogo) { + private InterestAndApplyPolicyListResponseDto(Long policyId, String policyName, String policyIntroduction, String policyLogo) { this.policyId = policyId; this.policyName = policyName; this.policyIntroduction = policyIntroduction; this.policyLogo = policyLogo; } - public static InterestPolicyListResponseDto of(Policy policy) { - return InterestPolicyListResponseDto.builder() + public static InterestAndApplyPolicyListResponseDto of(Policy policy) { + return InterestAndApplyPolicyListResponseDto.builder() .policyId(policy.getId()) .policyName(policy.getPolicyName()) .policyLogo(policy.getPolicyLogo()) diff --git a/src/main/java/com/cmc/zenefitserver/global/infra/notification/dao/NotificationQueryRepository.java b/src/main/java/com/cmc/zenefitserver/global/infra/notification/dao/NotificationQueryRepository.java index 55ba122..9e1f9fc 100644 --- a/src/main/java/com/cmc/zenefitserver/global/infra/notification/dao/NotificationQueryRepository.java +++ b/src/main/java/com/cmc/zenefitserver/global/infra/notification/dao/NotificationQueryRepository.java @@ -1,8 +1,6 @@ package com.cmc.zenefitserver.global.infra.notification.dao; import com.cmc.zenefitserver.domain.user.domain.User; -import com.cmc.zenefitserver.domain.userpolicy.dto.ApplyPolicyListResponseDto; -import com.cmc.zenefitserver.domain.userpolicy.dto.InterestPolicyListResponseDto; import com.cmc.zenefitserver.global.infra.notification.dto.NotificationListInfoResponseDto; import com.querydsl.core.types.Projections; import com.querydsl.core.types.dsl.BooleanExpression;