repository

package
v0.0.0-...-0ca6d7b Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Data storage

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCodeVerifyTooMany = cache.ErrCodeVerifyTooMany
	ErrCodeSendTooMany   = cache.ErrCodeSendTooMany
)
View Source
var (
	ErrDuplicatedUser = dao.ErrDuplicatedUser
	// NOTE: Strongly related to the service
	ErrUserNotFound = dao.ErrRecordNotFound
)
View Source
var ErrArticleNotFound = dao.ErrArticleNotFound

Functions

This section is empty.

Types

type ArticleAuthorRepository

type ArticleAuthorRepository interface {
	Create(ctx context.Context, article domain.Article) (int64, error)
	Update(ctx context.Context, article domain.Article) error
}

func NewArticleAuthorRepository

func NewArticleAuthorRepository(dao dao.ArticleDAO) ArticleAuthorRepository

type ArticleReaderRepository

type ArticleReaderRepository interface {
	// Insert or Update
	Save(ctx context.Context, article domain.Article) error
}

func NewArticleReaderRepository

func NewArticleReaderRepository(dao dao.ArticleDAO) ArticleReaderRepository

type ArticleRepository

type ArticleRepository interface {
	Create(ctx context.Context, article domain.Article) (int64, error)
	Update(ctx context.Context, article domain.Article) error
	Sync(ctx context.Context, article domain.Article) (int64, error)
	SyncStatus(
		ctx context.Context,
		userID int64,
		articleID int64,
		status domain.ArticleStatus,
	) error
	GetByAuthor(ctx context.Context, uid int64, offset int, limit int) ([]domain.Article, error)
	GetByID(ctx context.Context, id int64) (domain.Article, error)
	GetPubByID(ctx context.Context, id int64) (domain.Article, error)
}

func NewArticleRepository

func NewArticleRepository(
	l logger.Logger,
	dao dao.ArticleDAO,
	cache cache.ArticleCache,
	userRepo UserRepository,
) ArticleRepository

type AsyncSMSRepository

type AsyncSMSRepository interface {
	AddSMS(ctx context.Context, toNb string, body string, args string) error
	TrySend(
		ctx context.Context,
		f func(ctx context.Context, toNb string, body string, args ...string) error,
		maxRetry int,
	)
}

func NewAsyncSMSRepository

func NewAsyncSMSRepository(dao dao.AsyncSMSDAO, db *gorm.DB) AsyncSMSRepository

type CachedArticleAuthorRepository

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

func (*CachedArticleAuthorRepository) Create

func (c *CachedArticleAuthorRepository) Create(
	ctx context.Context,
	article domain.Article,
) (int64, error)

func (*CachedArticleAuthorRepository) Update

type CachedArticleReaderRepository

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

func (*CachedArticleReaderRepository) Save

type CachedArticleRepository

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

func NewArticleRepositoryV2

func NewArticleRepositoryV2(
	readerDAO dao.ArticleReaderDAO,
	authorDAO dao.ArticleAuthorDAO,
) *CachedArticleRepository

func (*CachedArticleRepository) Create

func (c *CachedArticleRepository) Create(
	ctx context.Context,
	article domain.Article,
) (int64, error)

func (*CachedArticleRepository) GetByAuthor

func (c *CachedArticleRepository) GetByAuthor(
	ctx context.Context,
	uid int64,
	offset int,
	limit int,
) ([]domain.Article, error)

GetByAuthor implements ArticleRepository.

func (*CachedArticleRepository) GetByID

GetByID implements ArticleRepository.

func (*CachedArticleRepository) GetPubByID

func (c *CachedArticleRepository) GetPubByID(
	ctx context.Context,
	id int64,
) (domain.Article, error)

GetPubByID implements ArticleRepository.

func (*CachedArticleRepository) Sync

func (c *CachedArticleRepository) Sync(
	ctx context.Context,
	article domain.Article,
) (int64, error)

func (*CachedArticleRepository) SyncStatus

func (c *CachedArticleRepository) SyncStatus(
	ctx context.Context,
	userID int64,
	articleID int64,
	status domain.ArticleStatus,
) error

func (*CachedArticleRepository) SyncV0

func (c *CachedArticleRepository) SyncV0(
	ctx context.Context,
	article domain.Article,
) (int64, error)

func (*CachedArticleRepository) SyncV1

func (c *CachedArticleRepository) SyncV1(
	ctx context.Context,
	article domain.Article,
) (int64, error)

func (*CachedArticleRepository) SyncV2

func (c *CachedArticleRepository) SyncV2(
	ctx context.Context,
	article domain.Article,
) (int64, error)

NOTE: manual transaction --> not recommended defauts: Depends on DAO's dependencies. Not interface-oriented. WARN: Should avoid as much as possible!

func (*CachedArticleRepository) Update

func (c *CachedArticleRepository) Update(ctx context.Context, article domain.Article) error

type CachedCodeRepository

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

func (*CachedCodeRepository) Set

func (c *CachedCodeRepository) Set(ctx context.Context, biz, phone, code string) error

func (*CachedCodeRepository) Verify

func (c *CachedCodeRepository) Verify(ctx context.Context, biz, phone, code string) (bool, error)

