Conversation
WalkthroughThis change introduces a new feature to retrieve unread articles for a user, including pagination and the total count of unread articles. It adds a new API endpoint, service and repository methods, and a response DTO to support this functionality across the controller, service, and data access layers. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Controller
participant Usecase
participant Service
participant Repository
Client->>Controller: GET /unread?pageNumber=&pageSize=
Controller->>Usecase: getUnreadArticles(user, pageNumber, pageSize)
Usecase->>Service: findAllByIsRead(userId, PageRequest)
Service->>Repository: findAllByIsReadFalse(userId, Pageable)
Repository-->>Service: ArticlesWithUnreadCount
Service-->>Usecase: ArticlesWithUnreadCount
Usecase-->>Controller: ArticleUnreadResponse
Controller-->>Client: ResponseDto<ArticleUnreadResponse>
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/main/java/com/pinback/pinback_server/domain/article/domain/service/ArticleGetService.java (1)
62-64: Consider renaming method for clarity.The method name
findAllByIsReadis misleading since it specifically finds unread articles. Consider renaming tofindAllUnreadorfindAllByIsReadFalseto better reflect the actual functionality.- public ArticlesWithUnreadCount findAllByIsRead(UUID userId, PageRequest pageRequest) { + public ArticlesWithUnreadCount findAllUnread(UUID userId, PageRequest pageRequest) { return articleRepository.findAllByIsReadFalse(userId, pageRequest); }src/main/java/com/pinback/pinback_server/domain/article/domain/repository/ArticleRepositoryCustomImpl.java (1)
111-137: Optimize redundant count queries.The implementation is functionally correct but contains redundant queries. Since you're already filtering by
isRead = false, theunReadCountquery will return the same result as thecountQuery. You can optimize this by using the same count query for both purposes.@Override public ArticlesWithUnreadCount findAllByIsReadFalse(UUID userId, Pageable pageable) { BooleanExpression conditions = article.user.id.eq(userId).and(article.isRead.isFalse()); List<Article> articles = queryFactory .selectFrom(article) .join(article.user, user).fetchJoin() .where(conditions) .offset(pageable.getOffset()) .limit(pageable.getPageSize()) .orderBy(article.createdAt.desc()) .fetch(); JPAQuery<Long> countQuery = queryFactory .select(article.count()) .from(article) .where(conditions); - Long unReadCount = queryFactory - .select(article.count()) - .from(article) - .where(conditions) - .fetchOne(); - - return new ArticlesWithUnreadCount(unReadCount, + return new ArticlesWithUnreadCount(countQuery.fetchOne(), PageableExecutionUtils.getPage(articles, pageable, countQuery::fetchOne)); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
src/main/java/com/pinback/pinback_server/domain/article/application/ArticleManagementUsecase.java(2 hunks)src/main/java/com/pinback/pinback_server/domain/article/domain/repository/ArticleRepositoryCustom.java(1 hunks)src/main/java/com/pinback/pinback_server/domain/article/domain/repository/ArticleRepositoryCustomImpl.java(1 hunks)src/main/java/com/pinback/pinback_server/domain/article/domain/service/ArticleGetService.java(1 hunks)src/main/java/com/pinback/pinback_server/domain/article/presentation/ArticleController.java(2 hunks)src/main/java/com/pinback/pinback_server/domain/article/presentation/dto/response/ArticleUnreadResponse.java(1 hunks)
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: rootTiket
PR: Pinback-Team/pinback-server#18
File: src/main/java/com/pinback/pinback_server/domain/article/application/ArticleManagementUsecase.java:38-41
Timestamp: 2025-07-07T15:33:02.748Z
Learning: In the Pinback server project, article detail retrieval (getArticleDetail method) does not require user authorization checks. Articles can be accessed by ID without ownership verification as per the project's design decision.
src/main/java/com/pinback/pinback_server/domain/article/presentation/ArticleController.java (1)
Learnt from: rootTiket
PR: Pinback-Team/pinback-server#18
File: src/main/java/com/pinback/pinback_server/domain/article/application/ArticleManagementUsecase.java:38-41
Timestamp: 2025-07-07T15:33:02.748Z
Learning: In the Pinback server project, article detail retrieval (getArticleDetail method) does not require user authorization checks. Articles can be accessed by ID without ownership verification as per the project's design decision.
src/main/java/com/pinback/pinback_server/domain/article/domain/service/ArticleGetService.java (1)
Learnt from: rootTiket
PR: Pinback-Team/pinback-server#18
File: src/main/java/com/pinback/pinback_server/domain/article/application/ArticleManagementUsecase.java:38-41
Timestamp: 2025-07-07T15:33:02.748Z
Learning: In the Pinback server project, article detail retrieval (getArticleDetail method) does not require user authorization checks. Articles can be accessed by ID without ownership verification as per the project's design decision.
src/main/java/com/pinback/pinback_server/domain/article/application/ArticleManagementUsecase.java (1)
Learnt from: rootTiket
PR: Pinback-Team/pinback-server#18
File: src/main/java/com/pinback/pinback_server/domain/article/application/ArticleManagementUsecase.java:38-41
Timestamp: 2025-07-07T15:33:02.748Z
Learning: In the Pinback server project, article detail retrieval (getArticleDetail method) does not require user authorization checks. Articles can be accessed by ID without ownership verification as per the project's design decision.
src/main/java/com/pinback/pinback_server/domain/article/domain/repository/ArticleRepositoryCustomImpl.java (1)
Learnt from: rootTiket
PR: Pinback-Team/pinback-server#18
File: src/main/java/com/pinback/pinback_server/domain/article/application/ArticleManagementUsecase.java:38-41
Timestamp: 2025-07-07T15:33:02.748Z
Learning: In the Pinback server project, article detail retrieval (getArticleDetail method) does not require user authorization checks. Articles can be accessed by ID without ownership verification as per the project's design decision.
src/main/java/com/pinback/pinback_server/domain/article/domain/repository/ArticleRepositoryCustom.java (1)
Learnt from: rootTiket
PR: Pinback-Team/pinback-server#18
File: src/main/java/com/pinback/pinback_server/domain/article/application/ArticleManagementUsecase.java:38-41
Timestamp: 2025-07-07T15:33:02.748Z
Learning: In the Pinback server project, article detail retrieval (getArticleDetail method) does not require user authorization checks. Articles can be accessed by ID without ownership verification as per the project's design decision.
🔇 Additional comments (6)
src/main/java/com/pinback/pinback_server/domain/article/domain/repository/ArticleRepositoryCustom.java (1)
19-19: LGTM! Method signature follows established patterns.The new method signature is consistent with existing methods in the interface and clearly indicates its purpose of retrieving unread articles for a user with pagination support.
src/main/java/com/pinback/pinback_server/domain/article/presentation/ArticleController.java (2)
20-20: LGTM! Import follows existing patterns.The import for
ArticleUnreadResponseis appropriately placed with other response DTOs.
94-102: LGTM! Endpoint implementation follows established patterns.The new
/unreadendpoint correctly implements:
- Authentication via
@CurrentUser- Standard pagination parameters
- Proper delegation to the use case layer
- Consistent response wrapping with
ResponseDtosrc/main/java/com/pinback/pinback_server/domain/article/presentation/dto/response/ArticleUnreadResponse.java (1)
5-15: LGTM! Clean record implementation with factory method.The record structure is well-designed with:
- Clear field names following camelCase convention
- Convenient static factory method for instantiation
- Appropriate encapsulation of unread articles data
src/main/java/com/pinback/pinback_server/domain/article/application/ArticleManagementUsecase.java (2)
25-25: Import addition looks good.The import for
ArticleUnreadResponseis properly added to support the new method return type.
209-223: Well-implemented unread articles retrieval method.The implementation follows the established patterns in the codebase:
- Appropriate use of
@Transactional(readOnly = true)for read-only operations- Consistent parameter structure with other pagination methods
- Proper service layer interaction using
articleGetService.findAllByIsRead- Standard DTO mapping pattern using streams
- Appropriate return type that includes both unread count and articles list
The method integrates seamlessly with the existing codebase architecture and maintains consistency with other similar methods.
🚀 PR 요약
기능 변경에 따라 전체조회 기능을 수정하여 안읽은 아티클 조회 기능을 구현합니다.
✨ PR 상세 내용
🚨 주의 사항
주의할 부분이 무엇인가요? - 지우고 작성
✅ 체크 리스트
Summary by CodeRabbit