Skip to content

채팅방 생성 API 개발 및 Chat Entity 필드 추가#125

Merged
ckdals4600 merged 2 commits intomainfrom
feature/#121-create-new-chat-api
Dec 18, 2025
Merged

채팅방 생성 API 개발 및 Chat Entity 필드 추가#125
ckdals4600 merged 2 commits intomainfrom
feature/#121-create-new-chat-api

Conversation

@ckdals4600
Copy link
Contributor

@ckdals4600 ckdals4600 commented Dec 14, 2025

관련 이슈

PR 설명

  • 사용자가 AI와 대화를 시작할 때 필요한 채팅방 생성 API(POST /v1/chats) 구현
  • 채팅방 생성 시 사용자의 첫 대화 내용을 기반으로 제목(title)을 자동 저장하도록 Entity 구조를 개선

작업 내용

1. API 명세 구현 (ChatController, ChatApi)

  • Endpoint: POST /v1/chats
  • Request: CreateChatReq (첫 대화 내용 포함, @NotBlank 검증).
  • Response: CreateChatRes (생성된 채팅방 ID, 제목, 첫 대화 내용 반환).

Request Example

 {
    "firstChat": "AI 관련 최신 뉴스 알려줘"
  }

Response Example

   {
      "success": true,
      "status": "OK",
      "message": "채팅방 생성 완료",
      "data": {
        "id": 1,
        "title": "임시 제목[AI 관련 최신 뉴스 알려줘]",
        "firstChat": "AI 관련 최신 뉴스 알려줘"
      }
    }

2. 비즈니스 로직 (ChatFacade, ChatService)

  • Facade 패턴 적용: ChatFacade가 컨트롤러와 서비스 계층 사이에서 트랜잭션과 객체 변환을 조율
  • 채팅방 생성 프로세스:
    1. 사용자 인증 정보(Member)와 첫 대화 내용(firstChat) 받음
    2. ChatService를 통해 채팅방 생성
      • 이때 ChatCommandServiceChatRepository를 호출하여 DB에 저장
    3. 저장된 Chat 엔티티를 CreateChatRes DTO로 변환하여 반환

3. Entity 수정 (Chat)

  • title 필드 추가: 채팅방의 제목을 저장하기 위해 String title 필드를 추가했습니다.
  • 생성자 빌더 패턴 적용: firstChat 내용을 초기 제목으로 설정하여 객체를 생성하도록 빌더를 구성했습니다.

4. 테스트 작성 (통합 및 유닛 테스트)

  • Integration Test (ChatControllerIntegrationTest):
    • API 엔드포인트 호출부터 DB 저장까지의 전체 흐름 성공 케이스 및 유효성 검증 실패 케이스를 테스트했습니다.
  • Unit Test (Service/Facade Layer):
    • ChatFacadeTest: Facade 계층에서 ChatService 호출 흐름과 DTO 변환 로직을 검증했습니다.
    • ChatServiceTest: ChatCommandService로 저장 로직이 정상적으로 위임되는지 단위 테스트를 수행했습니다.

@ckdals4600 ckdals4600 linked an issue Dec 14, 2025 that may be closed by this pull request
@ckdals4600 ckdals4600 self-assigned this Dec 14, 2025
@ckdals4600 ckdals4600 requested review from Goder-0 and minibr December 14, 2025 19:12
@github-actions
Copy link

github-actions bot commented Dec 14, 2025

📊 코드 커버리지 리포트

Overall Project 92.39% 🍏
Files changed 100% 🍏

File Coverage
CreateChatRes.java 100% 🍏
ChatCommandService.java 100% 🍏
ChatService.java 100% 🍏
MockAiTitleClient.java 100% 🍏
CreateChatReq.java 100% 🍏
ChatFacade.java 100% 🍏
ChatController.java 100% 🍏

@ckdals4600 ckdals4600 force-pushed the feature/#121-create-new-chat-api branch 2 times, most recently from 0531575 to 80128fe Compare December 15, 2025 13:17
@ckdals4600 ckdals4600 force-pushed the feature/#121-create-new-chat-api branch from 3bc2a2b to afad2ff Compare December 18, 2025 14:24
@ckdals4600 ckdals4600 force-pushed the feature/#121-create-new-chat-api branch from afad2ff to d66d24c Compare December 18, 2025 16:55
@ckdals4600 ckdals4600 force-pushed the feature/#121-create-new-chat-api branch from d66d24c to 656eff7 Compare December 18, 2025 17:22
@ckdals4600 ckdals4600 force-pushed the feature/#121-create-new-chat-api branch from 656eff7 to 814a641 Compare December 18, 2025 17:27
@ckdals4600 ckdals4600 merged commit 6be2123 into main Dec 18, 2025
1 check passed
@ckdals4600 ckdals4600 deleted the feature/#121-create-new-chat-api branch December 18, 2025 17:31
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.

채팅방 생성 API 개발

2 participants