draft grpc

This commit is contained in:
2026-03-13 02:17:18 +00:00
parent ea2edbb9e0
commit 91e5e3542b
116 changed files with 44505 additions and 558 deletions

View File

@@ -0,0 +1,32 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package model
import (
"time"
)
const TableNameAdTemplate = "ad_templates"
// AdTemplate mapped from table <ad_templates>
type AdTemplate struct {
ID string `gorm:"column:id;type:uuid;primaryKey" json:"id"`
UserID string `gorm:"column:user_id;type:uuid;not null;index:idx_ad_templates_user_id,priority:1" json:"user_id"`
Name string `gorm:"column:name;type:text;not null" json:"name"`
Description *string `gorm:"column:description;type:text" json:"description"`
VastTagURL string `gorm:"column:vast_tag_url;type:text;not null" json:"vast_tag_url"`
AdFormat *string `gorm:"column:ad_format;type:character varying(50);not null;default:pre-roll" json:"ad_format"`
Duration *int64 `gorm:"column:duration;type:bigint" json:"duration"`
IsActive *bool `gorm:"column:is_active;type:boolean;not null;default:true" json:"is_active"`
CreatedAt *time.Time `gorm:"column:created_at;type:timestamp with time zone" json:"created_at"`
UpdatedAt *time.Time `gorm:"column:updated_at;type:timestamp with time zone" json:"updated_at"`
IsDefault bool `gorm:"column:is_default;type:boolean;not null" json:"is_default"`
Version *int64 `gorm:"column:version;type:bigint;not null;default:1;version" json:"-"`
}
// TableName AdTemplate's table name
func (*AdTemplate) TableName() string {
return TableNameAdTemplate
}

View File

@@ -0,0 +1,26 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package model
import (
"time"
)
const TableNameDomain = "domains"
// Domain mapped from table <domains>
type Domain struct {
ID string `gorm:"column:id;type:uuid;primaryKey" json:"id"`
UserID string `gorm:"column:user_id;type:uuid;not null;index:idx_domains_user_id,priority:1" json:"user_id"`
Name string `gorm:"column:name;type:text;not null" json:"name"`
CreatedAt *time.Time `gorm:"column:created_at;type:timestamp with time zone" json:"created_at"`
UpdatedAt *time.Time `gorm:"column:updated_at;type:timestamp with time zone" json:"updated_at"`
Version *int64 `gorm:"column:version;type:bigint;not null;default:1;version" json:"-"`
}
// TableName Domain's table name
func (*Domain) TableName() string {
return TableNameDomain
}

View File

