repository

package
v1.15.4 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPageSize = 20
	MaxPageSize     = 100
)

Variables

This section is empty.

Functions

func NormalizePage added in v1.15.2

func NormalizePage(page, size int) (int, int)

NormalizePage clamps pagination inputs; module repo implementations share it.

func NormalizePageFloor added in v1.15.2

func NormalizePageFloor(page, size int) (int, int)

NormalizePageFloor clamps pagination inputs without a minimum page size.

Types

type AdsRepo added in v1.3.9

type AdsRepo interface {
	Insert(ctx context.Context, data *ads.Ads) error
	FindOne(ctx context.Context, id int64) (*ads.Ads, error)
	Update(ctx context.Context, data *ads.Ads) error
	Delete(ctx context.Context, id int64) error
	GetAdsListByPage(ctx context.Context, page, size int, filter ads.Filter) (int64, []*ads.Ads, error)
}

AdsRepo ads 数据访问接口

type AnnouncementRepo added in v1.3.9

type AnnouncementRepo interface {
	Insert(ctx context.Context, data *announcement.Announcement) error
	FindOne(ctx context.Context, id int64) (*announcement.Announcement, error)
	Update(ctx context.Context, data *announcement.Announcement) error
	Delete(ctx context.Context, id int64) error
	GetAnnouncementListByPage(ctx context.Context, page, size int, filter announcement.Filter) (int64, []*announcement.Announcement, error)
}

AnnouncementRepo announcement 数据访问接口

type AuthRepo added in v1.3.9

type AuthRepo interface {
	Insert(ctx context.Context, data *auth.Auth) error
	FindOne(ctx context.Context, id int64) (*auth.Auth, error)
	Update(ctx context.Context, data *auth.Auth) error
	Delete(ctx context.Context, id int64) error
	GetAuthListByPage(ctx context.Context) ([]*auth.Auth, error)
	FindOneByMethod(ctx context.Context, platform string) (*auth.Auth, error)
	FindAll(ctx context.Context) ([]*auth.Auth, error)
}

AuthRepo auth 数据访问接口

type BillingBuilder added in v1.15.2

type BillingBuilder func(conn ModuleConn) BillingRepos

type BillingRepos added in v1.15.2

type BillingRepos struct {
	Orders      OrderRepo
	OrderEvents OrderEventRepo
	Payments    PaymentRepo
	Coupons     CouponRepo
	Withdrawals UserWithdrawalRepo
	Wallets     WalletRepo
	// OrderStats feeds the identity bundle's user-statistics merge.
	OrderStats OrderStatsBridge
}

BillingRepos is the billing domain bundle.

type BillingStore added in v1.15.0

type BillingStore interface {
	Order() OrderRepo
	OrderEvent() OrderEventRepo
	Payment() PaymentRepo
	Coupon() CouponRepo
	UserWithdrawal() UserWithdrawalRepo
	Wallet() WalletRepo
	Inbox() InboxRepo
	Outbox() OutboxRepo
	Log() LogRepo
}

BillingStore is the billing domain's transactional surface: orders, payments, coupons, withdrawals and wallet movements.

type Builders added in v1.15.2

type Builders struct {
	Platform     PlatformBuilder
	Billing      BillingBuilder
	Subscription SubscriptionBuilder
	Identity     IdentityBuilder
	Network      NetworkBuilder
	Support      SupportBuilder
}

Builders carries every module's repo builder for store assembly.

type ClientRepo added in v1.3.9

type ClientRepo interface {
	Insert(ctx context.Context, data *client.SubscribeApplication) error
	FindOne(ctx context.Context, id int64) (*client.SubscribeApplication, error)
	Update(ctx context.Context, data *client.SubscribeApplication) error
	Delete(ctx context.Context, id int64) error
	List(ctx context.Context) ([]*client.SubscribeApplication, error)
}

ClientRepo subscribe application 数据访问接口

type CouponRepo added in v1.3.9

type CouponRepo interface {
	Insert(ctx context.Context, data *coupon.Coupon) error
	FindOne(ctx context.Context, id int64) (*coupon.Coupon, error)
	FindOneByCode(ctx context.Context, code string) (*coupon.Coupon, error)
	Update(ctx context.Context, data *coupon.Coupon) error
	Delete(ctx context.Context, id int64) error
	UpdateCount(ctx context.Context, code string) error
	ReserveUsage(ctx context.Context, code string, now int64, tx ...*gorm.DB) (bool, error)
	ReleaseUsage(ctx context.Context, code string, tx ...*gorm.DB) error
	QueryCouponListByPage(ctx context.Context, page, size int, subscribe int64, search string) (total int64, list []*coupon.Coupon, err error)
	BatchDelete(ctx context.Context, ids []int64) error
}

CouponRepo coupon 数据访问接口

type DocumentRepo added in v1.3.9

type DocumentRepo interface {
	Insert(ctx context.Context, data *document.Document) error
	FindOne(ctx context.Context, id int64) (*document.Document, error)
	Update(ctx context.Context, data *document.Document) error
	Delete(ctx context.Context, id int64) error
	QueryDocumentDetail(ctx context.Context, id int64) (*document.Document, error)
	QueryDocumentList(ctx context.Context, page, size int, tag string, search string) (int64, []*document.Document, error)
	GetDocumentListByAll(ctx context.Context) (int64, []*document.Document, error)
}

DocumentRepo document 数据访问接口

type GormStore

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

GormStore is the Store implementation assembled from per-module repo bundles over one shared connection pool.

func NewGormStoreWithBuilders added in v1.15.2

func NewGormStoreWithBuilders(db *gorm.DB, rds *redis.Client, builders Builders) *GormStore

NewGormStoreWithBuilders assembles the store from the given per-module repo builders.

func (*GormStore) Ads

