Files
mtusi2026lab5/app/internal/api/http/dto/message.go
T

38 lines
1.2 KiB
Go

package dto
import (
"encoding/json"
"errors"
)
// AttachmentIDList — необязательное поле: отсутствие равно [], но явный null по контракту неверен.
// Обычный срез принял бы null молча, поэтому разбор свой.
type AttachmentIDList []string
func (l *AttachmentIDList) UnmarshalJSON(data []byte) error {
if string(data) == "null" {
return errors.New("attachment_ids must be an array")
}
return json.Unmarshal(data, (*[]string)(l))
}
type CreateMessageRequest struct {
// Text — указатель: поле обязательно и при наличии вложений, а "" допустим только с ними.
Text *string `json:"text"`
AttachmentIDs AttachmentIDList `json:"attachment_ids"`
}
type MessageResponse struct {
ID string `json:"id"`
ChatID string `json:"chat_id"`
SenderID string `json:"sender_id"`
Text string `json:"text"`
CreatedAt Timestamp `json:"created_at"`
AttachmentIDs []string `json:"attachment_ids"`
}
type MessagesPageResponse struct {
Items []MessageResponse `json:"items"`
NextCursor *string `json:"next_cursor"`
}