@@ -0,0 +1,138 @@
package model
import (
"context"
"errors"
"strings"
"time"
"gorm.io/gorm"
)
const (
defaultPreferenceLanguage = "en"
defaultPreferenceLocale = "en"
)
func DefaultUserPreference(userID string) *UserPreference {
return &UserPreference{
UserID: userID,
Language: StringPtr(defaultPreferenceLanguage),
Locale: StringPtr(defaultPreferenceLocale),
EmailNotifications: BoolPtr(true),
PushNotifications: BoolPtr(true),
MarketingNotifications: false,
TelegramNotifications: false,
Autoplay: false,
Loop: false,
Muted: false,
ShowControls: BoolPtr(true),
Pip: BoolPtr(true),
Airplay: BoolPtr(true),
Chromecast: BoolPtr(true),
}
}
func FindOrCreateUserPreference(ctx context.Context, db *gorm.DB, userID string) (*UserPreference, error) {
var pref UserPreference
if err := db.WithContext(ctx).Where("user_id = ?", userID).First(&pref).Error; err == nil {
normalizeUserPreferenceDefaults(&pref)
return &pref, nil
} else if !errors.Is(err, gorm.ErrRecordNotFound) {
return nil, err
}
pref = *DefaultUserPreference(userID)
if err := db.WithContext(ctx).Create(&pref).Error; err != nil {
return nil, err
}
return &pref, nil
}
func GetWalletBalance(ctx context.Context, db *gorm.DB, userID string) (float64, error) {
var balance float64
if err := db.WithContext(ctx).
Model(&WalletTransaction{}).
Where("user_id = ?", userID).
Select("COALESCE(SUM(amount), 0)").
Scan(&balance).Error; err != nil {
return 0, err
}
return balance, nil
}
func GetLatestPlanSubscription(ctx context.Context, db *gorm.DB, userID string) (*PlanSubscription, error) {
userID = strings.TrimSpace(userID)
if userID == "" {
return nil, gorm.ErrRecordNotFound
}
var subscription PlanSubscription
if err := db.WithContext(ctx).
Where("user_id = ?", userID).
Order("created_at DESC").
Order("id DESC").
First(&subscription).Error; err != nil {
return nil, err
}
return &subscription, nil
}
func IsSubscriptionExpiringSoon(expiresAt time.Time, now time.Time) bool {
if expiresAt.IsZero() || !expiresAt.After(now) {
return false
}
return expiresAt.Sub(now) <= 7*24*time.Hour
}
func normalizeUserPreferenceDefaults(pref *UserPreference) {
if pref == nil {
return
}
if strings.TrimSpace(StringValue(pref.Language)) == "" {
pref.Language = StringPtr(defaultPreferenceLanguage)
}
if strings.TrimSpace(StringValue(pref.Locale)) == "" {
locale := StringValue(pref.Language)
if strings.TrimSpace(locale) == "" {
locale = defaultPreferenceLocale
}
pref.Locale = StringPtr(locale)
}
if pref.EmailNotifications == nil {
pref.EmailNotifications = BoolPtr(true)
}
if pref.PushNotifications == nil {
pref.PushNotifications = BoolPtr(true)
}
if pref.ShowControls == nil {
pref.ShowControls = BoolPtr(true)
}
if pref.Pip == nil {
pref.Pip = BoolPtr(true)
}
if pref.Airplay == nil {
pref.Airplay = BoolPtr(true)
}
if pref.Chromecast == nil {
pref.Chromecast = BoolPtr(true)
}
}
func StringPtr(value string) *string {
v := value
return &v
}
func BoolPtr(value bool) *bool {
v := value
return &v
}
func StringValue(value *string) string {
if value == nil {
return ""
}
return *value
}

View File

@@ -0,0 +1,37 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package model
import (
"time"
)
const TableNameJob = "jobs"
// Job mapped from table <jobs>
type Job struct {
ID string `gorm:"column:id;type:text;primaryKey" json:"id"`
Status *string `gorm:"column:status;type:text" json:"status"`
Priority *int64 `gorm:"column:priority;type:bigint;index:idx_jobs_priority,priority:1" json:"priority"`
InputURL *string `gorm:"column:input_url;type:text" json:"input_url"`
OutputURL *string `gorm:"column:output_url;type:text" json:"output_url"`
TotalDuration *int64 `gorm:"column:total_duration;type:bigint" json:"total_duration"`
CurrentTime *int64 `gorm:"column:current_time;type:bigint" json:"current_time"`
Progress *float64 `gorm:"column:progress;type:numeric" json:"progress"`
AgentID *int64 `gorm:"column:agent_id;type:bigint" json:"agent_id"`
Logs *string `gorm:"column:logs;type:text" json:"logs"`
Config *string `gorm:"column:config;type:text" json:"config"`
Cancelled *bool `gorm:"column:cancelled;type:boolean" json:"cancelled"`
RetryCount *int64 `gorm:"column:retry_count;type:bigint" json:"retry_count"`
MaxRetries *int64 `gorm:"column:max_retries;type:bigint;default:3" json:"max_retries"`
CreatedAt *time.Time `gorm:"column:created_at;type:timestamp with time zone" json:"created_at"`
UpdatedAt *time.Time `gorm:"column:updated_at;type:timestamp with time zone" json:"updated_at"`
Version *int64 `gorm:"column:version;type:bigint;version" json:"-"`
}
// TableName Job's table name
func (*Job) TableName() string {
return TableNameJob
}