func (s *GormStore) Ads() AdsRepo

func (*GormStore) Announcement

func (s *GormStore) Announcement() AnnouncementRepo

func (*GormStore) Auth

func (s *GormStore) Auth() AuthRepo

func (*GormStore) Client

func (s *GormStore) Client() ClientRepo

func (*GormStore) Coupon

func (s *GormStore) Coupon() CouponRepo

func (*GormStore) Document

func (s *GormStore) Document() DocumentRepo

func (*GormStore) InBillingTx added in v1.15.0

func (s *GormStore) InBillingTx(ctx context.Context, fn func(BillingStore) error) error

InBillingTx runs fn inside a transaction scoped to the billing domain.

func (*GormStore) InIdentityTx added in v1.15.0

func (s *GormStore) InIdentityTx(ctx context.Context, fn func(IdentityStore) error) error

InIdentityTx runs fn inside a transaction scoped to the identity domain.

func (*GormStore) InNetworkTx added in v1.15.0

func (s *GormStore) InNetworkTx(ctx context.Context, fn func(NetworkStore) error) error

InNetworkTx runs fn inside a transaction scoped to the network domain.

func (*GormStore) InPlatformTx added in v1.15.0

func (s *GormStore) InPlatformTx(ctx context.Context, fn func(PlatformStore) error) error

InPlatformTx runs fn inside a transaction scoped to the platform domain.

func (*GormStore) InSubscriptionTx added in v1.15.0

func (s *GormStore) InSubscriptionTx(ctx context.Context, fn func(SubscriptionStore) error) error

InSubscriptionTx runs fn inside a transaction scoped to the subscription domain.

func (*GormStore) InTx

func (s *GormStore) InTx(ctx context.Context, fn func(store Store) error) error

InTx runs fn within a database transaction. A new GormStore backed by the transaction is passed to fn, so all repository operations inside fn share the same transaction.

func (*GormStore) Inbox added in v1.15.0

func (s *GormStore) Inbox() InboxRepo

func (*GormStore) Log

func (s *GormStore) Log() LogRepo

func (*GormStore) Node

func (s *GormStore) Node() NodeRepo

func (*GormStore) Order

func (s *GormStore) Order() OrderRepo

func (*GormStore) OrderEvent added in v1.14.19

func (s *GormStore) OrderEvent() OrderEventRepo

func (*GormStore) Outbox added in v1.15.2

func (s *GormStore) Outbox() OutboxRepo

func (*GormStore) Payment

func (s *GormStore) Payment() PaymentRepo

func (*GormStore) Subscribe

func (s *GormStore) Subscribe() SubscribeRepo

func (*GormStore) SubscriptionTraffic added in v1.14.18

func (s *GormStore) SubscriptionTraffic() SubscriptionTrafficRepo

func (*GormStore) System

func (s *GormStore) System() SystemRepo

func (*GormStore) Task

func (s *GormStore) Task() TaskRepo

func (*GormStore) Ticket

func (s *GormStore) Ticket() TicketRepo

func (*GormStore) TrafficLog

func (s *GormStore) TrafficLog() TrafficRepo

func (*GormStore) User

func (s *GormStore) User() UserRepo

func (*GormStore) UserAuth added in v1.14.18

func (s *GormStore) UserAuth() UserAuthRepo

func (*GormStore) UserCache added in v1.14.18

func (s *GormStore) UserCache() UserCacheRepo

func (*GormStore) UserDevice added in v1.14.18

func (s *GormStore) UserDevice() UserDeviceRepo

func (*GormStore) UserSubscription added in v1.14.18

func (s *GormStore) UserSubscription() UserSubscriptionRepo

func (*GormStore) UserWithdrawal added in v1.14.18

func (s *GormStore) UserWithdrawal() UserWithdrawalRepo

func (*GormStore) Wallet added in v1.15.0

func (s *GormStore) Wallet() WalletRepo

Wallet exposes the billing view of the user table's money columns.

type IdentityBridges added in v1.15.3

type IdentityBridges struct {
	SubscriptionCache SubscriptionCacheBridge
	SubscriptionScope SubscriptionScopeBridge
	OrderStats        OrderStatsBridge
}

IdentityBridges collects the identity bundle's cross-domain windows.

type IdentityBuilder added in v1.15.2

type IdentityBuilder func(conn ModuleConn, bridges IdentityBridges) IdentityRepos

type IdentityRepos added in v1.15.2

type IdentityRepos struct {
	Users     UserRepo
	UserAuths UserAuthRepo
	Devices   UserDeviceRepo
	UserCache UserCacheRepo
	Auths     AuthRepo
}

IdentityRepos is the identity domain bundle. UserCache is the cross-domain cache facade (its subscription keys come through the injected reader).

type IdentityStore added in v1.15.0

type IdentityStore interface {
	User() UserRepo
	UserAuth() UserAuthRepo
	UserDevice() UserDeviceRepo
	Auth() AuthRepo
	Inbox() InboxRepo
	Outbox() OutboxRepo
	Log() LogRepo
}

IdentityStore is the identity domain's transactional surface: accounts, auth methods and devices.

type InboxRepo added in v1.15.0

type InboxRepo interface {
	// Find returns the processed marker, or (nil, nil) when the step has not
	// run yet.
	Find(ctx context.Context, consumer, eventKey string) (*inbox.Record, error)
	// Insert records the step as processed. It must run inside the same
	// transaction as the step's mutations; a duplicate-key error means a
	// concurrent delivery won the race and this transaction must roll back.
	Insert(ctx context.Context, consumer, eventKey, result string) error
	// DeleteProcessedBefore removes markers older than the replay contract;
	// every flow that consults the inbox resolves well inside the retention
	// window (deferred closes in minutes, bucket replays in hours).
	DeleteProcessedBefore(ctx context.Context, cutoff time.Time) (int64, error)
}

