feat: lab4 - S3 attachments, image validation, failover

This commit is contained in:
2026-11-11 21:42:08 +03:00
parent 312131c344
commit 9fc37b0d8a
18 changed files with 1050 additions and 59 deletions
+16
View File
@@ -0,0 +1,16 @@
package domain
import "errors"
// ErrNotFound covers both "missing" and "not visible to this user", so the API
// never reveals that someone else's object exists.
var ErrNotFound = errors.New("object not found")
// ErrUsernameTaken means the username uniqueness constraint was violated.
var ErrUsernameTaken = errors.New("username already taken")
// ErrIdempotencyConflict means the same key was reused with a different body.
var ErrIdempotencyConflict = errors.New("idempotency key reused with another body")
// ErrUnknownMembers means member_ids references users that do not exist.
var ErrUnknownMembers = errors.New("unknown chat members")
+67
View File
@@ -0,0 +1,67 @@
// 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"`
}