lab2: postgres, sessions, redis, persistence, stale read
Skeleton contracts / contracts (pull_request) Canceled after 0s

This commit is contained in:
2026-10-09 21:30:36 +03:00
parent 65003b6119
commit d8842a3de4
54 changed files with 3205 additions and 19 deletions
+50
View File
@@ -0,0 +1,50 @@
package repository
import (
"context"
"time"
"github.com/charawein/mtusi2026lab2/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)
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
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
}