Skip to content
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

[DDING-110] 지원자 상세조회시 파일 다운로드 로직 처리 #255

Merged
merged 3 commits into from
Feb 12, 2025

Conversation

KoSeonJe
Copy link
Collaborator

@KoSeonJe KoSeonJe commented Feb 11, 2025

🚀 작업 내용

  • 지원자 상세조회시 질문 유형이 파일일 경우 다운로드 URL을 반환하는 로직을 추가하였습니다

🤔 고민했던 내용

💬 리뷰 중점사항

Summary by CodeRabbit

  • New Features
    • 파일 형식 응답을 자동 감지하여 적절하게 처리하는 기능이 추가되었습니다.
    • 업로드한 파일의 메타데이터를 활용해 CDN 링크를 제공, 파일 응답 처리의 품질이 향상되었습니다.
    • 양식 응답 데이터를 재구성하는 방식이 최적화되어 사용자 경험이 개선되었습니다.
    • API 응답 형식이 변경되어 모든 양식 응답을 포괄하는 기능이 추가되었습니다.

Copy link

coderabbitai bot commented Feb 11, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

이번 변경 사항은 FormAnswer 클래스에 isFile() 메서드를 추가하여 해당 답변이 파일 타입인지 확인할 수 있도록 하였으며, 파일 처리 관련 import 구문을 추가하였습니다. 또한, FacadeCentralFormApplicationServiceImpl 클래스에서는 파일 메타데이터와 S3 파일 관련 서비스를 주입 받아 getAllFormApplication 메서드 내에서 파일 여부를 판단 후, 파일인 경우 CDN URL을 생성하는 로직을 추가하였습니다. FormApplicationQuery 관련 record에서는 FormFieldAnswerListQuery의 생성 방식을 개선하고, 메서드 시그니처를 변경하였습니다.

Changes

파일 경로 변경 내용
src/.../entity/FormAnswer.java - isFile() 메서드 추가 (답변이 파일 타입인지 체크)
- FieldType import 추가
src/.../service/FacadeCentralFormApplicationServiceImpl.java - FileMetaDataServiceS3FileService 관련 import 추가 및 private 필드 추가
- getMyFormApplicationPage 메서드 이름 변경 및 반환 타입 변경
- getFormApplication 메서드 내 반환 로직 변경 (새로운 buildFormFieldAnswerQueries 메서드 호출)
- 파일 여부에 따라 파일 메타데이터 조회 후 CDN URL 생성 로직 추가
src/.../service/dto/query/FormApplicationQuery.java - FormFieldAnswerListQuery record에 of 메서드 추가 (FormAnswer와 List 값을 인자로 받아 생성)
- FormApplicationQuery.of 메서드의 인자 변경 (List → List)
src/.../api/CentralFormApplicationApi.java - getMyFormApplicationPage 메서드 이름 변경 및 반환 타입 변경
src/.../controller/CentralFormApplicationController.java - getMyFormApplicationPage 메서드 이름 변경 및 반환 타입 변경
src/.../controller/dto/response/MyAllFormApplicationsResponse.java - MyFormApplicationsResponseMyAllFormApplicationsResponse로 이름 변경 및 관련 import 수정
src/.../service/FacadeCentralFormApplicationService.java - getMyFormApplicationPage 메서드 제거 및 getAllFormApplication 메서드 추가
src/.../service/dto/query/MyAllFormApplicationsQuery.java - MyFormApplicationsQueryMyAllFormApplicationsQuery로 이름 변경 및 관련 메서드 수정

Suggested labels

✨기능, D-1

Suggested reviewers

  • wonjunYou
  • 5uhwann
  • Seooooo24

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7c89a82 and 473c67a.

