deck

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const OwnedExpirationTime = 2 * time.Hour

Variables

This section is empty.

Functions

func ConvertToPublic

func ConvertToPublic(deck []domain.Deck) []domain.PublicDeck

ConvertToPublic converts a slice of domain.Deck to a slice of domain.PublicDeck.

Types

type IRedisRepository

type IRedisRepository interface {
	// GetByID returns the deck with the given id.
	GetByID(ctx context.Context, id uint) (string, error)
	// SetByID sets the deck with the given id.
	SetByID(ctx context.Context, id uint, deck string) error
	// DeleteByID deletes the deck with the given id.
	DeleteByID(ctx context.Context, id uint) error
	// SetOwnedByUser sets the deck with the given id as owned by the given user.
	SetOwnedByUser(ctx context.Context, userID uint, decks string) error
	// GetOwnedByUser returns the decks owned by the given user.
	GetOwnedByUser(ctx context.Context, userID uint) (string, error)
	// DeleteOwnedByUser deletes the decks owned by the given user.
	DeleteOwnedByUser(ctx context.Context, userID uint) error
	// SetLearningByUser sets the deck with the given id as learnt by the given user.
	SetLearningByUser(ctx context.Context, userID uint, decks string) error
	// GetLearningByUser returns the decks learnt by the given user.
	GetLearningByUser(ctx context.Context, userID uint) (string, error)
	// DeleteLearningByUser deletes the decks learnt by the given user.
	DeleteLearningByUser(ctx context.Context, userID uint) error
}

IRedisRepository is the interface for the deck redis repository.

func NewRedisRepository

func NewRedisRepository(redisConn *redis.Client) IRedisRepository

NewRedisRepository returns a new redis repository.

type IRepository

type IRepository interface {
	// GetByID returns the deck with the given id.
	GetByID(ctx context.Context, id uint) (domain.Deck, error)
	// Create creates a new deck.
	Create(ctx context.Context, deck *domain.Deck) error
	// Update updates the deck with the given id.
	Update(ctx context.Context, deck *domain.Deck) error
	// Delete deletes the deck with the given id.
	Delete(ctx context.Context, id uint) error
	// CreateFromUser creates a new deck from the given user.
	CreateFromUser(ctx context.Context, user domain.User, deck *domain.Deck) error
	// GetByUser returns the decks of the given user.
	GetByUser(ctx context.Context, user domain.User) ([]domain.Deck, error)
	// GetByLearner returns the decks of the given learner.
	GetByLearner(ctx context.Context, user domain.User) ([]domain.Deck, error)
	// GetPublic returns the public decks.
	GetPublic(ctx context.Context) ([]domain.Deck, error)
}

IRepository is the interface for the deck repository.

func NewRepository

func NewRepository(dbConn *gorm.DB) IRepository

NewRepository returns a new repository.

type IUseCase

type IUseCase interface {
	// GetByID returns the deck with the given id.
	GetByID(ctx context.Context, id uint) (domain.Deck, error)
	// Create creates a new deck.
	Create(ctx context.Context, deck *domain.Deck) error
	// CreateFromUser creates a new deck from the given user.
	CreateFromUser(ctx context.Context, user domain.User, deck *domain.Deck) error
	// GetByUser returns the decks of the given user.
	GetByUser(ctx context.Context, user domain.User) ([]domain.Deck, error)
	// GetByLearner returns the decks of the given learner.
	GetByLearner(ctx context.Context, user domain.User) ([]domain.Deck, error)
	// GetPublic returns the public decks.
	GetPublic(ctx context.Context) ([]domain.Deck, error)
}

IUseCase is the interface for the deck use case.

func NewUseCase

func NewUseCase(repo IRepository, redis IRedisRepository) IUseCase

NewUseCase returns a new deck use case.

type RedisRepository

type RedisRepository struct {
	RedisConn *redis.Client // RedisConn is the redis connection.
}

RedisRepository is the interface for the redis repository.

func (RedisRepository) DeleteByID

func (r RedisRepository) DeleteByID(ctx context.Context, id uint) error

DeleteByID deletes the deck by id.

func (RedisRepository) DeleteLearningByUser

