-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 아티클 전체 조회 구현 #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ebd31cc
feat: User가 가지고 있는 아티클을 페이지네이션을 적용하여 조회하는 기능 구현
rootTiket db4cfa9
feat: 아티클 전체조회 기능 구현
rootTiket bb31838
test: 아티클 전체조회 기능 테스트
rootTiket 00ce3e3
fix: 스웨거 서버 추가
rootTiket 0953f1b
feat: 컨트롤러 생성
rootTiket 51a71ac
fix: 읽음 여부 추가
rootTiket f6f8cd8
fix: 최대 아티클 개수 추가
rootTiket c473efc
fix: 최대 아티클 개수 추가
rootTiket File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
12 changes: 12 additions & 0 deletions
12
.../com/pinback/pinback_server/domain/article/domain/repository/ArticleRepositoryCustom.java
This file contains hidden or 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,12 @@ | ||
| package com.pinback.pinback_server.domain.article.domain.repository; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.Pageable; | ||
|
|
||
| import com.pinback.pinback_server.domain.article.domain.entity.Article; | ||
|
|
||
| public interface ArticleRepositoryCustom { | ||
| Page<Article> findAllCustom(UUID userId, Pageable pageable); | ||
| } |
44 changes: 44 additions & 0 deletions
44
.../pinback/pinback_server/domain/article/domain/repository/ArticleRepositoryCustomImpl.java
This file contains hidden or 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,44 @@ | ||
| package com.pinback.pinback_server.domain.article.domain.repository; | ||
|
|
||
| import static com.pinback.pinback_server.domain.article.domain.entity.QArticle.*; | ||
| import static com.pinback.pinback_server.domain.user.domain.entity.QUser.*; | ||
|
|
||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.data.support.PageableExecutionUtils; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import com.pinback.pinback_server.domain.article.domain.entity.Article; | ||
| import com.querydsl.jpa.impl.JPAQuery; | ||
| import com.querydsl.jpa.impl.JPAQueryFactory; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Repository | ||
| @RequiredArgsConstructor | ||
| public class ArticleRepositoryCustomImpl implements ArticleRepositoryCustom { | ||
|
|
||
| private final JPAQueryFactory queryFactory; | ||
|
|
||
| @Override | ||
| public Page<Article> findAllCustom(UUID userId, Pageable pageable) { | ||
| List<Article> articles = queryFactory | ||
| .selectFrom(article) | ||
| .join(article.user, user).fetchJoin() | ||
| .where(article.user.id.eq(userId)) | ||
| .offset(pageable.getOffset()) | ||
| .limit(pageable.getPageSize()) | ||
| .orderBy(article.createdAt.desc()) | ||
| .fetch(); | ||
|
|
||
| JPAQuery<Long> countQuery = queryFactory | ||
| .select(article.count()) | ||
| .from(article) | ||
| .where(article.user.id.eq(userId)); | ||
|
|
||
| return PageableExecutionUtils.getPage(articles, pageable, countQuery::fetchOne); | ||
| } | ||
| } | ||
This file contains hidden or 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
This file contains hidden or 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
15 changes: 15 additions & 0 deletions
15
...m/pinback/pinback_server/domain/article/presentation/dto/response/ArticleAllResponse.java
This file contains hidden or 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,15 @@ | ||
| package com.pinback.pinback_server.domain.article.presentation.dto.response; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public record ArticleAllResponse( | ||
| long totalArticle, | ||
| List<ArticlesResponse> articles | ||
| ) { | ||
| public static ArticleAllResponse of(long totalArticle, List<ArticlesResponse> articles) { | ||
| return new ArticleAllResponse( | ||
| totalArticle, | ||
| articles | ||
| ); | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
...com/pinback/pinback_server/domain/article/presentation/dto/response/ArticlesResponse.java
This file contains hidden or 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,19 @@ | ||
| package com.pinback.pinback_server.domain.article.presentation.dto.response; | ||
|
|
||
| import com.pinback.pinback_server.domain.article.domain.entity.Article; | ||
|
|
||
| public record ArticlesResponse( | ||
| long articleId, | ||
| String url, | ||
| String memo, | ||
| boolean isRead | ||
| ) { | ||
| public static ArticlesResponse from(Article article) { | ||
| return new ArticlesResponse( | ||
| article.getId(), | ||
| article.getUrl(), | ||
| article.getMemo(), | ||
| article.isRead() | ||
| ); | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
지금 구현하신 페이지네이션 방식은 offset 기반 외에도 cursor 기반이 있으니 시간이 될 때 공부하면 좋을 것 같습니당 💪💪💪