forked from mtusi2026/mtusi2026lab4
68 lines
1.6 KiB
Go
68 lines
1.6 KiB
Go
// Package domain holds the JSON shapes of the public contract.
|
|
package domain
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
)
|
|
|
|
// TimeFormat is the RFC 3339 UTC representation used by every response.
|
|
const TimeFormat = "2006-01-02T15:04:05.000000Z"
|
|
|
|
// Timestamp marshals with stable microsecond precision and a trailing Z.
|
|
type Timestamp struct {
|
|
time.Time
|
|
}
|
|
|
|
// NewTimestamp keeps the precision PostgreSQL stores and normalises to UTC.
|
|
func NewTimestamp(t time.Time) Timestamp {
|
|
return Timestamp{Time: t.UTC().Round(time.Microsecond)}
|
|
}
|
|
|
|
func (t Timestamp) MarshalJSON() ([]byte, error) {
|
|
return json.Marshal(t.UTC().Format(TimeFormat))
|
|
}
|
|
|
|
type User struct {
|
|
ID string `json:"id"`
|
|
Username string `json:"username"`
|
|
DisplayName string `json:"display_name"`
|
|
CreatedAt Timestamp `json:"created_at"`
|
|
}
|
|
|
|
type Chat struct {
|
|
ID string `json:"id"`
|
|
Title string `json:"title"`
|
|
MemberIDs []string `json:"member_ids"`
|
|
CreatedAt Timestamp `json:"created_at"`
|
|
}
|
|
|
|
type Message struct {
|
|
ID string `json:"id"`
|
|
ChatID string `json:"chat_id"`
|
|
SenderID string `json:"sender_id"`
|
|
Text string `json:"text"`
|
|
CreatedAt Timestamp `json:"created_at"`
|
|
}
|
|
|
|
type ChatPage struct {
|
|
Items []Chat `json:"items"`
|
|
NextCursor *string `json:"next_cursor"`
|
|
}
|
|
|
|
type MessagePage struct {
|
|
Items []Message `json:"items"`
|
|
NextCursor *string `json:"next_cursor"`
|
|
}
|
|
|
|
type Session struct {
|
|
Token string `json:"token"`
|
|
TokenType string `json:"token_type"`
|
|
ExpiresAt Timestamp `json:"expires_at"`
|
|
User User `json:"user"`
|
|
}
|
|
|
|
type Health struct {
|
|
Status string `json:"status"`
|
|
}
|