forked from mtusi2026/mtusi2026lab2
37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
"uuid"
|
|
|
|
"messenger/internal/domain"
|
|
)
|
|
|
|
type UserRepository interface {
|
|
CreateUser(ctx context.Context, u domain.User, passwordHash string) error
|
|
GetUser(ctx context.Context, id uuid.UUID) (domain.User, error)
|
|
GetUserByUsername(ctx context.Context, username string) (domain.User, string, error)
|
|
}
|
|
|
|
type ChatRepository interface {
|
|
CreateChat(ctx context.Context, c domain.Chat) error
|
|
GetChat(ctx context.Context, id uuid.UUID) (domain.Chat, error)
|
|
ListUserChats(ctx context.Context, userID uuid.UUID, after *domain.Cursor, limit int) ([]domain.Chat, bool, error)
|
|
}
|
|
|
|
type MessageRepository interface {
|
|
CreateMessage(ctx context.Context, m domain.Message) error
|
|
ListMessages(ctx context.Context, chatID uuid.UUID, after *domain.Cursor, limit int) ([]domain.Message, bool, error)
|
|
}
|
|
|
|
type SessionStore interface {
|
|
Create(ctx context.Context, tokenHash string, userID uuid.UUID, expiresAt time.Time) error
|
|
Get(ctx context.Context, tokenHash string) (uuid.UUID, error)
|
|
Delete(ctx context.Context, tokenHash string) error
|
|
}
|
|
|
|
func now() time.Time {
|
|
return time.Now().UTC().Truncate(time.Microsecond)
|
|
}
|