11package com.example.spring_ai_tutorial.controller
22
3+ import com.example.spring_ai_tutorial.domain.dto.ApiResponseDto
4+ import com.example.spring_ai_tutorial.domain.dto.ChatRequestDto
35import com.example.spring_ai_tutorial.service.ChatService
46import io.github.oshai.kotlinlogging.KotlinLogging
57import io.swagger.v3.oas.annotations.Operation
@@ -35,22 +37,22 @@ class ChatController(
3537 @SwaggerResponse(
3638 responseCode = " 200" ,
3739 description = " LLM 응답 성공" ,
38- content = [Content (schema = Schema (implementation = ApiResponse ::class ))]
40+ content = [Content (schema = Schema (implementation = ApiResponseDto ::class ))]
3941 )
4042 @SwaggerResponse(responseCode = " 400" , description = " 잘못된 요청" )
4143 @SwaggerResponse(responseCode = " 500" , description = " 서버 오류" )
4244 @PostMapping(" /query" )
4345 suspend fun sendMessage (
4446 @Parameter(description = " 채팅 요청 객체" , required = true )
45- @RequestBody request : ChatRequest
46- ): ResponseEntity <ApiResponse <Map <String , Any >>> {
47+ @RequestBody request : ChatRequestDto
48+ ): ResponseEntity <ApiResponseDto <Map <String , Any >>> {
4749 logger.info { " Chat API 요청 받음: model=${request.model} " }
4850
4951 // 유효성 검사
5052 if (request.query.isBlank()) {
5153 logger.warn { " 빈 질의가 요청됨" }
5254 return ResponseEntity .badRequest().body(
53- ApiResponse (success = false , error = " 질의가 비어있습니다." )
55+ ApiResponseDto (success = false , error = " 질의가 비어있습니다." )
5456 )
5557 }
5658
@@ -68,15 +70,15 @@ class ChatController(
6870
6971 response?.let { chatResponse ->
7072 ResponseEntity .ok(
71- ApiResponse (
73+ ApiResponseDto (
7274 success = true ,
7375 data = mapOf (" answer" to chatResponse.result.output.text)
7476 )
7577 )
7678 } ? : run {
7779 logger.error { " LLM 응답 생성 실패" }
7880 ResponseEntity .status(HttpStatus .INTERNAL_SERVER_ERROR ).body(
79- ApiResponse (
81+ ApiResponseDto (
8082 success = false ,
8183 error = " LLM 응답 생성 중 오류 발생"
8284 )
@@ -85,32 +87,11 @@ class ChatController(
8587 } catch (e: Exception ) {
8688 logger.error(e) { " Chat API 처리 중 오류 발생" }
8789 ResponseEntity .status(HttpStatus .INTERNAL_SERVER_ERROR ).body(
88- ApiResponse (
90+ ApiResponseDto (
8991 success = false ,
9092 error = e.message ? : " 알 수 없는 오류 발생"
9193 )
9294 )
9395 }
9496 }
9597}
96-
97- @Schema(description = " 채팅 요청 데이터 모델" )
98- data class ChatRequest (
99- @Schema(description = " 사용자 질문" , example = " 안녕하세요" )
100- val query : String ,
101-
102- @Schema(description = " 사용할 LLM 모델" , example = " gpt-3.5-turbo" , defaultValue = " gpt-3.5-turbo" )
103- val model : String = " gpt-3.5-turbo"
104- )
105-
106- @Schema(description = " API 응답 포맷" )
107- data class ApiResponse <T >(
108- @Schema(description = " 요청 처리 성공 여부" )
109- val success : Boolean ,
110-
111- @Schema(description = " 성공 응답 데이터" )
112- val data : T ? = null ,
113-
114- @Schema(description = " 실패 오류 메시지" )
115- val error : String? = null
116- )
0 commit comments