type LogRepo added in v1.3.9

type LogRepo interface {
	Insert(ctx context.Context, data *log.SystemLog) error
	FindOne(ctx context.Context, id int64) (*log.SystemLog, error)
	Update(ctx context.Context, data *log.SystemLog) error
	Delete(ctx context.Context, id int64) error
	FilterSystemLog(ctx context.Context, filter *log.FilterParams) ([]*log.SystemLog, int64, error)
	FindFirstByDateType(ctx context.Context, date string, typ uint8) (*log.SystemLog, error)
	FindByDatesType(ctx context.Context, dates []string, typ uint8) ([]*log.SystemLog, error)
	DeleteBefore(ctx context.Context, end time.Time) error
	SumAmountByTypeAndObjectID(ctx context.Context, typ uint8, objectID int64) (int64, error)
}

LogRepo log 数据访问接口

type ModuleConn added in v1.15.2

type ModuleConn struct {
	DB    *gorm.DB
	Redis *redis.Client
	// Invalidations batches cache invalidation keys during a transaction;
	// nil outside transactions.
	Invalidations *cache.InvalidationQueue
}

ModuleConn is the per-connection context handed to a repo builder.

func (ModuleConn) Conn added in v1.15.2

func (c ModuleConn) Conn() cache.CachedConn

Conn builds the cached connection every repository implementation wraps.

type NetworkBuilder added in v1.15.2

type NetworkBuilder func(conn ModuleConn) NetworkRepos

type NetworkRepos added in v1.15.2

type NetworkRepos struct {
	Nodes   NodeRepo
	Traffic TrafficRepo
	// NodeKeys feeds the subscription bundle's plan cache invalidation.
	NodeKeys NodeCacheKeyBridge
}

NetworkRepos is the network domain bundle.

type NetworkStore added in v1.15.0

type NetworkStore interface {
	Node() NodeRepo
	TrafficLog() TrafficRepo
	Inbox() InboxRepo
	Outbox() OutboxRepo
	Log() LogRepo
}

NetworkStore is the network domain's transactional surface: nodes and traffic statistics.

type NodeCacheKeyBridge added in v1.15.3

type NodeCacheKeyBridge interface {
	NodeUserListCacheKeys(ctx context.Context, nodeIDs []int64, tags []string) ([]string, error)
}

NodeCacheKeyBridge is the subscription bundle's window onto network's node-derived cache keys: plan cache invalidation includes the server user-list keys of the plan's nodes and node tags. The network bundle provides it.

type NodeRepo added in v1.3.9

type NodeRepo interface {
	// server
	InsertServer(ctx context.Context, data *node.Server, tx ...*gorm.DB) error
	FindOneServer(ctx context.Context, id int64) (*node.Server, error)
	UpdateServer(ctx context.Context, data *node.Server, tx ...*gorm.DB) error
	BatchUpdateServerLastReportedAt(ctx context.Context, reports map[int64]time.Time, tx ...*gorm.DB) error
	DeleteServer(ctx context.Context, id int64, tx ...*gorm.DB) error
	FindServerConfigOverride(ctx context.Context, serverId int64) (*node.ServerConfigOverride, error)
	SaveServerConfigOverride(ctx context.Context, data *node.ServerConfigOverride, tx ...*gorm.DB) error
	DeleteServerConfigOverride(ctx context.Context, serverId int64, tx ...*gorm.DB) error
	QueryServerList(ctx context.Context, ids []int64) (servers []*node.Server, err error)
	// node
	InsertNode(ctx context.Context, data *node.Node, tx ...*gorm.DB) error
	FindOneNode(ctx context.Context, id int64) (*node.Node, error)
	UpdateNode(ctx context.Context, data *node.Node, tx ...*gorm.DB) error
	DeleteNode(ctx context.Context, id int64, tx ...*gorm.DB) error
	// cache
	StatusCache(ctx context.Context, serverId int64) (node.Status, error)
	UpdateStatusCache(ctx context.Context, serverId int64, status *node.Status) error
	OnlineUserSubscribe(ctx context.Context, serverId int64, protocol string) (node.OnlineUserSubscribe, error)
	UpdateOnlineUserSubscribe(ctx context.Context, serverId int64, protocol string, subscribe node.OnlineUserSubscribe) error
	OnlineUserSubscribeGlobal(ctx context.Context) (int64, error)
	UpdateOnlineUserSubscribeGlobal(ctx context.Context, subscribe node.OnlineUserSubscribe) error
	// query
	FilterServerList(ctx context.Context, params *node.FilterParams) (int64, []*node.Server, error)
	FilterNodeList(ctx context.Context, params *node.FilterNodeParams) (int64, []*node.Node, error)
	QueryNodeSorts(ctx context.Context) ([]node.SortItem, error)
	QueryServerSorts(ctx context.Context) ([]node.SortItem, error)
	UpdateNodeSort(ctx context.Context, id int64, sort int64) error
	UpdateServerSort(ctx context.Context, id int64, sort int64) error
	QueryNodeTags(ctx context.Context) ([]string, error)
	CountEnabledNodes(ctx context.Context) (int64, error)
	CountServersByReportStatus(ctx context.Context, cutoff time.Time) (int64, int64, error)
	QueryServerAddresses(ctx context.Context) ([]string, error)
	QueryEnabledNodeProtocols(ctx context.Context) ([]string, error)
	ClearNodeCache(ctx context.Context, params *node.FilterNodeParams) error
	ClearServerCache(ctx context.Context, serverId int64) error
	ServerCacheGeneration(ctx context.Context, serverId int64) (int64, error)
	SetServerCache(ctx context.Context, serverId int64, key string, value interface{}, generation int64) error
}

NodeRepo node/server 数据访问接口