View File

@@ -0,0 +1,32 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package model
import (
"time"
)
const TableNameNotification = "notifications"
// Notification mapped from table <notifications>
type Notification struct {
ID string `gorm:"column:id;type:uuid;primaryKey" json:"id"`
UserID string `gorm:"column:user_id;type:uuid;not null;index:idx_notifications_user_id,priority:1" json:"user_id"`
Type string `gorm:"column:type;type:character varying(50);not null" json:"type"`
Title string `gorm:"column:title;type:text;not null" json:"title"`
Message string `gorm:"column:message;type:text;not null" json:"message"`
Metadata *string `gorm:"column:metadata;type:text" json:"metadata"`
ActionURL *string `gorm:"column:action_url;type:text" json:"action_url"`
ActionLabel *string `gorm:"column:action_label;type:text" json:"action_label"`
IsRead bool `gorm:"column:is_read;type:boolean;not null" json:"is_read"`
CreatedAt *time.Time `gorm:"column:created_at;type:timestamp with time zone" json:"created_at"`
UpdatedAt *time.Time `gorm:"column:updated_at;type:timestamp with time zone" json:"updated_at"`
Version *int64 `gorm:"column:version;type:bigint;not null;default:1;version" json:"-"`
}
// TableName Notification's table name
func (*Notification) TableName() string {
return TableNameNotification
}

View File

@@ -4,22 +4,26 @@
package model
import (
"github.com/lib/pq"
)
const TableNamePlan = "plan"
// Plan mapped from table <plan>
type Plan struct {
ID string `gorm:"column:id;type:uuid;primaryKey;default:gen_random_uuid()" json:"id"`
Name string `gorm:"column:name;type:text;not null" json:"name"`
Description *string `gorm:"column:description;type:text" json:"description"`
Price float64 `gorm:"column:price;type:numeric(65,30);not null" json:"price"`
Cycle string `gorm:"column:cycle;type:character varying(20);not null" json:"cycle"`
StorageLimit int64 `gorm:"column:storage_limit;type:bigint;not null" json:"storage_limit"`
UploadLimit int32 `gorm:"column:upload_limit;type:integer;not null" json:"upload_limit"`
DurationLimit int32 `gorm:"column:duration_limit;type:integer;not null" json:"duration_limit"`
QualityLimit string `gorm:"column:quality_limit;type:text;not null" json:"quality_limit"`
Features *string `gorm:"column:features;type:text[]" json:"features"`
IsActive *bool `gorm:"column:is_active;type:boolean;not null;default:true" json:"is_active"`
Version *int64 `gorm:"column:version;type:bigint;not null;default:1;version" json:"-"`
ID string `gorm:"column:id;type:uuid;primaryKey;default:gen_random_uuid()" json:"id"`
Name string `gorm:"column:name;type:text;not null" json:"name"`
Description *string `gorm:"column:description;type:text" json:"description"`
Price float64 `gorm:"column:price;type:numeric(65,30);not null" json:"price"`
Cycle string `gorm:"column:cycle;type:character varying(20);not null" json:"cycle"`
StorageLimit int64 `gorm:"column:storage_limit;type:bigint;not null" json:"storage_limit"`
UploadLimit int32 `gorm:"column:upload_limit;type:integer;not null" json:"upload_limit"`
DurationLimit int32 `gorm:"column:duration_limit;type:integer;not null" json:"duration_limit"`
QualityLimit string `gorm:"column:quality_limit;type:text;not null" json:"quality_limit"`
Features pq.StringArray `gorm:"column:features;type:text[]" json:"features"`
IsActive *bool `gorm:"column:is_active;type:boolean;not null;default:true" json:"is_active"`
Version *int64 `gorm:"column:version;type:bigint;not null;default:1;version" json:"-"`
}
// TableName Plan's table name

