package model import ( "strconv" "time" ) // Timestamp — детерминированная сериализация времени (ровно 3 знака миллисекунд). // Из lab1, без изменений. type Timestamp struct{ time.Time } func (t Timestamp) MarshalJSON() ([]byte, error) { s := t.UTC().Format("2006-01-02T15:04:05.000Z") return strconv.AppendQuote(nil, s), nil } func NowTS() Timestamp { return Timestamp{Time: time.Now().UTC().Truncate(time.Millisecond)} } // User — ответ API: пароль и его hash НЕ включены (контракт). type User struct { ID string `json:"id"` Username string `json:"username"` DisplayName string `json:"display_name"` CreatedAt Timestamp `json:"created_at"` } // CreateUserReq — вход регистрации: username + display_name + password. // Password только на входе, в User не попадает. type CreateUserReq struct { Username string `json:"username"` DisplayName string `json:"display_name"` Password string `json:"password"` } // LoginRequest — вход в систему через Basic Auth (парсится из заголовка Authorization). type LoginRequest struct { Username string Password string } // Session — внутренняя модель сессии (не отдаётся клиенту). type Session struct { TokenHash []byte // SHA-256 от opaque-токена UserID string ExpiresAt time.Time CreatedAt time.Time } // SessionResponse — ответ POST /auth/sessions (то, что отдаём клиенту). type SessionResponse struct { Token string `json:"token"` TokenType string `json:"token_type"` // всегда "Bearer" ExpiresAt Timestamp `json:"expires_at"` User User `json:"user"` } type Chat struct { ID string `json:"id"` Title string `json:"title"` MemberIDs []string `json:"member_ids"` CreatedAt Timestamp `json:"created_at"` } type CreateChatReq struct { Title string `json:"title"` MemberIDs []string `json:"member_ids"` } 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 CreateMessageReq struct { Text string `json:"text"` } // Page — дженерик-страница (из lab1). type Page[T any] struct { Items []T `json:"items"` NextCursor *string `json:"next_cursor"` } type Health struct { Status string `json:"status"` }