type OrderEventRepo added in v1.14.19

type OrderEventRepo interface {
	FindOne(ctx context.Context, id int64) (*order.Event, error)
	ListAfter(ctx context.Context, orderNo string, afterID int64, limit int) ([]*order.Event, error)
	EarliestID(ctx context.Context, orderNo string) (int64, error)
	ListUnpublished(ctx context.Context, limit int) ([]*order.Event, error)
	MarkPublished(ctx context.Context, id int64, publishedAt time.Time) (bool, error)
	DeletePublishedBefore(ctx context.Context, cutoff time.Time) (int64, error)
}

OrderEventRepo is deliberately separate from OrderRepo: order mutations write outbox rows atomically, while delivery workers and SSE handlers only need to read and mark these durable records.

type OrderRepo added in v1.3.9

type OrderRepo interface {
	Insert(ctx context.Context, data *order.Order, tx ...*gorm.DB) error
	FindOne(ctx context.Context, id int64) (*order.Order, error)
	FindOneByOrderNo(ctx context.Context, orderNo string) (*order.Order, error)
	FindOneByIdempotencyKey(ctx context.Context, key string) (*order.Order, error)
	FindOneByOrderNoForUpdate(ctx context.Context, orderNo string) (*order.Order, error)
	Update(ctx context.Context, data *order.Order, tx ...*gorm.DB) error
	Delete(ctx context.Context, id int64, tx ...*gorm.DB) error
	UpdateOrderStatusFrom(ctx context.Context, orderNo string, from, status uint8, tx ...*gorm.DB) (bool, error)
	UpdatePaymentExpectation(ctx context.Context, orderNo string, amount int64, currency string, tx ...*gorm.DB) (bool, error)
	SetPaymentTradeNoIfEmpty(ctx context.Context, orderNo, tradeNo string, tx ...*gorm.DB) (bool, error)
	MarkOrderPaid(ctx context.Context, orderNo, tradeNo string, tx ...*gorm.DB) (bool, error)
	CountPendingByPaymentID(ctx context.Context, paymentID int64) (int64, error)
	QueryOrdersByStatusAfterID(ctx context.Context, status uint8, afterID int64, limit int) ([]*order.Order, error)
	CountUserCouponUsage(ctx context.Context, userID int64, coupon string) (int64, error)
	QueryOrderListByPage(ctx context.Context, page, size int, status uint8, user, subscribe int64, search string) (int64, []*order.Details, error)
	FindOneDetails(ctx context.Context, id int64) (*order.Details, error)
	FindOneDetailsByOrderNo(ctx context.Context, orderNo string) (*order.Details, error)
	QueryMonthlyOrders(ctx context.Context, date time.Time) (order.OrdersTotal, error)
	QueryDateOrders(ctx context.Context, date time.Time) (order.OrdersTotal, error)
	QueryTotalOrders(ctx context.Context) (order.OrdersTotal, error)
	QueryMonthlyUserCounts(ctx context.Context, date time.Time) (int64, int64, error)
	QueryDateUserCounts(ctx context.Context, date time.Time) (int64, int64, error)
	QueryTotalUserCounts(ctx context.Context) (int64, int64, error)
	IsUserEligibleForNewOrder(ctx context.Context, userID int64) (bool, error)
	QueryDailyOrdersList(ctx context.Context, date time.Time) ([]order.OrdersTotalWithDate, error)
	QueryMonthlyOrdersList(ctx context.Context, date time.Time) ([]order.OrdersTotalWithDate, error)
}

OrderRepo order 数据访问接口

type OrderStatsBridge added in v1.15.3

type OrderStatsBridge interface {
	// OrderUserCountsByBucket counts distinct ordering users per date bucket
	// ("day" or "month"); isNew selects first-purchase orders.
	OrderUserCountsByBucket(ctx context.Context, isNew bool, since time.Time, until *time.Time, bucket string) (map[string]int64, error)
}

OrderStatsBridge is the identity bundle's window onto billing's order statistics: user-statistics dashboards merge these per-bucket counts with registration counts in Go. The billing bundle provides it.

type OutboxRepo added in v1.15.2

type OutboxRepo interface {
	Append(ctx context.Context, topic, eventKey, payload string) error
	ListUnpublished(ctx context.Context, limit int) ([]*outbox.Event, error)
	MarkPublished(ctx context.Context, id int64) error
	DeletePublishedBefore(ctx context.Context, cutoff time.Time) (int64, error)
}

InboxRepo is the idempotent-consumer inbox (ADR-001 step 2): a domain step records that it processed an event inside its own transaction, so at-least-once deliveries and reconciliation replays never apply the same mutation twice. OutboxRepo is the generic domain-event outbox: Append runs inside the owning domain's transaction; the dispatcher drains unpublished events and marks them published once every subscriber has processed them.

type PaymentRepo added in v1.3.9

type PaymentRepo interface {
	Insert(ctx context.Context, data *payment.Payment, tx ...*gorm.DB) error
	FindOne(ctx context.Context, id int64) (*payment.Payment, error)
	Update(ctx context.Context, data *payment.Payment, tx ...*gorm.DB) error
	Delete(ctx context.Context, id int64, tx ...*gorm.DB) error
	FindOneByPaymentToken(ctx context.Context, token string) (*payment.Payment, error)
	FindAll(ctx context.Context) ([]*payment.Payment, error)
	FindListByPage(ctx context.Context, page, size int, req *payment.Filter) (int64, []*payment.Payment, error)
	FindAvailableMethods(ctx context.Context) ([]*payment.Payment, error)
}

PaymentRepo payment 数据访问接口

type PlatformBuilder added in v1.15.2

type PlatformBuilder func(conn ModuleConn) PlatformRepos

type PlatformRepos added in v1.15.2

