Skip to content

feature/#185 image resizing 기능 구현#193

Merged
minjo-on merged 4 commits intodevelopfrom
feature/#185-image-resizing
Feb 7, 2025
Merged

feature/#185 image resizing 기능 구현#193
minjo-on merged 4 commits intodevelopfrom
feature/#185-image-resizing

Conversation

@minjo-on
Copy link
Copy Markdown
Contributor

@minjo-on minjo-on commented Feb 5, 2025

Summary

이미지 리사이징 기능 구현

Tasks

  • thumbnailator 의존성 추가
  • ImageResizingService 구현
  • FileStorageService.store에 추가

Screenshot

스크린샷 2025-02-05 오후 6 01 57

@minjo-on minjo-on added the ✨feature create new feature label Feb 5, 2025
@minjo-on minjo-on requested a review from a team February 5, 2025 09:17
@minjo-on minjo-on self-assigned this Feb 5, 2025
@minjo-on minjo-on linked an issue Feb 5, 2025 that may be closed by this pull request
1 task
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 5, 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

이번 변경 사항은 이미지 리사이징 기능을 추가하기 위해 기존 파일 저장 서비스와 관련 인터페이스, 구현체를 수정 및 추가하고, 관련 라이브러리 의존성을 포함하는 작업입니다. 또한, .gitignore 파일의 항목을 업데이트하여 /cloud 디렉토리를 무시하도록 하고, .vscode/ 항목을 수정하였습니다.

Changes

파일 변경 요약
.gitignore /cloud 디렉토리 무시 추가; .vscode/ 항목 수정 (포맷 조정)
aics-domain/.../FileStorageServiceImpl.java 생성자에 ImageResizingService 파라미터 추가; 이미지 파일 저장 시 이미지 리사이징 호출; 경로 계산 업데이트
aics-domain/.../ImageResizingService.java
aics-domain/.../ImageResizingServiceImpl.java
새 인터페이스 ImageResizingService와 해당 구현체 추가 (Thumbnailator 라이브러리 활용)
build.gradle net.coobird:thumbnailator:0.4.20 라이브러리 의존성 추가

Assessment against linked issues

Objective Addressed Explanation
이미지 리사이징 [#185]

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?

❤️ Share
🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 5, 2025

Test Coverage Report

Overall Project 95.74% 🍏

There is no coverage information present for the Files changed

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Impacted file tree graph

@@              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.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a2e8922...1e7d212. Read the comment docs.

Copy link
Copy Markdown
Contributor

@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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between a2e8922 and a599967.

📒 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 의존성이 적절히 추가되었습니다!

라이브러리 버전이 명시적으로 지정되어 있어 좋습니다.

Comment on lines +12 to +22
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;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

이미지 리사이징 구현 시 몇 가지 개선이 필요합니다.

  1. 입력 파일을 출력 파일로 덮어쓰고 있어 원본 이미지가 손실될 수 있습니다.
  2. 입력 매개변수에 대한 유효성 검사가 없습니다.

다음과 같이 수정하는 것을 제안합니다:

 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.

Suggested change
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;
}

Comment on lines +60 to +63
String contentType = file.getContentType();
if (contentType != null && contentType.startsWith("image/")) {
imageResizingService.imageResize(originalFile, 800, 600, 0.8);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

이미지 처리 로직 개선이 필요합니다.

  1. 이미지 크기와 품질값이 하드코딩되어 있습니다.
  2. 이미지 리사이징 실패 시 예외 처리가 구체적이지 않습니다.
  3. 이미지 타입 체크가 더 구체적일 필요가 있습니다.

다음과 같이 개선하는 것을 제안합니다:

+    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.

Suggested change
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());
}
}

Copy link
Copy Markdown
Member

@LeeHanEum LeeHanEum left a comment

Choose a reason for hiding this comment

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

깔끔하게 잘 구현해주신것 같아요. 코멘트 하나만 확인 부탁드립니다 👍

Copy link
Copy Markdown
Member

@LeeHanEum LeeHanEum left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@minjo-on minjo-on merged commit 2f743a5 into develop Feb 7, 2025
4 checks passed
@minjo-on minjo-on deleted the feature/#185-image-resizing branch February 7, 2025 01:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✨feature create new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

첨부파일 이미지 최적화

2 participants