forked from mtusi2026/mtusi2026lab4
50 lines
1.6 KiB
Go
50 lines
1.6 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"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 {
|
|
CreateMessageIdempotent(ctx context.Context, m domain.Message, key, requestHash string) (domain.Message, error)
|
|
ListMessages(ctx context.Context, chatID uuid.UUID, after *domain.Cursor, limit int) ([]domain.Message, bool, error)
|
|
}
|
|
|
|
type AttachmentRepository interface {
|
|
CreateAttachment(ctx context.Context, a domain.Attachment) error
|
|
GetAttachment(ctx context.Context, id uuid.UUID) (domain.Attachment, error)
|
|
}
|
|
|
|
type ObjectStore interface {
|
|
Put(ctx context.Context, key string, r io.Reader, size int64, contentType string) error
|
|
Get(ctx context.Context, key string) (io.ReadCloser, error)
|
|
Delete(ctx context.Context, key string) error
|
|
Ping(ctx context.Context) 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)
|
|
}
|