type PlatformRepos struct {
	System SystemRepo
	Logs   LogRepo
	Tasks  TaskRepo
	Client ClientRepo
	Inbox  InboxRepo
	Outbox OutboxRepo
}

PlatformRepos is the shared-kernel bundle.

type PlatformStore added in v1.15.0

type PlatformStore interface {
	System() SystemRepo
	Task() TaskRepo
	Log() LogRepo
	Inbox() InboxRepo
	Outbox() OutboxRepo
}

PlatformStore is the platform domain's transactional surface: system settings, scheduled-task bookkeeping and audit/message logs.

type Store

type Store interface {
	Ads() AdsRepo
	Announcement() AnnouncementRepo
	Auth() AuthRepo
	Client() ClientRepo
	Coupon() CouponRepo
	Document() DocumentRepo
	Inbox() InboxRepo
	// Outbox appends domain events that commit with the domain transaction.
	Outbox() OutboxRepo
	Log() LogRepo
	Node() NodeRepo
	Order() OrderRepo
	OrderEvent() OrderEventRepo
	Payment() PaymentRepo
	Subscribe() SubscribeRepo
	System() SystemRepo
	Task() TaskRepo
	Ticket() TicketRepo
	TrafficLog() TrafficRepo
	User() UserRepo
	UserAuth() UserAuthRepo
	UserSubscription() UserSubscriptionRepo
	UserDevice() UserDeviceRepo
	UserWithdrawal() UserWithdrawalRepo
	SubscriptionTraffic() SubscriptionTrafficRepo
	UserCache() UserCacheRepo
	// Wallet exposes the billing view of the user table's money columns
	// (ADR-001 step 5 data debt).
	Wallet() WalletRepo

	InTx(ctx context.Context, fn func(store Store) error) error

	// Domain-scoped transactions (ADR-001 step 2): the closure receives only
	// its domain's store view, so cross-domain writes fail to compile.
	InBillingTx(ctx context.Context, fn func(BillingStore) error) error
	InSubscriptionTx(ctx context.Context, fn func(SubscriptionStore) error) error
	InIdentityTx(ctx context.Context, fn func(IdentityStore) error) error
	InNetworkTx(ctx context.Context, fn func(NetworkStore) error) error
	InPlatformTx(ctx context.Context, fn func(PlatformStore) error) error
}

Store is the central data access facade, providing access to all domain repositories and transaction support.

type SubscribeRepo added in v1.3.9

type SubscribeRepo interface {
	Insert(ctx context.Context, data *subscribe.Subscribe, tx ...*gorm.DB) error
	FindOne(ctx context.Context, id int64) (*subscribe.Subscribe, error)
	Update(ctx context.Context, data *subscribe.Subscribe, tx ...*gorm.DB) error
	ReserveInventory(ctx context.Context, id int64, tx ...*gorm.DB) (bool, error)
	RestoreInventory(ctx context.Context, id int64, tx ...*gorm.DB) error
	Delete(ctx context.Context, id int64, tx ...*gorm.DB) error
	FilterList(ctx context.Context, params *subscribe.FilterParams) (int64, []*subscribe.Subscribe, error)
	ClearCache(ctx context.Context, id ...int64) error
	QuerySubscribeMinSortByIds(ctx context.Context, ids []int64) (int64, error)
	QueryResetCycleSubscribeIds(ctx context.Context, resetCycle int) ([]int64, error)
	UpdateSort(ctx context.Context, data []*subscribe.Subscribe) error
	QueryGroupList(ctx context.Context) (int64, []*subscribe.Group, error)
	CreateGroup(ctx context.Context, data *subscribe.Group) error
	UpdateGroup(ctx context.Context, data *subscribe.Group) error
	DeleteGroup(ctx context.Context, id int64) error
	BatchDeleteGroup(ctx context.Context, ids []int64) error
}

SubscribeRepo subscribe 数据访问接口

type SubscriptionBuilder added in v1.15.2

type SubscriptionBuilder func(conn ModuleConn, nodes NodeCacheKeyBridge) SubscriptionRepos

type SubscriptionCacheBridge added in v1.15.2

type SubscriptionCacheBridge interface {
	QueryUserSubscribe(ctx context.Context, userId int64, status ...int64) ([]*usersub.SubscribeDetails, error)
	ClearSubscribeCache(ctx context.Context, data ...*usersub.Subscribe) error
	UpdateUserSubscribeCache(ctx context.Context, data *usersub.Subscribe) error
}

SubscriptionCacheBridge is the identity bundle's window onto the subscription domain's cache concerns: the user-deletion cascade collects the user's subscription rows, and the UserCache facade delegates the subscription cache operations. The subscription bundle provides it.

type SubscriptionRepos added in v1.15.2

type SubscriptionRepos struct {
	Plans    SubscribeRepo
	UserSubs UserSubscriptionRepo
	Traffic  SubscriptionTrafficRepo
	// CacheBridge feeds the identity bundle's cross-domain cache cascade.
	CacheBridge SubscriptionCacheBridge
	// ScopeBridge feeds the identity bundle's subscription-membership
	// filters.
	ScopeBridge SubscriptionScopeBridge
}

SubscriptionRepos is the subscription domain bundle.

type SubscriptionScopeBridge added in v1.15.3

type SubscriptionScopeBridge interface {
	SubscriptionUserIDs(ctx context.Context, filter SubscriptionUserFilter) ([]int64, error)
}

SubscriptionScopeBridge is the identity bundle's window onto subscription membership: the admin user filter and the email-recipient scopes resolve "which users hold matching subscriptions" to an ID list here instead of querying the subscription table from identity SQL. The subscription bundle provides it.

type SubscriptionStore added in v1.15.0

