Skip to content

refactor/#261 Facade에서 FileEntity 대신 File의physicalPath를 사용하도록 수정#262

Merged
dkdltm221 merged 1 commit intodevelopfrom
refactor/#261
Sep 6, 2025
Merged

refactor/#261 Facade에서 FileEntity 대신 File의physicalPath를 사용하도록 수정#262
dkdltm221 merged 1 commit intodevelopfrom
refactor/#261

Conversation

@dkdltm221
Copy link
Copy Markdown
Contributor

Summary

해당 PR에 대한 요약을 작성해주세요.
현재 clubFacde, labFacade에서 FileEntity를 사용하는 문제가 있습니다.
File Entity관리를 FileQueryService 계층에서 진행하도록 수정합니다

Tasks

  • Facade에서 FileEntity 대신 File의physicalPath를 사용하도록 수정

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Sep 4, 2025

Walkthrough

클럽/랩 목록 조회 흐름에서 파일 매핑 타입을 FileEntity에서 물리 경로 String으로 전환했습니다. Facade 계층은 findPhysicalPathMapByIds를 사용하며, 각 Response의 from(...) 시그니처와 내부 로직이 이에 맞게 업데이트되었습니다. FilePathResponse 생성도 (fileId, physicalPath) 기반으로 변경되었습니다.

Changes

Cohort / File(s) Change summary
Facade 전환 (파일 맵 타입 변경)
aics-api/.../club/application/ClubFacade.java, aics-api/.../lab/application/LabFacade.java
파일 조회 맵 소스 변경: findFileEntityMapByIds(...)findPhysicalPathMapByIds(...)(반환 타입 Map<Long, String>)
Club 응답 DTO 업데이트
aics-api/.../club/presentation/response/ClubListResponse.java, aics-api/.../club/presentation/response/ClubDetailResponse.java
from(...) 시그니처 변경: 파일 맵 값 타입 FileEntityString(physicalPath); ClubDetailResponse.from(Club, FileEntity)from(Club, String); FilePathResponse.from(file) 호출 제거, FilePathResponse.of(fileId, physicalPath) 사용
Lab 응답 DTO 업데이트
aics-api/.../lab/presentation/response/LabListResponse.java, aics-api/.../lab/presentation/response/LabDetailResponse.java
from(...) 시그니처 변경: 파일 맵 값 타입 FileEntityString; LabDetailResponse.from(Lab, FileEntity)from(Lab, String); FilePathResponse.of(fileId, physicalPath) 사용 및 불필요한 FileEntity import 제거
파일 조회 서비스 API 변경
aics-domain/.../file/application/query/FileQueryService.java
공개 메서드 변경: findFileEntityMapByIds(List<Long>)findPhysicalPathMapByIds(List<Long>); 반환 타입 Map<Long, FileEntity>Map<Long, String>; 매핑 로직을 getPhysicalPath로 조정 및 Function import 제거

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

Suggested labels

🔨refactor

Suggested reviewers

  • JangYeongHu
  • LeeHanEum
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/#261

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@dkdltm221 dkdltm221 self-assigned this Sep 4, 2025
@dkdltm221 dkdltm221 added the 🔨refactor refactoring code label Sep 4, 2025
@github-actions
Copy link
Copy Markdown

github-actions bot commented Sep 4, 2025

Test Coverage Report

Overall Project 95.47% 🍏
Files changed 100% 🍏

Module Coverage
aics-api 99.53% 🍏
Files
Module File Coverage
aics-api ClubFacade.java 100% 🍏
LabFacade.java 100% 🍏

@dkdltm221 dkdltm221 linked an issue Sep 4, 2025 that may be closed by this pull request
1 task
@codecov
Copy link
Copy Markdown

codecov bot commented Sep 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@            Coverage Diff             @@
##             develop     #262   +/-   ##
==========================================
  Coverage      92.98%   92.98%           
  Complexity       160      160           
==========================================
  Files             49       49           
  Lines            456      456           
  Branches           6        6           
==========================================
  Hits             424      424           
  Misses            25       25           
  Partials           7        7           
Files with missing lines Coverage Δ Complexity Δ
...gu/developers/api/club/application/ClubFacade.java 100.00% <100.00%> (ø) 1.00 <0.00> (ø)
.../kgu/developers/api/lab/application/LabFacade.java 100.00% <100.00%> (ø) 1.00 <0.00> (ø)

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 85246d2...73d9581. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
aics-api/src/main/java/kgu/developers/api/club/presentation/response/ClubDetailResponse.java (1)

26-28: Swagger 예시(JSON)와 실제 응답 스키마를 일치시켜 주세요

현재 예시는 physicalPath만 담고 있으나, 실제 FilePathResponseidphysicalPath를 함께 포함합니다. 문서-실제 응답 불일치를 해소해 주세요.

