Skip to content

Commit

Permalink
feat: 포트폴리오 조회 기능 수정 [core-domain]
Browse files Browse the repository at this point in the history
  • Loading branch information
dbwp031 committed Jul 26, 2024
1 parent efbf912 commit 0014da0
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.sponus.coredomain.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.querydsl.jpa.impl.JPAQueryFactory;

import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;

@Configuration
public class QuerydslConfig {
@PersistenceContext
private EntityManager entityManager;

@Bean
public JPAQueryFactory jpaQueryFactory() {
return new JPAQueryFactory(entityManager);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.sponus.coredomain.domain.portfolio.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import com.sponus.coredomain.domain.portfolio.Portfolio;
import com.sponus.coredomain.domain.portfolio.repository.conditions.PortfolioSearchParam;

public interface PortfolioCustomRepository {
Page<Portfolio> findAllByConditions(PortfolioSearchParam portfolioSearchParam, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.sponus.coredomain.domain.portfolio.repository;

import static com.sponus.coredomain.domain.portfolio.QPortfolio.*;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.support.PageableExecutionUtils;

import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import com.sponus.coredomain.domain.portfolio.Portfolio;
import com.sponus.coredomain.domain.portfolio.repository.conditions.PortfolioSearchParam;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class PortfolioRepositoryImpl implements PortfolioCustomRepository {
private final JPAQueryFactory queryFactory;

@Override
public Page<Portfolio> findAllByConditions(PortfolioSearchParam portfolioSearchParam,
Pageable pageable) {
JPAQuery<Long> countQuery = queryFactory
.select(portfolio.count())
.from(portfolio);

List<Portfolio> portfolios = queryFactory
.select(portfolio)
.from(portfolio)
.where(
isClubId(portfolioSearchParam.clubId()),
isPortfolioId(portfolioSearchParam.portfolioId())
)
.orderBy(portfolio.id.asc())
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();

return PageableExecutionUtils.getPage(portfolios, pageable, countQuery::fetchOne);
}

private BooleanExpression isClubId(Long clubId) {
return clubId != null ? portfolio.club.id.eq(clubId) : null;
}

private BooleanExpression isPortfolioId(Long portfolioId) {
return portfolioId != null ? portfolio.club.id.eq(portfolioId) : null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.sponus.coredomain.domain.portfolio.repository.conditions;

public record PortfolioSearchParam(
Long portfolioId,
Long clubId
) {
}

0 comments on commit 0014da0

Please sign in to comment.