Skip to content

[network] #111 댓글 생성/목록 조회/수정/삭제 API 연동 - #112

Merged
dearosmar merged 10 commits into
mainfrom
network/#111
Jul 30, 2026
Merged

[network] #111 댓글 생성/목록 조회/수정/삭제 API 연동#112
dearosmar merged 10 commits into
mainfrom
network/#111

Conversation

@dearosmar

@dearosmar dearosmar commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

☘️ 작업한 이슈

🍀 작업한 내용

  1. 댓글/대댓글 생성 API를 연동하였습니다.
  2. 댓글 목록 조회 API를 연동하였습니다.
  3. 댓글 수정 API를 연동하였습니다.
  4. 댓글 삭제 API를 연동하였습니다. 삭제 후에는 명세와 동일하게 삭제 상태 표시로 남습니다.
  5. 서버 응답과 동일하게 날짜를 바꿔주는 매핑함수를 추가하였습니다.
  6. (수정됨) 케이스를 추가하였습니다.

🍃 작업 포인트

  • 모든 변경을 useComments 훅 안에서 VITE_USE_MOCK 분기로 처리해, 댓글 UI 컴포넌트(CommentItem 등)는 수정 없이 그대로 동작합니다. 목업 모드 동작도 기존과 동일합니다.
const addComment = async (newComment) => {
  if (USE_MOCK) { … }
  const data = await api.post(ENDPOINTS.posts.comments(postId), {
    content: newComment.content,
    parentId: null,
    isPrivate: newComment.isPrivate ?? false,
  });
  setComments((prev) => [...prev, { ...mapComment(data), replies: [] }]);
};

Summary by CodeRabbit

  • 새로운 기능
    • 게시글 댓글을 실제 서버에서 불러오고 페이지 단위로 추가 로드합니다.
    • 댓글과 대댓글을 계층 구조로 표시하며, 작성·대댓글 추가·수정·삭제가 서버와 연동됩니다.
    • 댓글 작성일 옆에 수정 여부를 (수정됨)으로 구분해 표시합니다.
  • 버그 수정
    • 댓글 변경 및 삭제 결과가 화면에 즉시 반영되도록 개선했습니다.
    • 댓글 처리 중 발생한 오류를 화면에서 확인할 수 있습니다.
  • 목업 데이터
    • 수정된 대댓글이 편집된 상태로 표시되도록 보완했습니다.

@dearosmar dearosmar self-assigned this Jul 27, 2026
@dearosmar dearosmar linked an issue Jul 27, 2026 that may be closed by this pull request
4 tasks
@vercel

vercel Bot commented Jul 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sprout-efub Ready Ready Preview, Comment Jul 27, 2026 2:02pm

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 0ae2c243-7653-4f47-947d-b44f37be5c78

📥 Commits

Reviewing files that changed from the base of the PR and between 827de12 and 6692e32.

📒 Files selected for processing (1)
  • src/features/post/api/useComments.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/features/post/api/useComments.js

Walkthrough

댓글 처리를 목업 중심에서 실제 API 연동 방식으로 확장했습니다. 댓글 응답 매핑과 트리 변환, 페이징 조회, 생성·수정·삭제 API 처리를 추가했으며 편집된 댓글에는 수정 표시를 렌더링합니다.

Changes

댓글 API 및 표시 흐름

Layer / File(s) Summary
댓글 응답 매핑 및 트리 조회
src/features/post/api/useComments.js
댓글 응답을 UI 구조로 변환하고 평면 댓글을 트리로 구성하며, 실제 모드에서 idAfter 기반 페이징 조회 결과를 상태에 저장합니다.
댓글 생성·수정·삭제 API 처리
src/features/post/api/useComments.js
댓글과 대댓글 생성, 수정, 삭제를 목업 또는 실제 API로 처리하고 결과와 오류를 상태에 반영합니다.
편집 상태 표시 데이터
src/mocks/mockComments.js, src/features/post/components/CommentContent.jsx
목 댓글에 isEdited 값을 추가하고 편집된 댓글의 작성일 뒤에 (수정됨)을 표시합니다.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CommentContent
  participant useComments
  participant api
  CommentContent->>useComments: 댓글 조회 또는 변경 요청
  useComments->>api: 댓글 API 호출
  api-->>useComments: 댓글 응답 반환
  useComments-->>CommentContent: 트리 구조와 isEdited 상태 제공
  CommentContent-->>CommentContent: 편집 표시 렌더링
Loading

Possibly related PRs

Suggested labels: 🍃 feat

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 제목이 댓글 생성/목록 조회/수정/삭제 API 연동이라는 핵심 변경을 정확히 요약합니다.
Linked Issues check ✅ Passed 댓글 생성/목록 조회/수정/삭제 API 연동이 useComments와 관련 UI 반영으로 모두 포함되어 있습니다.
Out of Scope Changes check ✅ Passed 수정됨 표시와 목업 데이터 보강은 댓글 연동 요구와 직접 연결되어 있어 별도 범위 이탈로 보이지 않습니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch network/#111

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/features/post/api/useComments.js (1)

80-175: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

댓글 작성/수정/삭제 시 로딩(제출 중) 상태 처리가 빠져있어요

