Skip to content

feat: 채팅 이미지 업로드 API 구현 (presign/confirm)#88

Open
HandoA01 wants to merge 2 commits into
developfrom
feature/chat-image
Open

feat: 채팅 이미지 업로드 API 구현 (presign/confirm)#88
HandoA01 wants to merge 2 commits into
developfrom
feature/chat-image

Conversation

@HandoA01

@HandoA01 HandoA01 commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator

작업 내용

채팅 메시지 이미지 첨부(FR-CHAT-05)를 위한 presign/confirm API 구현. (#87)

변경 사항

  • ChatImageController — presign / confirm 엔드포인트 2개, @AuthenticationPrincipal로 로그인 사용자 도출
  • ChatImageService — 공통 모듈(ImageStorageService) 사용, ImageCategory.CHAT + partyId로 발급. presign/confirm 모두 팟 참여자 검증 수행
  • ChatImageServiceTest — 참여자/비참여자 시나리오 단위 테스트 4개
  • 관련 DTO 3개 (presign 요청/응답, confirm 요청)

이슈(#87) 계획 대비 변경점

  • 참여자 검증: 이슈엔 "TODO로 남기고 뼈대 우선"이었으나, PartyParticipantRepository.existsByPartyIdAndUserIdAndStatus가 이미 있어 검증까지 구현했습니다. (실제 참여자 데이터로의 통과 테스트만 join API 머지 후)
  • confirm 후 저장 방식: 이슈엔 "confirm 후 chat_messages에 저장"이었으나, 채팅 이미지는 실시간 브로드캐스트가 필요하고 그 경로(ChatService.saveMessage + WebSocket)가 이미 있어, confirm은 검증만 하고 저장·전송은 클라이언트가 받은 key로 IMAGE 메시지를 WebSocket 발행하는 방식(기존 경로 재사용)으로 구현했습니다. 텍스트/이미지가 동일 경로로 흘러 중복을 피합니다.
  • ImageCategory.CHAT: 이미 정의돼 있어 추가 불필요.

설계

  • 팟 참여자 검증: 요청 사용자가 해당 팟에 JOINED 상태로 참여 중인지 확인. key에 적힌 partyId를 권한 근거로 삼지 않기 위함
  • DB에는 URL이 아니라 S3 객체 key 저장 (Presigned URL 만료 대응). 컬럼명 image_url → image_key 개명은 문서 방침대로 MVP 이후 별도 PR
  • 프론트 흐름: confirm 성공 후 { messageType: "IMAGE", imageUrl: key } 를 WebSocket(/app/parties/{partyId}/chat)으로 발행 (Swagger confirm 설명에 명시)

남은 작업

  • 실제 참여자 데이터로의 end-to-end 검증 — 배달팟 참여(join) API 머지 후 (코드 변경 없이 확인만)
  • 실제 S3 통합 테스트 — 로컬 AWS 자격증명 확보 후

Connected #87

Summary by CodeRabbit

  • New Features
    • Added chat image uploads through a two-step process: request an upload URL, then confirm the uploaded image.
    • Added support for validating image type and upload details.
    • Restricted chat image uploads and confirmations to joined party participants.
  • Bug Fixes
    • Invalid or unauthorized image uploads are rejected.
  • Tests
    • Added coverage for successful uploads, confirmations, and access validation.

@HandoA01 HandoA01 self-assigned this Jul 26, 2026
@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a two-step chat image upload flow with validated request/response DTOs, authenticated REST endpoints, joined-party authorization, S3 presigned upload delegation, upload confirmation, and service-level tests.

Changes

Chat image upload

Layer / File(s) Summary
Upload contracts and endpoints
src/main/java/com/leets/tdd/chat/dto/ChatImage*.java, src/main/java/com/leets/tdd/chat/controller/ChatImageController.java
Adds validated presign and confirmation requests, a presign response mapper, and POST /presign and POST /confirm endpoints.
Authorized upload service
src/main/java/com/leets/tdd/chat/service/ChatImageService.java
Requires JOINED party participation before issuing chat-image presigned URLs or confirming uploaded objects.
Upload service validation
src/test/java/com/leets/tdd/chat/service/ChatImageServiceTest.java
Tests successful storage delegation and rejection of non-participants for both upload steps.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant ChatImageController
  participant ChatImageService
  participant PartyParticipantRepository
  participant ImageStorageService
  Client->>ChatImageController: POST /presign
  ChatImageController->>ChatImageService: presignUpload(partyId, userId, contentType)
  ChatImageService->>PartyParticipantRepository: Check JOINED participation
  ChatImageService->>ImageStorageService: issueUploadUrl(CHAT, partyId, contentType)
  ImageStorageService-->>Client: Presigned upload URL and key
  Client->>ImageStorageService: Upload image
  Client->>ChatImageController: POST /confirm
  ChatImageController->>ChatImageService: confirmUpload(partyId, userId, key)
  ChatImageService->>PartyParticipantRepository: Check JOINED participation
  ChatImageService->>ImageStorageService: confirmUpload(key)
  ChatImageController-->>Client: Success response
Loading

Possibly related issues

Possibly related PRs

Suggested labels: common(공통)

Suggested reviewers: daekyochung, vyfhfhd, thesnackoverflow

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the new chat image upload API and the presign/confirm flow.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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 feature/chat-image

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

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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/main/java/com/leets/tdd/chat/service/ChatImageService.java`:
- Around line 44-48: Update ChatImageService.confirmUpload to validate the
upload key against ImageCategory.CHAT and the requested party through the
storage contract, then persist or tag a server-verifiable confirmed claim for
that key. Update the WebSocket bare-key IMAGE handling to require and consume
that claim before accepting the image, preserving participant validation and
existing upload validation.

In `@src/test/java/com/leets/tdd/chat/service/ChatImageServiceTest.java`:
- Around line 55-63: Update the ChatImageServiceTest stubbing and verification
of imageStorageService.issueUploadUrl to use eq("image/jpeg") instead of
anyString(), ensuring presignUpload forwards the request content type exactly.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e3633a5b-d21c-4881-87c6-a2784065ca72

📥 Commits

Reviewing files that changed from the base of the PR and between 0ce2711 and 1597843.

📒 Files selected for processing (6)
  • src/main/java/com/leets/tdd/chat/controller/ChatImageController.java
  • src/main/java/com/leets/tdd/chat/dto/ChatImageConfirmRequest.java
  • src/main/java/com/leets/tdd/chat/dto/ChatImagePresignRequest.java
  • src/main/java/com/leets/tdd/chat/dto/ChatImagePresignResponse.java
  • src/main/java/com/leets/tdd/chat/service/ChatImageService.java
  • src/test/java/com/leets/tdd/chat/service/ChatImageServiceTest.java

Comment thread src/main/java/com/leets/tdd/chat/service/ChatImageService.java
Comment on lines +55 to +63
when(imageStorageService.issueUploadUrl(eq(ImageCategory.CHAT), eq(PARTY_ID), anyString()))
.thenReturn(new PresignedUploadResponse(CHAT_KEY, "https://s3.example.com/put", "image/jpeg", 300));

ChatImagePresignResponse response =
chatImageService.presignUpload(PARTY_ID, USER_ID, new ChatImagePresignRequest("image/jpeg"));

assertThat(response.key()).isEqualTo(CHAT_KEY);
assertThat(response.uploadUrl()).isEqualTo("https://s3.example.com/put");
verify(imageStorageService).issueUploadUrl(eq(ImageCategory.CHAT), eq(PARTY_ID), anyString());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert the exact content type passed to storage.

Using anyString() allows the test to pass if request.contentType() is accidentally changed or ignored. Use eq("image/jpeg") in both the stub and verification so the forwarding contract is covered.

Proposed fix
-        when(imageStorageService.issueUploadUrl(eq(ImageCategory.CHAT), eq(PARTY_ID), anyString()))
+        when(imageStorageService.issueUploadUrl(eq(ImageCategory.CHAT), eq(PARTY_ID), eq("image/jpeg")))
...
-        verify(imageStorageService).issueUploadUrl(eq(ImageCategory.CHAT), eq(PARTY_ID), anyString());
+        verify(imageStorageService).issueUploadUrl(eq(ImageCategory.CHAT), eq(PARTY_ID), eq("image/jpeg"));
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
when(imageStorageService.issueUploadUrl(eq(ImageCategory.CHAT), eq(PARTY_ID), anyString()))
.thenReturn(new PresignedUploadResponse(CHAT_KEY, "https://s3.example.com/put", "image/jpeg", 300));
ChatImagePresignResponse response =
chatImageService.presignUpload(PARTY_ID, USER_ID, new ChatImagePresignRequest("image/jpeg"));
assertThat(response.key()).isEqualTo(CHAT_KEY);
assertThat(response.uploadUrl()).isEqualTo("https://s3.example.com/put");
verify(imageStorageService).issueUploadUrl(eq(ImageCategory.CHAT), eq(PARTY_ID), anyString());
when(imageStorageService.issueUploadUrl(eq(ImageCategory.CHAT), eq(PARTY_ID), eq("image/jpeg")))
.thenReturn(new PresignedUploadResponse(CHAT_KEY, "https://s3.example.com/put", "image/jpeg", 300));
ChatImagePresignResponse response =
chatImageService.presignUpload(PARTY_ID, USER_ID, new ChatImagePresignRequest("image/jpeg"));
assertThat(response.key()).isEqualTo(CHAT_KEY);
assertThat(response.uploadUrl()).isEqualTo("https://s3.example.com/put");
verify(imageStorageService).issueUploadUrl(eq(ImageCategory.CHAT), eq(PARTY_ID), eq("image/jpeg"));
🤖 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/test/java/com/leets/tdd/chat/service/ChatImageServiceTest.java` around
lines 55 - 63, Update the ChatImageServiceTest stubbing and verification of
imageStorageService.issueUploadUrl to use eq("image/jpeg") instead of
anyString(), ensuring presignUpload forwards the request content type exactly.

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