Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Walkthrough이번 변경 사항은 이미지 리사이징 기능을 추가하기 위해 기존 파일 저장 서비스와 관련 인터페이스, 구현체를 수정 및 추가하고, 관련 라이브러리 의존성을 포함하는 작업입니다. 또한, Changes
Assessment against linked issues
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Test Coverage Report
|
Codecov ReportAll modified and coverable lines are covered by tests ✅ @@ Coverage Diff @@
## develop #193 +/- ##
=============================================
- Coverage 93.18% 92.99% -0.20%
Complexity 129 129
=============================================
Files 48 48
Lines 367 371 +4
Branches 3 4 +1
=============================================
+ Hits 342 345 +3
Misses 21 21
- Partials 4 5 +1 see 2 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
aics-domain/src/main/java/kgu/developers/domain/file/infrastructure/ImageResizingServiceImpl.java (1)
10-11: Javadoc 문서화가 필요합니다.메서드의 목적, 매개변수, 반환값, 예외에 대한 문서화가 필요합니다.
다음과 같이 Javadoc을 추가하는 것을 제안합니다:
@Service +/** + * 이미지 리사이징 서비스 구현체 + */ public class ImageResizingServiceImpl implements ImageResizingService { + /** + * 주어진 입력 파일을 지정된 크기로 리사이징합니다. + * + * @param inputFile 리사이징할 이미지 파일 + * @param width 목표 너비 (픽셀) + * @param height 목표 높이 (픽셀) + * @param quality 이미지 품질 (0.0 ~ 1.0) + * @return 리사이징된 이미지 파일 + * @throws IOException 파일 처리 중 오류 발생 시 + * @throws IllegalArgumentException 잘못된 매개변수 입력 시 + */
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
.gitignore(1 hunks)aics-domain/src/main/java/kgu/developers/domain/file/infrastructure/FileStorageServiceImpl.java(3 hunks)aics-domain/src/main/java/kgu/developers/domain/file/infrastructure/ImageResizingService.java(1 hunks)aics-domain/src/main/java/kgu/developers/domain/file/infrastructure/ImageResizingServiceImpl.java(1 hunks)build.gradle(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- .gitignore
🔇 Additional comments (2)
aics-domain/src/main/java/kgu/developers/domain/file/infrastructure/ImageResizingService.java (1)
6-8: 인터페이스 설계가 명확하고 적절합니다!메서드 시그니처가 잘 정의되어 있으며, 예외 처리도 적절히 선언되어 있습니다.
build.gradle (1)
57-57: Thumbnailator 의존성이 적절히 추가되었습니다!라이브러리 버전이 명시적으로 지정되어 있어 좋습니다.
| public File imageResize(File inputFile, int width, int height, double quality) throws IOException { | ||
| File outputFile = new File(inputFile.getParent(), inputFile.getName()); | ||
|
|
||
| Thumbnails.of(inputFile) | ||
| .size(width, height) | ||
| .outputQuality(quality) | ||
| .keepAspectRatio(true) | ||
| .toFile(outputFile); | ||
|
|
||
| return outputFile; | ||
| } |
There was a problem hiding this comment.
이미지 리사이징 구현 시 몇 가지 개선이 필요합니다.
- 입력 파일을 출력 파일로 덮어쓰고 있어 원본 이미지가 손실될 수 있습니다.
- 입력 매개변수에 대한 유효성 검사가 없습니다.
다음과 같이 수정하는 것을 제안합니다:
public File imageResize(File inputFile, int width, int height, double quality) throws IOException {
+ if (width <= 0 || height <= 0 || quality <= 0 || quality > 1.0) {
+ throw new IllegalArgumentException("Invalid parameters: width and height must be positive, quality must be between 0 and 1");
+ }
- File outputFile = new File(inputFile.getParent(), inputFile.getName());
+ String fileName = inputFile.getName();
+ String name = fileName.substring(0, fileName.lastIndexOf('.'));
+ String ext = fileName.substring(fileName.lastIndexOf('.'));
+ File outputFile = new File(inputFile.getParent(), name + "_resized" + ext);
Thumbnails.of(inputFile)
.size(width, height)
.outputQuality(quality)
.keepAspectRatio(true)
.toFile(outputFile);
return outputFile;
}📝 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.
| public File imageResize(File inputFile, int width, int height, double quality) throws IOException { | |
| File outputFile = new File(inputFile.getParent(), inputFile.getName()); | |
| Thumbnails.of(inputFile) | |
| .size(width, height) | |
| .outputQuality(quality) | |
| .keepAspectRatio(true) | |
| .toFile(outputFile); | |
| return outputFile; | |
| } | |
| public File imageResize(File inputFile, int width, int height, double quality) throws IOException { | |
| if (width <= 0 || height <= 0 || quality <= 0 || quality > 1.0) { | |
| throw new IllegalArgumentException("Invalid parameters: width and height must be positive, quality must be between 0 and 1"); | |
| } | |
| String fileName = inputFile.getName(); | |
| String name = fileName.substring(0, fileName.lastIndexOf('.')); | |
| String ext = fileName.substring(fileName.lastIndexOf('.')); | |
| File outputFile = new File(inputFile.getParent(), name + "_resized" + ext); | |
| Thumbnails.of(inputFile) | |
| .size(width, height) | |
| .outputQuality(quality) | |
| .keepAspectRatio(true) | |
| .toFile(outputFile); | |
| return outputFile; | |
| } |
| String contentType = file.getContentType(); | ||
| if (contentType != null && contentType.startsWith("image/")) { | ||
| imageResizingService.imageResize(originalFile, 800, 600, 0.8); | ||
| } |
There was a problem hiding this comment.
🛠️ Refactor suggestion
이미지 처리 로직 개선이 필요합니다.
- 이미지 크기와 품질값이 하드코딩되어 있습니다.
- 이미지 리사이징 실패 시 예외 처리가 구체적이지 않습니다.
- 이미지 타입 체크가 더 구체적일 필요가 있습니다.
다음과 같이 개선하는 것을 제안합니다:
+ private static final int IMAGE_MAX_WIDTH = 800;
+ private static final int IMAGE_MAX_HEIGHT = 600;
+ private static final double IMAGE_QUALITY = 0.8;
+ private static final Set<String> SUPPORTED_IMAGE_TYPES = Set.of(
+ "image/jpeg", "image/png", "image/gif"
+ );
String contentType = file.getContentType();
- if (contentType != null && contentType.startsWith("image/")) {
+ if (contentType != null && SUPPORTED_IMAGE_TYPES.contains(contentType)) {
try {
- imageResizingService.imageResize(originalFile, 800, 600, 0.8);
+ imageResizingService.imageResize(originalFile, IMAGE_MAX_WIDTH, IMAGE_MAX_HEIGHT, IMAGE_QUALITY);
+ } catch (IOException e) {
+ throw new FileStoreFailedException("이미지 리사이징 중 오류가 발생했습니다: " + e.getMessage());
+ }
}📝 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.
| String contentType = file.getContentType(); | |
| if (contentType != null && contentType.startsWith("image/")) { | |
| imageResizingService.imageResize(originalFile, 800, 600, 0.8); | |
| } | |
| // At the class level | |
| private static final int IMAGE_MAX_WIDTH = 800; | |
| private static final int IMAGE_MAX_HEIGHT = 600; | |
| private static final double IMAGE_QUALITY = 0.8; | |
| private static final Set<String> SUPPORTED_IMAGE_TYPES = Set.of( | |
| "image/jpeg", "image/png", "image/gif" | |
| ); | |
| ... | |
| // Within the relevant method (e.g., store method) | |
| String contentType = file.getContentType(); | |
| if (contentType != null && SUPPORTED_IMAGE_TYPES.contains(contentType)) { | |
| try { | |
| imageResizingService.imageResize(originalFile, IMAGE_MAX_WIDTH, IMAGE_MAX_HEIGHT, IMAGE_QUALITY); | |
| } catch (IOException e) { | |
| throw new FileStoreFailedException("이미지 리사이징 중 오류가 발생했습니다: " + e.getMessage()); | |
| } | |
| } |
LeeHanEum
left a comment
There was a problem hiding this comment.
깔끔하게 잘 구현해주신것 같아요. 코멘트 하나만 확인 부탁드립니다 👍
Summary
이미지 리사이징 기능 구현
Tasks
Screenshot