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
Expand Up @@ -57,7 +57,8 @@ public void execute(CreateRecommendedLoanProductEvent event) {

RecommendedLoanProduct first = recommendedLoanProducts.stream()
.filter(it ->
it.getLoanProductBadges().contains(LoanProductBadge.LOWEST_MIN_INTEREST_RATE)
it.getLoanProductBadges().stream()
.anyMatch(badge -> badge == LoanProductBadge.LOWEST_MIN_INTEREST_RATE)
).findFirst().orElseThrow(() -> new BusinessException(ErrorCode.EMPTY_BADGES));

profileRepository.updateProfileAfterRecommend(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.List;
import java.util.UUID;

import static jakarta.persistence.FetchType.EAGER;
import static jakarta.persistence.FetchType.LAZY;

@Entity
Expand All @@ -30,7 +29,7 @@ public class RecommendedLoanProductEntity {
@JoinColumn(name = "loan_product_id")
private LoanProductEntity loanProductEntity;
private Float similarity;
@ElementCollection(fetch = EAGER)
@ElementCollection(fetch = LAZY)
private List<LoanProductBadge> loanProductBadgeList;

public static RecommendedLoanProductEntity of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
import org.springframework.data.domain.Slice;

public interface CustomRecommendedLoanProductJpaRepository {
Slice<RecommendedLoanProductProjection> findAllByProfileId(Long productId, Pageable pageable);
Slice<RecommendedLoanProductProjection> findAllByProfileIdPage(Long productId, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package finpik.jpa.repository.loanproduct.impl;

import com.querydsl.core.types.OrderSpecifier;
import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQueryFactory;
import finpik.entity.loanproduct.RecommendedLoanProductEntity;
import finpik.jpa.repository.loanproduct.CustomRecommendedLoanProductJpaRepository;
Expand All @@ -26,7 +25,7 @@ public class CustomRecommendedLoanProductJpaRepositoryImpl implements CustomReco
private final JPAQueryFactory jpaQueryFactory;
private static final String SIMILARITY_PROPERTY = "similarity";

public Slice<RecommendedLoanProductProjection> findAllByProfileId(Long profileId, Pageable pageable) {
public Slice<RecommendedLoanProductProjection> findAllByProfileIdPage(Long profileId, Pageable pageable) {
List<RecommendedLoanProductEntity> recommendedLoanProducts = jpaQueryFactory
.selectFrom(recommendedLoanProductEntity)
.leftJoin(recommendedLoanProductEntity.loanProductEntity, loanProductEntity).fetchJoin()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;

import finpik.LoanProduct;
import finpik.RecommendedLoanProduct;
Expand Down Expand Up @@ -116,33 +115,37 @@ private List<RecommendedLoanProduct> toDomainFrom(
List<RecommendedLoanProductEntity> entityList,
List<RecommendedLoanProduct> recommendedLoanProductList
) {
Map<Long, UUID> loanProductIdToRecommendedId = entityList.stream()
Map<Long, RecommendedLoanProductEntity> loanProductIdToRecommendedId = entityList.stream()
.collect(toMap(
e -> e.getLoanProductEntity().getId(),
RecommendedLoanProductEntity::getId
e -> e
));

return recommendedLoanProductList.stream()
.map(p -> RecommendedLoanProduct.rebuild(
loanProductIdToRecommendedId.get(p.getLoanProductId()),
p.getProfileId(),
p.getBankName(),
p.getLoanProductId(),
p.getProductName(),
p.getInterestRate().maxInterestRate(),
p.getInterestRate().minInterestRate(),
p.getMaxLoanLimitAmount(),
p.getSimilarity(),
p.getLoanProductBadges()
))
.map(p -> {
RecommendedLoanProductEntity entity = loanProductIdToRecommendedId.get(p.getLoanProductId());

return RecommendedLoanProduct.rebuild(
entity.getId(),
p.getProfileId(),
p.getBankName(),
p.getLoanProductId(),
p.getProductName(),
p.getInterestRate().maxInterestRate(),
p.getInterestRate().minInterestRate(),
p.getMaxLoanLimitAmount(),
p.getSimilarity(),
entity.getLoanProductBadgeList()
);
})
.toList();
}

@Override
@Transactional(readOnly = true)
public Slice<RecommendedLoanProduct> findAllRecommendedLoanProductSliceByProfileId(Long profileId, Pageable pageable) {
Slice<RecommendedLoanProductProjection> recommendedLoanProductList =
recommendedLoanProductJpaRepository.findAllByProfileId(profileId, pageable);
recommendedLoanProductJpaRepository.findAllByProfileIdPage(profileId, pageable);

List<RecommendedLoanProduct> content = recommendedLoanProductList
.stream()
Expand Down