addComment, addReply, updateComment, deleteComment 모두 API 호출은 하지만, 진행 중임을 나타내는 상태(isSubmitting 같은)가 전혀 없어요. 에러는 setError로 잡고 있는데 반해 로딩 처리가 빠져 있는 게 아쉬워요. 이러면 사용자가 버튼을 연타했을 때 같은 요청이 중복으로 나가서 댓글이 두 번 생성되거나 삭제 요청이 중복으로 갈 수 있어요.

작은 isSubmitting state 하나 추가해서 요청 중엔 버튼을 비활성화하도록 컴포넌트에 노출해주면 좋을 것 같아요.

🚦 addComment 기준 적용 예시 (다른 3개 함수도 동일 패턴)
+  const [isSubmitting, setIsSubmitting] = useState(false);
+
   const addComment = async (newComment) => {
     if (USE_MOCK) {
       setComments((prev) => [...prev, { ...newComment, replies: [] }]);
       return;
     }
+    setIsSubmitting(true);
     try {
       const data = await api.post(ENDPOINTS.posts.comments(postId), {
         content: newComment.content,
         parentId: null,
         isPrivate: newComment.isPrivate ?? false,
       });
       setComments((prev) => [...prev, { ...mapComment(data), replies: [] }]);
     } catch (e) {
       setError(e);
+    } finally {
+      setIsSubmitting(false);
     }
   };

As per path instructions for src/features/**/api/**, "로딩/에러 상태 처리가 누락되지 않았는지 확인하고" — 위 함수들의 로딩 상태 누락을 짚었어요.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/features/post/api/useComments.js` around lines 80 - 175, 댓글 mutation 흐름에
제출 중 상태를 추가하고 외부에 노출하세요. `addComment`, `addReply`, `updateComment`,
`deleteComment` 각각의 API 요청 시작 전에 `isSubmitting`을 true로 설정하고, 성공·실패와 mock 경로를 포함해
항상 false로 복원되도록 처리해 중복 요청을 막으세요. 컴포넌트가 버튼을 비활성화할 수 있도록 해당 상태를 hook 반환값에 포함하세요.

Source: Path instructions

🧹 Nitpick comments (1)
src/features/post/api/useComments.js (1)

80-175: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

반복되는 try/catch 패턴, 작은 헬퍼로 묶어도 좋을 것 같아요

addComment, addReply, updateComment, deleteComment가 전부 try { ...api 호출... } catch (e) { setError(e) } 구조를 그대로 반복하고 있어요. 필수는 아니지만, 공통 헬퍼로 뽑으면 나중에 로딩 상태나 재시도 로직을 추가할 때 한 곳만 고치면 돼서 유지보수가 편해져요.

+  const runApiCall = async (fn) => {
+    try {
+      return await fn();
+    } catch (e) {
+      setError(e);
+      return undefined;
+    }
+  };

위처럼 만들어두고 각 함수에서 const data = await runApiCall(() => api.post(...)) 형태로 감싸면 중복이 줄어들어요.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/features/post/api/useComments.js` around lines 80 - 175, Extract the
repeated API try/catch handling into a shared runApiCall helper that executes a
request and calls setError on failure. Update addComment, addReply,
updateComment, and deleteComment to use this helper while preserving their
existing request payloads and state updates.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/features/post/api/useComments.js`:
- Around line 151-152: Update the comment-edit flow around findComment so the
!current case records an error through setError before returning. Preserve the
existing early return, and use the established error-state format or message
convention in this hook.
- Around line 55-67: Update the pagination loop in the comments-loading flow
around hasNext and idAfter to prevent unbounded requests. Add a maximum
iteration guard and stop when hasNext remains true without a valid advancing
nextIdAfter, while preserving normal pagination until the server signals
completion.
- Around line 14-27: Update mapComment to read the response fields raw.isDeleted
and raw.isEdited instead of raw.deleted and raw.edited, while preserving the
existing false defaults for missing values.

---

Outside diff comments:
In `@src/features/post/api/useComments.js`:
- Around line 80-175: 댓글 mutation 흐름에 제출 중 상태를 추가하고 외부에 노출하세요. `addComment`,
`addReply`, `updateComment`, `deleteComment` 각각의 API 요청 시작 전에 `isSubmitting`을
true로 설정하고, 성공·실패와 mock 경로를 포함해 항상 false로 복원되도록 처리해 중복 요청을 막으세요. 컴포넌트가 버튼을 비활성화할
수 있도록 해당 상태를 hook 반환값에 포함하세요.

---

Nitpick comments:
In `@src/features/post/api/useComments.js`:
- Around line 80-175: Extract the repeated API try/catch handling into a shared
runApiCall helper that executes a request and calls setError on failure. Update
addComment, addReply, updateComment, and deleteComment to use this helper while
preserving their existing request payloads and state updates.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 4f508071-0904-4b3f-8146-bc7b66762485

📥 Commits

Reviewing files that changed from the base of the PR and between 79b8896 and 827de12.

📒 Files selected for processing (3)
  • src/features/post/api/useComments.js
  • src/features/post/components/CommentContent.jsx
  • src/mocks/mockComments.js

Comment thread src/features/post/api/useComments.js
Comment thread src/features/post/api/useComments.js
Comment thread src/features/post/api/useComments.js Outdated
@dearosmar
dearosmar merged commit 847a529 into main Jul 30, 2026
3 checks passed
@dearosmar
dearosmar deleted the network/#111 branch July 30, 2026 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[network] 댓글 생성/목록 조회/수정/삭제 API 연동

2 participants