Documentation
¶
Overview ¶
Package repository holds the modules' persistence contracts and the store assembled from them: the repository interfaces, the per-domain store views and scoped transactions, and GormStore, which builds every module's repositories over one shared connection pool with the builders the modules export. The implementations live in the owning modules, and each module uses only the contracts it owns (ADR-001), so moving a module to its own database only means pointing its builder at another connection.
Index ¶
- Constants
- func NormalizePage(page, size int) (int, int)
- func NormalizePageFloor(page, size int) (int, int)
- type AdsRepo
- type AnnouncementRepo
- type AuthRepo
- type BillingBuilder
- type BillingRepos
- type BillingStore
- type BillingTransactor
- type Builders
- type ClientRepo
- type CouponRepo
- type DocumentRepo
- type EntitlementRepo
- type GormStore
- func (s *GormStore) Ads() AdsRepo
- func (s *GormStore) Announcement() AnnouncementRepo
- func (s *GormStore) Auth() AuthRepo
- func (s *GormStore) Client() ClientRepo
- func (s *GormStore) Coupon() CouponRepo
- func (s *GormStore) Document() DocumentRepo
- func (s *GormStore) Entitlement() EntitlementRepo
- func (s *GormStore) InBillingTx(ctx context.Context, fn func(BillingStore) error) error
- func (s *GormStore) InIdentityTx(ctx context.Context, fn func(IdentityStore) error) error
- func (s *GormStore) InNetworkTx(ctx context.Context, fn func(NetworkStore) error) error
- func (s *GormStore) InPlatformTx(ctx context.Context, fn func(PlatformStore) error) error
- func (s *GormStore) InSubscriptionTx(ctx context.Context, fn func(SubscriptionStore) error) error
- func (s *GormStore) InTx(ctx context.Context, fn func(store Store) error) error
- func (s *GormStore) Inbox() InboxRepo
- func (s *GormStore) Log() LogRepo
- func (s *GormStore) Node() NodeRepo
- func (s *GormStore) Order() OrderRepo
- func (s *GormStore) OrderEvent() OrderEventRepo
- func (s *GormStore) Outbox() OutboxRepo
- func (s *GormStore) Payment() PaymentRepo
- func (s *GormStore) Subscribe() SubscribeRepo
- func (s *GormStore) SubscriptionTraffic() SubscriptionTrafficRepo
- func (s *GormStore) System() SystemRepo
- func (s *GormStore) Task() TaskRepo
- func (s *GormStore) TelegramTopic() TelegramTopicRepo
- func (s *GormStore) Ticket() TicketRepo
- func (s *GormStore) TrafficLog() TrafficRepo
- func (s *GormStore) User() UserRepo
- func (s *GormStore) UserAuth() UserAuthRepo
- func (s *GormStore) UserCache() UserCacheRepo
- func (s *GormStore) UserDevice() UserDeviceRepo
- func (s *GormStore) UserSubscription() UserSubscriptionRepo
- func (s *GormStore) UserWithdrawal() UserWithdrawalRepo
- func (s *GormStore) Wallet() WalletRepo
- type IdentityBridges
- type IdentityBuilder
- type IdentityRepos
- type IdentityStore
- type IdentityTransactor
- type InboxRepo
- type LogRepo
- type MobileNormalization
- type ModuleConn
- type NetworkBuilder
- type NetworkRepos
- type NetworkStore
- type NetworkTransactor
- type NodeCacheKeyBridge
- type NodeRepo
- type NotificationBuilder
- type NotificationRepos
- type OrderEventRepo
- type OrderRepo
- type OrderStatsBridge
- type OutboxRepo
- type PaymentRepo
- type PlatformBuilder
- type PlatformRepos
- type PlatformStore
- type PlatformTransactor
- type Store
- type SubscribeRepo
- type SubscriptionBuilder
- type SubscriptionCacheBridge
- type SubscriptionCredentialRotation
- type SubscriptionRepos
- type SubscriptionScopeBridge
- type SubscriptionStore
- type SubscriptionTrafficRepo
- type SubscriptionTransactor
- type SubscriptionUserFilter
- type SupportBuilder
- type SupportRepos
- type SystemRepo
- type TaskRepo
- type TelegramTopicRepo
- type TicketRepo
- type TrafficRepo
- type UserAuthRepo
- type UserCacheRepo
- type UserDeviceRepo
- type UserRepo
- type UserSubscriptionRepo
- type UserWithdrawalRepo
- type WalletRepo
Constants ¶
const ( DefaultPageSize = kernel.DefaultPageSize MaxPageSize = kernel.MaxPageSize )
The pagination helpers belong to the shared kernel; these re-export them.
Variables ¶
This section is empty.
Functions ¶
func NormalizePage ¶ added in v1.15.2
NormalizePage clamps pagination inputs; module repo implementations share it.
func NormalizePageFloor ¶ added in v1.15.2
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 manages the advertisements the clients display.
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 manages the announcements shown to users.
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 manages the auth_method rows: the settings of each sign-in method (email, mobile, device and the OAuth providers) administrators configure.
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 BillingTransactor ¶ added in v1.20.3
type BillingTransactor interface {
InBillingTx(context.Context, func(BillingStore) error) error
}
Transaction capabilities can be injected without granting the complete application store or unrelated domain transactions.
type Builders ¶ added in v1.15.2
type Builders struct {
Platform PlatformBuilder
Billing BillingBuilder
Subscription SubscriptionBuilder
Identity IdentityBuilder
Network NetworkBuilder
Support SupportBuilder
Notification NotificationBuilder
}
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 manages the subscribe_application rows: the client applications subscription delivery renders for (ADR-001 step 5 places the table in the subscription module).
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 atomically claims one coupon use. now is a Unix
// millisecond timestamp, matching the stored start/expire columns.
ReserveUsage(ctx context.Context, code string, now int64) (bool, error)
ReleaseUsage(ctx context.Context, code string) 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 manages the coupons and the count of their uses.
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 manages the help documents users browse.
type EntitlementRepo ¶ added in v1.21.0
type EntitlementRepo interface {
PlanIDs(context.Context, string) ([]int64, error)
InsertRevision(context.Context, *entitlement.Revision) error
FindStateForUpdate(context.Context, string) (*entitlement.State, error)
InsertState(context.Context, *entitlement.State) error
UpdateState(context.Context, *entitlement.State) error
FindPeriod(context.Context, string) (*entitlement.Period, error)
InsertPeriod(context.Context, *entitlement.Period) error
UpdatePeriod(context.Context, *entitlement.Period) error
}
EntitlementRepo is used only inside the subscription transaction.
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
NewGormStoreWithBuilders assembles the store from the given per-module repo builders.
func (*GormStore) Announcement ¶
func (s *GormStore) Announcement() AnnouncementRepo
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) Entitlement ¶ added in v1.21.0
func (s *GormStore) Entitlement() EntitlementRepo
func (*GormStore) InBillingTx ¶ added in v1.15.0
InBillingTx runs fn inside a transaction scoped to the billing domain.
func (*GormStore) InIdentityTx ¶ added in v1.15.0
InIdentityTx runs fn inside a transaction scoped to the identity domain.
func (*GormStore) InNetworkTx ¶ added in v1.15.0
InNetworkTx runs fn inside a transaction scoped to the network domain.
func (*GormStore) InPlatformTx ¶ added in v1.15.0
InPlatformTx runs fn inside a transaction scoped to the platform domain.
func (*GormStore) InSubscriptionTx ¶ added in v1.15.0
InSubscriptionTx runs fn inside a transaction scoped to the subscription domain.
func (*GormStore) InTx ¶
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) 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) TelegramTopic ¶ added in v1.15.18
func (s *GormStore) TelegramTopic() TelegramTopicRepo
func (*GormStore) Ticket ¶
func (s *GormStore) Ticket() TicketRepo
func (*GormStore) TrafficLog ¶
func (s *GormStore) TrafficLog() TrafficRepo
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 IdentityTransactor ¶ added in v1.20.3
type IdentityTransactor interface {
InIdentityTx(context.Context, func(IdentityStore) error) error
}
type InboxRepo ¶ added in v1.15.0
The shared kernel's contracts live in the kernel package, which depends on no module, so the platform module can use them without depending on the other modules' contracts in this package; they are re-exported here.
type LogRepo ¶ added in v1.3.9
The shared kernel's contracts live in the kernel package, which depends on no module, so the platform module can use them without depending on the other modules' contracts in this package; they are re-exported here.
type MobileNormalization ¶ added in v1.21.0
type MobileNormalization struct {
// Converted bindings now hold their number in E.164.
Converted int
// Conflicts kept their stored form because another binding already
// holds the E.164 number; Unparsable ones are not phone numbers.
Conflicts int
Unparsable int
}
MobileNormalization reports what NormalizeMobileIdentifiers did.
type ModuleConn ¶ added in v1.15.2
type ModuleConn = kernel.ModuleConn
ModuleConn is the per-connection context handed to a repo builder. The kernel package declares it, with the platform bundle below, so the platform module builds its repositories without depending on this package.
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 NetworkTransactor ¶ added in v1.20.3
type NetworkTransactor interface {
InNetworkTx(context.Context, func(NetworkStore) error) error
}
type NodeCacheKeyBridge ¶ added in v1.15.3
type NodeCacheKeyBridge interface {
ClearNodeUserListCaches(ctx context.Context, nodeIDs []int64, tags []string) error
}
NodeCacheKeyBridge is the subscription bundle's window onto network's node-facing caches: a plan write that changes which subscriptions the servers serve invalidates, through it, the user lists of the servers carrying the plan's nodes and node tags. The network bundle provides it and runs the invalidation under its cache generation fence, which a plain DEL of the list keys from the subscription bundle bypassed.
type NodeRepo ¶ added in v1.3.9
type NodeRepo interface {
// server
InsertServer(ctx context.Context, data *node.Server) error
FindOneServer(ctx context.Context, id int64) (*node.Server, error)
UpdateServer(ctx context.Context, data *node.Server) error
UpdateServerProtocolsIfCurrent(ctx context.Context, id int64, current, updated string) (bool, error)
BatchUpdateServerLastReportedAt(ctx context.Context, reports map[int64]time.Time) error
DeleteServer(ctx context.Context, id int64) error
FindServerConfigOverride(ctx context.Context, serverId int64) (*node.ServerConfigOverride, error)
SaveServerConfigOverride(ctx context.Context, data *node.ServerConfigOverride) error
DeleteServerConfigOverride(ctx context.Context, serverId int64) error
QueryServerList(ctx context.Context, ids []int64) (servers []*node.Server, err error)
// node
InsertNode(ctx context.Context, data *node.Node) error
FindOneNode(ctx context.Context, id int64) (*node.Node, error)
UpdateNode(ctx context.Context, data *node.Node) error
DeleteNode(ctx context.Context, id int64) 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)
ListNodes(ctx context.Context, params *node.FilterNodeParams) ([]*node.Node, error)
ListNodesByScope(ctx context.Context, nodeIDs []int64, tags []string, enabled *bool, preload bool) ([]*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)
ClearServerCache(ctx context.Context, serverId int64) error
ServerCacheGeneration(ctx context.Context, serverId int64) (int64, error)
SetServerCache(ctx context.Context, serverId int64, key string, value any, generation int64) error
}
NodeRepo manages the servers, their nodes and per-server configuration overrides, together with the cached node status and online users.
type NotificationBuilder ¶ added in v1.15.18
type NotificationBuilder func(conn ModuleConn) NotificationRepos
type NotificationRepos ¶ added in v1.15.18
type NotificationRepos struct {
TelegramTopics TelegramTopicRepo
}
NotificationRepos is the notification domain bundle.
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) 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) error
Delete(ctx context.Context, id int64) error
UpdateOrderStatusFrom(ctx context.Context, orderNo string, from, status uint8) (bool, error)
UpdatePaymentExpectation(ctx context.Context, orderNo string, amount int64, currency string) (bool, error)
SetPaymentTradeNoIfEmpty(ctx context.Context, orderNo, tradeNo string) (bool, error)
BeginPaymentSession(ctx context.Context, orderNo string) (bool, error)
CompletePaymentSession(ctx context.Context, orderNo, tradeNo, session string) (bool, error)
MarkOrderPaid(ctx context.Context, orderNo, tradeNo string) (bool, error)
// SetCommission records the referral commission paid for the order and
// the referrer credited with it; a refund reverses it in proportion
// against that referrer, whoever refers the buyer by then.
SetCommission(ctx context.Context, orderNo string, amount, refererID int64) error
// HasCommissionedOrder reports whether another order of the user has
// already earned a referral commission.
HasCommissionedOrder(ctx context.Context, userID int64, exceptOrderNo string) (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)
// CountPendingGuestOrders counts the unpaid orders a canonical guest
// identity created at or after since and still holds before its account
// exists.
CountPendingGuestOrders(ctx context.Context, authType, identifier string, since time.Time) (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)
// QueryDailyReport totals one day's settled orders with the plan and
// payment-method breakdowns the daily operations report needs.
QueryDailyReport(ctx context.Context, date time.Time) (*order.DailyReport, error)
QueryMonthlyOrdersList(ctx context.Context, date time.Time) ([]order.OrdersTotalWithDate, error)
}
OrderRepo manages the order table: an order from its creation through payment to settlement, and the order statistics of the dashboards.
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 = kernel.OutboxRepo
The shared kernel's contracts live in the kernel package, which depends on no module, so the platform module can use them without depending on the other modules' contracts in this package; they are re-exported here.
type PaymentRepo ¶ added in v1.3.9
type PaymentRepo interface {
Insert(ctx context.Context, data *payment.Payment) error
FindOne(ctx context.Context, id int64) (*payment.Payment, error)
Update(ctx context.Context, data *payment.Payment) error
Delete(ctx context.Context, id int64) 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 manages the payment methods administrators configure; a gateway callback finds its method by the token in its notify URL.
type PlatformBuilder ¶ added in v1.15.2
type PlatformBuilder = kernel.PlatformBuilder
PlatformRepos is the shared-kernel bundle.
type PlatformRepos ¶ added in v1.15.2
type PlatformRepos = kernel.PlatformRepos
PlatformRepos is the shared-kernel bundle.
type PlatformStore ¶ added in v1.15.0
type PlatformStore = kernel.PlatformStore
PlatformStore is the platform domain's transactional surface: system settings, scheduled-task bookkeeping and audit/message logs. It is the shared kernel's, re-exported from the kernel package.
type PlatformTransactor ¶ added in v1.20.3
type PlatformTransactor = kernel.PlatformTransactor
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
Entitlement() EntitlementRepo
System() SystemRepo
Task() TaskRepo
// TelegramTopic maps forum topics in the admin Telegram group to the
// conversation each carries.
TelegramTopic() TelegramTopicRepo
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) error
FindOne(ctx context.Context, id int64) (*subscribe.Subscribe, error)
Update(ctx context.Context, data *subscribe.Subscribe) error
ReserveInventory(ctx context.Context, id int64) (bool, error)
RestoreInventory(ctx context.Context, id int64) error
Delete(ctx context.Context, id int64) error
FilterList(ctx context.Context, params *subscribe.FilterParams) (int64, []*subscribe.Subscribe, error)
FindByNodeScope(ctx context.Context, nodeIDs []int64, tags []string) ([]*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 manages the plans (the subscribe table) and their groups, including each plan's inventory and its cached projections.
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 SubscriptionCredentialRotation ¶ added in v1.21.0
SubscriptionCredentialRotation replaces the token and UUID of one subscription. Previous is the row before the rotation; its cache keys are invalidated with the new ones.
type SubscriptionRepos ¶ added in v1.15.2
type SubscriptionRepos struct {
Entitlements EntitlementRepo
Plans SubscribeRepo
UserSubs UserSubscriptionRepo
Traffic SubscriptionTrafficRepo
// Clients holds the subscribe_application rows delivery renders for.
Clients ClientRepo
// 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 {
Entitlement() EntitlementRepo
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 {
// FindTrafficResetCandidates returns the in-term subscriptions of the
// plans a calendar reset may clear at now (started, unexpired, Active or
// Finished) that are not yet reset for day. Which of them are due is the
// reset cycle's decision; the rows carry what it needs.
FindTrafficResetCandidates(ctx context.Context, planIDs []int64, now, day time.Time) ([]*usersub.Subscribe, error)
// ResetSubscribeTrafficOnce locks the given subscriptions that are still
// candidates, clears their traffic, reactivates the Finished ones, marks
// them reset for day and returns them. Run it inside a subscription
// transaction together with the reset's audit rows.
ResetSubscribeTrafficOnce(ctx context.Context, ids []int64, now, day time.Time) ([]*usersub.Subscribe, error)
}
SubscriptionTrafficRepo manages the calendar traffic resets. A reset marks each subscription with the day it ran for, so a retried run never clears one cycle twice.
type SubscriptionTransactor ¶ added in v1.20.3
type SubscriptionTransactor interface {
InSubscriptionTx(context.Context, func(SubscriptionStore) error) error
}
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 = kernel.SystemRepo
The shared kernel's contracts live in the kernel package, which depends on no module, so the platform module can use them without depending on the other modules' contracts in this package; they are re-exported here.
type TaskRepo ¶ added in v1.3.9
The shared kernel's contracts live in the kernel package, which depends on no module, so the platform module can use them without depending on the other modules' contracts in this package; they are re-exported here.
type TelegramTopicRepo ¶ added in v1.15.18
type TelegramTopicRepo interface {
Insert(ctx context.Context, data *telegramtopic.Topic) error
FindByKindRef(ctx context.Context, chatID int64, kind uint8, refID int64) (*telegramtopic.Topic, error)
FindByThread(ctx context.Context, chatID, threadID int64) (*telegramtopic.Topic, error)
// UpdateThread repoints a mapping after its topic was deleted in
// Telegram and had to be recreated.
UpdateThread(ctx context.Context, id, threadID int64) error
UpdateStatus(ctx context.Context, id int64, status uint8) error
}
TelegramTopicRepo persists the mapping between forum topics in the administrators' Telegram group and what each topic carries. Lookups return gorm.ErrRecordNotFound when no mapping exists.
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 manages the support tickets and their follow-up messages.
type TrafficRepo ¶ added in v1.3.9
type TrafficRepo interface {
InsertBatch(ctx context.Context, data []*traffic.TrafficLog, batchSize int) error
QueryTrafficSummary(ctx context.Context, start, end time.Time) (*traffic.TotalTraffic, error)
TopServersTrafficByDay(ctx context.Context, date time.Time, limit int) ([]traffic.ServerTrafficRanking, error)
TopUsersTrafficByDay(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)
DeleteBeforeBatch(ctx context.Context, end time.Time, limit int) (int64, error)
}
TrafficRepo manages the traffic_log table: the traffic users consumed on each server, and the summaries and rankings computed from it.
type UserAuthRepo ¶ added in v1.14.18
type UserAuthRepo interface {
FindUserAuthMethods(ctx context.Context, userId int64) ([]*user.AuthMethods, error)
FindUserAuthMethodsByUserIds(ctx context.Context, method string, userIds []int64) ([]*user.AuthMethods, error)
FindUserAuthMethodByOpenID(ctx context.Context, method, openID string) (*user.AuthMethods, error)
// FindEmailAlias returns an email binding of a live account that reaches
// the same mailbox as email under another spelling.
FindEmailAlias(ctx context.Context, email 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) error
UpdateUserAuthMethods(ctx context.Context, data *user.AuthMethods) error
DeleteUserAuthMethods(ctx context.Context, userId int64, platform string) error
UpdateUserAuthMethodOwner(ctx context.Context, authType, identifier string, userId int64) error
DeleteUserAuthMethodByIdentifier(ctx context.Context, authType, identifier string) error
UpsertUserAuthMethod(ctx context.Context, data *user.AuthMethods) error
// NormalizeMobileIdentifiers converts the phone numbers stored in
// another form than E.164 (the admin panel used to store
// "<area>-<number>") to E.164. It is idempotent; a number whose E.164
// form another binding already holds stays as it is and is reported.
NormalizeMobileIdentifiers(ctx context.Context) (MobileNormalization, 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
// Deprecated: UpdateUserCache only ever cleared the cache; use
// ClearUserCache.
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) error
FindOneDevice(ctx context.Context, id int64) (*user.Device, error)
// FindDeviceForAuth always reads current state, bypassing cached projections.
FindDeviceForAuth(ctx context.Context, id int64) (*user.Device, error)
// TouchDevice only updates access metadata for the same enabled owner.
TouchDevice(ctx context.Context, id, userID int64, ip, userAgent string) (bool, error)
FindOneDeviceByIdentifier(ctx context.Context, id string) (*user.Device, error)
SetDeviceEnabled(ctx context.Context, id int64, enabled bool) error
SetDeviceOnline(ctx context.Context, id int64, online bool) error
DeleteDevice(ctx context.Context, id int64) 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) 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) error
FindOne(ctx context.Context, id int64) (*user.User, error)
FindAccountState(ctx context.Context, id int64) (*user.AccountState, 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)
// UpdateColumns writes only the named columns. There is deliberately no
// whole-row update: a snapshot saved back whole reverts whatever changed
// meanwhile, including an administrator's disable or demotion.
UpdateColumns(ctx context.Context, id int64, columns map[string]any) error
UpgradePasswordHash(ctx context.Context, id int64, currentHash, password, algo, salt string) (bool, error)
Delete(ctx context.Context, id int64) error
BatchDeleteUser(ctx context.Context, ids []int64) error
QueryPageList(ctx context.Context, page, size int, filter *user.UserFilterParams) ([]*user.User, int64, error)
FindUsersByIds(ctx context.Context, ids []int64) ([]*user.User, error)
FindEnabledUserIDs(ctx context.Context, ids []int64) ([]int64, 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)
// QueryRegisterUserTotal counts the registered accounts; the ByDate and
// ByMonthly variants count those registered on date's day or month.
QueryRegisterUserTotal(ctx context.Context) (int64, error)
QueryRegisterUserTotalByDate(ctx context.Context, date time.Time) (int64, error)
QueryRegisterUserTotalByMonthly(ctx context.Context, date time.Time) (int64, error)
// Deprecated: use QueryRegisterUserTotal.
QueryResisterUserTotal(ctx context.Context) (int64, error)
// Deprecated: use QueryRegisterUserTotalByDate.
QueryResisterUserTotalByDate(ctx context.Context, date time.Time) (int64, error)
// Deprecated: use QueryRegisterUserTotalByMonthly.
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) 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)
// UpdateSubscribeColumns writes only the named columns of data.Id (plus
// updated_at); concurrent writes to every other column survive. Callers
// that derive a column from the row's current value read the row with
// FindOneSubscribeForUpdate in the same subscription transaction first.
// A provider-managed row accepts only usersub.LocalControlColumns and is
// reactivated only inside its provider period; anything else fails with
// usersub.ErrProviderManaged.
UpdateSubscribeColumns(ctx context.Context, data *usersub.Subscribe, columns ...string) error
// RotateSubscribeCredentials gives each subscription the token and UUID
// of its rotation in batched column updates, and invalidates the cache
// entries of the previous credentials as well as the new ones.
RotateSubscribeCredentials(ctx context.Context, rotations []SubscriptionCredentialRotation) error
// ApplyEntitlementProjection is only called with a locked provider row.
ApplyEntitlementProjection(ctx context.Context, data *usersub.Subscribe) error
DeleteSubscribeById(ctx context.Context, id int64) error
// ClearSubscribeCache drops the cached entries of the subscriptions: by
// id, by token and their owners' subscription lists.
ClearSubscribeCache(ctx context.Context, data ...*usersub.Subscribe) error
BatchUpdateUserSubscribeWithTraffic(ctx context.Context, deltas []trafficEntity.SubscribeTrafficDelta) error
// FindUsersSubscribeBySubscribeIds returns the plans' subscriptions a
// node may serve now (usersub.ServableCondition).
FindUsersSubscribeBySubscribeIds(ctx context.Context, subscribeIds []int64) ([]*usersub.Subscribe, error)
FindUserSubscribesByStatus(ctx context.Context, status ...int64) ([]*usersub.Subscribe, error)
FindSubscribesByIds(ctx context.Context, ids []int64) ([]*usersub.Subscribe, error)
// FindSubscribeDetailsByIds loads the subscriptions with their plans in
// one round trip per table; missing ids are absent from the result.
FindSubscribeDetailsByIds(ctx context.Context, ids []int64) ([]*usersub.SubscribeDetails, error)
// FindSubscribeDetailsByUserIds loads every subscription of the users,
// whatever its status, with its plan: one round trip per table however
// many users there are.
FindSubscribeDetailsByUserIds(ctx context.Context, userIds []int64) ([]*usersub.SubscribeDetails, 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)
// FindExpiringSubscribes returns active subscriptions expiring inside the
// window, for the pre-expiry reminder.
FindExpiringSubscribes(ctx context.Context, from, to time.Time) ([]*usersub.Subscribe, error)
MarkSubscribesFinished(ctx context.Context, ids []int64, status uint8, finishedAt time.Time) 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) error
FindWithdrawalForUpdate(ctx context.Context, id int64) (*walletEntity.Withdrawal, error)
QueryWithdrawalList(ctx context.Context, userID int64, status *uint8, page, size int) ([]*walletEntity.Withdrawal, int64, error)
UpdateWithdrawalStatus(ctx context.Context, id int64, from, to uint8, reason string) (bool, 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) error
UpdateCommission(ctx context.Context, data *walletEntity.Wallet) error
}
WalletRepo is the billing domain's repository of the user_wallet table, the single source of every account's balance, gift amount and commission. Other modules read and move wallets through the billing facade.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package kernel holds the persistence contracts of the shared kernel: the platform-owned repositories every module may use (system settings, the audit log, task bookkeeping and the event inbox and outbox), the platform transaction view and the pagination helpers.
|
Package kernel holds the persistence contracts of the shared kernel: the platform-owned repositories every module may use (system settings, the audit log, task bookkeeping and the event inbox and outbox), the platform transaction view and the pagination helpers. |