dal

package
v0.0.0-...-22ea7d8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("not found")
)

Functions

This section is empty.

Types

type Cache

type Cache struct {
	Key       string
	Value     string
	ExpiresAt time.Time
}

type CallbackData

type CallbackData struct {
	ChatID    int64     `json:"-"`
	ID        string    `json:"-"`
	Word      string    `json:"word"`
	ExpiresAt time.Time `json:"-"`
}

type CallbacksRepository

type CallbacksRepository interface {
	InsertCallback(ctx context.Context, data CallbackData) (string, error)
	FindCallback(ctx context.Context, chatID int64, uuid string) (*CallbackData, error)
}

type Client

type Client interface {
	Begin(ctx context.Context) (pgx.Tx, error)
	Exec(ctx context.Context, sql string, args ...interface{}) (pgconn.CommandTag, error)
	QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row
	Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
}

type PostgreSQLRepository

type PostgreSQLRepository struct {
	// contains filtered or unexported fields
}

func NewPostgreSQLRepository

func NewPostgreSQLRepository(ctx context.Context, client Client, log *slog.Logger) *PostgreSQLRepository

func (*PostgreSQLRepository) AddToLearningBatch

func (r *PostgreSQLRepository) AddToLearningBatch(ctx context.Context, chatID int64, word string) error

func (*PostgreSQLRepository) AddWordTranslation

func (r *PostgreSQLRepository) AddWordTranslation(ctx context.Context, chatID int64, word, translation string) error

func (*PostgreSQLRepository) DeleteFromLearningBatchGtGuessedStreak

func (r *PostgreSQLRepository) DeleteFromLearningBatchGtGuessedStreak(ctx context.Context, chatID int64, guessedStreakLimit int) (int, error)

func (*PostgreSQLRepository) FindCallback

func (r *PostgreSQLRepository) FindCallback(ctx context.Context, chatID int64, uuid string) (*CallbackData, error)

func (*PostgreSQLRepository) FindRandomBatchedWordTranslation

func (r *PostgreSQLRepository) FindRandomBatchedWordTranslation(ctx context.Context, chatID int64) (*WordTranslation, error)

func (*PostgreSQLRepository) FindRandomNotBatchedWordTranslation

func (r *PostgreSQLRepository) FindRandomNotBatchedWordTranslation(ctx context.Context, chatID int64, streakLimit int) (*WordTranslation, error)

func (*PostgreSQLRepository) FindWordTranslation

func (r *PostgreSQLRepository) FindWordTranslation(ctx context.Context, chatID int64, word string) (*WordTranslation, error)

func (*PostgreSQLRepository) FindWordsToReview

func (r *PostgreSQLRepository) FindWordsToReview(ctx context.Context, chatID int64) ([]WordTranslation, error)

func (*PostgreSQLRepository) GetBatchedWordTranslationsCount

func (r *PostgreSQLRepository) GetBatchedWordTranslationsCount(ctx context.Context, chatID int64) (int, error)

func (*PostgreSQLRepository) GetStats

func (r *PostgreSQLRepository) GetStats(ctx context.Context, chatID int64) (*WordTranslationStats, error)

func (*PostgreSQLRepository) IncreaseGuessedStreak

func (r *PostgreSQLRepository) IncreaseGuessedStreak(ctx context.Context, chatID int64, word string) error

func (*PostgreSQLRepository) InsertCallback

func (r *PostgreSQLRepository) InsertCallback(ctx context.Context, data CallbackData) (string, error)

func (*PostgreSQLRepository) MarkToReviewAndResetStreak

func (r *PostgreSQLRepository) MarkToReviewAndResetStreak(ctx context.Context, chatID int64, word string) error

func (*PostgreSQLRepository) ResetGuessedStreak

func (r *PostgreSQLRepository) ResetGuessedStreak(ctx context.Context, chatID int64, word string) error

func (*PostgreSQLRepository) ResetToReview

func (r *PostgreSQLRepository) ResetToReview(ctx context.Context, chatID int64) error

func (*PostgreSQLRepository) Transact

func (r *PostgreSQLRepository) Transact(ctx context.Context, txFunc func(r Repository) error) error

type Repository

type Repository interface {
	Transact(ctx context.Context, txFunc func(r Repository) error) error
	WordTranslationsRepository
	CallbacksRepository
}

type WordTranslation

type WordTranslation struct {
	ChatID        int64
	Word          string
	Translation   string
	Description   string
	GuessedStreak int
	CreatedAt     time.Time
	UpdatedAt     time.Time
}

type WordTranslationStats

type WordTranslationStats struct {
	ChatID               int64
	GreaterThanOrEqual15 int
	Between10And14       int
	Between1And9         int
	Total                int
}

type WordTranslationsRepository

type WordTranslationsRepository interface {
	GetStats(ctx context.Context, chatID int64) (*WordTranslationStats, error)
	AddWordTranslation(ctx context.Context, chatID int64, word, translation string) error
	AddToLearningBatch(ctx context.Context, chatID int64, word string) error
	GetBatchedWordTranslationsCount(ctx context.Context, chatID int64) (int, error)
	FindWordTranslation(ctx context.Context, chatID int64, word string) (*WordTranslation, error)
	FindRandomBatchedWordTranslation(ctx context.Context, chatID int64) (*WordTranslation, error)
	FindRandomNotBatchedWordTranslation(ctx context.Context, chatID int64, streakLimit int) (*WordTranslation, error)
	FindWordsToReview(ctx context.Context, chatID int64) ([]WordTranslation, error)
	IncreaseGuessedStreak(ctx context.Context, chatID int64, word string) error
	ResetGuessedStreak(ctx context.Context, chatID int64, word string) error
	ResetToReview(ctx context.Context, chatID int64) error
	MarkToReviewAndResetStreak(ctx context.Context, chatID int64, word string) error
	DeleteFromLearningBatchGtGuessedStreak(ctx context.Context, chatID int64, guessedStreakLimit int) (int, error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL