-
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
Merged
feat: 프로필 업데이트 구현 #146
Changes from all 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
24 changes: 0 additions & 24 deletions
24
src/main/java/com/codeit/team5/mopl/binarycontent/BinaryContentStorage.java
This file was deleted.
Oops, something went wrong.
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(); | ||
| } | ||
| } |
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
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
8 changes: 8 additions & 0 deletions
8
src/main/java/com/codeit/team5/mopl/binarycontent/storage/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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package com.codeit.team5.mopl.binarycontent.storage; | ||
|
|
||
| public interface BinaryContentStorage { | ||
|
|
||
| String toUrl(String key); | ||
|
|
||
| void store(String key, byte[] bytes, String contentType); | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/codeit/team5/mopl/binarycontent/storage/GeneratedKey.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,10 @@ | ||
| package com.codeit.team5.mopl.binarycontent.storage; | ||
|
|
||
| /** | ||
| * 저장소 키와 그에 대응하는 Content-Type을 함께 전달하는 값 객체. | ||
| */ | ||
| public record GeneratedKey( | ||
| String key, | ||
| String contentType | ||
| ) { | ||
| } |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/codeit/team5/mopl/binarycontent/storage/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.storage; | ||
|
|
||
| /** | ||
| * 저장소 키의 최상위 폴더(prefix). 용도별로 추가하려면 상수만 추가하면 된다. | ||
| */ | ||
| public enum StorageDirectory { | ||
| THUMBNAIL("thumbnails"), | ||
| PROFILE("profiles"); | ||
|
|
||
| private final String value; | ||
|
|
||
| StorageDirectory(String value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| public String value() { | ||
| return value; | ||
| } | ||
| } |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/codeit/team5/mopl/binarycontent/storage/StorageKeyFactory.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,25 @@ | ||
| package com.codeit.team5.mopl.binarycontent.storage; | ||
|
|
||
| import com.codeit.team5.mopl.binarycontent.ImageExtension; | ||
| import com.codeit.team5.mopl.binarycontent.exception.InvalidImageExtensionException; | ||
| import java.util.Locale; | ||
| import java.util.UUID; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.util.StringUtils; | ||
|
|
||
| /** | ||
| * 저장소 키 생성 책임을 담당한다. | ||
| * 확장자 검증 → 폴더 prefix/소유자/난수 조합 → Content-Type 결정을 한 곳에서 처리한다. | ||
| */ | ||
| @Component | ||
| public class StorageKeyFactory { | ||
|
|
||
| public GeneratedKey generate(StorageDirectory directory, UUID ownerId, String originalFilename) { | ||
| String extension = StringUtils.getFilenameExtension(originalFilename); | ||
| ImageExtension imageExtension = ImageExtension.from(extension) | ||
| .orElseThrow(() -> new InvalidImageExtensionException(extension)); | ||
| String key = directory.value() + "/" + ownerId + "/" + UUID.randomUUID() | ||
| + "." + imageExtension.name().toLowerCase(Locale.ROOT); | ||
| return new GeneratedKey(key, imageExtension.contentType()); | ||
| } | ||
| } |
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); | ||
| } | ||
| } | ||
| } | ||
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
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.