51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
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
|
|
}
|