usecases

package
v0.1.93 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package usecases provides application-level use cases for subscription management.

Index

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

func (*ActivatePlanUseCase) Execute added in v0.1.6

func (uc *ActivatePlanUseCase) Execute(ctx context.Context, planSID string) error

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 (*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

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 CancelSubscriptionCommand

type CancelSubscriptionCommand struct {
	SubscriptionID uint
	Reason         string
	Immediate      bool
}

type CancelSubscriptionUseCase

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

func (*CancelSubscriptionUseCase) Execute

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

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 (*CreateSubscriptionUseCase) Execute

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

func (*DeactivatePlanUseCase) Execute added in v0.1.6

func (uc *DeactivatePlanUseCase) Execute(ctx context.Context, planSID string) error

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

func (*DeletePlanUseCase) Execute added in v0.1.26

func (uc *DeletePlanUseCase) Execute(ctx context.Context, planSID string) error

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

func (*DeleteSubscriptionUseCase) Execute added in v0.1.26

func (uc *DeleteSubscriptionUseCase) Execute(ctx context.Context, subscriptionID uint) error

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

func (*ExpireSubscriptionsUseCase) Execute added in v0.1.74

func (uc *ExpireSubscriptionsUseCase) Execute(ctx context.Context) (int, error)

Execute finds and marks all expired subscriptions. Returns the number of subscriptions marked as expired.

type GenerateSubscriptionTokenCommand

type GenerateSubscriptionTokenCommand struct {
	SubscriptionID uint
	Name           string
	Scope          string
	ExpiresAt      *time.Time
}

type GenerateSubscriptionTokenResult

type GenerateSubscriptionTokenResult struct {
	Token     string     `json:"token"`
	TokenID   uint       `json:"token_id"`
	Prefix    string     `json:"prefix"`
	ExpiresAt *time.Time `json:"expires_at,omitempty"`
	CreatedAt time.Time  `json:"created_at"`
}

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

type GetPlanPricingsQuery

type GetPlanPricingsQuery struct {
	PlanSID string
}

type GetPlanPricingsUseCase

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

func (*GetPlanPricingsUseCase) Execute

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 (uc *GetPlanUseCase) ExecuteByID(ctx context.Context, planID uint) (*dto.PlanDTO, error)

func (*GetPlanUseCase) ExecuteBySID added in v0.1.6

func (uc *GetPlanUseCase) ExecuteBySID(ctx context.Context, sid string) (*dto.PlanDTO, error)

func (*GetPlanUseCase) ExecuteBySlug added in v0.1.6

func (uc *GetPlanUseCase) ExecuteBySlug(ctx context.Context, slug string) (*dto.PlanDTO, error)

type GetPublicPlansUseCase

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

func (*GetPublicPlansUseCase) Execute

func (uc *GetPublicPlansUseCase) Execute(ctx context.Context) ([]*dto.PlanDTO, error)

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

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 (*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 ListPlansQuery struct {
	Status   *string
	IsPublic *bool
	PlanType *string // Optional: filter by plan type ("node" or "forward")
	Page     int
	PageSize int
}

type ListPlansResult added in v0.1.6

type ListPlansResult struct {
	Plans []*dto.PlanDTO `json:"plans"`
	Total int64          `json:"total"`
}

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 ListSubscriptionTokensQuery

type ListSubscriptionTokensQuery struct {
	SubscriptionID uint
	ActiveOnly     bool
}

type ListSubscriptionTokensUseCase

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

func (*ListSubscriptionTokensUseCase) Execute

type ListUserSubscriptionsQuery

type ListUserSubscriptionsQuery struct {
	UserID        *uint // nil means all users (admin only)
	PlanID        *uint
	Status        *string
	BillingCycle  *string
	CreatedFrom   *time.Time
	CreatedTo     *time.Time
	ExpiresBefore *time.Time
	Page          int
	PageSize      int
	SortBy        string
	SortDesc      *bool // nil means default (true = DESC)
}

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

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

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 RefreshSubscriptionTokenResult

type RefreshSubscriptionTokenResult struct {
	NewToken  string     `json:"new_token"`
	TokenID   uint       `json:"token_id"`
	ExpiresAt *time.Time `json:"expires_at,omitempty"`
}

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

type RenewSubscriptionCommand

type RenewSubscriptionCommand struct {
	SubscriptionID uint
	BillingCycle   string // Optional: billing cycle for renewal period. If empty, uses current subscription's billing cycle.
	IsAutoRenew    bool
}

type RenewSubscriptionUseCase

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

func (*RenewSubscriptionUseCase) Execute

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

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

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 (*RevokeSubscriptionTokenUseCase) Execute

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

type SuspendSubscriptionCommand struct {
	SubscriptionID uint
	Reason         string
}

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

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 TokenGenerator interface {
	Generate(prefix string) (plainToken string, hash string, err error)
	Hash(plainToken string) string
}

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

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 UpdatePlanCommand struct {
	PlanSID     string
	Description *string
	Limits      *map[string]interface{}
	NodeLimit   *int // Maximum number of user nodes (nil or 0 = unlimited)
	SortOrder   *int
	IsPublic    *bool
	Pricings    *[]dto.PricingOptionInput // Optional: update pricing options
}

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 ValidateSubscriptionTokenCommand

type ValidateSubscriptionTokenCommand struct {
	PlainToken    string
	RequiredScope string
	IPAddress     string
}

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 (*ValidateSubscriptionTokenUseCase) Execute

Jump to

Keyboard shortcuts

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