-  @Schema(description = "첨부 파일 정보",
-    example = "{\"physicalPath\": \"/cloud/file/3/2025-curriculum\"}",
-    requiredMode = NOT_REQUIRED)
+  @Schema(description = "첨부 파일 정보",
+    example = "{\"id\": 3, \"physicalPath\": \"/cloud/file/3/2025-curriculum\"}",
+    requiredMode = NOT_REQUIRED)
🧹 Nitpick comments (8)
aics-api/src/main/java/kgu/developers/api/lab/application/LabFacade.java (1)

31-31: 중복 ID 제거 및 가독성 개선 제안

fileIds에 distinct()를 적용해 불필요한 조회/매핑을 줄이고, 콤마 뒤 공백을 추가해 컨벤션을 맞추면 좋겠습니다.

아래처럼 변경을 제안합니다.

-        List<Long> fileIds = labs.stream()
-                .map(Lab::getFileId)
-                .filter(Objects::nonNull)
-                .toList();
+        List<Long> fileIds = labs.stream()
+                .map(Lab::getFileId)
+                .filter(Objects::nonNull)
+                .distinct()
+                .toList();

-        return LabListResponse.from(labs,fileQueryService.findPhysicalPathMapByIds(fileIds));
+        return LabListResponse.from(labs, fileQueryService.findPhysicalPathMapByIds(fileIds));
aics-api/src/main/java/kgu/developers/api/club/application/ClubFacade.java (1)

30-30: 중복 ID 제거 및 가독성 개선 제안

동일한 개선을 클럽에도 적용해주세요. distinct()로 조회 안정성을 높이고, 콤마 뒤 공백을 추가하는 것이 좋습니다.

-        List<Long> fileIds = clubs.stream()
-                .map(Club::getFileId)
-                .filter(Objects::nonNull)
-                .toList();
+        List<Long> fileIds = clubs.stream()
+                .map(Club::getFileId)
+                .filter(Objects::nonNull)
+                .distinct()
+                .toList();

-        return ClubListResponse.from(clubs,fileQueryService.findPhysicalPathMapByIds(fileIds));
+        return ClubListResponse.from(clubs, fileQueryService.findPhysicalPathMapByIds(fileIds));
aics-api/src/main/java/kgu/developers/api/club/presentation/response/ClubListResponse.java (2)

8-8: 불필요한 import 제거

FileEntity를 더 이상 사용하지 않으므로 import를 제거하세요.

-import kgu.developers.domain.file.domain.FileEntity;

25-31: 의미가 드러나는 파라미터명과 null 안전 처리 제안

fileMap보다는 physicalPathMap이 더 명확합니다. 또한 매핑 누락 시 null 전달이 의도인지 확인 바랍니다. 필요하면 placeholder로 대체하는 예시는 아래와 같습니다.