func (r RedisRepository) DeleteLearningByUser(ctx context.Context, userID uint) error

DeleteLearningByUser deletes the decks learning by the user.

func (RedisRepository) DeleteOwnedByUser

func (r RedisRepository) DeleteOwnedByUser(ctx context.Context, userID uint) error

DeleteOwnedByUser deletes the decks owned by the user.

func (RedisRepository) GetByID

func (r RedisRepository) GetByID(ctx context.Context, id uint) (string, error)

GetByID gets the deck by id.

func (RedisRepository) GetLearningByUser

func (r RedisRepository) GetLearningByUser(ctx context.Context, userID uint) (string, error)

GetLearningByUser gets the decks learning by the user.

func (RedisRepository) GetOwnedByUser

func (r RedisRepository) GetOwnedByUser(ctx context.Context, userID uint) (string, error)

GetOwnedByUser gets the decks owned by the user.

func (RedisRepository) SetByID

func (r RedisRepository) SetByID(ctx context.Context, id uint, deck string) error

SetByID sets the deck by id.

func (RedisRepository) SetLearningByUser

func (r RedisRepository) SetLearningByUser(ctx context.Context, userID uint, decks string) error

SetLearningByUser sets the decks learning by the user.

func (RedisRepository) SetOwnedByUser

func (r RedisRepository) SetOwnedByUser(ctx context.Context, userID uint, decks string) error

SetOwnedByUser sets the decks owned by the user.

type SQLRepository

type SQLRepository struct {
	DBConn *gorm.DB
}

SQLRepository is the repository for the deck.

func (*SQLRepository) Create

func (r *SQLRepository) Create(ctx context.Context, deck *domain.Deck) error

Create creates a new deck.

func (*SQLRepository) CreateFromUser

func (r *SQLRepository) CreateFromUser(ctx context.Context, user domain.User, deck *domain.Deck) error

CreateFromUser creates a new deck from the given user.

func (*SQLRepository) Delete

func (r *SQLRepository) Delete(ctx context.Context, id uint) error

Delete deletes the deck with the given id.

func (*SQLRepository) GetByID

func (r *SQLRepository) GetByID(ctx context.Context, id uint) (domain.Deck, error)

GetByID returns the deck with the given id.

func (*SQLRepository) GetByLearner

func (r *SQLRepository) GetByLearner(ctx context.Context, user domain.User) ([]domain.Deck, error)

GetByLearner returns the decks of the given learner.

func (*SQLRepository) GetByUser

func (r *SQLRepository) GetByUser(ctx context.Context, user domain.User) ([]domain.Deck, error)

GetByUser returns the decks of the given user.

func (*SQLRepository) GetPublic

func (r *SQLRepository) GetPublic(ctx context.Context) ([]domain.Deck, error)

GetPublic returns the public decks.

func (*SQLRepository) Update

func (r *SQLRepository) Update(ctx context.Context, deck *domain.Deck) error

Update updates the deck with the given id.

type UseCase

type UseCase struct {
	IRepository
	IRedisRepository
}

UseCase is the deck use case.

func (*UseCase) Create

func (u *UseCase) Create(ctx context.Context, deck *domain.Deck) error

Create creates a new deck.

func (*UseCase) CreateFromUser

func (u *UseCase) CreateFromUser(ctx context.Context, user domain.User, deck *domain.Deck) error

CreateFromUser creates a new deck from the given user.

func (*UseCase) GetByID

func (u *UseCase) GetByID(ctx context.Context, id uint) (domain.Deck, error)

GetByID returns the deck with the given id.

func (*UseCase) GetByLearner

func (u *UseCase) GetByLearner(ctx context.Context, user domain.User) ([]domain.Deck, error)

GetByLearner returns the decks of the given learner.

func (*UseCase) GetByUser

func (u *UseCase) GetByUser(ctx context.Context, user domain.User) ([]domain.Deck, error)

GetByUser returns the decks of the given user.

func (*UseCase) GetPublic

func (u *UseCase) GetPublic(ctx context.Context) ([]domain.Deck, error)

GetPublic returns the public decks.

Jump to

Keyboard shortcuts

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