Files
mtusi2026lab5-fork/backend/internal/domain/repository.go
T

78 lines
2.9 KiB
Go

package domain
import (
"context"
"time"
)
type UserRepository interface {
Create(ctx context.Context, user *User) error
GetByID(ctx context.Context, id string) (*User, error)
GetByUsername(ctx context.Context, username string) (*User, error)
}
type ChatRepository interface {
Create(ctx context.Context, chat *Chat) error
GetByID(ctx context.Context, id string) (*Chat, error)
ListByMember(ctx context.Context, userID string, limit int, cursor *string) ([]Chat, *string, error)
}
type MessageRepository interface {
Create(ctx context.Context, message *Message) error
ListByChat(ctx context.Context, chatID string, limit int, cursor *string) ([]Message, *string, error)
CreateIdempotent(
ctx context.Context,
scope IdempotencyScope,
requestHash []byte,
fresh *Message,
freshResponse []byte,
ttl time.Duration,
) (*CreateIdempotentResult, error)
}
type SessionRepository interface {
Create(ctx context.Context, session *Session) error
GetByTokenHash(ctx context.Context, tokenHash []byte) (*Session, error)
DeleteByTokenHash(ctx context.Context, tokenHash []byte) error
}
type AttachmentRepository interface {
Create(ctx context.Context, a *Attachment) error
GetByID(ctx context.Context, id string) (*Attachment, error)
MarkReady(ctx context.Context, id string) error
MarkFailed(ctx context.Context, id string, errorCode string) error
ExistingKeys(ctx context.Context, keys []string) ([]string, error)
CreateInTx(ctx context.Context, tx Tx, a *Attachment) error
ResetForReplay(ctx context.Context, tx Tx, id string) error
ListExpiredLeases(ctx context.Context, limit int) ([]Attachment, error)
ResetLease(ctx context.Context, id string) error
ListStagingToCleanup(ctx context.Context, limit int) ([]Attachment, error)
ClearStagingKey(ctx context.Context, id string) error
}
type OutboxRepository interface {
Enqueue(ctx context.Context, tx Tx, e *OutboxEntry) error
ClaimBatch(ctx context.Context, limit int) ([]OutboxEntry, error)
MarkPublished(ctx context.Context, ids []string) error
EnqueueDirect(ctx context.Context, e *OutboxEntry) error
}
type AttachmentJobRepository interface {
ClaimForProcessing(ctx context.Context, id string, version int, lease time.Duration) (*Attachment, error)
CompleteJob(ctx context.Context, id string, pipelineVersion int, variants []AttachmentVariant) (bool, error)
FailJob(ctx context.Context, id string, errorCode string) error
ScheduleRetry(ctx context.Context, id string, nextAttemptAt time.Time, errorCode string) error
}
type AttachmentVariantRepository interface {
Upsert(ctx context.Context, tx Tx, v *AttachmentVariant) error
ListByAttachment(ctx context.Context, id string) ([]AttachmentVariant, error)
}
type FailedJobRepository interface {
Record(ctx context.Context, f *FailedJob) error
Resolve(ctx context.Context, attachmentID string, resolution string) error
ResolveInTx(ctx context.Context, tx Tx, id string) error
}