forked from mtusi2026/mtusi2026lab2
43 lines
868 B
Go
43 lines
868 B
Go
package messages
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gitflic.ru/project/bulla-max/mtusi2026lab1/internal/common"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type Message struct {
|
|
ID uuid.UUID `json:"id"`
|
|
ChatID uuid.UUID `json:"chat_id"`
|
|
SenderID uuid.UUID `json:"sender_id"`
|
|
Text string `json:"text"`
|
|
CreatedAt common.RFCFormTime `json:"created_at"`
|
|
}
|
|
|
|
type CreateMessageRequest struct {
|
|
Text string `json:"text" validate:"required"`
|
|
}
|
|
|
|
func NewMessage(chatID, senderID uuid.UUID, text string) Message {
|
|
return Message{
|
|
ID: uuid.New(),
|
|
ChatID: chatID,
|
|
SenderID: senderID,
|
|
Text: text,
|
|
CreatedAt: common.NowUTC(),
|
|
}
|
|
}
|
|
|
|
func (m Message) GetID() uuid.UUID {
|
|
return m.ID
|
|
}
|
|
|
|
func (m Message) GetCreatedAt() time.Time {
|
|
return time.Time(m.CreatedAt)
|
|
}
|
|
|
|
func (m Message) GetChatID() uuid.UUID {
|
|
return m.ChatID
|
|
}
|