-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
core/core-domain/src/main/java/com/sponus/coredomain/config/QuerydslConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...ain/java/com/sponus/coredomain/domain/portfolio/repository/PortfolioCustomRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
52 changes: 52 additions & 0 deletions
52
.../main/java/com/sponus/coredomain/domain/portfolio/repository/PortfolioRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...va/com/sponus/coredomain/domain/portfolio/repository/conditions/PortfolioSearchParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) { | ||
} |