-    public static ClubListResponse from(List<Club> clubs, Map<Long,String> fileMap) {
+    public static ClubListResponse from(List<Club> clubs, Map<Long, String> physicalPathMap) {
         return ClubListResponse.builder()
             .contents(clubs.stream()
-                .map(club -> ClubDetailResponse.from(club,
-                        fileMap.get(club.getFileId())))
+                .map(club -> {
+                    String path = physicalPathMap.get(club.getFileId());
+                    return ClubDetailResponse.from(club, path /* null 허용/대체 여부 확인 */);
+                })
                 .toList())
             .build();
     }
aics-domain/src/main/java/kgu/developers/domain/file/application/query/FileQueryService.java (1)

21-25: 빈 입력 최적화(미세 최적화)

ids가 비어있으면 조기 반환하여 불필요한 DB 호출을 피할 수 있습니다.

-    public Map<Long,String> findPhysicalPathMapByIds(List<Long> ids) {
+    public Map<Long, String> findPhysicalPathMapByIds(List<Long> ids) {
+        if (ids == null || ids.isEmpty()) {
+            return Map.of();
+        }
         return fileRepository.findAllByIds(ids)
             .stream()
             .collect(Collectors.toMap(FileEntity::getId, FileEntity::getPhysicalPath));
     }
aics-api/src/main/java/kgu/developers/api/lab/presentation/response/LabListResponse.java (1)

26-31: 의미가 드러나는 파라미터명과 null 처리 확인

Club과 동일하게 physicalPathMap으로 이름을 명확히 하고, 매핑 누락 시 처리 방식을 확인해주세요.

-    public static LabListResponse from(List<Lab> labs, Map<Long, String> fileMap) {
+    public static LabListResponse from(List<Lab> labs, Map<Long, String> physicalPathMap) {
         return LabListResponse.builder()
             .contents(labs.stream()
-                .map(lab -> LabDetailResponse.from(lab,fileMap.get(lab.getFileId())))
+                .map(lab -> LabDetailResponse.from(lab, physicalPathMap.get(lab.getFileId())))
                 .toList())
             .build();
     }
aics-api/src/main/java/kgu/developers/api/lab/presentation/response/LabDetailResponse.java (1)

35-44: 물리 경로가 null/공백일 때 불완전한 응답 생성을 방지하세요

fileId는 있지만 physicalPathnull/공백일 수 있는 경우를 가드하지 않으면, 불완전한 FilePathResponse가 내려갈 수 있습니다. 안전하게 가드해 주세요.

다음과 같이 생성 로직을 한 단계 풀어 가드를 추가하는 것을 제안합니다.

-      .advisor(lab.getAdvisor())
-      .img(lab.getFileId() != null ? FilePathResponse.of(lab.getFileId(), physicalPath) : null)
+      .advisor(lab.getAdvisor())
+      .img(buildImg(lab, physicalPath))
       .build();
   }
+
+  private static FilePathResponse buildImg(Lab lab, String physicalPath) {
+    if (lab.getFileId() == null) return null;
+    if (physicalPath == null || physicalPath.isBlank()) return null;
+    return FilePathResponse.of(lab.getFileId(), physicalPath);
+  }
aics-api/src/main/java/kgu/developers/api/club/presentation/response/ClubDetailResponse.java (1)

31-38: physicalPath null/공백 가드로 응답 일관성 확보

club.getFileId()만 체크하면 physicalPath가 누락된 상태로 FilePathResponse를 만들 가능성이 있습니다. Lab과 동일하게 가드를 추가해 주세요.

-      .site(club.getSite())
-      .file(club.getFileId() != null ? FilePathResponse.of(club.getFileId(), physicalPath) : null)
+      .site(club.getSite())
+      .file(buildFile(club, physicalPath))
       .build();
   }
+
+  private static FilePathResponse buildFile(Club club, String physicalPath) {
+    if (club.getFileId() == null) return null;
+    if (physicalPath == null || physicalPath.isBlank()) return null;
+    return FilePathResponse.of(club.getFileId(), physicalPath);
+  }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 85246d2 and 73d9581.

📒 Files selected for processing (7)
  • aics-api/src/main/java/kgu/developers/api/club/application/ClubFacade.java (1 hunks)
  • aics-api/src/main/java/kgu/developers/api/club/presentation/response/ClubDetailResponse.java (1 hunks)
  • aics-api/src/main/java/kgu/developers/api/club/presentation/response/ClubListResponse.java (1 hunks)
  • aics-api/src/main/java/kgu/developers/api/lab/application/LabFacade.java (1 hunks)
  • aics-api/src/main/java/kgu/developers/api/lab/presentation/response/LabDetailResponse.java (1 hunks)
  • aics-api/src/main/java/kgu/developers/api/lab/presentation/response/LabListResponse.java (1 hunks)
  • aics-domain/src/main/java/kgu/developers/domain/file/application/query/FileQueryService.java (1 hunks)
🔇 Additional comments (5)
aics-api/src/main/java/kgu/developers/api/lab/application/LabFacade.java (1)

31-31: physicalPath 누락 시 처리 확인 필요

fileMap.get(lab.getFileId())가 null이 될 수 있습니다. LabDetailResponse.from이 null physicalPath를 안전하게 처리(placeholder 등)하는지 확인 부탁드립니다.

aics-api/src/main/java/kgu/developers/api/club/application/ClubFacade.java (1)

30-30: physicalPath 누락 시 처리 확인 필요

fileMap에서 매핑을 찾지 못하면 null이 전달됩니다. ClubDetailResponse.from이 null을 허용하는지(또는 기본 이미지로 대체하는지) 확인 바랍니다.

aics-api/src/main/java/kgu/developers/api/lab/presentation/response/LabListResponse.java (1)

21-23: public 노출 경로 점검

예시의 "physicalPath"가 서버 내부 물리 경로가 아니라 클라이언트에 노출 가능한 공개 경로(또는 프록시/CDN 경로)인지 확인 바랍니다. 내부 경로 노출은 보안/운영 리스크가 있습니다.

aics-api/src/main/java/kgu/developers/api/lab/presentation/response/LabDetailResponse.java (1)

42-42: 의존 역전 정리 좋습니다

Facade에서 엔티티를 숨기고 DTO가 경로 문자열만 받도록 한 점이 깔끔합니다. 호출자-응답 간 결합도가 줄었습니다.

aics-api/src/main/java/kgu/developers/api/club/presentation/response/ClubDetailResponse.java (1)

31-38: 엔티티 의존성 제거 방향 LGTM

Facade → DTO 경계에서 엔티티 노출을 제거하고 경로 문자열로 치환한 방향은 타 계층과의 결합도를 줄여 유지보수성에 유리합니다.

FilePathResponse img
) {
public static LabDetailResponse from(Lab lab, FileEntity file) {
public static LabDetailResponse from(Lab lab, String physicalPath) {
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.

💡 Verification agent

🧩 Analysis chain

시그니처 변경(physicalPath) 반영 범위 확인 부탁

from(Lab, String)로 바뀐 만큼, 호출부에서 FileEntity를 넘기던 코드가 남아있지 않은지 확인 필요합니다. 또한 FilePathResponse.from(...) 사용이 모두 of(Long, String)으로 교체되었는지 점검해 주세요.

아래 스크립트로 잔여 사용처를 빠르게 확인할 수 있습니다.


🏁 Script executed:

#!/bin/bash
# 남아있는 구 시그니처/팩토리 사용 탐지
rg -nP 'FilePathResponse\.from\s*\(' -C2
rg -nP 'LabDetailResponse\.from\s*\(' -C2
rg -nP 'new\s+FileEntity\(|\bFileEntity\b' -g '!**/build/**' -C2

Length of output: 34599


FilePathResponse.from 호출부 교체 필요

  • aics-domain/src/main/java/kgu/developers/domain/post/application/response/PostDetailResponse.java:79
    FilePathResponse.from(post.getFile())FilePathResponse.of(post.getFile().getId(), post.getFile().getPhysicalPath())
  • aics-admin/src/main/java/kgu/developers/admin/file/application/FileAdminFacade.java:22
    FilePathResponse.from(savedFile)FilePathResponse.of(savedFile.getId(), storedPath)

LabDetailResponse.from 호출부는 모두 String physicalPath 형태로 변경되어 문제 없습니다.

🤖 Prompt for AI Agents
In
aics-api/src/main/java/kgu/developers/api/lab/presentation/response/LabDetailResponse.java
around line 35, the factory should use the new FilePathResponse.of(id,
physicalPath) signature instead of FilePathResponse.from(...); update the
LabDetailResponse.from(Lab lab, String physicalPath) implementation to call
FilePathResponse.of(lab.getFile().getId(), physicalPath) (and adjust/remove any
now-incorrect FilePathResponse.from(...) calls), and add/update imports if
necessary.

Comment on lines +21 to 25
public Map<Long,String> findPhysicalPathMapByIds(List<Long> ids) {
return fileRepository.findAllByIds(ids)
.stream()
.collect(Collectors.toMap(FileEntity::getId, Function.identity()));
.collect(Collectors.toMap(FileEntity::getId, FileEntity::getPhysicalPath));
}
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

toMap 중복 키 병합 함수 추가로 안전성 확보

중복 ID가 반환될 경우 Collectors.toMap이 IllegalStateException을 던질 수 있습니다. 병합 함수를 명시해 런타임 예외를 방지하세요. (첫 값 유지)

-        return fileRepository.findAllByIds(ids)
-                .stream()
-                .collect(Collectors.toMap(FileEntity::getId, FileEntity::getPhysicalPath));
+        return fileRepository.findAllByIds(ids)
+                .stream()
+                .collect(Collectors.toMap(
+                        FileEntity::getId,
+                        FileEntity::getPhysicalPath,
+                        (prev, curr) -> prev
+                ));
📝 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 Map<Long,String> findPhysicalPathMapByIds(List<Long> ids) {
return fileRepository.findAllByIds(ids)
.stream()
.collect(Collectors.toMap(FileEntity::getId, Function.identity()));
.collect(Collectors.toMap(FileEntity::getId, FileEntity::getPhysicalPath));
}
public Map<Long, String> findPhysicalPathMapByIds(List<Long> ids) {
return fileRepository.findAllByIds(ids)
.stream()
.collect(Collectors.toMap(
FileEntity::getId,
FileEntity::getPhysicalPath,
(prev, curr) -> prev
));
}
🤖 Prompt for AI Agents
In
aics-domain/src/main/java/kgu/developers/domain/file/application/query/FileQueryService.java
around lines 21 to 25, the Collectors.toMap call can throw IllegalStateException
if duplicate IDs appear; update the collector to supply a merge function that
keeps the first value (e.g., (existing, replacement) -> existing) so duplicates
are merged safely and the method returns a stable Map.

Copy link
Copy Markdown
Contributor

@JangYeongHu JangYeongHu left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@dkdltm221 dkdltm221 merged commit 0f39385 into develop Sep 6, 2025
5 checks passed
@dkdltm221 dkdltm221 deleted the refactor/#261 branch September 6, 2025 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨refactor refactoring code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FileQueryService에서 FileEntity를 반환하는 로직 수정

2 participants