Skip to content

fix: Ai 채팅요청에 대한 응답으로 Url 포함하도록 개선#245

Merged
yooooonshine merged 1 commit intodevelopfrom
feature/244-fix-chat-image-url
Nov 9, 2025
Merged

fix: Ai 채팅요청에 대한 응답으로 Url 포함하도록 개선#245
yooooonshine merged 1 commit intodevelopfrom
feature/244-fix-chat-image-url

Conversation

@yooooonshine
Copy link
Contributor

@yooooonshine yooooonshine commented Nov 9, 2025

개요

작업사항

  • Ai 채팅요청에 대한 응답으로 Url 포함하도록 개선

Summary by CodeRabbit

릴리스 노트

  • 버그 수정

    • 채팅 메시지에서 이미지 URL 처리 로직을 개선했습니다.
    • 이미지가 있을 때 메시지 응답 구성이 더욱 명확해졌습니다.
  • 개선 사항

    • 채팅 메시지 응답 생성 방식을 최적화했습니다.
    • 이미지 생성 후 응답 처리 흐름이 개선되었습니다.

@coderabbitai
Copy link

coderabbitai bot commented Nov 9, 2025

개요

채팅 응답의 이미지 URL 처리 방식을 개선하기 위해 ChatMessageResponse 팩토리 메서드를 from(entity, imageUrl)에서 of(entity, imageUrl)로 변경하고, 서비스 계층에서 이미지 엔티티를 일관되게 전달하도록 리팩토링했습니다. 또한 AiServerService에 새로운 의존성을 추가하여 이미지 URL 생성 로직을 통합했습니다.

변경사항

코호트 / 파일 변경 요약
ChatMessageResponse 팩토리 메서드 변경
src/main/java/hanium/modic/backend/web/ai/aiChat/dto/response/ChatMessageResponse.java
공개 팩토리 메서드 from(entity, imageUrl)of(entity, imageUrl)으로 이름 변경. from(entity) 메서드는 새로운 of(entity, null)로 위임하도록 업데이트
서비스 계층의 팩토리 메서드 호출 변경
src/main/java/hanium/modic/backend/domain/ai/aiChat/service/AiChatMessageService.java, src/main/java/hanium/modic/backend/domain/ai/aiServer/listener/AiImageCreatedListener.java, src/main/java/hanium/modic/backend/domain/ai/aiServer/service/AiServerService.java
모든 호출 위치에서 팩토리 메서드 from(message, imageUrl)of(message, imageUrl) 변경. 이미지가 없을 때는 from(message) 사용
AiServerService 의존성 확장
src/main/java/hanium/modic/backend/domain/ai/aiServer/service/AiServerService.java
AiChatImageService 의존성 추가. processAiRequestrequestChatCreation 메서드 시그니처에 List<AiChatImageEntity> aiChatImages 파라미터 추가. 이미지 URL 조회 로직 구현: 비어있지 않은 경우 aiChatImageService.createImageGetUrl 호출

시퀀스 다이어그램

sequenceDiagram
    participant Client
    participant Service as AiServerService
    participant ChatService as AiChatService
    participant ImageService as AiChatImageService
    participant Response as ChatMessageResponse

    Client->>Service: processAiRequest(aiChatImages)
    Service->>ChatService: requestChatCreation(message, aiChatImages)
    ChatService->>ImageService: createImageGetUrl (if images exist)
    ImageService-->>ChatService: imageUrl
    ChatService->>Response: of(message, imageUrl)
    Response-->>ChatService: ChatMessageResponse
    ChatService-->>Service: response with image
    Service-->>Client: SSE response
Loading

예상 코드 리뷰 노력

🎯 2 (Simple) | ⏱️ ~10분

  • 주의 깊게 검토할 영역:
    • AiServerService에서 aiChatImages 파라미터 전달 및 이미지 URL 조회 로직이 올바르게 구현되었는지 확인 필요
    • 이미지가 없는 경우(null 또는 빈 리스트)에 대한 ChatMessageResponse 생성이 일관되게 처리되는지 검증
    • 기존 코드와의 호환성 확인 (팩토리 메서드 이름 변경에 따른 영향도)

관련 가능성 있는 PR

🐰 Chat's flowing smooth, images bright,
No more null values in the night,
Factory methods dance with grace,
Images now find their place,
Service layers shine just right! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed PR 제목이 변경사항의 핵심을 명확하게 설명합니다: AI 채팅 요청 응답에 URL 포함하도록 개선.
Description check ✅ Passed PR 설명이 제공된 템플릿 구조를 따르며 필수 섹션(개요, 작업사항)을 모두 포함합니다.
Linked Issues check ✅ Passed 코드 변경사항이 연결된 이슈 #244의 요구사항(ImageUrl이 null로 들어가는 오류 수정)을 충족합니다.
Out of Scope Changes check ✅ Passed 모든 변경사항이 AI 채팅 응답의 ImageUrl 포함이라는 단일 목표에 집중되어 있습니다.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/244-fix-chat-image-url

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@yooooonshine yooooonshine merged commit 3e10dbc into develop Nov 9, 2025
1 of 2 checks passed
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 UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f634c78 and 8f03165.

