forked from mtusi2026/mtusi2026lab6
ЛР 6 — БПИ2302 — Нурлыгаянова — на 3
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
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"`
|
||||
}
|
||||
Reference in New Issue
Block a user