Files
stream.api/internal/repository/billing_repository.go
lethdat a0ae2b681a feat: Implement video workflow repository and related services
- Added videoWorkflowRepository with methods to manage video and user interactions.
- Introduced catalog_mapper for converting database models to protobuf representations.
- Created domain_helpers for normalizing domain and ad format values.
- Defined service interfaces for payment, account, notification, domain, ad template, player config, video, and user management.
- Implemented OAuth helpers for generating state and caching keys.
- Developed payment_proto_helpers for mapping payment-related models to protobuf.
- Added service policy helpers to enforce plan requirements and user permissions.
- Created user_mapper for converting user payloads to protobuf format.
- Implemented value_helpers for handling various value conversions and nil checks.
- Developed video_helpers for normalizing video statuses and managing storage types.
- Created video_mapper for mapping video models to protobuf format.
- Implemented render workflow for managing video creation and job processing.
2026-03-26 18:38:47 +07:00

42 lines
1.2 KiB
Go

package repository
import (
"context"
"time"
"gorm.io/gorm"
"stream.api/internal/database/model"
)
type billingRepository struct {
db *gorm.DB
}
func NewBillingRepository(db *gorm.DB) *billingRepository {
return &billingRepository{db: db}
}
func (r *billingRepository) GetWalletBalance(ctx context.Context, userID string) (float64, error) {
return model.GetWalletBalance(ctx, r.db, userID)
}
func (r *billingRepository) GetWalletBalanceTx(tx *gorm.DB, ctx context.Context, userID string) (float64, error) {
return model.GetWalletBalance(ctx, tx, userID)
}
func (r *billingRepository) GetLatestPlanSubscription(ctx context.Context, userID string) (*model.PlanSubscription, error) {
return model.GetLatestPlanSubscription(ctx, r.db, userID)
}
func (r *billingRepository) GetLatestPlanSubscriptionTx(tx *gorm.DB, ctx context.Context, userID string) (*model.PlanSubscription, error) {
return model.GetLatestPlanSubscription(ctx, tx, userID)
}
func (r *billingRepository) CountActiveSubscriptions(ctx context.Context, now time.Time) (int64, error) {
var count int64
if err := r.db.WithContext(ctx).Model(&model.PlanSubscription{}).Where("expires_at > ?", now).Count(&count).Error; err != nil {
return 0, err
}
return count, nil
}