📒 Files selected for processing (4)
  • src/main/java/hanium/modic/backend/domain/ai/aiChat/service/AiChatMessageService.java (4 hunks)
  • src/main/java/hanium/modic/backend/domain/ai/aiServer/listener/AiImageCreatedListener.java (1 hunks)
  • src/main/java/hanium/modic/backend/domain/ai/aiServer/service/AiServerService.java (7 hunks)
  • src/main/java/hanium/modic/backend/web/ai/aiChat/dto/response/ChatMessageResponse.java (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (14)
src/main/java/hanium/modic/backend/domain/ai/aiServer/listener/AiImageCreatedListener.java (1)

121-121: API 변경사항이 올바르게 적용되었습니다.

ChatMessageResponse.of()로의 메서드 이름 변경이 정확하게 반영되었으며, imageUrl 파라미터가 적절히 전달되고 있습니다.

src/main/java/hanium/modic/backend/web/ai/aiChat/dto/response/ChatMessageResponse.java (2)

22-33: 팩토리 메서드 이름 변경이 적절합니다.

of() 메서드명은 여러 파라미터를 받는 정적 팩토리 메서드의 자바 네이밍 컨벤션에 부합합니다. 구현도 정확합니다.


35-37: 편의 메서드 위임 패턴이 잘 구현되었습니다.

from(entity) 메서드가 of(entity, null)로 위임하는 구조가 명확하며, imageUrl이 없는 경우를 간결하게 처리할 수 있습니다.

src/main/java/hanium/modic/backend/domain/ai/aiChat/service/AiChatMessageService.java (3)

144-148: 마지막 페이지 계산 로직이 정확합니다.

0-기반 인덱스를 위한 (totalMessages - 1) / size 계산이 올바르며, 메시지가 없는 경우의 엣지 케이스도 적절히 처리되었습니다.


159-159: API 사용이 적절합니다.

이미지가 없는 경우 from(msg) 편의 메서드를 사용하는 것이 올바른 패턴입니다.


162-164: 이미지 URL 처리가 올바르게 구현되었습니다.

이미지가 존재하는 경우 URL을 생성하고 of() 메서드에 전달하는 로직이 정확합니다.

src/main/java/hanium/modic/backend/domain/ai/aiServer/service/AiServerService.java (8)

18-18: 필요한 의존성 추가가 적절합니다.

이미지 URL 생성을 위한 AiChatImageService import가 추가되었습니다.


45-61: 필드 구성과 주석 정리가 잘 되었습니다.

관련 의존성들을 주석으로 그룹화하여 코드 가독성이 향상되었으며, 새로운 협력 객체들이 적절히 추가되었습니다.


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

사용자가 보낸 이미지 리스트를 명시적으로 받도록 변경되었으며, 빈 리스트 처리가 명확히 문서화되었습니다.


86-86: 메서드 호출이 업데이트된 시그니처와 일치합니다.

aiChatImages 파라미터가 올바르게 전달되고 있습니다.


105-112: 분류 로직 설명이 개선되었습니다.

IMAGE_GENERATIONCHAT_GENERATION 구분 기준이 더 명확하게 문서화되었습니다.


129-132: 메서드 시그니처 업데이트가 적절합니다.

채팅 생성 시 사용자가 보낸 이미지 정보를 받을 수 있도록 파라미터가 추가되었습니다.


163-169: 이미지 URL 결정 로직이 구현되었습니다.

사용자가 보낸 이미지가 있는 경우 첫 번째 이미지의 URL을 생성하여 응답에 포함시키는 로직이 추가되었습니다. 리스트의 첫 번째 이미지를 사용하는 것이 비즈니스 로직상 올바른지 확인하세요.


172-175: SSE 응답에 imageUrl이 올바르게 포함되었습니다.

ChatMessageResponse.of() 메서드를 사용하여 imageUrl을 포함한 응답이 전송되며, PR의 목표(채팅 응답에 imageUrl 포함)가 달성되었습니다.

aiServerService.processAiRequest(userId, message, aiChatImages);

return ChatMessageResponse.from(message);
return ChatMessageResponse.of(message, aiChatImageService.createImageGetUrl(request.aiChatImageId()));
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

null 안전성 문제를 수정해야 합니다.

request.aiChatImageId()가 null일 수 있는 상황에서 aiChatImageService.createImageGetUrl()을 호출하면 문제가 발생할 수 있습니다. 158-164번 라인의 패턴과 동일하게 null 체크를 수행해야 합니다.

다음 diff를 적용하여 수정하세요:

-	return ChatMessageResponse.of(message, aiChatImageService.createImageGetUrl(request.aiChatImageId()));
+	String imageUrl = request.aiChatImageId() != null 
+		? aiChatImageService.createImageGetUrl(request.aiChatImageId()) 
+		: null;
+	return ChatMessageResponse.of(message, imageUrl);
📝 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
return ChatMessageResponse.of(message, aiChatImageService.createImageGetUrl(request.aiChatImageId()));
String imageUrl = request.aiChatImageId() != null
? aiChatImageService.createImageGetUrl(request.aiChatImageId())
: null;
return ChatMessageResponse.of(message, imageUrl);
🤖 Prompt for AI Agents
In
src/main/java/hanium/modic/backend/domain/ai/aiChat/service/AiChatMessageService.java
around line 99, the code unconditionally calls
aiChatImageService.createImageGetUrl(request.aiChatImageId()) even though
request.aiChatImageId() can be null; mirror the null-safety pattern used at
lines 158-164 by checking if request.aiChatImageId() is non-null before calling
createImageGetUrl and pass null to ChatMessageResponse.of when the id is null,
ensuring no method is invoked with a null argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FIX] : 채팅 전송 시 ImageUrl에 null들어가는 오류 수정

1 participant