type CachedInteractiveRepository

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

func (*CachedInteractiveRepository) AddCollectionItem

func (c *CachedInteractiveRepository) AddCollectionItem(
	ctx context.Context,
	biz string,
	id int64,
	cid int64,
	uid int64,
) error

AddCollectionItem implements InteractiveRepository.

func (*CachedInteractiveRepository) Collected

func (c *CachedInteractiveRepository) Collected(
	ctx context.Context,
	biz string,
	bizID int64,
	uid int64,
) (bool, error)

Collected implements InteractiveRepository.

func (*CachedInteractiveRepository) DecrLike

func (c *CachedInteractiveRepository) DecrLike(
	ctx context.Context,
	biz string,
	id int64,
	uid int64,
) error

func (*CachedInteractiveRepository) DeleteCollectionItem

func (c *CachedInteractiveRepository) DeleteCollectionItem(
	ctx context.Context,
	biz string,
	id int64,
	cid int64,
	uid int64,
) error

DeleteCollectionItem implements InteractiveRepository.

func (*CachedInteractiveRepository) Get

Get implements InteractiveRepository.

func (*CachedInteractiveRepository) IncrLike

func (c *CachedInteractiveRepository) IncrLike(
	ctx context.Context,
	biz string,
	id int64,
	uid int64,
) error

func (*CachedInteractiveRepository) IncrReadCnt

func (c *CachedInteractiveRepository) IncrReadCnt(
	ctx context.Context,
	biz string,
	bizID int64,
) error

IncrReadCnt implements InteractiveRepository.

func (*CachedInteractiveRepository) Liked

func (c *CachedInteractiveRepository) Liked(
	ctx context.Context,
	biz string,
	bizID int64,
	uid int64,
) (bool, error)

Liked implements InteractiveRepository.

type CachedUserRepository

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

func (*CachedUserRepository) Create

func (repo *CachedUserRepository) Create(ctx context.Context, u domain.User) (domain.User, error)

func (*CachedUserRepository) FindByEmail

func (repo *CachedUserRepository) FindByEmail(
	ctx context.Context,
	email string,
) (domain.User, error)

func (*CachedUserRepository) FindByID

func (repo *CachedUserRepository) FindByID(ctx context.Context, userID int64) (domain.User, error)

NOTE: Ok for normal case. But if cache penetration happens, the DB can be crashed by queries

func (*CachedUserRepository) FindByIdV1

func (repo *CachedUserRepository) FindByIdV1(
	ctx context.Context,
	userID int64,
) (domain.User, error)

NOTE: Conservative method, for tasks with low priority. This helps keep the database working for other services.

func (*CachedUserRepository) FindByPhone

func (repo *CachedUserRepository) FindByPhone(
	ctx context.Context,
	phone string,
) (domain.User, error)

func (*CachedUserRepository) UpdateProfile

func (repo *CachedUserRepository) UpdateProfile(ctx context.Context, user *domain.User) error

type CodeRepository

type CodeRepository interface {
	Set(ctx context.Context, biz, phone, code string) error
	Verify(ctx context.Context, biz, phone, code string) (bool, error)
}

func NewCodeRepository

func NewCodeRepository(cc cache.CodeCache) CodeRepository

type InteractiveRepository

type InteractiveRepository interface {
	IncrReadCnt(ctx context.Context, biz string, bizID int64) error
	IncrLike(ctx context.Context, biz string, id int64, uid int64) error
	DecrLike(ctx context.Context, biz string, id int64, uid int64) error
	AddCollectionItem(ctx context.Context, biz string, id int64, cid int64, uid int64) error
	DeleteCollectionItem(ctx context.Context, biz string, id int64, cid int64, uid int64) error
	Get(ctx context.Context, biz string, bizID int64) (domain.Interactive, error)
	Liked(ctx context.Context, biz string, bizID int64, uid int64) (bool, error)
	Collected(ctx context.Context, biz string, bizID int64, uid int64) (bool, error)
}

func NewCachedInteractiveRepository

func NewCachedInteractiveRepository(
	l logger.Logger,
	dao dao.InteractiveDAO,
	cache cache.InteractiveCache,
) InteractiveRepository

type UserRepository

type UserRepository interface {
	Create(ctx context.Context, u domain.User) (domain.User, error)
	FindByEmail(ctx context.Context, email string) (domain.User, error)
	FindByPhone(ctx context.Context, phone string) (domain.User, error)
	UpdateProfile(ctx context.Context, user *domain.User) error
	FindByID(ctx context.Context, userID int64) (domain.User, error)
}

func NewUserRepository

func NewUserRepository(dao dao.UserDAO, cache cache.UserCache) UserRepository

Directories

Path Synopsis
Cache access
Cache access
mocks
Package cachemocks is a generated GoMock package.
Package cachemocks is a generated GoMock package.
rediscache/mocks
Package redismock is a generated GoMock package.
Package redismock is a generated GoMock package.
dao
Database access
Database access
mocks
Package daomocks is a generated GoMock package.
Package daomocks is a generated GoMock package.
Package repomocks is a generated GoMock package.
Package repomocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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