View File

@@ -0,0 +1,36 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package model
import (
"time"
)
const TableNamePlanSubscription = "plan_subscriptions"
// PlanSubscription mapped from table <plan_subscriptions>
type PlanSubscription struct {
ID string `gorm:"column:id;type:uuid;primaryKey" json:"id"`
UserID string `gorm:"column:user_id;type:uuid;not null;index:idx_plan_subscriptions_user_id,priority:1" json:"user_id"`
PaymentID string `gorm:"column:payment_id;type:uuid;not null;index:idx_plan_subscriptions_payment_id,priority:1" json:"payment_id"`
PlanID string `gorm:"column:plan_id;type:uuid;not null;index:idx_plan_subscriptions_plan_id,priority:1" json:"plan_id"`
TermMonths int32 `gorm:"column:term_months;type:integer;not null" json:"term_months"`
PaymentMethod string `gorm:"column:payment_method;type:character varying(20);not null" json:"payment_method"`
WalletAmount float64 `gorm:"column:wallet_amount;type:numeric(65,30);not null" json:"wallet_amount"`
TopupAmount float64 `gorm:"column:topup_amount;type:numeric(65,30);not null" json:"topup_amount"`
StartedAt time.Time `gorm:"column:started_at;type:timestamp with time zone;not null" json:"started_at"`
ExpiresAt time.Time `gorm:"column:expires_at;type:timestamp with time zone;not null;index:idx_plan_subscriptions_expires_at,priority:1" json:"expires_at"`
Reminder7DSentAt *time.Time `gorm:"column:reminder_7d_sent_at;type:timestamp with time zone" json:"reminder_7d_sent_at"`
Reminder3DSentAt *time.Time `gorm:"column:reminder_3d_sent_at;type:timestamp with time zone" json:"reminder_3d_sent_at"`
Reminder1DSentAt *time.Time `gorm:"column:reminder_1d_sent_at;type:timestamp with time zone" json:"reminder_1d_sent_at"`
CreatedAt *time.Time `gorm:"column:created_at;type:timestamp with time zone" json:"created_at"`
UpdatedAt *time.Time `gorm:"column:updated_at;type:timestamp with time zone" json:"updated_at"`
Version *int64 `gorm:"column:version;type:bigint;not null;default:1;version" json:"-"`
}
// TableName PlanSubscription's table name
func (*PlanSubscription) TableName() string {
return TableNamePlanSubscription
}

View File

@@ -0,0 +1,38 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package model
import (
"time"
)
const TableNameUserPreference = "user_preferences"
// UserPreference mapped from table <user_preferences>
type UserPreference struct {
UserID string `gorm:"column:user_id;type:uuid;primaryKey" json:"user_id"`
Language *string `gorm:"column:language;type:text;not null;default:en" json:"language"`
Locale *string `gorm:"column:locale;type:text;not null;default:en" json:"locale"`
EmailNotifications *bool `gorm:"column:email_notifications;type:boolean;not null;default:true" json:"email_notifications"`
PushNotifications *bool `gorm:"column:push_notifications;type:boolean;not null;default:true" json:"push_notifications"`
MarketingNotifications bool `gorm:"column:marketing_notifications;type:boolean;not null" json:"marketing_notifications"`
TelegramNotifications bool `gorm:"column:telegram_notifications;type:boolean;not null" json:"telegram_notifications"`
Autoplay bool `gorm:"column:autoplay;type:boolean;not null" json:"autoplay"`
Loop bool `gorm:"column:loop;type:boolean;not null" json:"loop"`
Muted bool `gorm:"column:muted;type:boolean;not null" json:"muted"`
ShowControls *bool `gorm:"column:show_controls;type:boolean;not null;default:true" json:"show_controls"`
Pip *bool `gorm:"column:pip;type:boolean;not null;default:true" json:"pip"`
Airplay *bool `gorm:"column:airplay;type:boolean;not null;default:true" json:"airplay"`
Chromecast *bool `gorm:"column:chromecast;type:boolean;not null;default:true" json:"chromecast"`
CreatedAt *time.Time `gorm:"column:created_at;type:timestamp with time zone" json:"created_at"`
UpdatedAt *time.Time `gorm:"column:updated_at;type:timestamp with time zone" json:"updated_at"`
EncrytionM3u8 bool `gorm:"column:encrytion_m3u8;type:boolean;not null" json:"encrytion_m3u8"`
Version *int64 `gorm:"column:version;type:bigint;not null;default:1;version" json:"-"`
}
// TableName UserPreference's table name
func (*UserPreference) TableName() string {
return TableNameUserPreference
}

