Skip to content

Commit

Permalink
#78 [refactor] : Chatbot 도메인을 DDD 구조로 리팩토링한다
Browse files Browse the repository at this point in the history
bbbang105 committed Nov 27, 2024
1 parent 7ff6324 commit 7a63099
Showing 12 changed files with 28 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kusitms.backend.chatbot.dto.request;
package kusitms.backend.chatbot.application.dto.request;

import java.util.List;

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kusitms.backend.chatbot.dto.request;
package kusitms.backend.chatbot.application.dto.request;

import java.util.ArrayList;
import java.util.List;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kusitms.backend.chatbot.dto.request;
package kusitms.backend.chatbot.application.dto.request;


import jakarta.validation.constraints.NotBlank;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kusitms.backend.chatbot.dto.request;
package kusitms.backend.chatbot.application.dto.request;

public record MessageDto(
String role,
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kusitms.backend.chatbot.dto.response;
package kusitms.backend.chatbot.application.dto.response;

public record ClovaChatbotAnswerDto(
ResultDto result
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kusitms.backend.chatbot.dto.response;
package kusitms.backend.chatbot.application.dto.response;

public record GetClovaChatbotAnswerResponseDto(
String answer
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kusitms.backend.chatbot.dto.response;
package kusitms.backend.chatbot.application.dto.response;

public record GetGuideChatbotAnswerResponseDto(
String[] answers,
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package kusitms.backend.chatbot.dto.response;
package kusitms.backend.chatbot.application.dto.response;

import kusitms.backend.chatbot.dto.request.MessageDto;
import kusitms.backend.chatbot.application.dto.request.MessageDto;

import java.util.List;

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package kusitms.backend.chatbot.application;
package kusitms.backend.chatbot.application.factory;

import kusitms.backend.chatbot.dto.request.ChatbotRequestDto;
import kusitms.backend.chatbot.dto.request.ClovaRequestDto;
import kusitms.backend.chatbot.dto.request.MessageDto;
import kusitms.backend.chatbot.application.dto.request.ChatbotRequestDto;
import kusitms.backend.chatbot.application.dto.request.ClovaRequestDto;
import kusitms.backend.chatbot.application.dto.request.MessageDto;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package kusitms.backend.chatbot.application;
package kusitms.backend.chatbot.application.factory;

import kusitms.backend.chatbot.domain.enums.Role;
import kusitms.backend.chatbot.dto.request.MessageDto;
import kusitms.backend.chatbot.application.dto.request.MessageDto;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

Original file line number Diff line number Diff line change
@@ -3,11 +3,10 @@
import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import kusitms.backend.chatbot.application.ChatbotService;
import kusitms.backend.chatbot.application.ClovaService;
import kusitms.backend.chatbot.dto.request.GetClovaChatbotAnswerRequestDto;
import kusitms.backend.chatbot.dto.response.GetClovaChatbotAnswerResponseDto;
import kusitms.backend.chatbot.dto.response.GetGuideChatbotAnswerResponseDto;
import kusitms.backend.chatbot.application.service.ChatbotApplicationService;
import kusitms.backend.chatbot.application.dto.request.GetClovaChatbotAnswerRequestDto;
import kusitms.backend.chatbot.application.dto.response.GetClovaChatbotAnswerResponseDto;
import kusitms.backend.chatbot.application.dto.response.GetGuideChatbotAnswerResponseDto;
import kusitms.backend.chatbot.status.ChatbotSuccessStatus;
import kusitms.backend.global.dto.ApiResponse;
import lombok.RequiredArgsConstructor;
@@ -21,8 +20,7 @@
@RequestMapping("/api/v1/chatbot")
@Validated
public class ChatbotController {
private final ChatbotService chatbotService;
private final ClovaService clovaService;
private final ChatbotApplicationService chatbotApplicationService;

/**
* 가이드 챗봇 답변 조회 API
@@ -42,7 +40,7 @@ public ResponseEntity<ApiResponse<GetGuideChatbotAnswerResponseDto>> getGuideCha
@RequestParam("categoryName") @NotBlank String categoryName,
@RequestParam("orderNumber") @Min(1) int orderNumber){

GetGuideChatbotAnswerResponseDto response = chatbotService.getGuideChatbotAnswer(stadiumName, categoryName, orderNumber);
GetGuideChatbotAnswerResponseDto response = chatbotApplicationService.getGuideChatbotAnswer(stadiumName, categoryName, orderNumber);

return ApiResponse.onSuccess(ChatbotSuccessStatus._GET_GUIDE_CHATBOT_ANSWER, response);
}
@@ -60,7 +58,7 @@ public ResponseEntity<ApiResponse<GetGuideChatbotAnswerResponseDto>> getGuideCha
public Mono<ResponseEntity<ApiResponse<GetClovaChatbotAnswerResponseDto>>> getClovaChatbotAnswer(
@Valid @RequestBody GetClovaChatbotAnswerRequestDto request) {

return clovaService.getClovaChatbotAnswer(request.message())
return chatbotApplicationService.getClovaChatbotAnswer(request.message())
.map(response -> ApiResponse.onSuccess(ChatbotSuccessStatus._GET_CLOVA_CHATBOT_ANSWER, response));
}
}
16 changes: 6 additions & 10 deletions src/test/java/kusitms/backend/chatbot/ChatbotControllerTest.java
Original file line number Diff line number Diff line change
@@ -3,10 +3,9 @@
import com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper;
import com.epages.restdocs.apispec.ResourceSnippetParameters;
import com.epages.restdocs.apispec.Schema;
import kusitms.backend.chatbot.application.ChatbotService;
import kusitms.backend.chatbot.application.ClovaService;
import kusitms.backend.chatbot.dto.response.GetClovaChatbotAnswerResponseDto;
import kusitms.backend.chatbot.dto.response.GetGuideChatbotAnswerResponseDto;
import kusitms.backend.chatbot.application.dto.response.GetClovaChatbotAnswerResponseDto;
import kusitms.backend.chatbot.application.dto.response.GetGuideChatbotAnswerResponseDto;
import kusitms.backend.chatbot.application.service.ChatbotApplicationService;
import kusitms.backend.chatbot.presentation.ChatbotController;
import kusitms.backend.configuration.ControllerTestConfig;
import org.junit.jupiter.api.DisplayName;
@@ -34,10 +33,7 @@
public class ChatbotControllerTest extends ControllerTestConfig {

@MockBean
private ChatbotService chatbotService;

@MockBean
private ClovaService clovaService;
private ChatbotApplicationService chatbotApplicationService;

@Test
@DisplayName("가이드 챗봇 답변 조회")
@@ -51,7 +47,7 @@ public void getGuideChatbotAnswer() throws Exception {
"종합운동장역을 나가기 전, 역사에 위치한 ‘라커디움파크 종합운동장역점’에서도 굿즈를 판매 중이에요!"
}, null);

Mockito.when(chatbotService.getGuideChatbotAnswer(anyString(), anyString(), anyInt()))
Mockito.when(chatbotApplicationService.getGuideChatbotAnswer(anyString(), anyString(), anyInt()))
.thenReturn(response);

// when
@@ -105,7 +101,7 @@ public void getClovaChatbotAnswer() throws Exception {
GetClovaChatbotAnswerResponseDto response = new GetClovaChatbotAnswerResponseDto(
"안녕하세요! 저는 야구 가이드 챗봇 '루키'에요! 야구에 대한 궁금한 점이 있다면 언제든지 물어봐 주세요!");

Mockito.when(clovaService.getClovaChatbotAnswer(anyString()))
Mockito.when(chatbotApplicationService.getClovaChatbotAnswer(anyString()))
.thenReturn(Mono.just(response));

String clovaChatbotAnswerJsonRequest = """

0 comments on commit 7a63099

Please sign in to comment.