Skip to content

🔨 Refactor: 이미지 파일 도메인 처리 구조 개선#154

Merged
WhiteBin-bin merged 1 commit into
DoDo-Project:developfrom
WhiteBin-bin:refactor/153
Jun 4, 2026
Merged

🔨 Refactor: 이미지 파일 도메인 처리 구조 개선#154
WhiteBin-bin merged 1 commit into
DoDo-Project:developfrom
WhiteBin-bin:refactor/153

Conversation

@WhiteBin-bin
Copy link
Copy Markdown
Contributor

📄 작업 내용 (Description)

이번 PR에서 변경되거나 추가된 주요 작업을 간단히 설명해주세요.

  • 펫 생성 및 수정 시 imageFileUrl 저장/수정 로직을 ImageFileService로 위임
  • ImageFileException 및 ImageFileErrorCode 추가로 이미지 파일 전용 예외 처리 분리
  • ImageFileMapper를 추가해 프로필 이미지 URL 동적 업데이트 처리
  • 이미지 파일 및 펫 서비스 테스트 보강

🔗 관련 이슈 (Related Issues)

작업한 이슈 번호를 아래 형식으로 PULL REQUEST BODY에 작성해주세요.
(PR 머지 시 해당 이슈가 자동으로 종료됩니다.)


✅ 체크리스트 (Checklist)

PR을 보내기 전 아래 항목들을 모두 확인해주세요.

  • PR 제목은 커밋 컨벤션을 따랐습니다.
  • 관련 이슈를 연결했습니다.
  • 스스로 코드를 검토하고 불필요한 코드를 제거했습니다.
  • 코드 스타일이 프로젝트 규칙과 일치합니다. (Style)
  • 새로운 기능에 대한 테스트 코드를 추가했거나, 기존 테스트가 모두 통과했습니다. (Test)

📸 스크린샷 (Screenshots)

작업 내용과 관련된 스크린샷이 있다면 첨부해주세요. (UI 변경이 있는 경우)

Before After

💬 기타 사항 (Etc)

리뷰어에게 전달하고 싶은 추가 정보가 있다면 자유롭게 작성해주세요.

펫 생성 api를 사용할때 url이미지가 들어가지 않아서 로직 변경했습니다.

@WhiteBin-bin WhiteBin-bin requested a review from limhb708 June 4, 2026 10:29
@WhiteBin-bin WhiteBin-bin self-assigned this Jun 4, 2026
@WhiteBin-bin WhiteBin-bin added ⚒️ Refactor 기존 코드 및 아키텍처를 개선 🐯 백현빈 백현빈 파트 labels Jun 4, 2026
@github-project-automation github-project-automation Bot moved this to 📝 할 일 in 칸반 보드 Jun 4, 2026
@WhiteBin-bin WhiteBin-bin moved this from 📝 할 일 to ☑️ 완료 in 칸반 보드 Jun 4, 2026
@WhiteBin-bin WhiteBin-bin moved this from ☑️ 완료 to 🏃 진행 중 in 칸반 보드 Jun 4, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces pet profile image management, allowing users to register and update pet profile image URLs. It adds exception handling for the image file domain, implements image saving and updating logic in ImageFileServiceImpl, and integrates these changes into the pet registration and update flows. The review feedback highlights a compilation error in ImageFileServiceImpl due to an incorrect lambda signature in ThrowingFunction.of. Additionally, it suggests removing @Transactional from the image upload method to prevent database connection pool exhaustion during external network I/O, and recommends using Spring Data JPA instead of introducing a new MyBatis mapper to update ImageFile entities.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines 84 to 85
@Transactional(readOnly = true)
@Override
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

uploadImages 메서드는 데이터베이스와 상호작용하지 않고 외부 서비스(Cloudinary)로의 네트워크 I/O 작업만 수행합니다. 느린 외부 네트워크 호출 동안 데이터베이스 트랜잭션(@Transactional)을 유지하면 커넥션 풀의 커넥션을 불필요하게 오래 점유하게 되어, 트래픽이 몰릴 때 커넥션 풀 고갈(Connection Pool Exhaustion) 문제를 유발할 수 있습니다. 이 메서드에서 @Transactional(readOnly = true) 어노테이션을 제거하는 것을 권장합니다.

Suggested change
@Transactional(readOnly = true)
@Override
@Override

Comment on lines +143 to +151
int updatedRows = imageFileMapper.updatePetProfileImage(
pet.getPetId(),
imageFileUrl,
extractOriginalFilename(imageFileUrl)
);

if (updatedRows == 0) {
savePetProfileImage(pet, imageFileUrl);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

JPA로 관리되는 ImageFile 엔티티를 업데이트하기 위해 새로운 MyBatis Mapper(ImageFileMapper)를 도입하는 것은 불필요한 복잡성을 초래하며, JPA 영속성 컨텍스트(1차 캐시)와 데이터베이스 상태 간의 불일치 문제를 발생시킬 수 있습니다.

MyBatis를 사용하는 대신 Spring Data JPA를 활용하여 일관된 데이터 접근 기술을 사용하는 것이 좋습니다. 다음과 같은 방법으로 개선할 수 있습니다:

  1. ImageFileRepositoryfindByPet_PetId 메서드를 정의하여 기존 엔티티를 조회한 후, 엔티티의 필드를 직접 수정하여 JPA의 더티 체킹(Dirty Checking)을 활용합니다.
  2. 또는 ImageFileRepository@Modifying@Query를 사용하여 벌크 업데이트 쿼리를 작성합니다.

이렇게 개선하면 추가적인 ImageFileMapper.java 인터페이스와 ImageFileMapper.xml 파일을 완전히 제거할 수 있어 유지보수성이 크게 향상됩니다.

        imageFileRepository.findByPet_PetId(pet.getPetId())
                .ifPresentOrElse(
                        imageFile -> {
                            // TODO: ImageFile 엔티티에 업데이트 메서드 추가 필요
                            imageFile.updateProfileImage(imageFileUrl, extractOriginalFilename(imageFileUrl));
                        },
                        () -> savePetProfileImage(pet, imageFileUrl)
                );

- 펫 생성 및 수정 시 imageFileUrl 저장/수정 로직을 ImageFileService로 위임
- ImageFileException 및 ImageFileErrorCode 추가로 이미지 파일 전용 예외 처리 분리
- ImageFileMapper를 추가해 프로필 이미지 URL 동적 업데이트 처리
- 이미지 파일 및 펫 서비스 테스트 보강

Closes DoDo-Project#153
@WhiteBin-bin WhiteBin-bin merged commit 96e284c into DoDo-Project:develop Jun 4, 2026
1 check passed
@WhiteBin-bin WhiteBin-bin deleted the refactor/153 branch June 4, 2026 10:36
@github-project-automation github-project-automation Bot moved this from 🏃 진행 중 to ☑️ 완료 in 칸반 보드 Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⚒️ Refactor 기존 코드 및 아키텍처를 개선 🐯 백현빈 백현빈 파트

Projects

Status: ☑️ 완료

Development

Successfully merging this pull request may close these issues.

[Refactor] 이미지 파일 도메인 예외 및 프로필 이미지 처리 구조 개선

1 participant