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
+57
View File
@@ -0,0 +1,57 @@
package repository
import (
"context"
"time"
"github.com/charawein/mtusi2026lab4/internal/domain"
)
var ErrNotFound = errNotFound{}
type errNotFound struct{}
func (errNotFound) Error() string { return "not found" }
var ErrConflict = errConflict{}
type errConflict struct{}
func (errConflict) Error() string { return "conflict" }
// UserRepository
type UserRepository interface {
Create(ctx context.Context, user *domain.User, passwordHash string) error
GetByID(ctx context.Context, id string) (*domain.User, error)
GetByUsername(ctx context.Context, username string) (*domain.User, error)
GetPasswordHash(ctx context.Context, userID string) (string, error)
}
// ChatRepository
type ChatRepository interface {
Create(ctx context.Context, chat *domain.Chat) error
GetByID(ctx context.Context, id string) (*domain.Chat, error)
IsMember(ctx context.Context, chatID, userID string) (bool, error)
// MemberVersion — версия истории чата (растёт с каждым сообщением) и членство.
MemberVersion(ctx context.Context, chatID, userID string) (version int64, member bool, err error)
ListByMember(ctx context.Context, userID string, cursor time.Time, cursorID string, limit int) ([]*domain.Chat, error)
}
// MessageRepository
type MessageRepository interface {
Create(ctx context.Context, msg *domain.Message) error
// CreateIdempotent атомарно создаёт сообщение и запись ключа идемпотентности.
// Если ключ уже есть с тем же requestHash — возвращает ранее созданное сообщение
// и created=false; с другим requestHash — ErrConflict.
CreateIdempotent(ctx context.Context, msg *domain.Message, key, requestHash string, ttl time.Duration) (stored *domain.Message, created bool, err error)
DeleteExpiredKeys(ctx context.Context, ttl time.Duration) (int64, error)
ListByChat(ctx context.Context, chatID string, cursor time.Time, cursorID string, limit int) ([]*domain.Message, error)
}
// SessionRepository
type SessionRepository interface {
Create(ctx context.Context, s *domain.Session) error
GetByToken(ctx context.Context, token string) (*domain.Session, error)
Delete(ctx context.Context, token string) error
DeleteExpired(ctx context.Context) error
}