Documentation
¶
Overview ¶
Package usecases provides application-level use cases for subscription management.
Index ¶
- type ActivatePlanUseCase
- type ActivateSubscriptionCommand
- type ActivateSubscriptionUseCase
- type AggregateUsageUseCase
- type CancelSubscriptionCommand
- type CancelSubscriptionUseCase
- type ChangePlanCommand
- type ChangePlanUseCase
- type ChangeType
- type CreatePlanCommand
- type CreatePlanUseCase
- type CreateSubscriptionCommand
- type CreateSubscriptionResult
- type CreateSubscriptionUseCase
- type DeactivatePlanUseCase
- type DeletePlanUseCase
- type DeleteSubscriptionUseCase
- type EffectiveDate
- type ExpireSubscriptionsUseCase
- type GenerateSubscriptionTokenCommand
- type GenerateSubscriptionTokenResult
- type GenerateSubscriptionTokenUseCase
- type GetPlanPricingsQuery
- type GetPlanPricingsUseCase
- type GetPlanUseCase
- type GetPublicPlansUseCase
- type GetSubscriptionQuery
- type GetSubscriptionUsageStatsQuery
- type GetSubscriptionUsageStatsResponse
- type GetSubscriptionUsageStatsUseCase
- type GetSubscriptionUseCase
- type ListPlansQuery
- type ListPlansResult
- type ListPlansUseCase
- type ListSubscriptionTokensQuery
- type ListSubscriptionTokensUseCase
- type ListUserSubscriptionsQuery
- type ListUserSubscriptionsResult
- type ListUserSubscriptionsUseCase
- type OnlineDeviceCounter
- type PlanChangeNotifier
- type QuotaCacheManager
- type QuotaCheckResult
- type QuotaService
- type QuotaServiceImpl
- func (s *QuotaServiceImpl) CheckUserForwardQuotaExceeded(ctx context.Context, userID uint) (bool, error)
- func (s *QuotaServiceImpl) GetCurrentPeriodUsage(ctx context.Context, subscriptionID uint, periodStart time.Time, ...) (int64, error)
- func (s *QuotaServiceImpl) GetSubscriptionQuota(ctx context.Context, subscriptionID uint) (*QuotaCheckResult, error)
- func (s *QuotaServiceImpl) GetUserForwardQuota(ctx context.Context, userID uint) ([]*QuotaCheckResult, error)
- func (s *QuotaServiceImpl) GetUserNodeQuota(ctx context.Context, userID uint) ([]*QuotaCheckResult, error)
- type RefreshSubscriptionTokenCommand
- type RefreshSubscriptionTokenResult
- type RefreshSubscriptionTokenUseCase
- type RenewSubscriptionCommand
- type RenewSubscriptionUseCase
- type ResetSubscriptionLinkCommand
- type ResetSubscriptionLinkUseCase
- type ResetSubscriptionUsageCommand
- type ResetSubscriptionUsageUseCase
- func (uc *ResetSubscriptionUsageUseCase) Execute(ctx context.Context, cmd ResetSubscriptionUsageCommand) error
- func (uc *ResetSubscriptionUsageUseCase) SetQuotaCacheManager(manager QuotaCacheManager)
- func (uc *ResetSubscriptionUsageUseCase) SetSubscriptionNotifier(notifier SubscriptionChangeNotifier)
- type RevokeSubscriptionTokenCommand
- type RevokeSubscriptionTokenUseCase
- type SubscriptionChangeNotifier
- type SubscriptionUsageStatsRecord
- type SubscriptionUsageSummary
- type SuspendSubscriptionCommand
- type SuspendSubscriptionUseCase
- type TokenGenerator
- type UnsuspendSubscriptionCommand
- type UnsuspendSubscriptionUseCase
- type UpdatePlanCommand
- type UpdatePlanUseCase
- type ValidateSubscriptionTokenCommand
- type ValidateSubscriptionTokenResult
- type ValidateSubscriptionTokenUseCase
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActivatePlanUseCase ¶ added in v0.1.6
type ActivatePlanUseCase struct {
// contains filtered or unexported fields
}
func NewActivatePlanUseCase ¶ added in v0.1.6
func NewActivatePlanUseCase( planRepo subscription.PlanRepository, logger logger.Interface, ) *ActivatePlanUseCase
type ActivateSubscriptionCommand ¶
type ActivateSubscriptionCommand struct {
SubscriptionID uint
}
type ActivateSubscriptionUseCase ¶
type ActivateSubscriptionUseCase struct {
// contains filtered or unexported fields
}
func NewActivateSubscriptionUseCase ¶
func NewActivateSubscriptionUseCase( subscriptionRepo subscription.SubscriptionRepository, logger logger.Interface, ) *ActivateSubscriptionUseCase
func (*ActivateSubscriptionUseCase) Execute ¶
func (uc *ActivateSubscriptionUseCase) Execute(ctx context.Context, cmd ActivateSubscriptionCommand) error
func (*ActivateSubscriptionUseCase) SetSubscriptionNotifier ¶ added in v0.1.57
func (uc *ActivateSubscriptionUseCase) SetSubscriptionNotifier(notifier SubscriptionChangeNotifier)
SetSubscriptionNotifier sets the subscription change notifier (optional).
type AggregateUsageUseCase ¶ added in v0.1.52
type AggregateUsageUseCase struct {
// contains filtered or unexported fields
}
AggregateUsageUseCase handles aggregating subscription usage data from raw hourly data (Redis hourly buckets or subscription_usages fallback) to aggregated stats (subscription_usage_stats).
func NewAggregateUsageUseCase ¶ added in v0.1.52
func NewAggregateUsageUseCase( usageRepo subscription.SubscriptionUsageRepository, usageStatsRepo subscription.SubscriptionUsageStatsRepository, hourlyCache cache.HourlyTrafficCache, logger logger.Interface, ) *AggregateUsageUseCase
NewAggregateUsageUseCase creates a new aggregate usage use case instance.
func (*AggregateUsageUseCase) AggregateDailyUsage ¶ added in v0.1.52
func (uc *AggregateUsageUseCase) AggregateDailyUsage(ctx context.Context) error
AggregateDailyUsage aggregates hourly data from yesterday into daily stats. It reads from Redis hourly buckets and writes to subscription_usage_stats table. After successful aggregation, it cleans up the Redis data for processed hours.
func (*AggregateUsageUseCase) AggregateMonthlyUsage ¶ added in v0.1.52
func (uc *AggregateUsageUseCase) AggregateMonthlyUsage(ctx context.Context) error
AggregateMonthlyUsage aggregates daily data from last month into monthly stats. It reads from subscription_usage_stats table (daily granularity) and writes monthly aggregated records to the same table.
func (*AggregateUsageUseCase) CleanupOldUsageData ¶ added in v0.1.52
func (uc *AggregateUsageUseCase) CleanupOldUsageData(ctx context.Context, retentionDays int) error
CleanupOldUsageData deletes raw usage records older than the specified retention days. This helps manage storage by removing historical data that has already been aggregated.
type CancelSubscriptionUseCase ¶
type CancelSubscriptionUseCase struct {
// contains filtered or unexported fields
}
func NewCancelSubscriptionUseCase ¶
func NewCancelSubscriptionUseCase( subscriptionRepo subscription.SubscriptionRepository, tokenRepo subscription.SubscriptionTokenRepository, logger logger.Interface, ) *CancelSubscriptionUseCase
func (*CancelSubscriptionUseCase) Execute ¶
func (uc *CancelSubscriptionUseCase) Execute(ctx context.Context, cmd CancelSubscriptionCommand) error
func (*CancelSubscriptionUseCase) SetSubscriptionNotifier ¶ added in v0.1.57
func (uc *CancelSubscriptionUseCase) SetSubscriptionNotifier(notifier SubscriptionChangeNotifier)
SetSubscriptionNotifier sets the subscription change notifier (optional).
type ChangePlanCommand ¶
type ChangePlanCommand struct {
SubscriptionID uint
NewPlanID uint // Internal plan ID (used if NewPlanSID is empty)
NewPlanSID string // Stripe-style plan SID (takes precedence over NewPlanID)
ChangeType ChangeType
EffectiveDate EffectiveDate
}
type ChangePlanUseCase ¶
type ChangePlanUseCase struct {
// contains filtered or unexported fields
}
func NewChangePlanUseCase ¶
func NewChangePlanUseCase( subscriptionRepo subscription.SubscriptionRepository, planRepo subscription.PlanRepository, logger logger.Interface, ) *ChangePlanUseCase
func (*ChangePlanUseCase) Execute ¶
func (uc *ChangePlanUseCase) Execute(ctx context.Context, cmd ChangePlanCommand) error
type ChangeType ¶
type ChangeType string
const ( ChangeTypeUpgrade ChangeType = "upgrade" ChangeTypeDowngrade ChangeType = "downgrade" )
type CreatePlanCommand ¶ added in v0.1.6
type CreatePlanCommand struct {
Name string
Slug string
Description string
PlanType string // Required: "node" or "forward"
Limits map[string]interface{}
NodeLimit *int // Maximum number of user nodes (nil or 0 = unlimited)
IsPublic bool
SortOrder int
Pricings []dto.PricingOptionInput // Required: multiple pricing options
}
type CreatePlanUseCase ¶ added in v0.1.6
type CreatePlanUseCase struct {
// contains filtered or unexported fields
}
func NewCreatePlanUseCase ¶ added in v0.1.6
func NewCreatePlanUseCase( planRepo subscription.PlanRepository, pricingRepo subscription.PlanPricingRepository, logger logger.Interface, ) *CreatePlanUseCase
func (*CreatePlanUseCase) Execute ¶ added in v0.1.6
func (uc *CreatePlanUseCase) Execute( ctx context.Context, cmd CreatePlanCommand, ) (*dto.PlanDTO, error)
type CreateSubscriptionCommand ¶
type CreateSubscriptionCommand struct {
UserID uint // Internal user ID (used if UserSID is empty)
UserSID string // Stripe-style user SID (takes precedence over UserID)
PlanID uint // Internal plan ID (used if PlanSID is empty)
PlanSID string // Stripe-style plan SID (takes precedence over PlanID)
StartDate time.Time
AutoRenew bool
PaymentInfo map[string]interface{}
BillingCycle string // User selected billing cycle
ActivateImmediately bool // If true, activate subscription immediately (for admin use)
}
type CreateSubscriptionResult ¶
type CreateSubscriptionResult struct {
Subscription *subscription.Subscription
Plan *subscription.Plan // Plan used for this subscription (for DTO device_limit)
Token *subscription.SubscriptionToken
PlainToken string // Plain token value, only available at creation time
}
type CreateSubscriptionUseCase ¶
type CreateSubscriptionUseCase struct {
// contains filtered or unexported fields
}
func NewCreateSubscriptionUseCase ¶
func NewCreateSubscriptionUseCase( subscriptionRepo subscription.SubscriptionRepository, planRepo subscription.PlanRepository, tokenRepo subscription.SubscriptionTokenRepository, pricingRepo subscription.PlanPricingRepository, userRepo user.Repository, tokenGenerator TokenGenerator, txMgr *db.TransactionManager, logger logger.Interface, ) *CreateSubscriptionUseCase
func (*CreateSubscriptionUseCase) Execute ¶
func (uc *CreateSubscriptionUseCase) Execute(ctx context.Context, cmd CreateSubscriptionCommand) (*CreateSubscriptionResult, error)
func (*CreateSubscriptionUseCase) SetSubscriptionNotifier ¶ added in v0.1.57
func (uc *CreateSubscriptionUseCase) SetSubscriptionNotifier(notifier SubscriptionChangeNotifier)
SetSubscriptionNotifier sets the subscription change notifier (optional).
type DeactivatePlanUseCase ¶ added in v0.1.6
type DeactivatePlanUseCase struct {
// contains filtered or unexported fields
}
func NewDeactivatePlanUseCase ¶ added in v0.1.6
func NewDeactivatePlanUseCase( planRepo subscription.PlanRepository, logger logger.Interface, ) *DeactivatePlanUseCase
type DeletePlanUseCase ¶ added in v0.1.26
type DeletePlanUseCase struct {
// contains filtered or unexported fields
}
func NewDeletePlanUseCase ¶ added in v0.1.26
func NewDeletePlanUseCase( planRepo subscription.PlanRepository, subscriptionRepo subscription.SubscriptionRepository, pricingRepo subscription.PlanPricingRepository, txMgr *db.TransactionManager, logger logger.Interface, ) *DeletePlanUseCase
type DeleteSubscriptionUseCase ¶ added in v0.1.26
type DeleteSubscriptionUseCase struct {
// contains filtered or unexported fields
}
func NewDeleteSubscriptionUseCase ¶ added in v0.1.26
func NewDeleteSubscriptionUseCase( subscriptionRepo subscription.SubscriptionRepository, tokenRepo subscription.SubscriptionTokenRepository, txMgr *db.TransactionManager, logger logger.Interface, ) *DeleteSubscriptionUseCase
type EffectiveDate ¶
type EffectiveDate string
const ( EffectiveDateImmediate EffectiveDate = "immediate" EffectiveDatePeriodEnd EffectiveDate = "period_end" )
type ExpireSubscriptionsUseCase ¶ added in v0.1.74
type ExpireSubscriptionsUseCase struct {
// contains filtered or unexported fields
}
ExpireSubscriptionsUseCase handles marking expired subscriptions. This is a background job that runs periodically to ensure database consistency. Note: The display layer uses EffectiveStatus() for real-time accuracy, this job is mainly for data consistency in reports and statistics.
func NewExpireSubscriptionsUseCase ¶ added in v0.1.74
func NewExpireSubscriptionsUseCase( subscriptionRepo subscription.SubscriptionRepository, logger logger.Interface, ) *ExpireSubscriptionsUseCase
NewExpireSubscriptionsUseCase creates a new ExpireSubscriptionsUseCase
type GenerateSubscriptionTokenUseCase ¶
type GenerateSubscriptionTokenUseCase struct {
// contains filtered or unexported fields
}
func NewGenerateSubscriptionTokenUseCase ¶
func NewGenerateSubscriptionTokenUseCase( subscriptionRepo subscription.SubscriptionRepository, tokenRepo subscription.SubscriptionTokenRepository, tokenGenerator TokenGenerator, logger logger.Interface, ) *GenerateSubscriptionTokenUseCase
func (*GenerateSubscriptionTokenUseCase) Execute ¶
func (uc *GenerateSubscriptionTokenUseCase) Execute(ctx context.Context, cmd GenerateSubscriptionTokenCommand) (*GenerateSubscriptionTokenResult, error)
type GetPlanPricingsQuery ¶
type GetPlanPricingsQuery struct {
PlanSID string
}
type GetPlanPricingsUseCase ¶
type GetPlanPricingsUseCase struct {
// contains filtered or unexported fields
}
func NewGetPlanPricingsUseCase ¶
func NewGetPlanPricingsUseCase( planRepo subscription.PlanRepository, pricingRepo subscription.PlanPricingRepository, logger logger.Interface, ) *GetPlanPricingsUseCase
func (*GetPlanPricingsUseCase) Execute ¶
func (uc *GetPlanPricingsUseCase) Execute( ctx context.Context, query GetPlanPricingsQuery, ) ([]*dto.PricingOptionDTO, error)
type GetPlanUseCase ¶ added in v0.1.6
type GetPlanUseCase struct {
// contains filtered or unexported fields
}
func NewGetPlanUseCase ¶ added in v0.1.6
func NewGetPlanUseCase( planRepo subscription.PlanRepository, pricingRepo subscription.PlanPricingRepository, logger logger.Interface, ) *GetPlanUseCase
func (*GetPlanUseCase) ExecuteByID ¶ added in v0.1.6
func (*GetPlanUseCase) ExecuteBySID ¶ added in v0.1.6
func (*GetPlanUseCase) ExecuteBySlug ¶ added in v0.1.6
type GetPublicPlansUseCase ¶
type GetPublicPlansUseCase struct {
// contains filtered or unexported fields
}
func NewGetPublicPlansUseCase ¶
func NewGetPublicPlansUseCase( planRepo subscription.PlanRepository, pricingRepo subscription.PlanPricingRepository, logger logger.Interface, ) *GetPublicPlansUseCase
type GetSubscriptionQuery ¶
type GetSubscriptionQuery struct {
SubscriptionID uint
}
type GetSubscriptionUsageStatsQuery ¶ added in v0.1.6
type GetSubscriptionUsageStatsQuery struct {
SubscriptionID uint
From time.Time
To time.Time
Granularity string // hour, day, month
Page int
PageSize int
}
GetSubscriptionUsageStatsQuery represents the query parameters for subscription usage stats
type GetSubscriptionUsageStatsResponse ¶ added in v0.1.6
type GetSubscriptionUsageStatsResponse struct {
Records []*SubscriptionUsageStatsRecord `json:"records"`
Summary *SubscriptionUsageSummary `json:"summary"`
Total int `json:"total"`
Page int `json:"page"`
PageSize int `json:"page_size"`
}
GetSubscriptionUsageStatsResponse represents the response for subscription usage stats
type GetSubscriptionUsageStatsUseCase ¶ added in v0.1.6
type GetSubscriptionUsageStatsUseCase struct {
// contains filtered or unexported fields
}
GetSubscriptionUsageStatsUseCase handles retrieving usage statistics for a subscription
func NewGetSubscriptionUsageStatsUseCase ¶ added in v0.1.6
func NewGetSubscriptionUsageStatsUseCase( usageRepo subscription.SubscriptionUsageRepository, usageStatsRepo subscription.SubscriptionUsageStatsRepository, hourlyCache cache.HourlyTrafficCache, nodeRepo node.NodeRepository, forwardRuleRepo forward.Repository, logger logger.Interface, ) *GetSubscriptionUsageStatsUseCase
NewGetSubscriptionUsageStatsUseCase creates a new GetSubscriptionUsageStatsUseCase
func (*GetSubscriptionUsageStatsUseCase) Execute ¶ added in v0.1.6
func (uc *GetSubscriptionUsageStatsUseCase) Execute( ctx context.Context, query GetSubscriptionUsageStatsQuery, ) (*GetSubscriptionUsageStatsResponse, error)
Execute retrieves usage statistics for a subscription
type GetSubscriptionUseCase ¶
type GetSubscriptionUseCase struct {
// contains filtered or unexported fields
}
func NewGetSubscriptionUseCase ¶
func NewGetSubscriptionUseCase( subscriptionRepo subscription.SubscriptionRepository, planRepo subscription.PlanRepository, userRepo user.Repository, logger logger.Interface, baseURL string, onlineDeviceCounter OnlineDeviceCounter, ) *GetSubscriptionUseCase
func (*GetSubscriptionUseCase) Execute ¶
func (uc *GetSubscriptionUseCase) Execute(ctx context.Context, query GetSubscriptionQuery) (*dto.SubscriptionDTO, error)
func (*GetSubscriptionUseCase) ExecuteBySID ¶ added in v0.1.6
func (uc *GetSubscriptionUseCase) ExecuteBySID(ctx context.Context, sid string) (*dto.SubscriptionDTO, error)
ExecuteBySID retrieves a subscription by its Stripe-style SID
type ListPlansQuery ¶ added in v0.1.6
type ListPlansResult ¶ added in v0.1.6
type ListPlansUseCase ¶ added in v0.1.6
type ListPlansUseCase struct {
// contains filtered or unexported fields
}
func NewListPlansUseCase ¶ added in v0.1.6
func NewListPlansUseCase( planRepo subscription.PlanRepository, pricingRepo subscription.PlanPricingRepository, logger logger.Interface, ) *ListPlansUseCase
func (*ListPlansUseCase) Execute ¶ added in v0.1.6
func (uc *ListPlansUseCase) Execute( ctx context.Context, query ListPlansQuery, ) (*ListPlansResult, error)
type ListSubscriptionTokensUseCase ¶
type ListSubscriptionTokensUseCase struct {
// contains filtered or unexported fields
}
func NewListSubscriptionTokensUseCase ¶
func NewListSubscriptionTokensUseCase( tokenRepo subscription.SubscriptionTokenRepository, logger logger.Interface, ) *ListSubscriptionTokensUseCase
func (*ListSubscriptionTokensUseCase) Execute ¶
func (uc *ListSubscriptionTokensUseCase) Execute(ctx context.Context, query ListSubscriptionTokensQuery) ([]*dto.SubscriptionTokenDTO, error)
type ListUserSubscriptionsResult ¶
type ListUserSubscriptionsResult struct {
Subscriptions []*dto.SubscriptionDTO `json:"subscriptions"`
Total int64 `json:"total"`
Page int `json:"page"`
PageSize int `json:"page_size"`
}
type ListUserSubscriptionsUseCase ¶
type ListUserSubscriptionsUseCase struct {
// contains filtered or unexported fields
}
func NewListUserSubscriptionsUseCase ¶
func NewListUserSubscriptionsUseCase( subscriptionRepo subscription.SubscriptionRepository, planRepo subscription.PlanRepository, userRepo user.Repository, logger logger.Interface, baseURL string, onlineDeviceCounter OnlineDeviceCounter, ) *ListUserSubscriptionsUseCase
func (*ListUserSubscriptionsUseCase) Execute ¶
func (uc *ListUserSubscriptionsUseCase) Execute(ctx context.Context, query ListUserSubscriptionsQuery) (*ListUserSubscriptionsResult, error)
type OnlineDeviceCounter ¶ added in v0.1.93
type OnlineDeviceCounter interface {
GetOnlineDeviceCount(ctx context.Context, subscriptionID uint) (int, error)
GetOnlineDeviceCounts(ctx context.Context, subscriptionIDs []uint) (map[uint]int, error)
}
OnlineDeviceCounter queries online device counts from Redis. Defined in subscription application layer to avoid cross-domain dependency.
type PlanChangeNotifier ¶ added in v0.1.93
type PlanChangeNotifier interface {
NotifyPlanFeaturesChanged(ctx context.Context, planID uint) error
}
PlanChangeNotifier notifies nodes when plan features change
type QuotaCacheManager ¶ added in v0.1.65
type QuotaCacheManager interface {
// InvalidateQuota removes quota cache for a subscription, forcing reload on next access.
InvalidateQuota(ctx context.Context, subscriptionID uint) error
// SyncQuotaFromSubscription syncs quota from subscription to cache.
SyncQuotaFromSubscription(ctx context.Context, sub *subscription.Subscription) error
// SetSuspended updates only the suspended status in cache.
SetSuspended(ctx context.Context, subscriptionID uint, suspended bool) error
}
QuotaCacheManager defines the interface for managing subscription quota cache. This is used to invalidate or update cache when subscription status changes.
type QuotaCheckResult ¶ added in v0.1.52
type QuotaCheckResult struct {
SubscriptionID uint // Internal subscription ID
SubscriptionSID string // Stripe-style subscription ID
PlanType string // Plan type (node, forward, hybrid)
UsedBytes uint64 // Total traffic used in current period
LimitBytes uint64 // Traffic limit (0 = unlimited)
PeriodStart time.Time // Current billing period start
PeriodEnd time.Time // Current billing period end
IsExceeded bool // Whether quota is exceeded
RemainingBytes uint64 // Remaining traffic (0 if exceeded or unlimited)
}
QuotaCheckResult represents the quota usage status for a subscription.
type QuotaService ¶ added in v0.1.52
type QuotaService interface {
// GetSubscriptionQuota returns the quota usage for a single subscription.
GetSubscriptionQuota(ctx context.Context, subscriptionID uint) (*QuotaCheckResult, error)
// GetUserForwardQuota returns quota usage for all Forward-type subscriptions of a user.
GetUserForwardQuota(ctx context.Context, userID uint) ([]*QuotaCheckResult, error)
// GetUserNodeQuota returns quota usage for all Node-type subscriptions of a user.
GetUserNodeQuota(ctx context.Context, userID uint) ([]*QuotaCheckResult, error)
// CheckUserForwardQuotaExceeded checks if user's Forward quota is exceeded.
// Returns true if all Forward subscriptions have exceeded their quota.
CheckUserForwardQuotaExceeded(ctx context.Context, userID uint) (bool, error)
// GetCurrentPeriodUsage returns the total usage for the current billing period.
// This method is used for real-time traffic limit checking.
GetCurrentPeriodUsage(ctx context.Context, subscriptionID uint, periodStart, periodEnd time.Time) (int64, error)
}
QuotaService provides unified quota calculation for subscriptions.
type QuotaServiceImpl ¶ added in v0.1.52
type QuotaServiceImpl struct {
// contains filtered or unexported fields
}
QuotaServiceImpl implements the QuotaService interface.
func NewQuotaService ¶ added in v0.1.52
func NewQuotaService( subscriptionRepo subscription.SubscriptionRepository, usageStatsRepo subscription.SubscriptionUsageStatsRepository, hourlyCache cache.HourlyTrafficCache, planRepo subscription.PlanRepository, logger logger.Interface, ) *QuotaServiceImpl
NewQuotaService creates a new QuotaServiceImpl instance.
func (*QuotaServiceImpl) CheckUserForwardQuotaExceeded ¶ added in v0.1.52
func (s *QuotaServiceImpl) CheckUserForwardQuotaExceeded(ctx context.Context, userID uint) (bool, error)
CheckUserForwardQuotaExceeded checks if user's Forward quota is exceeded.
func (*QuotaServiceImpl) GetCurrentPeriodUsage ¶ added in v0.1.65
func (s *QuotaServiceImpl) GetCurrentPeriodUsage( ctx context.Context, subscriptionID uint, periodStart time.Time, periodEnd time.Time, ) (int64, error)
GetCurrentPeriodUsage returns the total usage for the current billing period. This method aggregates all resource types (forward_rule + node) for the subscription. It is used for real-time traffic limit checking and implements the SubscriptionUsageReader interface.
func (*QuotaServiceImpl) GetSubscriptionQuota ¶ added in v0.1.52
func (s *QuotaServiceImpl) GetSubscriptionQuota(ctx context.Context, subscriptionID uint) (*QuotaCheckResult, error)
GetSubscriptionQuota returns the quota usage for a single subscription.
func (*QuotaServiceImpl) GetUserForwardQuota ¶ added in v0.1.52
func (s *QuotaServiceImpl) GetUserForwardQuota(ctx context.Context, userID uint) ([]*QuotaCheckResult, error)
GetUserForwardQuota returns quota usage for all Forward-type subscriptions of a user.
func (*QuotaServiceImpl) GetUserNodeQuota ¶ added in v0.1.52
func (s *QuotaServiceImpl) GetUserNodeQuota(ctx context.Context, userID uint) ([]*QuotaCheckResult, error)
GetUserNodeQuota returns quota usage for all Node-type subscriptions of a user.
type RefreshSubscriptionTokenCommand ¶
type RefreshSubscriptionTokenCommand struct {
OldTokenID uint
}
type RefreshSubscriptionTokenUseCase ¶
type RefreshSubscriptionTokenUseCase struct {
// contains filtered or unexported fields
}
func NewRefreshSubscriptionTokenUseCase ¶
func NewRefreshSubscriptionTokenUseCase( tokenRepo subscription.SubscriptionTokenRepository, subscriptionRepo subscription.SubscriptionRepository, tokenGenerator TokenGenerator, logger logger.Interface, ) *RefreshSubscriptionTokenUseCase
func (*RefreshSubscriptionTokenUseCase) Execute ¶
func (uc *RefreshSubscriptionTokenUseCase) Execute(ctx context.Context, cmd RefreshSubscriptionTokenCommand) (*RefreshSubscriptionTokenResult, error)
type RenewSubscriptionUseCase ¶
type RenewSubscriptionUseCase struct {
// contains filtered or unexported fields
}
func NewRenewSubscriptionUseCase ¶
func NewRenewSubscriptionUseCase( subscriptionRepo subscription.SubscriptionRepository, planRepo subscription.PlanRepository, pricingRepo subscription.PlanPricingRepository, logger logger.Interface, ) *RenewSubscriptionUseCase
func (*RenewSubscriptionUseCase) Execute ¶
func (uc *RenewSubscriptionUseCase) Execute(ctx context.Context, cmd RenewSubscriptionCommand) error
func (*RenewSubscriptionUseCase) SetSubscriptionNotifier ¶ added in v0.1.57
func (uc *RenewSubscriptionUseCase) SetSubscriptionNotifier(notifier SubscriptionChangeNotifier)
SetSubscriptionNotifier sets the subscription change notifier (optional).
type ResetSubscriptionLinkCommand ¶ added in v0.0.3
type ResetSubscriptionLinkCommand struct {
SubscriptionID uint
}
type ResetSubscriptionLinkUseCase ¶ added in v0.0.3
type ResetSubscriptionLinkUseCase struct {
// contains filtered or unexported fields
}
func NewResetSubscriptionLinkUseCase ¶ added in v0.0.3
func NewResetSubscriptionLinkUseCase( subscriptionRepo subscription.SubscriptionRepository, planRepo subscription.PlanRepository, userRepo user.Repository, logger logger.Interface, baseURL string, onlineDeviceCounter OnlineDeviceCounter, ) *ResetSubscriptionLinkUseCase
func (*ResetSubscriptionLinkUseCase) Execute ¶ added in v0.0.3
func (uc *ResetSubscriptionLinkUseCase) Execute(ctx context.Context, cmd ResetSubscriptionLinkCommand) (*dto.SubscriptionDTO, error)
type ResetSubscriptionUsageCommand ¶ added in v0.1.65
type ResetSubscriptionUsageCommand struct {
SubscriptionID uint
}
ResetSubscriptionUsageCommand represents the command to reset subscription usage
type ResetSubscriptionUsageUseCase ¶ added in v0.1.65
type ResetSubscriptionUsageUseCase struct {
// contains filtered or unexported fields
}
ResetSubscriptionUsageUseCase handles resetting subscription usage
func NewResetSubscriptionUsageUseCase ¶ added in v0.1.65
func NewResetSubscriptionUsageUseCase( subscriptionRepo subscription.SubscriptionRepository, logger logger.Interface, ) *ResetSubscriptionUsageUseCase
NewResetSubscriptionUsageUseCase creates a new instance of ResetSubscriptionUsageUseCase
func (*ResetSubscriptionUsageUseCase) Execute ¶ added in v0.1.65
func (uc *ResetSubscriptionUsageUseCase) Execute(ctx context.Context, cmd ResetSubscriptionUsageCommand) error
Execute resets a subscription's usage by updating the period start time
func (*ResetSubscriptionUsageUseCase) SetQuotaCacheManager ¶ added in v0.1.65
func (uc *ResetSubscriptionUsageUseCase) SetQuotaCacheManager(manager QuotaCacheManager)
SetQuotaCacheManager sets the quota cache manager (optional).
func (*ResetSubscriptionUsageUseCase) SetSubscriptionNotifier ¶ added in v0.1.65
func (uc *ResetSubscriptionUsageUseCase) SetSubscriptionNotifier(notifier SubscriptionChangeNotifier)
SetSubscriptionNotifier sets the subscription change notifier (optional).
type RevokeSubscriptionTokenCommand ¶
type RevokeSubscriptionTokenCommand struct {
TokenID uint
}
type RevokeSubscriptionTokenUseCase ¶
type RevokeSubscriptionTokenUseCase struct {
// contains filtered or unexported fields
}
func NewRevokeSubscriptionTokenUseCase ¶
func NewRevokeSubscriptionTokenUseCase( tokenRepo subscription.SubscriptionTokenRepository, logger logger.Interface, ) *RevokeSubscriptionTokenUseCase
func (*RevokeSubscriptionTokenUseCase) Execute ¶
func (uc *RevokeSubscriptionTokenUseCase) Execute(ctx context.Context, cmd RevokeSubscriptionTokenCommand) error
type SubscriptionChangeNotifier ¶ added in v0.1.57
type SubscriptionChangeNotifier interface {
// NotifySubscriptionActivation notifies nodes when a subscription becomes active.
NotifySubscriptionActivation(ctx context.Context, sub *subscription.Subscription) error
// NotifySubscriptionDeactivation notifies nodes when a subscription is deactivated/expired/cancelled.
NotifySubscriptionDeactivation(ctx context.Context, sub *subscription.Subscription) error
// NotifySubscriptionUpdate notifies nodes when a subscription is updated.
NotifySubscriptionUpdate(ctx context.Context, sub *subscription.Subscription) error
}
SubscriptionChangeNotifier defines the interface for notifying subscription changes to node agents.
type SubscriptionUsageStatsRecord ¶ added in v0.1.6
type SubscriptionUsageStatsRecord struct {
ResourceType string `json:"resource_type"`
ResourceSID string `json:"resource_id"` // Stripe-style SID (node_xxx or fwd_xxx)
Upload uint64 `json:"upload"`
Download uint64 `json:"download"`
Total uint64 `json:"total"`
Period time.Time `json:"period"`
}
SubscriptionUsageStatsRecord represents a single usage stats record
type SubscriptionUsageSummary ¶ added in v0.1.6
type SubscriptionUsageSummary struct {
TotalUpload uint64 `json:"total_upload"`
TotalDownload uint64 `json:"total_download"`
Total uint64 `json:"total"`
}
SubscriptionUsageSummary represents aggregated usage summary
type SuspendSubscriptionCommand ¶ added in v0.1.65
SuspendSubscriptionCommand represents the command to suspend a subscription
type SuspendSubscriptionUseCase ¶ added in v0.1.65
type SuspendSubscriptionUseCase struct {
// contains filtered or unexported fields
}
SuspendSubscriptionUseCase handles suspending subscriptions
func NewSuspendSubscriptionUseCase ¶ added in v0.1.65
func NewSuspendSubscriptionUseCase( subscriptionRepo subscription.SubscriptionRepository, logger logger.Interface, ) *SuspendSubscriptionUseCase
NewSuspendSubscriptionUseCase creates a new instance of SuspendSubscriptionUseCase
func (*SuspendSubscriptionUseCase) Execute ¶ added in v0.1.65
func (uc *SuspendSubscriptionUseCase) Execute(ctx context.Context, cmd SuspendSubscriptionCommand) error
Execute suspends a subscription
func (*SuspendSubscriptionUseCase) SetSubscriptionNotifier ¶ added in v0.1.65
func (uc *SuspendSubscriptionUseCase) SetSubscriptionNotifier(notifier SubscriptionChangeNotifier)
SetSubscriptionNotifier sets the subscription change notifier (optional).
type TokenGenerator ¶
type UnsuspendSubscriptionCommand ¶ added in v0.1.65
type UnsuspendSubscriptionCommand struct {
SubscriptionID uint
}
UnsuspendSubscriptionCommand represents the command to unsuspend a subscription
type UnsuspendSubscriptionUseCase ¶ added in v0.1.65
type UnsuspendSubscriptionUseCase struct {
// contains filtered or unexported fields
}
UnsuspendSubscriptionUseCase handles unsuspending (reactivating) subscriptions
func NewUnsuspendSubscriptionUseCase ¶ added in v0.1.65
func NewUnsuspendSubscriptionUseCase( subscriptionRepo subscription.SubscriptionRepository, logger logger.Interface, ) *UnsuspendSubscriptionUseCase
NewUnsuspendSubscriptionUseCase creates a new instance of UnsuspendSubscriptionUseCase
func (*UnsuspendSubscriptionUseCase) Execute ¶ added in v0.1.65
func (uc *UnsuspendSubscriptionUseCase) Execute(ctx context.Context, cmd UnsuspendSubscriptionCommand) error
Execute unsuspends a subscription
func (*UnsuspendSubscriptionUseCase) SetQuotaCacheManager ¶ added in v0.1.65
func (uc *UnsuspendSubscriptionUseCase) SetQuotaCacheManager(manager QuotaCacheManager)
SetQuotaCacheManager sets the quota cache manager (optional).
func (*UnsuspendSubscriptionUseCase) SetSubscriptionNotifier ¶ added in v0.1.65
func (uc *UnsuspendSubscriptionUseCase) SetSubscriptionNotifier(notifier SubscriptionChangeNotifier)
SetSubscriptionNotifier sets the subscription change notifier (optional).
type UpdatePlanCommand ¶ added in v0.1.6
type UpdatePlanUseCase ¶ added in v0.1.6
type UpdatePlanUseCase struct {
// contains filtered or unexported fields
}
func NewUpdatePlanUseCase ¶ added in v0.1.6
func NewUpdatePlanUseCase( planRepo subscription.PlanRepository, pricingRepo subscription.PlanPricingRepository, logger logger.Interface, ) *UpdatePlanUseCase
func (*UpdatePlanUseCase) Execute ¶ added in v0.1.6
func (uc *UpdatePlanUseCase) Execute( ctx context.Context, cmd UpdatePlanCommand, ) (*dto.PlanDTO, error)
func (*UpdatePlanUseCase) SetPlanChangeNotifier ¶ added in v0.1.93
func (uc *UpdatePlanUseCase) SetPlanChangeNotifier(notifier PlanChangeNotifier)
SetPlanChangeNotifier sets the notifier for plan feature changes.
type ValidateSubscriptionTokenResult ¶
type ValidateSubscriptionTokenResult struct {
Token *subscription.SubscriptionToken
Subscription *subscription.Subscription
Plan *subscription.Plan
}
type ValidateSubscriptionTokenUseCase ¶
type ValidateSubscriptionTokenUseCase struct {
// contains filtered or unexported fields
}
func NewValidateSubscriptionTokenUseCase ¶
func NewValidateSubscriptionTokenUseCase( tokenRepo subscription.SubscriptionTokenRepository, subscriptionRepo subscription.SubscriptionRepository, planRepo subscription.PlanRepository, tokenGenerator TokenGenerator, logger logger.Interface, ) *ValidateSubscriptionTokenUseCase
func (*ValidateSubscriptionTokenUseCase) Execute ¶
func (uc *ValidateSubscriptionTokenUseCase) Execute(ctx context.Context, cmd ValidateSubscriptionTokenCommand) (*ValidateSubscriptionTokenResult, error)
Source Files
¶
- activateplan.go
- activatesubscription.go
- aggregateusage.go
- cancelsubscription.go
- changeplan.go
- createplan.go
- createsubscription.go
- deactivateplan.go
- deleteplan.go
- deletesubscription.go
- expiresubscriptions.go
- generatesubscriptiontoken.go
- getplan.go
- getplanpricings.go
- getpublicplans.go
- getsubscription.go
- getsubscriptionusagestats.go
- interfaces.go
- listplans.go
- listsubscriptiontokens.go
- listusersubscriptions.go
- onlinedevicecounter.go
- quotaservice.go
- refreshsubscriptiontoken.go
- renewsubscription.go
- resetsubscriptionlink.go
- resetsubscriptionusage.go
- revokesubscriptiontoken.go
- suspendsubscription.go
- updateplan.go
- validatesubscriptiontoken.go