type SubscriptionStore interface {
	Subscribe() SubscribeRepo
	UserSubscription() UserSubscriptionRepo
	SubscriptionTraffic() SubscriptionTrafficRepo
	Inbox() InboxRepo
	Outbox() OutboxRepo
	Log() LogRepo
}

SubscriptionStore is the subscription domain's transactional surface: plans, user subscriptions and their traffic quota state.

type SubscriptionTrafficRepo added in v1.14.18

type SubscriptionTrafficRepo interface {
	QueryMonthlyResetSubscribeIds(ctx context.Context, subscribeIds []int64, now time.Time) ([]int64, error)
	QueryFirstResetSubscribeIds(ctx context.Context, subscribeIds []int64, now time.Time) ([]int64, error)
	QueryYearlyResetSubscribeIds(ctx context.Context, subscribeIds []int64, now time.Time) ([]int64, error)
	ResetSubscribeTrafficByIds(ctx context.Context, ids []int64, tx ...*gorm.DB) error
}

SubscriptionTrafficRepo manages scheduled subscription traffic resets.

type SubscriptionUserFilter added in v1.15.3

type SubscriptionUserFilter struct {
	UserSubscribeID *int64
	SubscribeID     *int64
	// Token matches the subscription token or UUID.
	Token    string
	Statuses []int64
}

SubscriptionUserFilter narrows SubscriptionUserIDs. Zero-value fields do not constrain; a nil Statuses matches any subscription row.

type SupportBuilder added in v1.15.2

type SupportBuilder func(conn ModuleConn) SupportRepos

type SupportRepos added in v1.15.2

type SupportRepos struct {
	Tickets       TicketRepo
	Announcements AnnouncementRepo
	Ads           AdsRepo
	Documents     DocumentRepo
}

SupportRepos is the support domain bundle.

type SystemRepo added in v1.3.9

type SystemRepo interface {
	Insert(ctx context.Context, data *system.System) error
	FindOne(ctx context.Context, id int64) (*system.System, error)
	FindOneByKey(ctx context.Context, email string) (*system.System, error)
	Update(ctx context.Context, data *system.System) error
	Delete(ctx context.Context, id int64) error
	GetSmsConfig(ctx context.Context) ([]*system.System, error)
	GetSiteConfig(ctx context.Context) ([]*system.System, error)
	GetEmailConfig(ctx context.Context) ([]*system.System, error)
	GetSubscribeConfig(ctx context.Context) ([]*system.System, error)
	GetRegisterConfig(ctx context.Context) ([]*system.System, error)
	GetVerifyConfig(ctx context.Context) ([]*system.System, error)
	GetNodeConfig(ctx context.Context) ([]*system.System, error)
	GetInviteConfig(ctx context.Context) ([]*system.System, error)
	GetTelegramConfig(ctx context.Context) ([]*system.System, error)
	GetTosConfig(ctx context.Context) ([]*system.System, error)
	GetCurrencyConfig(ctx context.Context) ([]*system.System, error)
	GetVerifyCodeConfig(ctx context.Context) ([]*system.System, error)
	GetLogConfig(ctx context.Context) ([]*system.System, error)
	UpdateValueByCategoryKey(ctx context.Context, category, key, value string, valueType ...string) error
	UpdateNodeMultiplierConfig(ctx context.Context, config string) error
	FindNodeMultiplierConfig(ctx context.Context) (*system.System, error)
}

SystemRepo system 数据访问接口

type TaskRepo added in v1.3.9

type TaskRepo interface {
	Insert(ctx context.Context, data *task.Task) error
	FindOne(ctx context.Context, id int64) (*task.Task, error)
	FindOneByType(ctx context.Context, id int64, typ task.Type) (*task.Task, error)
	QueryTaskList(ctx context.Context, filter *task.Filter) (int64, []*task.Task, error)
	Update(ctx context.Context, data *task.Task) error
	UpdateStatus(ctx context.Context, id int64, status int8) error
}

TaskRepo task 数据访问接口

type TicketRepo added in v1.3.9

type TicketRepo interface {
	Insert(ctx context.Context, data *ticket.Ticket) error
	FindOne(ctx context.Context, id int64) (*ticket.Ticket, error)
	Update(ctx context.Context, data *ticket.Ticket) error
	Delete(ctx context.Context, id int64) error
	QueryTicketDetail(ctx context.Context, id int64) (*ticket.Details, error)
	InsertTicketFollow(ctx context.Context, data *ticket.Follow) error
	QueryTicketList(ctx context.Context, page, size int, userId int64, status *uint8, search string) (int64, []*ticket.Ticket, error)
	UpdateTicketStatus(ctx context.Context, id, userId int64, status uint8) error
	QueryWaitReplyTotal(ctx context.Context) (int64, error)
}

TicketRepo ticket 数据访问接口

type TrafficRepo added in v1.3.9

type TrafficRepo interface {
	Insert(ctx context.Context, data *traffic.TrafficLog) error
	InsertBatch(ctx context.Context, data []*traffic.TrafficLog, batchSize int, tx ...*gorm.DB) error
	FindOne(ctx context.Context, id int64) (*traffic.TrafficLog, error)
	Update(ctx context.Context, data *traffic.TrafficLog) error
	Delete(ctx context.Context, id int64) error
	QueryServerTrafficByDay(ctx context.Context, serverId int64, date time.Time) (*traffic.TotalTraffic, error)
	QueryTrafficByDay(ctx context.Context, date time.Time) (*traffic.TotalTraffic, error)
	QueryTrafficByMonthly(ctx context.Context, date time.Time) (*traffic.TotalTraffic, error)
	QueryTrafficSummary(ctx context.Context, start, end time.Time) (*traffic.TotalTraffic, error)
	TopServersTrafficByDay(ctx context.Context, date time.Time, limit int) ([]traffic.ServerTrafficRanking, error)
	TopServersTrafficByMonthly(ctx context.Context, date time.Time, limit int) ([]traffic.ServerTrafficRanking, error)
	TopUsersTrafficByDay(ctx context.Context, date time.Time, limit int) ([]traffic.UserTrafficRanking, error)
	TopUsersTrafficByMonthly(ctx context.Context, date time.Time, limit int) ([]traffic.UserTrafficRanking, error)
	QueryServerTrafficRanking(ctx context.Context, start, end time.Time) ([]traffic.ServerTrafficRanking, error)
	QueryUserTrafficRanking(ctx context.Context, start, end time.Time) ([]traffic.UserTrafficRanking, error)
	QueryTrafficLogPageList(ctx context.Context, userId, subscribeId int64, page, size int) ([]*traffic.TrafficLog, int64, error)
	QueryTrafficLogDetails(ctx context.Context, filter *traffic.TrafficLogDetailsFilter) ([]*traffic.TrafficLog, int64, error)
	DeleteBefore(ctx context.Context, end time.Time) error
}

