feat(chat): 외부 캐릭터 챗 세션 API
- 응답값에 Response 모델에 JsonIgnoreProperties 추가하여 필요한 데이터만 파싱할 수 있도록 수정
This commit is contained in:
parent
6f9fc659f3
commit
3ac4ebded3
|
@ -1,5 +1,8 @@
|
||||||
package kr.co.vividnext.sodalive.chat.room.dto
|
package kr.co.vividnext.sodalive.chat.room.dto
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 채팅방 생성 요청 DTO
|
* 채팅방 생성 요청 DTO
|
||||||
*/
|
*/
|
||||||
|
@ -46,10 +49,10 @@ data class ChatRoomListQueryDto(
|
||||||
/**
|
/**
|
||||||
* 외부 API 채팅 세션 생성 응답 DTO
|
* 외부 API 채팅 세션 생성 응답 DTO
|
||||||
*/
|
*/
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
data class ExternalChatSessionCreateResponse(
|
data class ExternalChatSessionCreateResponse(
|
||||||
val success: Boolean,
|
@JsonProperty("success") val success: Boolean,
|
||||||
val message: String?,
|
@JsonProperty("data") val data: ExternalChatSessionCreateData?
|
||||||
val data: ExternalChatSessionCreateData?
|
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,21 +60,22 @@ data class ExternalChatSessionCreateResponse(
|
||||||
* 공통: sessionId, status
|
* 공통: sessionId, status
|
||||||
* 생성 전용: userId, characterId, character, createdAt
|
* 생성 전용: userId, characterId, character, createdAt
|
||||||
*/
|
*/
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
data class ExternalChatSessionCreateData(
|
data class ExternalChatSessionCreateData(
|
||||||
val sessionId: String,
|
@JsonProperty("sessionId") val sessionId: String,
|
||||||
val userId: String,
|
@JsonProperty("userId") val userId: String,
|
||||||
val characterId: String,
|
@JsonProperty("character") val character: ExternalCharacterData,
|
||||||
val character: ExternalCharacterData,
|
@JsonProperty("status") val status: String,
|
||||||
val status: String,
|
@JsonProperty("createdAt") val createdAt: String,
|
||||||
val createdAt: String
|
@JsonProperty("message") val message: String?
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 외부 API 채팅 세션 조회 응답 DTO
|
* 외부 API 채팅 세션 조회 응답 DTO
|
||||||
*/
|
*/
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
data class ExternalChatSessionGetResponse(
|
data class ExternalChatSessionGetResponse(
|
||||||
val success: Boolean,
|
val success: Boolean,
|
||||||
val message: String?,
|
|
||||||
val data: ExternalChatSessionGetData?
|
val data: ExternalChatSessionGetData?
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -79,19 +83,23 @@ data class ExternalChatSessionGetResponse(
|
||||||
* 외부 API 채팅 세션 조회 데이터 DTO
|
* 외부 API 채팅 세션 조회 데이터 DTO
|
||||||
* 세션 조회에서 사용하는 공통 필드만 포함
|
* 세션 조회에서 사용하는 공통 필드만 포함
|
||||||
*/
|
*/
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
data class ExternalChatSessionGetData(
|
data class ExternalChatSessionGetData(
|
||||||
val sessionId: String,
|
@JsonProperty("sessionId") val sessionId: String,
|
||||||
val status: String
|
@JsonProperty("userId") val userId: String,
|
||||||
|
@JsonProperty("characterId") val characterId: String,
|
||||||
|
@JsonProperty("status") val status: String
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 외부 API 캐릭터 데이터 DTO
|
* 외부 API 캐릭터 데이터 DTO
|
||||||
*/
|
*/
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
data class ExternalCharacterData(
|
data class ExternalCharacterData(
|
||||||
val id: String,
|
@JsonProperty("id") val id: String,
|
||||||
val name: String,
|
@JsonProperty("name") val name: String,
|
||||||
val age: String,
|
@JsonProperty("age") val age: String,
|
||||||
val gender: String
|
@JsonProperty("gender") val gender: String
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -111,26 +119,28 @@ data class SendChatMessageResponse(
|
||||||
/**
|
/**
|
||||||
* 외부 API 채팅 전송 응답 DTO
|
* 외부 API 채팅 전송 응답 DTO
|
||||||
*/
|
*/
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
data class ExternalChatSendResponse(
|
data class ExternalChatSendResponse(
|
||||||
val success: Boolean,
|
@JsonProperty("success") val success: Boolean,
|
||||||
val message: String?,
|
@JsonProperty("data") val data: ExternalChatSendData?
|
||||||
val data: ExternalChatSendData?
|
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 외부 API 채팅 전송 데이터 DTO
|
* 외부 API 채팅 전송 데이터 DTO
|
||||||
*/
|
*/
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
data class ExternalChatSendData(
|
data class ExternalChatSendData(
|
||||||
val sessionId: String,
|
@JsonProperty("sessionId") val sessionId: String,
|
||||||
val characterResponse: ExternalCharacterMessage
|
@JsonProperty("characterResponse") val characterResponse: ExternalCharacterMessage
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 외부 API 캐릭터 메시지 DTO
|
* 외부 API 캐릭터 메시지 DTO
|
||||||
*/
|
*/
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
data class ExternalCharacterMessage(
|
data class ExternalCharacterMessage(
|
||||||
val id: String,
|
@JsonProperty("id") val id: String,
|
||||||
val content: String,
|
@JsonProperty("content") val content: String,
|
||||||
val timestamp: String,
|
@JsonProperty("timestamp") val timestamp: String,
|
||||||
val messageType: String
|
@JsonProperty("messageType") val messageType: String
|
||||||
)
|
)
|
||||||
|
|
|
@ -165,21 +165,21 @@ class ChatRoomService(
|
||||||
|
|
||||||
// success가 false이면 throw
|
// success가 false이면 throw
|
||||||
if (!apiResponse.success) {
|
if (!apiResponse.success) {
|
||||||
throw SodaException(apiResponse.message ?: "채팅방 생성에 실패했습니다. 다시 시도해 주세요.")
|
throw SodaException("채팅방 생성에 실패했습니다. 다시 시도해 주세요.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// success가 true이면 파라미터로 넘긴 값과 일치하는지 확인
|
// success가 true이면 파라미터로 넘긴 값과 일치하는지 확인
|
||||||
val data = apiResponse.data ?: throw SodaException("채팅방 생성에 실패했습니다. 다시 시도해 주세요.")
|
val data = apiResponse.data ?: throw SodaException("채팅방 생성에 실패했습니다. 다시 시도해 주세요.")
|
||||||
|
|
||||||
if (data.userId != userId && data.characterId != characterUUID && data.status != "active") {
|
if (data.userId != userId && data.character.id != characterUUID && data.status != "active") {
|
||||||
throw SodaException("채팅방 생성에 실패했습니다. 다시 시도해 주세요.")
|
throw SodaException("채팅방 생성에 실패했습니다. 다시 시도해 주세요.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 세션 ID 반환
|
// 세션 ID 반환
|
||||||
return data.sessionId
|
return data.sessionId
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
log.error(e.message)
|
||||||
throw SodaException("${e.message}, 채팅방 생성에 실패했습니다. 다시 시도해 주세요.")
|
throw SodaException("채팅방 생성에 실패했습니다. 다시 시도해 주세요.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -484,7 +484,7 @@ class ChatRoomService(
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!apiResponse.success) {
|
if (!apiResponse.success) {
|
||||||
throw SodaException(apiResponse.message ?: "메시지 전송을 실패했습니다.")
|
throw SodaException("메시지 전송을 실패했습니다.")
|
||||||
}
|
}
|
||||||
val data = apiResponse.data ?: throw SodaException("메시지 전송을 실패했습니다.")
|
val data = apiResponse.data ?: throw SodaException("메시지 전송을 실패했습니다.")
|
||||||
val characterContent = data.characterResponse.content
|
val characterContent = data.characterResponse.content
|
||||||
|
|
Loading…
Reference in New Issue