fix: Ai 채팅요청에 대한 응답으로 Url 포함하도록 개선#245
Conversation
개요채팅 응답의 이미지 URL 처리 방식을 개선하기 위해 변경사항
시퀀스 다이어그램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
예상 코드 리뷰 노력🎯 2 (Simple) | ⏱️ ~10분
관련 가능성 있는 PR
시
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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 생성을 위한
AiChatImageServiceimport가 추가되었습니다.
45-61: 필드 구성과 주석 정리가 잘 되었습니다.관련 의존성들을 주석으로 그룹화하여 코드 가독성이 향상되었으며, 새로운 협력 객체들이 적절히 추가되었습니다.
68-72: 메서드 시그니처 변경이 적절합니다.사용자가 보낸 이미지 리스트를 명시적으로 받도록 변경되었으며, 빈 리스트 처리가 명확히 문서화되었습니다.
86-86: 메서드 호출이 업데이트된 시그니처와 일치합니다.
aiChatImages파라미터가 올바르게 전달되고 있습니다.
105-112: 분류 로직 설명이 개선되었습니다.
IMAGE_GENERATION과CHAT_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())); |
There was a problem hiding this comment.
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.
| 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.
개요
작업사항
Summary by CodeRabbit
릴리스 노트
버그 수정
개선 사항