Files
mtusi2026lab5-fork/backend/internal/httpapi/dto/chat.go
T

40 lines
957 B
Go

package dto
import (
"high-loud-apps-labs/internal/domain"
)
type CreateChatRequest struct {
Title string `json:"title" binding:"required,min=1,max=100"`
MemberIDs []string `json:"member_ids" binding:"required,min=1,max=100,dive,uuid"`
}
type ChatResponse struct {
ID string `json:"id"`
Title string `json:"title"`
MemberIDs []string `json:"member_ids"`
CreatedAt string `json:"created_at"`
}
type ChatPageResponse struct {
Items []ChatResponse `json:"items"`
NextCursor *string `json:"next_cursor"`
}
func ChatFromDomain(c *domain.Chat) ChatResponse {
return ChatResponse{
ID: c.ID,
Title: c.Title,
MemberIDs: append([]string(nil), c.MemberIDs...),
CreatedAt: c.CreatedAt.UTC().Format(timeFormat),
}
}
func ChatsFromDomain(items []domain.Chat) []ChatResponse {
out := make([]ChatResponse, len(items))
for i := range items {
out[i] = ChatFromDomain(&items[i])
}
return out
}