📒 Files selected for processing (7)
  • src/main/java/ddingdong/ddingdongBE/domain/formapplication/api/CentralFormApplicationApi.java (2 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/formapplication/controller/CentralFormApplicationController.java (2 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/formapplication/controller/dto/response/MyAllFormApplicationsResponse.java (3 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/formapplication/service/FacadeCentralFormApplicationService.java (1 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/formapplication/service/FacadeCentralFormApplicationServiceImpl.java (3 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/formapplication/service/dto/query/FormApplicationQuery.java (1 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/formapplication/service/dto/query/MyAllFormApplicationsQuery.java (2 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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.

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.

Copy link

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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a330587 and 7c89a82.

📒 Files selected for processing (3)
  • src/main/java/ddingdong/ddingdongBE/domain/formapplication/entity/FormAnswer.java (2 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/formapplication/service/FacadeCentralFormApplicationServiceImpl.java (4 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/formapplication/service/dto/query/FormApplicationQuery.java (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build and analyze
🔇 Additional comments (6)
src/main/java/ddingdong/ddingdongBE/domain/formapplication/entity/FormAnswer.java (2)

5-5: 필요한 import 구문이 잘 추가되었습니다.

FieldType enum을 사용하기 위한 import 구문이 적절히 추가되었습니다.


48-50: 파일 타입 체크 메서드가 잘 구현되었습니다.

메서드가 간단하고 명확하며, 단일 책임 원칙을 잘 따르고 있습니다.

src/main/java/ddingdong/ddingdongBE/domain/formapplication/service/dto/query/FormApplicationQuery.java (2)

51-62: 새로운 팩토리 메서드가 적절히 추가되었습니다.

기존 from 메서드와 구분되는 새로운 of 메서드가 추가되어 파일 URL과 같은 커스텀 값을 주입할 수 있게 되었습니다.


65-66: 메서드 시그니처 변경이 적절합니다.

FormFieldAnswerListQuery 리스트를 직접 받도록 변경되어 파일 URL 처리와 같은 전처리된 데이터를 수용할 수 있게 되었습니다.

src/main/java/ddingdong/ddingdongBE/domain/formapplication/service/FacadeCentralFormApplicationServiceImpl.java (2)

32-33: 파일 관련 서비스 의존성이 잘 추가되었습니다.

FileMetaDataServiceS3FileService가 적절히 주입되어 파일 처리 기능을 지원합니다.


59-60: 리팩토링된 코드가 잘 적용되었습니다.

기존 코드가 새로운 buildFormFieldAnswerQueries 메서드를 사용하도록 깔끔하게 수정되었습니다.

Comment on lines +71 to +83
private List<FormFieldAnswerListQuery> buildFormFieldAnswerQueries(List<FormAnswer> formAnswers) {
return formAnswers.stream()
.map(formAnswer -> {
if (formAnswer.isFile()) {
String fileId = formAnswer.getValue().get(0);
FileMetaData fileMetaData = fileMetaDataService.getById(fileId);
String cdnUrl = s3FileService.getUploadedFileUrl(fileMetaData.getFileKey()).cdnUrl();
return FormFieldAnswerListQuery.of(formAnswer, List.of(cdnUrl));
}
return FormFieldAnswerListQuery.from(formAnswer);
})
.toList();
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

파일 처리 로직에 대한 개선이 필요합니다.

  1. 파일 메타데이터 조회 및 URL 생성 시 예외 처리가 필요합니다.
  2. formAnswer.getValue().get(0)는 리스트가 비어있을 경우 예외가 발생할 수 있습니다.
  3. 스트림 연산이 많은 데이터를 처리할 때 성능 이슈가 발생할 수 있습니다.

다음과 같이 개선을 제안드립니다:

 private List<FormFieldAnswerListQuery> buildFormFieldAnswerQueries(List<FormAnswer> formAnswers) {
     return formAnswers.stream()
             .map(formAnswer -> {
                 if (formAnswer.isFile()) {
-                    String fileId = formAnswer.getValue().get(0);
+                    List<String> values = formAnswer.getValue();
+                    if (values == null || values.isEmpty()) {
+                        return FormFieldAnswerListQuery.of(formAnswer, List.of());
+                    }
+                    String fileId = values.get(0);
+                    try {
                         FileMetaData fileMetaData = fileMetaDataService.getById(fileId);
                         String cdnUrl = s3FileService.getUploadedFileUrl(fileMetaData.getFileKey()).cdnUrl();
                         return FormFieldAnswerListQuery.of(formAnswer, List.of(cdnUrl));
+                    } catch (Exception e) {
+                        log.error("파일 처리 중 오류 발생: {}", e.getMessage());
+                        return FormFieldAnswerListQuery.of(formAnswer, List.of());
+                    }
                 }
                 return FormFieldAnswerListQuery.from(formAnswer);
             })
             .toList();
 }
📝 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
private List<FormFieldAnswerListQuery> buildFormFieldAnswerQueries(List<FormAnswer> formAnswers) {
return formAnswers.stream()
.map(formAnswer -> {
if (formAnswer.isFile()) {
String fileId = formAnswer.getValue().get(0);
FileMetaData fileMetaData = fileMetaDataService.getById(fileId);
String cdnUrl = s3FileService.getUploadedFileUrl(fileMetaData.getFileKey()).cdnUrl();
return FormFieldAnswerListQuery.of(formAnswer, List.of(cdnUrl));
}
return FormFieldAnswerListQuery.from(formAnswer);
})
.toList();
}
private List<FormFieldAnswerListQuery> buildFormFieldAnswerQueries(List<FormAnswer> formAnswers) {
return formAnswers.stream()
.map(formAnswer -> {
if (formAnswer.isFile()) {
List<String> values = formAnswer.getValue();
if (values == null || values.isEmpty()) {
return FormFieldAnswerListQuery.of(formAnswer, List.of());
}
String fileId = values.get(0);
try {
FileMetaData fileMetaData = fileMetaDataService.getById(fileId);
String cdnUrl = s3FileService.getUploadedFileUrl(fileMetaData.getFileKey()).cdnUrl();
return FormFieldAnswerListQuery.of(formAnswer, List.of(cdnUrl));
} catch (Exception e) {
log.error("파일 처리 중 오류 발생: {}", e.getMessage());
return FormFieldAnswerListQuery.of(formAnswer, List.of());
}
}
return FormFieldAnswerListQuery.from(formAnswer);
})
.toList();
}

Copy link
Collaborator

@Seooooo24 Seooooo24 left a comment

Choose a reason for hiding this comment

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

고생하셨습니다!

@github-actions github-actions bot added the D-3 label Feb 12, 2025
@KoSeonJe KoSeonJe merged commit 4387670 into develop Feb 12, 2025
1 of 2 checks passed
@KoSeonJe KoSeonJe deleted the feature/DDING-110 branch February 12, 2025 15:49
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants