Skip to content

[Feature] 가게 프로필 이미지 등록 기능 추가#11

Merged
mingdodev merged 9 commits intomainfrom
feature/10-upload-image
Jul 6, 2025
Merged

[Feature] 가게 프로필 이미지 등록 기능 추가#11
mingdodev merged 9 commits intomainfrom
feature/10-upload-image

Conversation

@mingdodev
Copy link
Owner

@mingdodev mingdodev commented Jul 6, 2025

Summary by CodeRabbit

  • 신규 기능

    • 회원가입 시 사업자(가맹점주) 등록에서 이미지 파일 업로드 기능이 추가되었습니다.
    • AWS S3 및 CloudFront를 통한 이미지 저장 및 접근이 지원됩니다.
    • 이미지 업로드 실패 시 새로운 에러 메시지가 안내됩니다.
  • 버그 수정

    • 사업장 이미지 URL 필드가 선택 사항으로 변경되고, 길이 제한(최대 512자)이 적용되었습니다.
  • 문서화

    • 멀티파트 JSON 요청을 위한 어노테이션이 추가되어 API 명세가 개선되었습니다.
  • 환경설정

    • AWS 관련 환경설정 및 의존성이 추가되었습니다.

mingdodev added 8 commits July 7, 2025 04:56
- ion-java는 취약점 패치된 버전으로 오버라이딩

#10
- 안전한 의존성의 URL이 다름, 따라서 명시적으로 취약한 모듈을 제외하고 새로 추가

#10
- CloudFront를 사용함에 따라, 모든 퍼블릭 액세스를 차단하고 ACL을 적용함

#10
- Swagger에서 이미지 업로드 시 JSON 요청 타입을 octet-stream으로 인식하는 문제
- 명시적으로 지정
- Swagger의 @RequestBody 어노테이션 기반 커스텀 어노테이션 생성

#10
- 이메일 일부로 파일명 생성

#10
@mingdodev mingdodev linked an issue Jul 6, 2025 that may be closed by this pull request
2 tasks
@coderabbitai
Copy link

coderabbitai bot commented Jul 6, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

AWS S3를 통한 상점 프로필 이미지 업로드 기능이 도입되었습니다. 이를 위해 S3 클라이언트 및 업로더 유틸리티, 환경설정, 예외 메시지, multipart/form-data 요청 처리, 엔티티 및 DTO 구조 변경이 반영되었습니다. 상점 생성 시 이미지 파일을 선택적으로 업로드할 수 있습니다.

Changes

파일/경로 변경 요약
build.gradle, src/main/resources/application.yml AWS Spring Cloud, S3, CloudFront 관련 의존성 및 환경설정 추가
src/main/java/danji/danjiapi/domain/user/controller/UserController.java 상점 회원가입 API가 multipart/form-data 및 이미지 파일 파라미터 지원, 커스텀 어노테이션 적용
src/main/java/danji/danjiapi/domain/user/dto/request/UserCreateMerchantRequest.java marketImageUrl 필드 제거, marketAddress만 유지
src/main/java/danji/danjiapi/domain/user/service/UserService.java signupMerchant 메서드가 MultipartFile 파라미터 추가, S3Uploader를 통한 이미지 업로드 및 URL 저장 로직 도입
src/main/java/danji/danjiapi/domain/market/entity/Market.java imageUrl 컬럼 nullable 허용, 길이 제한(512) 추가
src/main/java/danji/danjiapi/global/annotation/MultipartJsonRequest.java multipart/form-data 내 JSON 파트 명세를 위한 커스텀 어노테이션 신설
src/main/java/danji/danjiapi/global/config/AwsConfig.java AWS S3 클라이언트 빈을 제공하는 설정 클래스 신설
src/main/java/danji/danjiapi/global/util/S3Uploader.java S3에 파일 업로드 및 URL 반환 유틸리티 컴포넌트 신설
src/main/java/danji/danjiapi/global/exception/ErrorMessage.java 이미지 업로드 실패 관련 에러 메시지 상수 추가

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant UserController
    participant UserService
    participant S3Uploader
    participant AmazonS3
    participant MarketRepository

    Client->>UserController: multipart/form-data로 상점 회원가입 요청 (JSON + 이미지)
    UserController->>UserService: signupMerchant(request, image)
    alt 이미지 파일이 존재할 경우
        UserService->>S3Uploader: upload(image, dirName, userEmail)
        S3Uploader->>AmazonS3: putObject
        S3Uploader-->>UserService: 업로드된 이미지 URL 반환
    else 이미지 파일 미첨부
        UserService-->>UserService: 이미지 URL null 처리
    end
    UserService->>MarketRepository: Market 엔티티 생성 (imageUrl 포함)
    UserService-->>UserController: 가입 결과 반환
    UserController-->>Client: 응답 반환
