Skip to content

Conversation

@7zrv
Copy link
Collaborator

@7zrv 7zrv commented Nov 28, 2024

resolved : #36

📌 과제 설명

s3에 이미지를 업로드 하는 기능 구현입니다.

👩‍💻 요구 사항과 구현 내용

  • aws s3 연동을 위한 의존성 추가
  • 환경변수 추가
  • S3 연결을 위한 config 클래스 구현
  • 서비스 레이어에 이미지 업로드 기능 구현
  • 업로드 실패 예외와 예외 메세지 추
  • test.yml에 테스트에 필요한 환경변수 추가
  • 테스트 코드 작성및 검증 완료

✅ PR 포인트 & 궁금한 점

7zrv added 2 commits November 28, 2024 11:25
- aws s3 연동을 위한 의존성 추가
- 환경변수 추가
- S3 연결을 위한 config 클래스 구현
- 서비스 레이어에 이미지 업로드 기능 구현
- 업로드 실패 예외와 예외 메세지 추
- test.yml에 테스트에 필요한 환경변수 추가
- 테스트 코드 작성및 검증 완료
- cicd workflow 에 이미지 업로드 관련 환경변수 추가
- appication.yml에 이미지 업로드 관련 환경변수 이름 변경
Copy link
Collaborator

@m-a-king m-a-king left a comment

Choose a reason for hiding this comment

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

수고하셨습니다! 외부 시스템과 연결된 인프라 관리 작업은 정말 고민할 거리가 많죠 ㅠㅠ

BACK_URL: ${{secrets.BACK_URL}}
BUCKET_NAME: ${{secrets.BUCKET_NAME}}
BUCKET_REGION: ${{secrets.BUCKET_REGION}}
BASE_URL:https: ${{secrets.BASE_URL}}
Copy link
Collaborator

@m-a-king m-a-king Nov 28, 2024

Choose a reason for hiding this comment

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

BASE_URL:https: ${{secrets.BASE_URL}}

이 부분 조금 어색한데, 괜찮은지 여쭤보고 싶습니다~

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

더 명시적인 이름으로 수정해보겠습니다

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

변수명 집어넣다가 실수했네요 수정하겠습니다