TrafficRepo traffic 数据访问接口

type UserAuthRepo added in v1.14.18

type UserAuthRepo interface {
	FindUserAuthMethods(ctx context.Context, userId int64) ([]*user.AuthMethods, error)
	FindUserAuthMethodByOpenID(ctx context.Context, method, openID string) (*user.AuthMethods, error)
	ValidateEmailIdentityUniqueness(ctx context.Context) error
	FindUserAuthMethodByPlatform(ctx context.Context, userId int64, platform string) (*user.AuthMethods, error)
	FindUserAuthMethodByUserId(ctx context.Context, method string, userId int64) (*user.AuthMethods, error)
	InsertUserAuthMethods(ctx context.Context, data *user.AuthMethods, tx ...*gorm.DB) error
	UpdateUserAuthMethods(ctx context.Context, data *user.AuthMethods, tx ...*gorm.DB) error
	DeleteUserAuthMethods(ctx context.Context, userId int64, platform string, tx ...*gorm.DB) error
	UpdateUserAuthMethodOwner(ctx context.Context, authType, identifier string, userId int64, tx ...*gorm.DB) error
	DeleteUserAuthMethodByIdentifier(ctx context.Context, authType, identifier string, tx ...*gorm.DB) error
	UpsertUserAuthMethod(ctx context.Context, data *user.AuthMethods) error
}

UserAuthRepo manages external authentication identities linked to users.

type UserCacheRepo added in v1.14.18

type UserCacheRepo interface {
	ClearUserCache(ctx context.Context, data ...*user.User) error
	ClearSubscribeCache(ctx context.Context, data ...*usersub.Subscribe) error
	ClearDeviceCache(ctx context.Context, data ...*user.Device) error
	ClearAuthMethodCache(ctx context.Context, data ...*user.AuthMethods) error
	BatchClearRelatedCache(ctx context.Context, data *user.User) error
	UpdateUserCache(ctx context.Context, data *user.User) error
	UpdateUserSubscribeCache(ctx context.Context, data *usersub.Subscribe) error
}

UserCacheRepo manages cached user-related projections.

type UserDeviceRepo added in v1.14.18

type UserDeviceRepo interface {
	InsertDevice(ctx context.Context, data *user.Device, tx ...*gorm.DB) error
	FindOneDevice(ctx context.Context, id int64) (*user.Device, error)
	FindOneDeviceByIdentifier(ctx context.Context, id string) (*user.Device, error)
	UpdateDevice(ctx context.Context, data *user.Device, tx ...*gorm.DB) error
	DeleteDevice(ctx context.Context, id int64, tx ...*gorm.DB) error
	QueryDeviceList(ctx context.Context, userid int64) ([]*user.Device, int64, error)
	QueryDevicePageList(ctx context.Context, userid, subscribeId int64, page, size int) ([]*user.Device, int64, error)
	FindDeviceOnlineRecord(ctx context.Context, userId int64, startTime, endTime string) (*user.DeviceOnlineRecord, error)
	InsertDeviceOnlineRecord(ctx context.Context, data *user.DeviceOnlineRecord, tx ...*gorm.DB) error
}

UserDeviceRepo manages registered devices and their online records.

type UserRepo added in v1.3.9

type UserRepo interface {
	Insert(ctx context.Context, data *user.User, tx ...*gorm.DB) error
	FindOne(ctx context.Context, id int64) (*user.User, error)
	FindOneForUpdate(ctx context.Context, id int64) (*user.User, error)
	FindOneByEmail(ctx context.Context, email string) (*user.User, error)
	FindOneByReferCode(ctx context.Context, referCode string) (*user.User, error)
	Update(ctx context.Context, data *user.User, tx ...*gorm.DB) error
	UpgradePasswordHash(ctx context.Context, id int64, currentHash, password, algo, salt string) (bool, error)
	Delete(ctx context.Context, id int64, tx ...*gorm.DB) error
	BatchDeleteUser(ctx context.Context, ids []int64, tx ...*gorm.DB) error
	QueryPageList(ctx context.Context, page, size int, filter *user.UserFilterParams) ([]*user.User, int64, error)
	FindUsersByIds(ctx context.Context, ids []int64) ([]*user.User, error)
	CountAffiliates(ctx context.Context, refererId int64) (int64, error)
	QueryAffiliateList(ctx context.Context, refererId int64, page, size int) ([]*user.User, int64, error)
	QueryAdminUsers(ctx context.Context) ([]*user.User, error)
	CountEnabledUsers(ctx context.Context) (int64, error)
	QueryResisterUserTotal(ctx context.Context) (int64, error)
	QueryResisterUserTotalByDate(ctx context.Context, date time.Time) (int64, error)
	QueryResisterUserTotalByMonthly(ctx context.Context, date time.Time) (int64, error)
	QueryEmailRecipients(ctx context.Context, filter *user.EmailRecipientFilter) ([]string, error)
	CountEmailRecipients(ctx context.Context, filter *user.EmailRecipientFilter) (int64, error)
	QueryDailyUserStatisticsList(ctx context.Context, date time.Time) ([]user.UserStatisticsWithDate, error)
	QueryMonthlyUserStatisticsList(ctx context.Context, date time.Time) ([]user.UserStatisticsWithDate, error)
}

