forked from mtusi2026/mtusi2026lab3
51 lines
995 B
Go
51 lines
995 B
Go
package dto
|
|
|
|
import (
|
|
"mtusi2026-messenger/internal/model"
|
|
"strings"
|
|
"time"
|
|
"unicode/utf8"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type CreateChatRequest struct {
|
|
Title string `json:"title"`
|
|
MemberIDs []uuid.UUID `json:"member_ids"`
|
|
}
|
|
|
|
type ChatResponse struct {
|
|
ID uuid.UUID `json:"id"`
|
|
Title string `json:"title"`
|
|
MemberIDs []uuid.UUID `json:"member_ids"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
type ChatPageResponse struct {
|
|
Items []ChatResponse `json:"items"`
|
|
NextCursor *string `json:"next_cursor"`
|
|
}
|
|
|
|
func (r CreateChatRequest) Validate() bool {
|
|
if strings.TrimSpace(r.Title) == "" ||
|
|
strings.ContainsRune(r.Title, 0) ||
|
|
utf8.RuneCountInString(r.Title) > 100 {
|
|
return false
|
|
}
|
|
|
|
if len(r.MemberIDs) < 1 || len(r.MemberIDs) > 100 {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
func ToChatResponse(c model.Chat) ChatResponse {
|
|
return ChatResponse{
|
|
ID: c.ID,
|
|
Title: c.Title,
|
|
MemberIDs: c.MemberIDs,
|
|
CreatedAt: c.CreatedAt,
|
|
}
|
|
}
|