-
Notifications
You must be signed in to change notification settings - Fork 2
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
[π§ μμ μ€] 리μμ€ μμ μ κ΄λ ¨ μ΄λ―Έμ§ νμΌλ μμ λλλ‘ κ΅¬ν #711
base: main
Are you sure you want to change the base?
Conversation
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 (
|
Quality Gate passedIssues Measures |
There was a problem hiding this 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
π§Ή Outside diff range and nitpick comments (4)
src/main/java/balancetalk/file/domain/repository/FileRepositoryCustom.java (1)
Line range hint
8-13
: λ©μλ ν΅ν© κ²ν μ μνμ¬ λΉμ·ν λͺ©μ μ κ°μ§ μΈ κ°μ λ©μλκ° μ‘΄μ¬ν©λλ€:
- findImgUrlsByResourceIdAndFileType
- findIdsByResourceIdAndFileType
- findAllByResourceIdAndFileType
κ°κ°μ λ©μλκ° File μν°ν°μ νΉμ νλλ§ μ‘°ννλ κ²μΌλ‘ 보μ λλ€. μ±λ₯ μ΅μ νκ° νΉλ³ν νμν κ²½μ°κ° μλλΌλ©΄, νλμ λ©μλλ‘ ν΅ν©νκ³ νμν μ λ³΄λ§ λ§€ννμ¬ μ¬μ©νλ κ²μ κ³ λ €ν΄λ³΄μκΈ° λ°λλλ€.
src/main/java/balancetalk/file/domain/repository/FileRepositoryImpl.java (1)
35-41
: ꡬνμ΄ μ¬λ°λ₯΄μ§λ§ μ½λ μ¬μ¬μ©μ±μ κ°μ ν μ μμ΅λλ€.μλ‘μ΄ λ©μλμ ꡬνμ΄ μ μ νλ©° κΈ°μ‘΄ ν¨ν΄μ μ λ°λ₯΄κ³ μμ΅λλ€. νμ§λ§ λ€λ₯Έ λ λ©μλ(
findImgUrlsByResourceIdAndFileType
,findIdsByResourceIdAndFileType
)κ° μ΄ λ©μλλ₯Ό κΈ°λ°μΌλ‘ 리ν©ν λ§λ μ μμ κ² κ°μ΅λλ€.λ€μκ³Ό κ°μ΄ 리ν©ν λ§νλ κ²μ κ³ λ €ν΄λ³΄μΈμ:
+ @Override + public List<File> findAllByResourceIdAndFileType(Long resourceId, FileType fileType) { + return queryFactory.select(file) + .from(file) + .where(file.fileType.eq(fileType), file.resourceId.eq(resourceId)) + .fetch(); + } + @Override public List<String> findImgUrlsByResourceIdAndFileType(Long resourceId, FileType fileType) { - List<File> images = queryFactory.selectFrom(file) - .where(file.fileType.eq(fileType), file.resourceId.eq(resourceId)) - .fetch(); + List<File> images = findAllByResourceIdAndFileType(resourceId, fileType); return images.stream() .map(File::getS3Url) .toList(); } @Override public List<Long> findIdsByResourceIdAndFileType(Long resourceId, FileType fileType) { - return queryFactory.select(file.id) - .from(file) - .where(file.fileType.eq(fileType), file.resourceId.eq(resourceId)) - .fetch(); + return findAllByResourceIdAndFileType(resourceId, fileType).stream() + .map(File::getId) + .toList(); }src/main/java/balancetalk/file/domain/FileHandler.java (1)
63-68
: μ±λ₯ μ΅μ νλ₯Ό μν μ μλλμ νμΌμ μ²λ¦¬ν λ μ±λ₯ ν₯μμ μν΄ λ³λ ¬ μ²λ¦¬λ₯Ό κ³ λ €ν΄λ³΄μλ κ²μ μ΄λ¨κΉμ?
λ€μκ³Ό κ°μ ꡬνμ μ μλ립λλ€:
@Transactional public void deleteFiles(List<File> files) { + if (files.isEmpty()) { + return; + } + + // S3 νμΌ μμ λ₯Ό λ³λ ¬λ‘ μ²λ¦¬ + files.parallelStream().forEach(file -> { try { - s3Operations.deleteObject(bucket, file.getS3Key()); + s3Operations.deleteObject(bucket, file.getS3Key()); } catch (Exception e) { + throw new FileDeleteException("S3 νμΌ μμ μ€ μ€λ₯ λ°μ: " + file.getS3Key(), e); } - } + }); + fileRepository.deleteAll(files); }src/main/java/balancetalk/talkpick/application/TalkPickService.java (1)
101-106
: λ‘κΉ μΆκ° μ μνμΌ μμ μμ μ λͺ¨λν°λ§κ³Ό λλ²κΉ μ μν΄ λ‘κΉ μ μΆκ°νλ κ²μ΄ μ’μ΅λλ€. νΉν νμΌ μμ μμ/μλ£ μμ κ³Ό μμ λ νμΌμ μλ₯Ό κΈ°λ‘νλ©΄ μ μ©ν κ² κ°μ΅λλ€.
private void deleteFiles(Long talkPickId) { + log.debug("Starting file deletion for talkPickId: {}", talkPickId); List<File> files = fileRepository.findAllByResourceIdAndFileType(talkPickId, TALK_PICK); if (files.isEmpty()) { + log.debug("No files found for talkPickId: {}", talkPickId); return; } + log.info("Deleting {} files for talkPickId: {}", files.size(), talkPickId); fileHandler.deleteFiles(files); + log.debug("File deletion completed for talkPickId: {}", talkPickId); }
π Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
π Files selected for processing (4)
src/main/java/balancetalk/file/domain/FileHandler.java
(3 hunks)src/main/java/balancetalk/file/domain/repository/FileRepositoryCustom.java
(2 hunks)src/main/java/balancetalk/file/domain/repository/FileRepositoryImpl.java
(1 hunks)src/main/java/balancetalk/talkpick/application/TalkPickService.java
(1 hunks)
π Additional comments (3)
src/main/java/balancetalk/file/domain/repository/FileRepositoryCustom.java (1)
13-13
: λ©μλ μΆκ°κ° μ μ ν©λλ€
리μμ€ IDμ νμΌ νμ μ κΈ°λ°μΌλ‘ μ 체 File μν°ν°λ₯Ό μ‘°ννλ κΈ°λ₯μ΄ μ ꡬνλμ΄ μμ΅λλ€. μ΄λ PRμ λͺ©μ μΈ λ¦¬μμ€ μμ μ κ΄λ ¨ μ΄λ―Έμ§ νμΌ μμ κΈ°λ₯μ μ§μνλλ° μ ν©ν©λλ€.
src/main/java/balancetalk/file/domain/repository/FileRepositoryImpl.java (1)
35-41
: μΈν°νμ΄μ€ μ μΈκ³Ό μ¬μ©μ²λ₯Ό νμΈν΄μ£ΌμΈμ.
μλ‘ μΆκ°λ λ©μλκ° μ¬λ°λ₯΄κ² μ¬μ©λκ³ μλμ§ νμΈμ΄ νμν©λλ€.
β Verification successful
νμΈ μλ£: μλ‘ μΆκ°λ λ©μλκ° μΈν°νμ΄μ€μ μ¬λ°λ₯΄κ² μ μΈλμμΌλ©°, μ¬μ©μ²λ μ μμ μΌλ‘ νμΈλμμ΅λλ€.
π Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: FileRepositoryCustom μΈν°νμ΄μ€ μ μΈκ³Ό μ¬μ©μ² νμΈ
# μΈν°νμ΄μ€ μ μΈ νμΈ
echo "Checking interface declaration..."
rg -A 2 "findAllByResourceIdAndFileType.*FileType.*\)" --type java
# λ©μλ μ¬μ©μ² νμΈ
echo "Checking usage..."
rg "findAllByResourceIdAndFileType\(" --type java
Length of output: 1346
src/main/java/balancetalk/file/domain/FileHandler.java (1)
18-18
: μμ‘΄μ± μ£Όμ
μ΄ μ¬λ°λ₯΄κ² ꡬνλμμ΅λλ€!
@RequiredArgsConstructor
λ₯Ό ν΅ν μμ±μ μ£Όμ
λ°©μμ΄ μ μ νκ² μ¬μ©λμμ΅λλ€.
public void deleteFiles(List<File> files) { | ||
for (File file : files) { | ||
s3Operations.deleteObject(bucket, file.getS3Key()); | ||
} | ||
fileRepository.deleteAll(files); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μμΈ μ²λ¦¬μ νΈλμμ κ΄λ¦¬κ° νμν©λλ€.
νμ¬ κ΅¬νμλ λ€μκ³Ό κ°μ κ°μ μ΄ νμν©λλ€:
- S3 μμ μ€ν¨ μμ μμΈ μ²λ¦¬
- S3μ λ°μ΄ν°λ² μ΄μ€ μμ κ°μ νΈλμμ κ΄λ¦¬
λ€μκ³Ό κ°μ΄ κ°μ νλ κ²μ μ μλ립λλ€:
+@Transactional
public void deleteFiles(List<File> files) {
+ try {
for (File file : files) {
- s3Operations.deleteObject(bucket, file.getS3Key());
+ try {
+ s3Operations.deleteObject(bucket, file.getS3Key());
+ } catch (Exception e) {
+ throw new FileDeleteException("S3 νμΌ μμ μ€ μ€λ₯ λ°μ: " + file.getS3Key(), e);
+ }
}
fileRepository.deleteAll(files);
+ } catch (Exception e) {
+ throw new FileDeleteException("νμΌ μμ μ€ μ€λ₯κ° λ°μνμ΅λλ€", e);
+ }
}
μΆκ°λ‘ μμΈ ν΄λμ€λ μμ±μ΄ νμν©λλ€:
public class FileDeleteException extends RuntimeException {
public FileDeleteException(String message, Throwable cause) {
super(message, cause);
}
}
deleteFiles(talkPickId); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π οΈ Refactor suggestion
νμΌ μμ μ€ν¨ μ νΈλμμ μ²λ¦¬ κ°μ νμ
νμΌ μμ κ° μ€ν¨νλλΌλ TalkPick μν°ν°λ μ΄λ―Έ μμ λ μνκ° λ μ μμ΅λλ€. νμΌ μμ€ν μ μΌκ΄μ±μ μν΄ λ€μκ³Ό κ°μ κ°μ μ κ³ λ €ν΄λ³΄μΈμ:
- νμΌμ λ¨Όμ μμ ν ν μν°ν°λ₯Ό μμ
- νμΌ μμ μ€ν¨ μ μμΈ μ²λ¦¬ μΆκ°
@Transactional
public void deleteTalkPick(Long talkPickId, ApiMember apiMember) {
Member member = apiMember.toMember(memberRepository);
TalkPick talkPick = member.getTalkPickById(talkPickId);
+ deleteFiles(talkPickId);
talkPickRepository.delete(talkPick);
- deleteFiles(talkPickId);
}
π 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.
deleteFiles(talkPickId); | |
} | |
deleteFiles(talkPickId); | |
talkPickRepository.delete(talkPick); | |
} |
π‘ μμ λ΄μ©
π‘ μμΈν μ€λͺ
ν‘ν½, κ²μ λ± λ¦¬μμ€ μ κ±° API μμ² μ κ΄λ ¨ μ΄λ―Έμ§ νμΌλ μ κ±°λλλ‘ κ΅¬ννμ΅λλ€.
β μ ν 체ν¬λ¦¬μ€νΈ
closes #664
Summary by CodeRabbit
TalkPick
μμ μ κ΄λ ¨ νμΌλ ν¨κ» μμ λ©λλ€.resourceId
μfileType
μ λ°λΌ νμΌ λͺ©λ‘μ κ²μν μ μλ κΈ°λ₯μ΄ μΆκ°λμμ΅λλ€.