Loading

Possibly related issues

Possibly related PRs

  • [Feature] 가게 도메인 API 구현 #5: Market 도메인 및 API 초기 정의 PR로, 이번 PR의 Market 엔티티 및 상점 회원가입 흐름 변경과 도메인 차원에서 밀접한 연관이 있습니다.

🪧 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: 3

🧹 Nitpick comments (4)
src/main/java/danji/danjiapi/global/config/AwsConfig.java (1)

24-29: S3 클라이언트 생성 로직에 예외 처리를 추가하세요.

S3 클라이언트 생성 시 잘못된 자격증명이나 리전 설정으로 인한 예외가 발생할 수 있습니다. 초기화 시점에서 연결 테스트나 예외 처리를 추가하는 것을 고려해보세요.

src/main/java/danji/danjiapi/domain/user/service/UserService.java (1)

42-44: S3 업로드 실패 시 사용자 경험 개선을 고려해보세요.

현재 S3 업로드가 실패하면 전체 회원가입 프로세스가 실패합니다. 이미지 업로드 실패 시에도 회원가입은 성공하고 이미지만 별도로 재시도할 수 있는 방안을 고려해보세요.

src/main/java/danji/danjiapi/global/util/S3Uploader.java (1)

39-41: 예외 처리 시 로깅을 추가하세요.

IOException이 발생했을 때 원본 예외 정보가 손실됩니다. 디버깅과 모니터링을 위해 로깅을 추가해보세요.

} catch (IOException e) {
+    log.error("S3 업로드 실패: bucket={}, filename={}", bucket, filename, e);
    throw new CustomException(ErrorMessage.USER_IMAGE_UPLOAD_FAILED);
}
src/main/java/danji/danjiapi/domain/user/controller/UserController.java (1)

39-40: 이미지 파일 유효성 검증을 추가하는 것을 고려해보세요.

컨트롤러 레벨에서 이미지 파일에 대한 기본적인 유효성 검증(파일 크기, 타입 등)을 추가하면 더 안전한 API가 될 것입니다.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between de67ff4 and fb8259d.