Comment on lines 7 to 9
private ImageUploadUtils() {
throw new UnsupportedOperationException("인스턴스화 할 수 없는 클래스 입니다.");
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

명시적으로 처리하는 것을 처음 봤어요! 신기하네용

Copy link
Collaborator

Choose a reason for hiding this comment

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

이 부분도 ENUM으로 처리하면 좋을 것 같습니다

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

넵 좋은 의견 감사합니다 반영하겠습니다

Comment on lines 41 to 45
try {
s3Client.putObject(request, RequestBody.fromInputStream(
requestDto.imageFile().getInputStream(),
requestDto.imageFile().getSize()
));
Copy link
Collaborator

Choose a reason for hiding this comment

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

리퀘스트바디에서 이미지를 가져오는 과정을 추출해낼 수 있을 것 같아요!

Comment on lines 35 to 39
PutObjectRequest request = PutObjectRequest.builder()
.bucket(bucket)
.key(fileName)
.contentType(requestDto.imageFile().getContentType())
.build();
Copy link
Collaborator

Choose a reason for hiding this comment

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

서비스 퍼블릭 메서드에 빌더 패턴을 추출해낼 수 있을 것 같습니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

private PutObjectRequest createPutObjectRequest(MultipartFile file) {
String fileName = ImageUploadUtils.generateUniqueFileName(file.getOriginalFilename());
return PutObjectRequest.builder()
.bucket(bucket)
.key(fileName)
.contentType(file.getContentType())
.build();
}

혹시 이런 느낌을 말씀하신게 맞나요?

Copy link
Collaborator

Choose a reason for hiding this comment

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

네, 감사합니다.

fileName같은 경우에는

최하단 return에서 사용되고 있고
이미 추상화 수준을 적절히 맞춰뒀다고 생각해서

굳이 넣지 않으셔도 되지만, 넣으셔도 무방할 것 같습니다!

createPutObjectRequest 맞습니다

Comment on lines 17 to 19
public static String extractFileExtension(String fileName) {
return fileName.substring(fileName.lastIndexOf("."));
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

private가 되는 것이 맞다고 생각하는데 어떻게 생각하시나요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

맞습니다 자동으로 메서드 추출해봤는데 실수가 있었던거 같아요

- 이미지 크기를 8MB로 제한
- 이미지의 크기 초과를 검증하는 기능 구현
- 이미지의 확장자명을 검증하는 기능 구현
- 이미지 업로드시 검증 기능들을 수행하도록 수정
- 전역 예외처리 핸들러에 이미지 업로드 예외 추가
- 예외 메세지 추가
- 테스트 코드 작성및 검증 완
Copy link
Collaborator

@ayoung-dev ayoung-dev left a comment

Choose a reason for hiding this comment

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

수고하셨어용..


ImageUploadRequestDto requestDto = new ImageUploadRequestDto(multipartFile);

// when, then
Copy link
Collaborator

Choose a reason for hiding this comment

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

//when
//then
저희 이렇게 쓰기로 했던 거 같아요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

너무 짧은 테스트라 두개를 합쳐놨는데 분리시켜보겠습니다

Copy link
Collaborator

@leebs0521 leebs0521 left a comment

Choose a reason for hiding this comment

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

잘 작성하신 것 같습니다.
고생하셨어요

- BASE_URL을 S3_BASE_URL라는 더 명시적인 이름으로 변경
- ImageUploadUtils private 생성자의 예외처리 메세지를 ExceptionMessage에 등록하여 사용하도록 수정
- 이미지 업로드 메서드의 내부 기능을 메서드로 추출하여 가독성 향상
- ImageUploadUtils의 일부 기능의 접근 제어자를 private으로 수정
- 테스트 코드의 when, then을 더 명확하게 분
@sonarqubecloud
Copy link

Copy link
Collaborator

@m-a-king m-a-king left a comment

Choose a reason for hiding this comment

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

수고하셨습니다!

@7zrv 7zrv merged commit 0be3598 into main Nov 28, 2024
2 checks passed
@7zrv 7zrv deleted the feature/36-add-image-upload-to-s3 branch November 28, 2024 05:36
ayoung-dev added a commit that referenced this pull request Nov 28, 2024
* test(community): communityComment 생성 기능 테스트 작성

* feat(community): communityComment Entity, Repository 추가

* feat(community): communityComment 생성 RequestDto, Usecase 추가 및 Service 구현

* refactor(community): CommunityBoardRepository 네이밍 변경

* refactor(community): community board/comment 폴더 구조 변경

* chore(community): 불필요한 import 및 public 키워드 제거

* Feature/36 s3 이미지 업로드 기능 구현 (#66)

* feat: 이미지 업로드 기능 구현

- aws s3 연동을 위한 의존성 추가
- 환경변수 추가
- S3 연결을 위한 config 클래스 구현
- 서비스 레이어에 이미지 업로드 기능 구현
- 업로드 실패 예외와 예외 메세지 추
- test.yml에 테스트에 필요한 환경변수 추가
- 테스트 코드 작성및 검증 완료

* chore: 환경변수 추가

- cicd workflow 에 이미지 업로드 관련 환경변수 추가
- appication.yml에 이미지 업로드 관련 환경변수 이름 변경

* feat: 이미지 파일 검증 기능 구현

- 이미지 크기를 8MB로 제한
- 이미지의 크기 초과를 검증하는 기능 구현
- 이미지의 확장자명을 검증하는 기능 구현
- 이미지 업로드시 검증 기능들을 수행하도록 수정
- 전역 예외처리 핸들러에 이미지 업로드 예외 추가
- 예외 메세지 추가
- 테스트 코드 작성및 검증 완

* fix: 코드 리뷰 사항 반영

- BASE_URL을 S3_BASE_URL라는 더 명시적인 이름으로 변경
- ImageUploadUtils private 생성자의 예외처리 메세지를 ExceptionMessage에 등록하여 사용하도록 수정
- 이미지 업로드 메서드의 내부 기능을 메서드로 추출하여 가독성 향상
- ImageUploadUtils의 일부 기능의 접근 제어자를 private으로 수정
- 테스트 코드의 when, then을 더 명확하게 분

* test(community): 커뮤니티 댓글 생성 테스트 추가

- repository 테스트에 findById 테스트 추가
- service 테스트에 대댓글 예외 테스트 추가

* chore(community): 소문자로 네이밍 변경

* fix(community): 커뮤니티 댓글 생성 requestDto 수정

- parentCommentId Dto 필드로 수정

* feat(community): 커뮤니티 댓글 생성 예외 처리 및 메세지 추가

* refactor(community): 코드 리뷰 사항 반영

- ServiceTest 오타 수정
- validateParentCommentExists 메서드 추출

* test(community): communityComment 생성 기능 테스트 작성

* feat(community): communityComment Entity, Repository 추가

* feat(community): communityComment 생성 RequestDto, Usecase 추가 및 Service 구현

* refactor(community): CommunityBoardRepository 네이밍 변경

* refactor(community): community board/comment 폴더 구조 변경

* chore(community): 불필요한 import 및 public 키워드 제거

* test(community): 커뮤니티 댓글 생성 테스트 추가

- repository 테스트에 findById 테스트 추가
- service 테스트에 대댓글 예외 테스트 추가

* chore(community): 소문자로 네이밍 변경

* fix(community): 커뮤니티 댓글 생성 requestDto 수정

- parentCommentId Dto 필드로 수정

* feat(community): 커뮤니티 댓글 생성 예외 처리 및 메세지 추가

* refactor(community): 코드 리뷰 사항 반영

- ServiceTest 오타 수정
- validateParentCommentExists 메서드 추출

* feat(community): 커뮤니티 댓글 존재 여부 메서드 및 테스트 추가

* chore(community): 불필요한 import 제거

---------

Co-authored-by: seojin Yoon <[email protected]>
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.

[FEATURE]이미지 업로드 기능

5 participants