Documentation ¶
Index ¶
- Constants
- func ConvertToPublic(deck []domain.Deck) []domain.PublicDeck
- type IRedisRepository
- type IRepository
- type IUseCase
- type RedisRepository
- func (r RedisRepository) DeleteByID(ctx context.Context, id uint) error
- func (r RedisRepository) DeleteLearningByUser(ctx context.Context, userID uint) error
- func (r RedisRepository) DeleteOwnedByUser(ctx context.Context, userID uint) error
- func (r RedisRepository) GetByID(ctx context.Context, id uint) (string, error)
- func (r RedisRepository) GetLearningByUser(ctx context.Context, userID uint) (string, error)
- func (r RedisRepository) GetOwnedByUser(ctx context.Context, userID uint) (string, error)
- func (r RedisRepository) SetByID(ctx context.Context, id uint, deck string) error
- func (r RedisRepository) SetLearningByUser(ctx context.Context, userID uint, decks string) error
- func (r RedisRepository) SetOwnedByUser(ctx context.Context, userID uint, decks string) error
- type SQLRepository
- func (r *SQLRepository) Create(ctx context.Context, deck *domain.Deck) error
- func (r *SQLRepository) CreateFromUser(ctx context.Context, user domain.User, deck *domain.Deck) error
- func (r *SQLRepository) Delete(ctx context.Context, id uint) error
- func (r *SQLRepository) GetByID(ctx context.Context, id uint) (domain.Deck, error)
- func (r *SQLRepository) GetByLearner(ctx context.Context, user domain.User) ([]domain.Deck, error)
- func (r *SQLRepository) GetByUser(ctx context.Context, user domain.User) ([]domain.Deck, error)
- func (r *SQLRepository) GetPublic(ctx context.Context) ([]domain.Deck, error)
- func (r *SQLRepository) Update(ctx context.Context, deck *domain.Deck) error
- type UseCase
- func (u *UseCase) Create(ctx context.Context, deck *domain.Deck) error
- func (u *UseCase) CreateFromUser(ctx context.Context, user domain.User, deck *domain.Deck) error
- func (u *UseCase) GetByID(ctx context.Context, id uint) (domain.Deck, error)
- func (u *UseCase) GetByLearner(ctx context.Context, user domain.User) ([]domain.Deck, error)
- func (u *UseCase) GetByUser(ctx context.Context, user domain.User) ([]domain.Deck, error)
- func (u *UseCase) GetPublic(ctx context.Context) ([]domain.Deck, error)
Constants ¶
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) GetLearningByUser ¶
GetLearningByUser gets the decks learning by the user.
func (RedisRepository) GetOwnedByUser ¶
GetOwnedByUser gets the decks owned by the user.
func (RedisRepository) SetLearningByUser ¶
SetLearningByUser sets the decks learning by the user.
func (RedisRepository) SetOwnedByUser ¶
SetOwnedByUser sets the decks owned by the user.
type SQLRepository ¶
SQLRepository is the repository for the 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) GetByLearner ¶
GetByLearner returns the decks of the given learner.
type UseCase ¶
type UseCase struct { IRepository IRedisRepository }
UseCase is the deck use case.
func (*UseCase) CreateFromUser ¶
CreateFromUser creates a new deck from the given user.
func (*UseCase) GetByLearner ¶
GetByLearner returns the decks of the given learner.