-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 프로필 업데이트 구현 #146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+751
−131
Merged
feat: 프로필 업데이트 구현 #146
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
98ea88d
feat: 프로필 업데이트 구현
dstle 2c154fb
feat: 프로필 변경/S3 테스트 추가 및 코드래빗 리뷰 반영
dstle 48d1512
fix: Exception import 수정
dstle 6669456
test: S3/프로필 업로드 테스트 인자 검증 강화
dstle fa3ec71
refactor: 프로필 업로드 구조 개선 및 패키지/네이밍 정리
dstle 18a5f76
fix: 부분 자격증명 양방향 검증 + thumbnail FileRequest 내용 검증
dstle 05c60bf
refactor: 스토리지 키 생성 책임 분리 및 저장소 설정 정리
dstle c690e69
refactor: storage 패키지 정리
dstle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 12 additions & 9 deletions
21
src/main/java/com/codeit/team5/mopl/binarycontent/BinaryContentStorage.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/com/codeit/team5/mopl/binarycontent/ImageExtension.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package com.codeit.team5.mopl.binarycontent; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Locale; | ||
| import java.util.Optional; | ||
|
|
||
| /** | ||
| * 허용 이미지 확장자와 그에 대응하는 Content-Type을 한 곳에서 관리한다. | ||
| * 확장자를 추가하려면 이 enum에 상수만 추가하면 된다. | ||
| */ | ||
| public enum ImageExtension { | ||
| JPG("image/jpeg"), | ||
| JPEG("image/jpeg"), | ||
| PNG("image/png"), | ||
| GIF("image/gif"), | ||
| WEBP("image/webp"); | ||
|
|
||
| private final String contentType; | ||
|
|
||
| ImageExtension(String contentType) { | ||
| this.contentType = contentType; | ||
| } | ||
|
|
||
| public String contentType() { | ||
| return contentType; | ||
| } | ||
|
|
||
| public static Optional<ImageExtension> from(String extension) { | ||
| if (extension == null || extension.isBlank()) { | ||
| return Optional.empty(); | ||
| } | ||
| String normalized = extension.toLowerCase(Locale.ROOT); | ||
| return Arrays.stream(values()) | ||
| .filter(e -> e.name().toLowerCase(Locale.ROOT).equals(normalized)) | ||
| .findFirst(); | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/codeit/team5/mopl/binarycontent/StorageDirectory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package com.codeit.team5.mopl.binarycontent; | ||
|
|
||
| /** | ||
| * 저장소 키의 최상위 폴더(prefix). 용도별로 추가하려면 상수만 추가하면 된다. | ||
| */ | ||
| public enum StorageDirectory { | ||
| THUMBNAIL("thumbnails"), | ||
| PROFILE("profiles"); | ||
|
|
||
| private final String value; | ||
|
|
||
| StorageDirectory(String value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| public String value() { | ||
| return value; | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
...in/java/com/codeit/team5/mopl/binarycontent/exception/InvalidImageExtensionException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package com.codeit.team5.mopl.binarycontent.exception; | ||
|
|
||
| import com.codeit.team5.mopl.global.exception.BusinessException; | ||
| import org.springframework.http.HttpStatus; | ||
|
|
||
| public class InvalidImageExtensionException extends BusinessException { | ||
|
|
||
| public InvalidImageExtensionException(String extension) { | ||
| super(HttpStatus.BAD_REQUEST, "허용되지 않는 이미지 확장자입니다: " + extension); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/com/codeit/team5/mopl/binarycontent/support/MultipartFiles.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package com.codeit.team5.mopl.binarycontent.support; | ||
|
|
||
| import com.codeit.team5.mopl.binarycontent.ImageExtension; | ||
| import com.codeit.team5.mopl.binarycontent.exception.BinaryContentStorageException; | ||
| import com.codeit.team5.mopl.binarycontent.exception.InvalidImageExtensionException; | ||
| import com.codeit.team5.mopl.global.dto.FileRequest; | ||
| import java.io.IOException; | ||
| import lombok.experimental.UtilityClass; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.util.StringUtils; | ||
| import org.springframework.web.multipart.MultipartFile; | ||
|
|
||
| /** | ||
| * MultipartFile(web 타입)을 서비스 계층용 {@link FileRequest}로 변환한다. | ||
| * 변환 시점에 확장자를 검증(fail-fast)하고 바이트를 읽어, web/IO 의존을 컨트롤러 경계에서 차단한다. | ||
| */ | ||
| @UtilityClass | ||
| public class MultipartFiles { | ||
|
|
||
| public FileRequest toImageResource(MultipartFile file) { | ||
| if (file == null || file.isEmpty()) { | ||
| return null; | ||
| } | ||
| String extension = StringUtils.getFilenameExtension(file.getOriginalFilename()); | ||
| if (ImageExtension.from(extension).isEmpty()) { | ||
| throw new InvalidImageExtensionException(extension); | ||
| } | ||
| try { | ||
| return new FileRequest(file.getBytes(), file.getOriginalFilename()); | ||
| } catch (IOException e) { | ||
| throw new BinaryContentStorageException( | ||
| HttpStatus.INTERNAL_SERVER_ERROR, | ||
| "파일을 읽을 수 없습니다: " + file.getOriginalFilename(), e); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/com/codeit/team5/mopl/global/dto/FileRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package com.codeit.team5.mopl.global.dto; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * 업로드 파일을 웹 계층(MultipartFile)에서 분리한 순수 데이터 홀더. | ||
| * 서비스 계층이 web 타입에 의존하지 않도록 컨트롤러에서 변환하여 전달한다. | ||
| * Content-Type은 클라이언트 값을 신뢰하지 않고 저장 시점에 확장자로 결정한다. | ||
| */ | ||
| public record FileRequest( | ||
| byte[] bytes, | ||
| String filename | ||
| ) { | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (!(o instanceof FileRequest other)) { | ||
| return false; | ||
| } | ||
| return Arrays.equals(bytes, other.bytes) && Objects.equals(filename, other.filename); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(Arrays.hashCode(bytes), filename); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "FileRequest{filename='" + filename + "', size=" | ||
| + (bytes != null ? bytes.length : 0) + "}"; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.