Skip to content

feat: 댓글 likeCount 응답 포함 및 웹 좋아요 토글 연동#284

Merged
HeesooJun merged 2 commits into
developfrom
commentLike
Oct 20, 2025
Merged

feat: 댓글 likeCount 응답 포함 및 웹 좋아요 토글 연동#284
HeesooJun merged 2 commits into
developfrom
commentLike

Conversation

@HeesooJun

Copy link
Copy Markdown
Contributor
image image

DB에는 likes 배열만 저장되고 컨트롤러에서 내려주지 않으면 응답에 없어서
모델쪽에서 toJSON()에서만 likeCount = likes.length 계산
컨트롤러는 toObject() 기반으로 응답 생성 -> ikeCount 미포함

웹: 댓글 좋아요 토글 기능 추가
서버: 댓글 리스트 응답에 likeCount 포함

위 내용을 구현했습니다.

제가 한건 likeCount 계산 위치가 지금 컨트롤러라 추후에 바꿔야 할 수도 있을것 같습니다.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @HeesooJun, 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은 댓글 기능의 사용자 경험을 향상시키기 위해 서버와 웹 클라이언트 양쪽에서 변경 사항을 도입합니다. 서버는 이제 각 댓글에 대한 좋아요 수를 응답에 포함하며, 웹 애플리케이션은 사용자가 댓글에 좋아요를 누르거나 취소할 수 있는 상호작용적인 토글 버튼을 제공합니다. 이를 통해 사용자는 댓글의 인기도를 쉽게 파악하고 직접 참여할 수 있게 됩니다.

Highlights

  • 서버 응답 개선: 댓글 목록 응답에 likeCount 필드를 추가하여 각 댓글의 좋아요 수를 클라이언트에 제공합니다.
  • 웹 좋아요 토글 기능 구현: 웹 인터페이스에서 댓글 좋아요를 토글할 수 있는 기능을 추가하고, 좋아요 상태 및 개수를 시각적으로 표시합니다.
  • API 연동: 댓글 좋아요 토글을 위한 새로운 API 호출 함수를 웹 클라이언트에 추가했습니다.
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.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

안녕하세요! 댓글 좋아요 기능 추가와 likeCount 응답 포함을 위한 변경사항 잘 보았습니다. 서버와 웹 양쪽에서 필요한 기능이 잘 구현되었습니다.

서버 측에서는 likeCount를 계산하는 로직이 컨트롤러에 추가되었는데, 이 부분의 중복을 줄이고 모델에서 처리하도록 리팩토링하는 방안에 대해 코멘트를 남겼습니다. 웹 측에서는 react-query를 사용한 좋아요 토글 기능이 잘 동작하지만, 사용자 경험을 더욱 향상시킬 수 있는 낙관적 업데이트(Optimistic Update) 적용에 대한 제안을 드렸습니다.

전반적으로 기능 구현은 훌륭하며, 제안드린 내용들은 코드의 유지보수성과 사용자 경험을 개선하기 위한 것이니 참고해주시면 좋겠습니다. 수고하셨습니다!

...comment.toObject(),
isAuthor: comment.get('userId')?.equals(req.user._id),
isLiked: comment.get('likes')?.includes(req.user._id),
likeCount: comment.get('likes')?.length || 0,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

새로운 likeCount 필드가 응답에 잘 추가되었습니다. 다만, 이 로직은 apps/server/src/models/comments.tstoJSON 메서드에 정의된 로직과 중복됩니다. 작성자님께서도 PR 설명에 언급해주셨듯이, 현재는 toObject()를 사용하기 때문에 모델의 toJSON에 정의된 likeCount가 포함되지 않는 문제가 있습니다.

장기적인 유지보수성을 위해, 모델 레이어에서 데이터 가공을 처리하는 것이 좋습니다. 한 가지 방법은 Mongoose의 가상(virtual) 프로퍼티를 사용하는 것입니다. 모델 스키마에 likeCount를 가상 프로퍼티로 정의하고 toObject: { virtuals: true } 옵션을 활성화하면, 컨트롤러에서 별도의 로직 없이 comment.toObject()를 통해 일관되게 likeCount 값을 얻을 수 있습니다. 이는 코드 중복을 줄이고 역할을 명확히 분리하는 데 도움이 될 것입니다. 추후 리팩토링 시 고려해보시면 좋겠습니다.

Comment on lines +39 to +47
const likeMutation = useMutation({
mutationFn: ({ eventId, commentId }: { eventId: string; commentId: string }) => toggleEventCommentLike(eventId, commentId),
onSuccess: async () => {
await queryClient.invalidateQueries({ queryKey: ['comments', comment.eventId] })
},
onError: () => {
toast.error(<span>좋아요 처리에 실패했습니다.</span>)
},
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

좋아요 기능이 useMutation을 사용해 잘 구현되었습니다. 사용자 경험을 한 단계 더 향상시키기 위해 낙관적 업데이트(Optimistic Updates) 적용을 고려해볼 수 있습니다. 현재는 onSuccess에서 invalidateQueries를 호출하여 데이터를 다시 가져오는 방식인데, 이 경우 네트워크 지연에 따라 UI 업데이트가 늦어질 수 있습니다.

낙관적 업데이트를 사용하면, 서버 응답을 기다리지 않고 UI를 먼저 변경하여 사용자에게 즉각적인 피드백을 줄 수 있습니다. 만약 서버 요청이 실패하면 원래 상태로 되돌립니다.

react-queryonMutateonError 콜백을 사용하여 이를 구현할 수 있습니다. onMutate에서 queryClient.setQueryData를 사용해 캐시를 직접 업데이트하고, onError에서 롤백하는 방식입니다. 이 방식은 사용자에게 더 빠르고 부드러운 경험을 제공할 수 있습니다.

await queryClient.invalidateQueries({ queryKey: ['comments', comment.eventId] })
},
onError: () => {
toast.error(<span>좋아요 처리에 실패했습니다.</span>)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

좋아요가 제대로 반영되지 않았어요. 다시 시도해주세요.

이런것 처럼 문구를 바꾸는게 좋을 것 같아요.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

변경 했습니다!

@HeesooJun HeesooJun merged commit 069be8d into develop Oct 20, 2025
2 checks 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.

3 participants