View File

@@ -0,0 +1,29 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package model
import (
"time"
)
const TableNameVideoAdConfig = "video_ad_configs"
// VideoAdConfig mapped from table <video_ad_configs>
type VideoAdConfig struct {
VideoID string `gorm:"column:video_id;type:uuid;primaryKey" json:"video_id"`
UserID string `gorm:"column:user_id;type:uuid;not null;index:idx_video_ad_configs_user_id,priority:1" json:"user_id"`
AdTemplateID string `gorm:"column:ad_template_id;type:uuid;not null" json:"ad_template_id"`
VastTagURL string `gorm:"column:vast_tag_url;type:text;not null" json:"vast_tag_url"`
AdFormat *string `gorm:"column:ad_format;type:character varying(50);not null;default:pre-roll" json:"ad_format"`
Duration *int64 `gorm:"column:duration;type:bigint" json:"duration"`
CreatedAt *time.Time `gorm:"column:created_at;type:timestamp with time zone" json:"created_at"`
UpdatedAt *time.Time `gorm:"column:updated_at;type:timestamp with time zone" json:"updated_at"`
Version *int64 `gorm:"column:version;type:bigint;not null;default:1;version" json:"-"`
}
// TableName VideoAdConfig's table name
func (*VideoAdConfig) TableName() string {
return TableNameVideoAdConfig
}

View File

@@ -0,0 +1,32 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package model
import (
"time"
)
const TableNameWalletTransaction = "wallet_transactions"
// WalletTransaction mapped from table <wallet_transactions>
type WalletTransaction struct {
ID string `gorm:"column:id;type:uuid;primaryKey" json:"id"`
UserID string `gorm:"column:user_id;type:uuid;not null;index:idx_wallet_transactions_user_id,priority:1" json:"user_id"`
Type string `gorm:"column:type;type:character varying(50);not null" json:"type"`
Amount float64 `gorm:"column:amount;type:numeric(65,30);not null" json:"amount"`
Currency *string `gorm:"column:currency;type:text;not null;default:USD" json:"currency"`
Note *string `gorm:"column:note;type:text" json:"note"`
CreatedAt *time.Time `gorm:"column:created_at;type:timestamp with time zone" json:"created_at"`
UpdatedAt *time.Time `gorm:"column:updated_at;type:timestamp with time zone" json:"updated_at"`
PaymentID *string `gorm:"column:payment_id;type:uuid;index:idx_wallet_transactions_payment_id,priority:1" json:"payment_id"`
PlanID *string `gorm:"column:plan_id;type:uuid;index:idx_wallet_transactions_plan_id,priority:1" json:"plan_id"`
TermMonths *int32 `gorm:"column:term_months;type:integer" json:"term_months"`
Version *int64 `gorm:"column:version;type:bigint;not null;default:1;version" json:"-"`
}
// TableName WalletTransaction's table name
func (*WalletTransaction) TableName() string {
return TableNameWalletTransaction
}