Skip to content

Comments

[feat] posts 조회수(view_count) 기능 추가#87

Merged
k3vin7 merged 3 commits intomainfrom
feat/viewCount
Feb 22, 2026
Merged

[feat] posts 조회수(view_count) 기능 추가#87
k3vin7 merged 3 commits intomainfrom
feat/viewCount

Conversation

@k3vin7
Copy link
Contributor

@k3vin7 k3vin7 commented Feb 22, 2026

Summary

  • Post 엔티티에 view_count 컬럼 추가
  • 게시글 상세 조회(GET /posts/{postId}) 시 조회수 자동 증가
  • PostDetailResponseviewCount 필드 추가

DB 변경

  • V7__add_view_count_to_posts.sql: posts 테이블에 view_count INT NOT NULL DEFAULT 0 컬럼 추가

@gemini-code-assist
Copy link

Summary of Changes

Hello @k3vin7, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

이 PR은 게시글 조회수 기능을 도입합니다. Post 엔티티에 view_count 필드를 추가하고, 게시글 상세 조회 시 해당 필드가 자동으로 증가하도록 로직을 구현했습니다. 또한, 이 조회수 정보가 게시글 상세 응답에 포함되도록 하여 사용자들이 게시글의 인기도를 확인할 수 있도록 개선되었습니다.

Highlights

  • Post 엔티티에 조회수(view_count) 컬럼 추가: Post 엔티티에 view_count 필드가 추가되었으며, 기본값은 0으로 설정됩니다.
  • 게시글 상세 조회 시 조회수 자동 증가: GET /posts/{postId} 엔드포인트를 통해 게시글을 상세 조회할 때마다 해당 게시글의 view_count가 자동으로 1씩 증가하도록 로직이 구현되었습니다.
  • PostDetailResponse에 조회수 필드 추가: 게시글 상세 조회 응답(PostDetailResponse)에 viewCount 필드가 추가되어 클라이언트가 게시글의 조회수를 확인할 수 있습니다.
  • 데이터베이스 마이그레이션 스크립트 추가: posts 테이블에 view_count 컬럼을 추가하는 Flyway 마이그레이션 스크립트(V7__add_view_count_to_posts.sql)가 포함되었습니다.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/main/java/com/daramg/server/post/application/PostQueryService.java
    • getPostById 메서드에 @Transactional 어노테이션이 추가되었습니다.
    • getPostById 메서드 내에서 post.incrementViewCount()가 호출되도록 수정되었습니다.
  • src/main/java/com/daramg/server/post/domain/Post.java
    • view_count 필드가 기본값 0으로 추가되었습니다.
    • incrementViewCount() 메서드가 추가되었습니다.
  • src/main/java/com/daramg/server/post/dto/PostDetailResponse.java
    • viewCount 필드가 레코드에 추가되었습니다.
    • from 메서드에서 post.getViewCount()viewCount에 매핑하도록 수정되었습니다.
  • src/main/resources/db/migration/V7__add_view_count_to_posts.sql
    • posts 테이블에 view_count 컬럼이 추가되었습니다.
Activity
  • 이 PR에 대한 활동 내역은 아직 없습니다.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request successfully implements the view count feature for posts. It includes adding a view_count column to the Post entity, incrementing the view count when a post is viewed, and including the viewCount in the PostDetailResponse. The database migration script is also correctly provided. The changes are well-contained and address the stated objective.

);
}

@Transactional

Choose a reason for hiding this comment

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

medium

The @Transactional annotation is correctly applied here to ensure that the incrementViewCount() operation, which modifies the Post entity, is part of a transaction. This is good practice for data consistency.

@Transactional
public PostDetailResponse getPostById(Long postId, User user) {
Post post = entityUtils.getEntity(postId, Post.class);
post.incrementViewCount();

Choose a reason for hiding this comment

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

medium

Incrementing the view count directly within the getPostById method is a straightforward approach. However, consider if this operation should be asynchronous or debounced to prevent excessive database writes on rapid page refreshes, especially for high-traffic posts. For now, this is acceptable, but it's a potential area for optimization if performance becomes an issue.

Comment on lines +56 to +57
@Column(name = "view_count", nullable = false)
private int viewCount = 0;

Choose a reason for hiding this comment

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

medium

The addition of view_count with nullable = false and DEFAULT 0 is correctly implemented, ensuring data integrity and a sensible default value for new posts.

Comment on lines +139 to +141
public void incrementViewCount(){
viewCount++;
}

Choose a reason for hiding this comment

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

medium

The incrementViewCount() method is a simple and effective way to encapsulate the logic for increasing the view count within the Post entity itself, adhering to the principles of object-oriented design.

PostStatus postStatus,
int likeCount,
int commentCount,
int viewCount,

Choose a reason for hiding this comment

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

medium

Adding viewCount to the PostDetailResponse record ensures that the client receives the updated view count when requesting post details. This is consistent with the feature's requirements.

post.getPostStatus(),
post.getLikeCount(),
post.getCommentCount(),
post.getViewCount(),

Choose a reason for hiding this comment

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

medium

The post.getViewCount() is correctly mapped to the viewCount field in the PostDetailResponse.from method, ensuring the data is properly transferred to the DTO.

@@ -0,0 +1 @@
ALTER TABLE posts ADD COLUMN view_count INT NOT NULL DEFAULT 0;

Choose a reason for hiding this comment

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

medium

The SQL migration script correctly adds the view_count column with INT NOT NULL DEFAULT 0, which aligns with the Post entity definition and ensures that existing posts will have a default view count of 0.

@k3vin7 k3vin7 merged commit 141984d into main Feb 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant