lab4: вложения в S3 (MinIO), reconciler PostgreSQL↔S3, тесты и CI

This commit is contained in:
2026-11-04 20:11:33 +03:00
parent ec540a1a72
commit 77b6e5c2c7
86 changed files with 6921 additions and 2 deletions
+51
View File
@@ -0,0 +1,51 @@
package domain
import (
"encoding/json"
"time"
)
const (
AttachmentUploading = "uploading"
AttachmentReady = "ready"
AttachmentMissing = "missing"
)
// Attachment — метаданные вложения. ObjectKey никогда не уходит клиенту.
type Attachment struct {
ID string
ChatID string
OwnerID string
Filename string
ObjectKey string
Status string
ContentType string
SizeBytes int64
SHA256 string
CreatedAt time.Time
UpdatedAt time.Time
}
// MarshalJSON — представление по контракту lab4: только ready, вариантов нет.
func (a Attachment) MarshalJSON() ([]byte, error) {
return json.Marshal(struct {
ID string `json:"id"`
ChatID string `json:"chat_id"`
OwnerID string `json:"owner_id"`
Filename string `json:"filename"`
ContentType string `json:"content_type"`
SizeBytes int64 `json:"size_bytes"`
SHA256 string `json:"sha256"`
Status string `json:"status"`
Variants []string `json:"variants"`
ErrorCode *string `json:"error_code"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}{
ID: a.ID, ChatID: a.ChatID, OwnerID: a.OwnerID, Filename: a.Filename,
ContentType: a.ContentType, SizeBytes: a.SizeBytes, SHA256: a.SHA256,
Status: a.Status, Variants: []string{}, ErrorCode: nil,
CreatedAt: a.CreatedAt.UTC().Truncate(time.Second).Format(time.RFC3339),
UpdatedAt: a.UpdatedAt.UTC().Truncate(time.Second).Format(time.RFC3339),
})
}
+30
View File
@@ -0,0 +1,30 @@
package domain
import (
"encoding/json"
"time"
)
type Chat struct {
ID string `json:"id"`
Title string `json:"title"`
MemberIDs []string `json:"member_ids"`
CreatedAt time.Time `json:"created_at"`
}
func (c Chat) MarshalJSON() ([]byte, error) {
type Alias Chat
members := c.MemberIDs
if members == nil {
members = []string{}
}
return json.Marshal(&struct {
Alias
MemberIDs []string `json:"member_ids"`
CreatedAt string `json:"created_at"`
}{
Alias: Alias(c),
MemberIDs: members,
CreatedAt: c.CreatedAt.UTC().Truncate(time.Second).Format(time.RFC3339),
})
}
+30
View File
@@ -0,0 +1,30 @@
package domain
import (
"encoding/json"
"time"
)
type Message struct {
ID string `json:"id"`
ChatID string `json:"chat_id"`
SenderID string `json:"sender_id"`
Text string `json:"text"`
CreatedAt time.Time `json:"created_at"`
// AttachmentIDs — в порядке отправки; всегда массив (пустой, если вложений нет).
AttachmentIDs []string `json:"attachment_ids"`
}
func (m Message) MarshalJSON() ([]byte, error) {
type Alias Message
if m.AttachmentIDs == nil {
m.AttachmentIDs = []string{}
}
return json.Marshal(&struct {
Alias
CreatedAt string `json:"created_at"`
}{
Alias: Alias(m),
CreatedAt: m.CreatedAt.UTC().Truncate(time.Second).Format(time.RFC3339),
})
}
+10
View File
@@ -0,0 +1,10 @@
package domain
import "time"
type Session struct {
Token string `json:"token"`
UserID string `json:"-"`
ExpiresAt time.Time `json:"expires_at"`
CreatedAt time.Time `json:"-"`
}
+25
View File
@@ -0,0 +1,25 @@
package domain
import (
"encoding/json"
"time"
)
type User struct {
ID string `json:"id"`
Username string `json:"username"`
DisplayName string `json:"display_name"`
CreatedAt time.Time `json:"created_at"`
}
// MarshalJSON форматирует CreatedAt в RFC3339 без микросекунд.
func (u User) MarshalJSON() ([]byte, error) {
type Alias User
return json.Marshal(&struct {
Alias
CreatedAt string `json:"created_at"`
}{
Alias: Alias(u),
CreatedAt: u.CreatedAt.UTC().Truncate(time.Second).Format(time.RFC3339),
})
}