48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package dto
|
|
|
|
import (
|
|
"high-loud-apps-labs/internal/domain"
|
|
)
|
|
|
|
type CreateMessageRequest struct {
|
|
Text string `json:"text" binding:"max=4000"`
|
|
AttachmentIDs []string `json:"attachment_ids" binding:"max=10,dive,uuid"`
|
|
}
|
|
|
|
type MessageResponse struct {
|
|
ID string `json:"id"`
|
|
ChatID string `json:"chat_id"`
|
|
SenderID string `json:"sender_id"`
|
|
Text string `json:"text"`
|
|
AttachmentIDs []string `json:"attachment_ids"`
|
|
CreatedAt string `json:"created_at"`
|
|
}
|
|
|
|
type MessagePageResponse struct {
|
|
Items []MessageResponse `json:"items"`
|
|
NextCursor *string `json:"next_cursor"`
|
|
}
|
|
|
|
func MessageFromDomain(m *domain.Message) MessageResponse {
|
|
ids := m.AttachmentIDs
|
|
if ids == nil {
|
|
ids = []string{}
|
|
}
|
|
return MessageResponse{
|
|
ID: m.ID,
|
|
ChatID: m.ChatID,
|
|
SenderID: m.SenderID,
|
|
Text: m.Text,
|
|
AttachmentIDs: ids,
|
|
CreatedAt: m.CreatedAt.UTC().Format(timeFormat),
|
|
}
|
|
}
|
|
|
|
func MessagesFromDomain(items []domain.Message) []MessageResponse {
|
|
out := make([]MessageResponse, len(items))
|
|
for i := range items {
|
|
out[i] = MessageFromDomain(&items[i])
|
|
}
|
|
return out
|
|
}
|