📒 Files selected for processing (10)
  • build.gradle (1 hunks)
  • src/main/java/danji/danjiapi/domain/market/entity/Market.java (1 hunks)
  • src/main/java/danji/danjiapi/domain/user/controller/UserController.java (2 hunks)
  • src/main/java/danji/danjiapi/domain/user/dto/request/UserCreateMerchantRequest.java (1 hunks)
  • src/main/java/danji/danjiapi/domain/user/service/UserService.java (2 hunks)
  • src/main/java/danji/danjiapi/global/annotation/MultipartJsonRequest.java (1 hunks)
  • src/main/java/danji/danjiapi/global/config/AwsConfig.java (1 hunks)
  • src/main/java/danji/danjiapi/global/exception/ErrorMessage.java (1 hunks)
  • src/main/java/danji/danjiapi/global/util/S3Uploader.java (1 hunks)
  • src/main/resources/application.yml (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
src/main/java/danji/danjiapi/domain/user/dto/request/UserCreateMerchantRequest.java (1)
Learnt from: mingdodev
PR: mingdodev/danji-api#7
File: src/main/java/danji/danjiapi/domain/product/service/ProductService.java:23-32
Timestamp: 2025-07-06T10:15:26.201Z
Learning: danji-api 프로젝트의 데이터 스키마에서는 사용자당 하나의 마켓만 존재하도록 설계되어 있어서 MarketRepository.findByUserId()를 사용하는 것이 적절하다.
🧬 Code Graph Analysis (2)
src/main/java/danji/danjiapi/global/util/S3Uploader.java (1)
src/main/java/danji/danjiapi/global/exception/CustomException.java (1)
  • CustomException (3-14)
src/main/java/danji/danjiapi/domain/user/controller/UserController.java (1)
src/main/java/danji/danjiapi/domain/auth/controller/AuthController.java (1)
  • RestController (16-28)
🔇 Additional comments (8)
build.gradle (1)

36-39: AWS 종속성 최신 버전 및 보안 확인 완료

Spring Cloud AWS 스타터(2.4.4)와 ion-java(1.11.10)는 Maven Central에서 확인된 최신 버전이며, GitHub 보안 권고에도 취약점 보고가 없습니다. 추가 조치가 필요하지 않습니다.

src/main/resources/application.yml (1)

19-28: AWS 구성이 올바르게 추가되었습니다

AWS 구성이 보안 모범 사례에 따라 올바르게 구현되었습니다:

  • 민감한 정보(액세스 키, 시크릿 키 등)를 환경 변수로 외부화
  • S3 버킷 및 CloudFront 도메인 설정 포함
  • 서울 리전(ap-northeast-2) 사용

리전이 하드코딩되어 있는 것은 한국 서비스 특성상 적절해 보입니다.

src/main/java/danji/danjiapi/domain/user/dto/request/UserCreateMerchantRequest.java (1)

18-18: DTO 구조 개선이 적절합니다

marketImageUrl 필드를 제거하고 이미지 업로드를 멀티파트 파일 업로드로 분리한 것은 좋은 설계 결정입니다. 이는 JSON 요청 데이터와 파일 데이터를 명확하게 구분하여 코드의 가독성과 유지보수성을 향상시킵니다.

src/main/java/danji/danjiapi/global/exception/ErrorMessage.java (1)

28-28: 이미지 업로드 실패 에러 메시지 추가가 적절합니다

새로운 에러 메시지가 올바르게 추가되었습니다:

  • SERVICE_UNAVAILABLE 상태 코드는 S3 업로드 실패와 같은 일시적 서비스 문제에 적합
  • 한국어 메시지가 명확하고 사용자 친화적
  • user 섹션에 논리적으로 배치됨
src/main/java/danji/danjiapi/domain/market/entity/Market.java (1)

43-44: imageUrl null 허용 동작 확인

Market.create 메서드에서 imageUrl이 null로 전달될 경우에도
@builder가 해당 값을 그대로 설정하며, @column의 기본 nullable=true 제약으로 DB 저장 시 문제가 없습니다.
따라서 추가 조치 없이 변경사항을 승인합니다.

src/main/java/danji/danjiapi/global/annotation/MultipartJsonRequest.java (1)

1-21: 잘 구현된 커스텀 어노테이션입니다.

MultipartJsonRequest 어노테이션이 올바르게 구현되었습니다. Swagger 통합과 OpenAPI 문서화를 위한 메타데이터 설정이 적절합니다.

src/main/java/danji/danjiapi/domain/user/service/UserService.java (1)

38-44: 이미지 업로드 로직이 잘 구현되었습니다.

조건부 이미지 업로드 로직이 적절하게 구현되어 있습니다. null 체크와 빈 파일 체크를 통해 안전한 처리가 되고 있습니다.

src/main/java/danji/danjiapi/domain/user/controller/UserController.java (1)

35-42: 멀티파트 요청 처리가 잘 구현되었습니다.

@MultipartJsonRequest 어노테이션과 @RequestPart를 사용한 멀티파트 요청 처리가 적절하게 구현되었습니다. JSON 요청과 이미지 파일을 분리하여 처리하는 방식이 올바릅니다.

Comment on lines +27 to +42
public String upload(MultipartFile file, String dirName, String userEmail) {
String filename = getFilenameFromEmail(file, dirName, userEmail);

try {
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentType(file.getContentType());
metadata.setContentLength(file.getSize());

amazonS3.putObject(new PutObjectRequest(bucket, filename, file.getInputStream(), metadata));

return cloudFrontDomain + "/" + filename;

} catch (IOException e) {
throw new CustomException(ErrorMessage.USER_IMAGE_UPLOAD_FAILED);
}
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

파일 업로드 유효성 검증을 추가하세요.

현재 구현에서는 파일 타입, 크기, 내용에 대한 검증이 없습니다. 보안과 안정성을 위해 다음을 추가하는 것을 권장합니다:

  • 허용된 파일 타입 검증 (예: 이미지 파일만)
  • 파일 크기 제한
  • 파일 내용 검증 (악성 파일 방지)
🤖 Prompt for AI Agents
In src/main/java/danji/danjiapi/global/util/S3Uploader.java between lines 27 and
42, the upload method lacks validation for the uploaded file. Add checks to
verify the file type against allowed image MIME types, enforce a maximum file
size limit, and implement content validation to detect potentially malicious
files before proceeding with the upload. If any validation fails, throw an
appropriate exception to prevent unsafe files from being uploaded.

- 특수문자 제거 및 중복 예방

#10
@mingdodev mingdodev merged commit 68f6387 into main Jul 6, 2025
1 check passed
@mingdodev mingdodev deleted the feature/10-upload-image branch July 6, 2025 21:09
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.

[Feature] 가게 프로필 이미지 등록 기능 추가

1 participant