UserRepo provides user profile, account, reporting, and marketing queries. Related authentication, subscription, device, cache, withdrawal, and traffic operations live behind their own focused repository interfaces below.

type UserSubscriptionRepo added in v1.14.18

type UserSubscriptionRepo interface {
	// LockUserSerial serializes subscription-creating flows per user inside
	// the current transaction (seed-and-lock on the subscription domain's
	// serial table). It replaces the fulfillment stage's cross-domain
	// user-row lock.
	LockUserSerial(ctx context.Context, userID int64) error
	InsertSubscribe(ctx context.Context, data *usersub.Subscribe, tx ...*gorm.DB) error
	FindOneSubscribe(ctx context.Context, id int64) (*usersub.Subscribe, error)
	FindOneSubscribeForUpdate(ctx context.Context, id int64) (*usersub.Subscribe, error)
	FindOneSubscribeByOrderId(ctx context.Context, orderId int64) (*usersub.Subscribe, error)
	FindOneSubscribeByToken(ctx context.Context, token string) (*usersub.Subscribe, error)
	FindOneSubscribeByTokenForUpdate(ctx context.Context, token string) (*usersub.Subscribe, error)
	UpdateSubscribe(ctx context.Context, data *usersub.Subscribe, tx ...*gorm.DB) error
	DeleteSubscribe(ctx context.Context, token string, tx ...*gorm.DB) error
	DeleteSubscribeById(ctx context.Context, id int64, tx ...*gorm.DB) error
	UpdateUserSubscribeWithTraffic(ctx context.Context, id, download, upload int64, tx ...*gorm.DB) error
	BatchUpdateUserSubscribeWithTraffic(ctx context.Context, deltas []trafficEntity.SubscribeTrafficDelta, tx ...*gorm.DB) error
	FindUsersSubscribeBySubscribeId(ctx context.Context, subscribeId int64) ([]*usersub.Subscribe, error)
	FindUserSubscribesByStatus(ctx context.Context, status ...int64) ([]*usersub.Subscribe, error)
	FindSubscribesByIds(ctx context.Context, ids []int64) ([]*usersub.Subscribe, error)
	ActivatePendingSubscribesBySubscribeId(ctx context.Context, subscribeId int64) error
	CountQuotaConsumingSubscriptions(ctx context.Context, userId, subscribeId int64) (int64, error)
	HasBlockingSubscription(ctx context.Context, userId int64) (bool, error)
	CountUserSubscribesBySubscribeIdAndStatus(ctx context.Context, subscribeId int64, status ...int64) (int64, error)
	QueryActiveSubscriptions(ctx context.Context, subscribeId ...int64) (map[int64]int64, error)
	QueryUserSubscribe(ctx context.Context, userId int64, status ...int64) ([]*usersub.SubscribeDetails, error)
	FindOneSubscribeDetailsById(ctx context.Context, id int64) (*usersub.SubscribeDetails, error)
	FindOneUserSubscribe(ctx context.Context, id int64) (*usersub.SubscribeDetails, error)
	FindTrafficExceededSubscribes(ctx context.Context) ([]*usersub.Subscribe, error)
	FindExpiredSubscribes(ctx context.Context, now time.Time) ([]*usersub.Subscribe, error)
	MarkSubscribesFinished(ctx context.Context, ids []int64, status uint8, finishedAt time.Time, tx ...*gorm.DB) error
	QuerySubscribeIdsByFilter(ctx context.Context, filter *usersub.SubscribeFilter) ([]int64, error)
	CountSubscribesByFilter(ctx context.Context, filter *usersub.SubscribeFilter) (int64, error)
}

UserSubscriptionRepo manages user subscription records and their lifecycle.

type UserWithdrawalRepo added in v1.14.18

type UserWithdrawalRepo interface {
	InsertWithdrawal(ctx context.Context, data *walletEntity.Withdrawal, tx ...*gorm.DB) error
}

UserWithdrawalRepo manages affiliate withdrawal records.

type WalletRepo added in v1.15.0

type WalletRepo interface {
	// FindOneForUpdate locks and returns the wallet row, seeding it from a
	// zero state when the account has none yet.
	FindOneForUpdate(ctx context.Context, userId int64) (*walletEntity.Wallet, error)
	// FindWallet and FindWalletsByUserIds are the plain (non-locking) reads
	// of the wallet table for display composition; a missing row reads as
	// nil (single) or is absent from the map (batch).
	FindWallet(ctx context.Context, userId int64) (*walletEntity.Wallet, error)
	FindWalletsByUserIds(ctx context.Context, userIds []int64) (map[int64]*walletEntity.Wallet, error)
	// UpdateBalanceFields persists the balance and gift columns;
	// UpdateCommission persists the commission column.
	UpdateBalanceFields(ctx context.Context, data *walletEntity.Wallet, tx ...*gorm.DB) error
	UpdateCommission(ctx context.Context, data *walletEntity.Wallet, tx ...*gorm.DB) error
}

WalletRepo is the billing domain's window onto the user table's money columns (Balance, GiftAmount, Commission). The columns living on the user row is recorded data debt: ADR-001 step 5 moves them into a wallet table owned by billing. Until then this view keeps wallet movements inside billing transactions without exposing the rest of the identity repository.

Jump to

Keyboard shortcuts

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