Skip to content

feat: 안읽은 아티클 조회 기능 구현#73

Merged
ose0221 merged 5 commits intodevfrom
feat/#68
Jul 15, 2025
Merged

feat: 안읽은 아티클 조회 기능 구현#73
ose0221 merged 5 commits intodevfrom
feat/#68

Conversation

@ose0221
Copy link
Contributor

@ose0221 ose0221 commented Jul 15, 2025

🚀 PR 요약

기능 변경에 따라 전체조회 기능을 수정하여 안읽은 아티클 조회 기능을 구현합니다.

✨ PR 상세 내용

  • 안읽은 아티클 조회 기능 구현

🚨 주의 사항

주의할 부분이 무엇인가요? - 지우고 작성

✅ 체크 리스트

  • 리뷰어 설정했나요?
  • Label 설정했나요?
  • 제목 양식 맞췄나요? (ex. feat: 기능 추가)
  • 변경 사항에 대한 테스트를 진행했나요?

Summary by CodeRabbit

  • New Features
    • Added a new API endpoint to retrieve a paginated list of unread articles for the current user, including the total count of unread articles.
    • The response includes both the unread article count and a list of unread articles.

@ose0221 ose0221 requested a review from rootTiket July 15, 2025 18:33
@ose0221 ose0221 self-assigned this Jul 15, 2025
@ose0221 ose0221 added the FEAT label Jul 15, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jul 15, 2025

Walkthrough

This 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

File(s) Change Summary
.../ArticleManagementUsecase.java, .../ArticleGetService.java Added methods to fetch unread articles for a user, including pagination and unread count.
.../ArticleRepositoryCustom.java, .../ArticleRepositoryCustomImpl.java Introduced method to query unread articles and return total unread count with pagination.
.../presentation/ArticleController.java Added GET endpoint /unread to retrieve unread articles for the current user with pagination.
.../presentation/dto/response/ArticleUnreadResponse.java New DTO record to encapsulate total unread article count and a list of article responses.

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>
Loading

Possibly related PRs

  • Pinback-Team/pinback-server#22: Adds functionality for fetching all articles with total count; related by modifying similar service and repository layers for article retrieval.
  • Pinback-Team/pinback-server#27: Implements fetching articles by category and updating methods to include unread counts; related by use of unread counts but differs in filtering logic.

Suggested labels

feat

Suggested reviewers

  • rootTiket

Poem

Hopping through code with a twitch of my nose,
I found unread articles, bundled in rows.
With counts and with pages, the data now flows,
A new endpoint appears, as the feature list grows!
🥕✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 findAllByIsRead is misleading since it specifically finds unread articles. Consider renaming to findAllUnread or findAllByIsReadFalse to 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, the unReadCount query will return the same result as the countQuery. 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

📥 Commits

Reviewing files that changed from the base of the PR and between 15f569b and 6be61cc.

📒 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 ArticleUnreadResponse is appropriately placed with other response DTOs.


94-102: LGTM! Endpoint implementation follows established patterns.

The new /unread endpoint correctly implements:

  • Authentication via @CurrentUser
  • Standard pagination parameters
  • Proper delegation to the use case layer
  • Consistent response wrapping with ResponseDto
src/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 ArticleUnreadResponse is 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.

Copy link
Contributor

@rootTiket rootTiket left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

많이 본 코드네요 고생하셧습니다 ㅎ

@ose0221 ose0221 merged commit 317d686 into dev Jul 15, 2025
5 checks passed
@ose0221 ose0221 deleted the feat/#68 branch July 15, 2025 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants