78 lines
2.1 KiB
Go
78 lines
2.1 KiB
Go
package mapper
|
|
|
|
import (
|
|
"narasi-ahli-be/app/database/entity"
|
|
"narasi-ahli-be/app/module/chat_history/response"
|
|
)
|
|
|
|
// Chat History Sessions Mapper
|
|
func ChatHistorySessionsResponseMapper(entity *entity.ChatSessions) *response.ChatHistorySessionsResponse {
|
|
if entity == nil {
|
|
return nil
|
|
}
|
|
|
|
return &response.ChatHistorySessionsResponse{
|
|
ID: entity.ID,
|
|
SessionID: entity.SessionID,
|
|
UserID: entity.UserID,
|
|
AgentID: entity.AgentID,
|
|
Title: entity.Title,
|
|
MessageCount: entity.MessageCount,
|
|
Status: entity.Status,
|
|
CreatedAt: entity.CreatedAt,
|
|
UpdatedAt: entity.UpdatedAt,
|
|
}
|
|
}
|
|
|
|
// Chat History Messages Mapper
|
|
func ChatHistoryMessagesResponseMapper(entity *entity.ChatMessagesNew) *response.ChatHistoryMessagesResponse {
|
|
if entity == nil {
|
|
return nil
|
|
}
|
|
|
|
return &response.ChatHistoryMessagesResponse{
|
|
ID: entity.ID,
|
|
SessionID: entity.SessionID,
|
|
MessageType: entity.MessageType,
|
|
Content: entity.Content,
|
|
CreatedAt: entity.CreatedAt,
|
|
}
|
|
}
|
|
|
|
// Chat History Session with Messages Mapper
|
|
func ChatHistorySessionWithMessagesResponseMapper(session *entity.ChatSessions, messages []*entity.ChatMessagesNew) *response.ChatHistorySessionWithMessagesResponse {
|
|
if session == nil {
|
|
return nil
|
|
}
|
|
|
|
sessionResponse := ChatHistorySessionsResponseMapper(session)
|
|
|
|
var messagesResponse []response.ChatHistoryMessagesResponse
|
|
for _, message := range messages {
|
|
if message != nil {
|
|
messagesResponse = append(messagesResponse, *ChatHistoryMessagesResponseMapper(message))
|
|
}
|
|
}
|
|
|
|
return &response.ChatHistorySessionWithMessagesResponse{
|
|
Session: *sessionResponse,
|
|
Messages: messagesResponse,
|
|
}
|
|
}
|
|
|
|
// Chat History List Mapper
|
|
func ChatHistoryListResponseMapper(sessions []*entity.ChatSessions) *response.ChatHistoryListResponse {
|
|
var sessionsResponse []response.ChatHistorySessionsResponse
|
|
|
|
for _, session := range sessions {
|
|
if session != nil {
|
|
sessionsResponse = append(sessionsResponse, *ChatHistorySessionsResponseMapper(session))
|
|
}
|
|
}
|
|
|
|
return &response.ChatHistoryListResponse{
|
|
Sessions: sessionsResponse,
|
|
Total: len(sessionsResponse),
|
|
}
|
|
}
|