Skip to content

Commit

Permalink
feat : 내용이 같기 때문에,
Browse files Browse the repository at this point in the history
InterestPolicyListResponseDto 와 ApplyPolicyListResponseDto 를 InterestAndApplyPolicyListResponseDto 으로 병합
  • Loading branch information
LHS-11 committed Nov 15, 2023
1 parent 9d646dd commit 7ac1fa7
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

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;
import io.swagger.annotations.Api;
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
Expand Down Expand Up @@ -53,15 +50,15 @@ public CommonResponse<String> saveApplyPolicy(@AuthUser User user, @PathVariable

@GetMapping
@Operation(summary = "관심 정책 리스트 조회 API", description = "유저의 관심 정책 리스트를 보여줄 때 사용합니다.")
public CommonResponse<Page<InterestPolicyListResponseDto>> getInterestPolicesByPaging(@AuthUser User user, @RequestParam int page, @RequestParam int size) {
Page<InterestPolicyListResponseDto> result = userPolicyService.getUserPoliciesByInterestFlag(user, true, page, size);
public CommonResponse<Page<InterestAndApplyPolicyListResponseDto>> getInterestPolicesByPaging(@AuthUser User user, @RequestParam int page, @RequestParam int size) {
Page<InterestAndApplyPolicyListResponseDto> result = userPolicyService.getUserPoliciesByInterestFlag(user, true, page, size);
return CommonResponse.success(result);
}

@GetMapping("/apply")
@Operation(summary = "수혜(신청) 정책 리스트 조회 API", description = "유저의 수혜(신청) 정책 리스트를 보여줄 때 사용합니다.")
public CommonResponse<Page<ApplyPolicyListResponseDto>> getApplyPolicesByPaging(@AuthUser User user, @RequestParam int page, @RequestParam int size) {
Page<ApplyPolicyListResponseDto> result = userPolicyService.getUserPoliciesByApplyFlag(user, true, page, size);
public CommonResponse<Page<InterestAndApplyPolicyListResponseDto>> getApplyPolicesByPaging(@AuthUser User user, @RequestParam int page, @RequestParam int size) {
Page<InterestAndApplyPolicyListResponseDto> result = userPolicyService.getUserPoliciesByApplyFlag(user, true, page, size);
return CommonResponse.success(result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,39 @@

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 {

private final UserRepository userRepository;
private final PolicyRepository policyRepository;
private final UserPolicyRepository userPolicyRepository;
private final UserPolicyQueryRepository userPolicyQueryRepository;

public Page<InterestAndApplyPolicyListResponseDto> 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<InterestAndApplyPolicyListResponseDto> 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) {
Expand Down Expand Up @@ -93,47 +96,6 @@ public void saveApplyPolicy(User user, Long policyId) {
userPolicyRepository.save(findUserPolicy);
}

public Slice<InterestPolicyListResponseDto> getInterestPolicyListByPaging(User user, Long lastPolicyId, Pageable pageable) {
return userPolicyQueryRepository.searchInterestPolicyBySlice(user, lastPolicyId, pageable);
}

public Slice<ApplyPolicyListResponseDto> getApplyPolicyListByPaging(User user, Long lastPolicyId, Pageable pageable) {
return userPolicyQueryRepository.searchApplyPolicyBySlice(user, lastPolicyId, pageable);
}

public List<InterestPolicyListResponseDto> 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<ApplyPolicyListResponseDto> 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)
Expand Down Expand Up @@ -188,16 +150,46 @@ public PolicySizeResponseDto getAllApplyPolicySize(User user) {
.build();
}

public Page<InterestPolicyListResponseDto> 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<ApplyPolicyListResponseDto> 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<InterestAndApplyPolicyListResponseDto> getInterestPolicyListByPaging(User user, Long lastPolicyId, Pageable pageable) {
// return userPolicyQueryRepository.searchInterestPolicyBySlice(user, lastPolicyId, pageable);
// }
//
// public Slice<ApplyPolicyListResponseDto> getApplyPolicyListByPaging(User user, Long lastPolicyId, Pageable pageable) {
// return userPolicyQueryRepository.searchApplyPolicyBySlice(user, lastPolicyId, pageable);
// }
//
// public List<InterestAndApplyPolicyListResponseDto> 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<ApplyPolicyListResponseDto> 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());
//
// }

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -24,9 +23,9 @@ public class UserPolicyQueryRepository {
private final JPAQueryFactory jpaQueryFactory;


public Slice<InterestPolicyListResponseDto> searchInterestPolicyBySlice(User user, Long lastPolicyId, Pageable pageable) {
List<InterestPolicyListResponseDto> results = jpaQueryFactory.select(
Projections.constructor(InterestPolicyListResponseDto.class,
public Slice<InterestAndApplyPolicyListResponseDto> searchInterestPolicyBySlice(User user, Long lastPolicyId, Pageable pageable) {
List<InterestAndApplyPolicyListResponseDto> results = jpaQueryFactory.select(
Projections.constructor(InterestAndApplyPolicyListResponseDto.class,
userPolicy.policy.id,
userPolicy.policy.policyName,
userPolicy.policy.policyIntroduction,
Expand All @@ -47,28 +46,28 @@ public Slice<InterestPolicyListResponseDto> searchInterestPolicyBySlice(User use
return checkLastPage(pageable, results);
}

public Slice<ApplyPolicyListResponseDto> searchApplyPolicyBySlice(User user, Long lastPolicyId, Pageable pageable) {
List<ApplyPolicyListResponseDto> 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<ApplyPolicyListResponseDto> searchApplyPolicyBySlice(User user, Long lastPolicyId, Pageable pageable) {
// List<ApplyPolicyListResponseDto> 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) {
Expand All @@ -78,7 +77,7 @@ private BooleanExpression ltPolicyId(Long policyId) {
}

// 무한 스크롤 방식 처리하는 메서드
private Slice<InterestPolicyListResponseDto> checkLastPage(Pageable pageable, List<InterestPolicyListResponseDto> results) {
private Slice<InterestAndApplyPolicyListResponseDto> checkLastPage(Pageable pageable, List<InterestAndApplyPolicyListResponseDto> results) {

boolean hasNext = false;

Expand All @@ -91,16 +90,16 @@ private Slice<InterestPolicyListResponseDto> checkLastPage(Pageable pageable, Li
return new SliceImpl<>(results, pageable, hasNext);
}

private Slice<ApplyPolicyListResponseDto> checkLastPageApply(Pageable pageable, List<ApplyPolicyListResponseDto> 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<ApplyPolicyListResponseDto> checkLastPageApply(Pageable pageable, List<ApplyPolicyListResponseDto> results) {
//
// boolean hasNext = false;
//
// // 조회한 결과 개수가 요청한 페이지 사이즈보다 크면 뒤에 더 있음, next = true
// if (results.size() > pageable.getPageSize()) {
// hasNext = true;
// results.remove(pageable.getPageSize());
// }
//
// return new SliceImpl<>(results, pageable, hasNext);
// }
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Getter
@NoArgsConstructor
@ApiModel(description = "관심 정책 리스트 정보 조회 API response")
public class InterestPolicyListResponseDto {
public class InterestAndApplyPolicyListResponseDto {

@ApiModelProperty(notes = "정책 ID", example = "12")
private Long policyId;
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 7ac1fa7

Please sign in to comment.