Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
97f14b7a
Unverified
Commit
97f14b7a
authored
Apr 11, 2026
by
Wesley Liddick
Committed by
GitHub
Apr 11, 2026
Browse files
Merge pull request #1572 from touwaeriol/feat/payment-system-v2
feat(payment): add complete payment system with multi-provider support
parents
1ef3782d
6793503e
Changes
174
Show whitespace changes
Inline
Side-by-side
backend/ent/subscriptionplan/where.go
0 → 100644
View file @
97f14b7a
// Code generated by ent, DO NOT EDIT.
package
subscriptionplan
import
(
"time"
"entgo.io/ent/dialect/sql"
"github.com/Wei-Shaw/sub2api/ent/predicate"
)
// ID filters vertices based on their ID field.
func
ID
(
id
int64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEQ
(
FieldID
,
id
))
}
// IDEQ applies the EQ predicate on the ID field.
func
IDEQ
(
id
int64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEQ
(
FieldID
,
id
))
}
// IDNEQ applies the NEQ predicate on the ID field.
func
IDNEQ
(
id
int64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldNEQ
(
FieldID
,
id
))
}
// IDIn applies the In predicate on the ID field.
func
IDIn
(
ids
...
int64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldIn
(
FieldID
,
ids
...
))
}
// IDNotIn applies the NotIn predicate on the ID field.
func
IDNotIn
(
ids
...
int64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldNotIn
(
FieldID
,
ids
...
))
}
// IDGT applies the GT predicate on the ID field.
func
IDGT
(
id
int64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldGT
(
FieldID
,
id
))
}
// IDGTE applies the GTE predicate on the ID field.
func
IDGTE
(
id
int64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldGTE
(
FieldID
,
id
))
}
// IDLT applies the LT predicate on the ID field.
func
IDLT
(
id
int64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldLT
(
FieldID
,
id
))
}
// IDLTE applies the LTE predicate on the ID field.
func
IDLTE
(
id
int64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldLTE
(
FieldID
,
id
))
}
// GroupID applies equality check predicate on the "group_id" field. It's identical to GroupIDEQ.
func
GroupID
(
v
int64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEQ
(
FieldGroupID
,
v
))
}
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
func
Name
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEQ
(
FieldName
,
v
))
}
// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ.
func
Description
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEQ
(
FieldDescription
,
v
))
}
// Price applies equality check predicate on the "price" field. It's identical to PriceEQ.
func
Price
(
v
float64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEQ
(
FieldPrice
,
v
))
}
// OriginalPrice applies equality check predicate on the "original_price" field. It's identical to OriginalPriceEQ.
func
OriginalPrice
(
v
float64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEQ
(
FieldOriginalPrice
,
v
))
}
// ValidityDays applies equality check predicate on the "validity_days" field. It's identical to ValidityDaysEQ.
func
ValidityDays
(
v
int
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEQ
(
FieldValidityDays
,
v
))
}
// ValidityUnit applies equality check predicate on the "validity_unit" field. It's identical to ValidityUnitEQ.
func
ValidityUnit
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEQ
(
FieldValidityUnit
,
v
))
}
// Features applies equality check predicate on the "features" field. It's identical to FeaturesEQ.
func
Features
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEQ
(
FieldFeatures
,
v
))
}
// ProductName applies equality check predicate on the "product_name" field. It's identical to ProductNameEQ.
func
ProductName
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEQ
(
FieldProductName
,
v
))
}
// ForSale applies equality check predicate on the "for_sale" field. It's identical to ForSaleEQ.
func
ForSale
(
v
bool
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEQ
(
FieldForSale
,
v
))
}
// SortOrder applies equality check predicate on the "sort_order" field. It's identical to SortOrderEQ.
func
SortOrder
(
v
int
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEQ
(
FieldSortOrder
,
v
))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func
CreatedAt
(
v
time
.
Time
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEQ
(
FieldCreatedAt
,
v
))
}
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
func
UpdatedAt
(
v
time
.
Time
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEQ
(
FieldUpdatedAt
,
v
))
}
// GroupIDEQ applies the EQ predicate on the "group_id" field.
func
GroupIDEQ
(
v
int64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEQ
(
FieldGroupID
,
v
))
}
// GroupIDNEQ applies the NEQ predicate on the "group_id" field.
func
GroupIDNEQ
(
v
int64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldNEQ
(
FieldGroupID
,
v
))
}
// GroupIDIn applies the In predicate on the "group_id" field.
func
GroupIDIn
(
vs
...
int64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldIn
(
FieldGroupID
,
vs
...
))
}
// GroupIDNotIn applies the NotIn predicate on the "group_id" field.
func
GroupIDNotIn
(
vs
...
int64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldNotIn
(
FieldGroupID
,
vs
...
))
}
// GroupIDGT applies the GT predicate on the "group_id" field.
func
GroupIDGT
(
v
int64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldGT
(
FieldGroupID
,
v
))
}
// GroupIDGTE applies the GTE predicate on the "group_id" field.
func
GroupIDGTE
(
v
int64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldGTE
(
FieldGroupID
,
v
))
}
// GroupIDLT applies the LT predicate on the "group_id" field.
func
GroupIDLT
(
v
int64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldLT
(
FieldGroupID
,
v
))
}
// GroupIDLTE applies the LTE predicate on the "group_id" field.
func
GroupIDLTE
(
v
int64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldLTE
(
FieldGroupID
,
v
))
}
// NameEQ applies the EQ predicate on the "name" field.
func
NameEQ
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEQ
(
FieldName
,
v
))
}
// NameNEQ applies the NEQ predicate on the "name" field.
func
NameNEQ
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldNEQ
(
FieldName
,
v
))
}
// NameIn applies the In predicate on the "name" field.
func
NameIn
(
vs
...
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldIn
(
FieldName
,
vs
...
))
}
// NameNotIn applies the NotIn predicate on the "name" field.
func
NameNotIn
(
vs
...
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldNotIn
(
FieldName
,
vs
...
))
}
// NameGT applies the GT predicate on the "name" field.
func
NameGT
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldGT
(
FieldName
,
v
))
}
// NameGTE applies the GTE predicate on the "name" field.
func
NameGTE
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldGTE
(
FieldName
,
v
))
}
// NameLT applies the LT predicate on the "name" field.
func
NameLT
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldLT
(
FieldName
,
v
))
}
// NameLTE applies the LTE predicate on the "name" field.
func
NameLTE
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldLTE
(
FieldName
,
v
))
}
// NameContains applies the Contains predicate on the "name" field.
func
NameContains
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldContains
(
FieldName
,
v
))
}
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
func
NameHasPrefix
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldHasPrefix
(
FieldName
,
v
))
}
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
func
NameHasSuffix
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldHasSuffix
(
FieldName
,
v
))
}
// NameEqualFold applies the EqualFold predicate on the "name" field.
func
NameEqualFold
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEqualFold
(
FieldName
,
v
))
}
// NameContainsFold applies the ContainsFold predicate on the "name" field.
func
NameContainsFold
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldContainsFold
(
FieldName
,
v
))
}
// DescriptionEQ applies the EQ predicate on the "description" field.
func
DescriptionEQ
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEQ
(
FieldDescription
,
v
))
}
// DescriptionNEQ applies the NEQ predicate on the "description" field.
func
DescriptionNEQ
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldNEQ
(
FieldDescription
,
v
))
}
// DescriptionIn applies the In predicate on the "description" field.
func
DescriptionIn
(
vs
...
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldIn
(
FieldDescription
,
vs
...
))
}
// DescriptionNotIn applies the NotIn predicate on the "description" field.
func
DescriptionNotIn
(
vs
...
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldNotIn
(
FieldDescription
,
vs
...
))
}
// DescriptionGT applies the GT predicate on the "description" field.
func
DescriptionGT
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldGT
(
FieldDescription
,
v
))
}
// DescriptionGTE applies the GTE predicate on the "description" field.
func
DescriptionGTE
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldGTE
(
FieldDescription
,
v
))
}
// DescriptionLT applies the LT predicate on the "description" field.
func
DescriptionLT
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldLT
(
FieldDescription
,
v
))
}
// DescriptionLTE applies the LTE predicate on the "description" field.
func
DescriptionLTE
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldLTE
(
FieldDescription
,
v
))
}
// DescriptionContains applies the Contains predicate on the "description" field.
func
DescriptionContains
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldContains
(
FieldDescription
,
v
))
}
// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field.
func
DescriptionHasPrefix
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldHasPrefix
(
FieldDescription
,
v
))
}
// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field.
func
DescriptionHasSuffix
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldHasSuffix
(
FieldDescription
,
v
))
}
// DescriptionEqualFold applies the EqualFold predicate on the "description" field.
func
DescriptionEqualFold
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEqualFold
(
FieldDescription
,
v
))
}
// DescriptionContainsFold applies the ContainsFold predicate on the "description" field.
func
DescriptionContainsFold
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldContainsFold
(
FieldDescription
,
v
))
}
// PriceEQ applies the EQ predicate on the "price" field.
func
PriceEQ
(
v
float64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEQ
(
FieldPrice
,
v
))
}
// PriceNEQ applies the NEQ predicate on the "price" field.
func
PriceNEQ
(
v
float64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldNEQ
(
FieldPrice
,
v
))
}
// PriceIn applies the In predicate on the "price" field.
func
PriceIn
(
vs
...
float64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldIn
(
FieldPrice
,
vs
...
))
}
// PriceNotIn applies the NotIn predicate on the "price" field.
func
PriceNotIn
(
vs
...
float64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldNotIn
(
FieldPrice
,
vs
...
))
}
// PriceGT applies the GT predicate on the "price" field.
func
PriceGT
(
v
float64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldGT
(
FieldPrice
,
v
))
}
// PriceGTE applies the GTE predicate on the "price" field.
func
PriceGTE
(
v
float64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldGTE
(
FieldPrice
,
v
))
}
// PriceLT applies the LT predicate on the "price" field.
func
PriceLT
(
v
float64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldLT
(
FieldPrice
,
v
))
}
// PriceLTE applies the LTE predicate on the "price" field.
func
PriceLTE
(
v
float64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldLTE
(
FieldPrice
,
v
))
}
// OriginalPriceEQ applies the EQ predicate on the "original_price" field.
func
OriginalPriceEQ
(
v
float64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEQ
(
FieldOriginalPrice
,
v
))
}
// OriginalPriceNEQ applies the NEQ predicate on the "original_price" field.
func
OriginalPriceNEQ
(
v
float64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldNEQ
(
FieldOriginalPrice
,
v
))
}
// OriginalPriceIn applies the In predicate on the "original_price" field.
func
OriginalPriceIn
(
vs
...
float64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldIn
(
FieldOriginalPrice
,
vs
...
))
}
// OriginalPriceNotIn applies the NotIn predicate on the "original_price" field.
func
OriginalPriceNotIn
(
vs
...
float64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldNotIn
(
FieldOriginalPrice
,
vs
...
))
}
// OriginalPriceGT applies the GT predicate on the "original_price" field.
func
OriginalPriceGT
(
v
float64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldGT
(
FieldOriginalPrice
,
v
))
}
// OriginalPriceGTE applies the GTE predicate on the "original_price" field.
func
OriginalPriceGTE
(
v
float64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldGTE
(
FieldOriginalPrice
,
v
))
}
// OriginalPriceLT applies the LT predicate on the "original_price" field.
func
OriginalPriceLT
(
v
float64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldLT
(
FieldOriginalPrice
,
v
))
}
// OriginalPriceLTE applies the LTE predicate on the "original_price" field.
func
OriginalPriceLTE
(
v
float64
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldLTE
(
FieldOriginalPrice
,
v
))
}
// OriginalPriceIsNil applies the IsNil predicate on the "original_price" field.
func
OriginalPriceIsNil
()
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldIsNull
(
FieldOriginalPrice
))
}
// OriginalPriceNotNil applies the NotNil predicate on the "original_price" field.
func
OriginalPriceNotNil
()
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldNotNull
(
FieldOriginalPrice
))
}
// ValidityDaysEQ applies the EQ predicate on the "validity_days" field.
func
ValidityDaysEQ
(
v
int
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEQ
(
FieldValidityDays
,
v
))
}
// ValidityDaysNEQ applies the NEQ predicate on the "validity_days" field.
func
ValidityDaysNEQ
(
v
int
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldNEQ
(
FieldValidityDays
,
v
))
}
// ValidityDaysIn applies the In predicate on the "validity_days" field.
func
ValidityDaysIn
(
vs
...
int
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldIn
(
FieldValidityDays
,
vs
...
))
}
// ValidityDaysNotIn applies the NotIn predicate on the "validity_days" field.
func
ValidityDaysNotIn
(
vs
...
int
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldNotIn
(
FieldValidityDays
,
vs
...
))
}
// ValidityDaysGT applies the GT predicate on the "validity_days" field.
func
ValidityDaysGT
(
v
int
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldGT
(
FieldValidityDays
,
v
))
}
// ValidityDaysGTE applies the GTE predicate on the "validity_days" field.
func
ValidityDaysGTE
(
v
int
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldGTE
(
FieldValidityDays
,
v
))
}
// ValidityDaysLT applies the LT predicate on the "validity_days" field.
func
ValidityDaysLT
(
v
int
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldLT
(
FieldValidityDays
,
v
))
}
// ValidityDaysLTE applies the LTE predicate on the "validity_days" field.
func
ValidityDaysLTE
(
v
int
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldLTE
(
FieldValidityDays
,
v
))
}
// ValidityUnitEQ applies the EQ predicate on the "validity_unit" field.
func
ValidityUnitEQ
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEQ
(
FieldValidityUnit
,
v
))
}
// ValidityUnitNEQ applies the NEQ predicate on the "validity_unit" field.
func
ValidityUnitNEQ
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldNEQ
(
FieldValidityUnit
,
v
))
}
// ValidityUnitIn applies the In predicate on the "validity_unit" field.
func
ValidityUnitIn
(
vs
...
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldIn
(
FieldValidityUnit
,
vs
...
))
}
// ValidityUnitNotIn applies the NotIn predicate on the "validity_unit" field.
func
ValidityUnitNotIn
(
vs
...
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldNotIn
(
FieldValidityUnit
,
vs
...
))
}
// ValidityUnitGT applies the GT predicate on the "validity_unit" field.
func
ValidityUnitGT
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldGT
(
FieldValidityUnit
,
v
))
}
// ValidityUnitGTE applies the GTE predicate on the "validity_unit" field.
func
ValidityUnitGTE
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldGTE
(
FieldValidityUnit
,
v
))
}
// ValidityUnitLT applies the LT predicate on the "validity_unit" field.
func
ValidityUnitLT
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldLT
(
FieldValidityUnit
,
v
))
}
// ValidityUnitLTE applies the LTE predicate on the "validity_unit" field.
func
ValidityUnitLTE
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldLTE
(
FieldValidityUnit
,
v
))
}
// ValidityUnitContains applies the Contains predicate on the "validity_unit" field.
func
ValidityUnitContains
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldContains
(
FieldValidityUnit
,
v
))
}
// ValidityUnitHasPrefix applies the HasPrefix predicate on the "validity_unit" field.
func
ValidityUnitHasPrefix
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldHasPrefix
(
FieldValidityUnit
,
v
))
}
// ValidityUnitHasSuffix applies the HasSuffix predicate on the "validity_unit" field.
func
ValidityUnitHasSuffix
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldHasSuffix
(
FieldValidityUnit
,
v
))
}
// ValidityUnitEqualFold applies the EqualFold predicate on the "validity_unit" field.
func
ValidityUnitEqualFold
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEqualFold
(
FieldValidityUnit
,
v
))
}
// ValidityUnitContainsFold applies the ContainsFold predicate on the "validity_unit" field.
func
ValidityUnitContainsFold
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldContainsFold
(
FieldValidityUnit
,
v
))
}
// FeaturesEQ applies the EQ predicate on the "features" field.
func
FeaturesEQ
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEQ
(
FieldFeatures
,
v
))
}
// FeaturesNEQ applies the NEQ predicate on the "features" field.
func
FeaturesNEQ
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldNEQ
(
FieldFeatures
,
v
))
}
// FeaturesIn applies the In predicate on the "features" field.
func
FeaturesIn
(
vs
...
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldIn
(
FieldFeatures
,
vs
...
))
}
// FeaturesNotIn applies the NotIn predicate on the "features" field.
func
FeaturesNotIn
(
vs
...
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldNotIn
(
FieldFeatures
,
vs
...
))
}
// FeaturesGT applies the GT predicate on the "features" field.
func
FeaturesGT
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldGT
(
FieldFeatures
,
v
))
}
// FeaturesGTE applies the GTE predicate on the "features" field.
func
FeaturesGTE
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldGTE
(
FieldFeatures
,
v
))
}
// FeaturesLT applies the LT predicate on the "features" field.
func
FeaturesLT
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldLT
(
FieldFeatures
,
v
))
}
// FeaturesLTE applies the LTE predicate on the "features" field.
func
FeaturesLTE
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldLTE
(
FieldFeatures
,
v
))
}
// FeaturesContains applies the Contains predicate on the "features" field.
func
FeaturesContains
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldContains
(
FieldFeatures
,
v
))
}
// FeaturesHasPrefix applies the HasPrefix predicate on the "features" field.
func
FeaturesHasPrefix
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldHasPrefix
(
FieldFeatures
,
v
))
}
// FeaturesHasSuffix applies the HasSuffix predicate on the "features" field.
func
FeaturesHasSuffix
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldHasSuffix
(
FieldFeatures
,
v
))
}
// FeaturesEqualFold applies the EqualFold predicate on the "features" field.
func
FeaturesEqualFold
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEqualFold
(
FieldFeatures
,
v
))
}
// FeaturesContainsFold applies the ContainsFold predicate on the "features" field.
func
FeaturesContainsFold
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldContainsFold
(
FieldFeatures
,
v
))
}
// ProductNameEQ applies the EQ predicate on the "product_name" field.
func
ProductNameEQ
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEQ
(
FieldProductName
,
v
))
}
// ProductNameNEQ applies the NEQ predicate on the "product_name" field.
func
ProductNameNEQ
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldNEQ
(
FieldProductName
,
v
))
}
// ProductNameIn applies the In predicate on the "product_name" field.
func
ProductNameIn
(
vs
...
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldIn
(
FieldProductName
,
vs
...
))
}
// ProductNameNotIn applies the NotIn predicate on the "product_name" field.
func
ProductNameNotIn
(
vs
...
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldNotIn
(
FieldProductName
,
vs
...
))
}
// ProductNameGT applies the GT predicate on the "product_name" field.
func
ProductNameGT
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldGT
(
FieldProductName
,
v
))
}
// ProductNameGTE applies the GTE predicate on the "product_name" field.
func
ProductNameGTE
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldGTE
(
FieldProductName
,
v
))
}
// ProductNameLT applies the LT predicate on the "product_name" field.
func
ProductNameLT
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldLT
(
FieldProductName
,
v
))
}
// ProductNameLTE applies the LTE predicate on the "product_name" field.
func
ProductNameLTE
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldLTE
(
FieldProductName
,
v
))
}
// ProductNameContains applies the Contains predicate on the "product_name" field.
func
ProductNameContains
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldContains
(
FieldProductName
,
v
))
}
// ProductNameHasPrefix applies the HasPrefix predicate on the "product_name" field.
func
ProductNameHasPrefix
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldHasPrefix
(
FieldProductName
,
v
))
}
// ProductNameHasSuffix applies the HasSuffix predicate on the "product_name" field.
func
ProductNameHasSuffix
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldHasSuffix
(
FieldProductName
,
v
))
}
// ProductNameEqualFold applies the EqualFold predicate on the "product_name" field.
func
ProductNameEqualFold
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEqualFold
(
FieldProductName
,
v
))
}
// ProductNameContainsFold applies the ContainsFold predicate on the "product_name" field.
func
ProductNameContainsFold
(
v
string
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldContainsFold
(
FieldProductName
,
v
))
}
// ForSaleEQ applies the EQ predicate on the "for_sale" field.
func
ForSaleEQ
(
v
bool
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEQ
(
FieldForSale
,
v
))
}
// ForSaleNEQ applies the NEQ predicate on the "for_sale" field.
func
ForSaleNEQ
(
v
bool
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldNEQ
(
FieldForSale
,
v
))
}
// SortOrderEQ applies the EQ predicate on the "sort_order" field.
func
SortOrderEQ
(
v
int
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEQ
(
FieldSortOrder
,
v
))
}
// SortOrderNEQ applies the NEQ predicate on the "sort_order" field.
func
SortOrderNEQ
(
v
int
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldNEQ
(
FieldSortOrder
,
v
))
}
// SortOrderIn applies the In predicate on the "sort_order" field.
func
SortOrderIn
(
vs
...
int
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldIn
(
FieldSortOrder
,
vs
...
))
}
// SortOrderNotIn applies the NotIn predicate on the "sort_order" field.
func
SortOrderNotIn
(
vs
...
int
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldNotIn
(
FieldSortOrder
,
vs
...
))
}
// SortOrderGT applies the GT predicate on the "sort_order" field.
func
SortOrderGT
(
v
int
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldGT
(
FieldSortOrder
,
v
))
}
// SortOrderGTE applies the GTE predicate on the "sort_order" field.
func
SortOrderGTE
(
v
int
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldGTE
(
FieldSortOrder
,
v
))
}
// SortOrderLT applies the LT predicate on the "sort_order" field.
func
SortOrderLT
(
v
int
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldLT
(
FieldSortOrder
,
v
))
}
// SortOrderLTE applies the LTE predicate on the "sort_order" field.
func
SortOrderLTE
(
v
int
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldLTE
(
FieldSortOrder
,
v
))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func
CreatedAtEQ
(
v
time
.
Time
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEQ
(
FieldCreatedAt
,
v
))
}
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
func
CreatedAtNEQ
(
v
time
.
Time
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldNEQ
(
FieldCreatedAt
,
v
))
}
// CreatedAtIn applies the In predicate on the "created_at" field.
func
CreatedAtIn
(
vs
...
time
.
Time
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldIn
(
FieldCreatedAt
,
vs
...
))
}
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
func
CreatedAtNotIn
(
vs
...
time
.
Time
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldNotIn
(
FieldCreatedAt
,
vs
...
))
}
// CreatedAtGT applies the GT predicate on the "created_at" field.
func
CreatedAtGT
(
v
time
.
Time
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldGT
(
FieldCreatedAt
,
v
))
}
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
func
CreatedAtGTE
(
v
time
.
Time
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldGTE
(
FieldCreatedAt
,
v
))
}
// CreatedAtLT applies the LT predicate on the "created_at" field.
func
CreatedAtLT
(
v
time
.
Time
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldLT
(
FieldCreatedAt
,
v
))
}
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
func
CreatedAtLTE
(
v
time
.
Time
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldLTE
(
FieldCreatedAt
,
v
))
}
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
func
UpdatedAtEQ
(
v
time
.
Time
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldEQ
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
func
UpdatedAtNEQ
(
v
time
.
Time
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldNEQ
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtIn applies the In predicate on the "updated_at" field.
func
UpdatedAtIn
(
vs
...
time
.
Time
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldIn
(
FieldUpdatedAt
,
vs
...
))
}
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
func
UpdatedAtNotIn
(
vs
...
time
.
Time
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldNotIn
(
FieldUpdatedAt
,
vs
...
))
}
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
func
UpdatedAtGT
(
v
time
.
Time
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldGT
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
func
UpdatedAtGTE
(
v
time
.
Time
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldGTE
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
func
UpdatedAtLT
(
v
time
.
Time
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldLT
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
func
UpdatedAtLTE
(
v
time
.
Time
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
FieldLTE
(
FieldUpdatedAt
,
v
))
}
// And groups predicates with the AND operator between them.
func
And
(
predicates
...
predicate
.
SubscriptionPlan
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
AndPredicates
(
predicates
...
))
}
// Or groups predicates with the OR operator between them.
func
Or
(
predicates
...
predicate
.
SubscriptionPlan
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
OrPredicates
(
predicates
...
))
}
// Not applies the not operator on the given predicate.
func
Not
(
p
predicate
.
SubscriptionPlan
)
predicate
.
SubscriptionPlan
{
return
predicate
.
SubscriptionPlan
(
sql
.
NotPredicates
(
p
))
}
backend/ent/subscriptionplan_create.go
0 → 100644
View file @
97f14b7a
// Code generated by ent, DO NOT EDIT.
package
ent
import
(
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/subscriptionplan"
)
// SubscriptionPlanCreate is the builder for creating a SubscriptionPlan entity.
type
SubscriptionPlanCreate
struct
{
config
mutation
*
SubscriptionPlanMutation
hooks
[]
Hook
conflict
[]
sql
.
ConflictOption
}
// SetGroupID sets the "group_id" field.
func
(
_c
*
SubscriptionPlanCreate
)
SetGroupID
(
v
int64
)
*
SubscriptionPlanCreate
{
_c
.
mutation
.
SetGroupID
(
v
)
return
_c
}
// SetName sets the "name" field.
func
(
_c
*
SubscriptionPlanCreate
)
SetName
(
v
string
)
*
SubscriptionPlanCreate
{
_c
.
mutation
.
SetName
(
v
)
return
_c
}
// SetDescription sets the "description" field.
func
(
_c
*
SubscriptionPlanCreate
)
SetDescription
(
v
string
)
*
SubscriptionPlanCreate
{
_c
.
mutation
.
SetDescription
(
v
)
return
_c
}
// SetNillableDescription sets the "description" field if the given value is not nil.
func
(
_c
*
SubscriptionPlanCreate
)
SetNillableDescription
(
v
*
string
)
*
SubscriptionPlanCreate
{
if
v
!=
nil
{
_c
.
SetDescription
(
*
v
)
}
return
_c
}
// SetPrice sets the "price" field.
func
(
_c
*
SubscriptionPlanCreate
)
SetPrice
(
v
float64
)
*
SubscriptionPlanCreate
{
_c
.
mutation
.
SetPrice
(
v
)
return
_c
}
// SetOriginalPrice sets the "original_price" field.
func
(
_c
*
SubscriptionPlanCreate
)
SetOriginalPrice
(
v
float64
)
*
SubscriptionPlanCreate
{
_c
.
mutation
.
SetOriginalPrice
(
v
)
return
_c
}
// SetNillableOriginalPrice sets the "original_price" field if the given value is not nil.
func
(
_c
*
SubscriptionPlanCreate
)
SetNillableOriginalPrice
(
v
*
float64
)
*
SubscriptionPlanCreate
{
if
v
!=
nil
{
_c
.
SetOriginalPrice
(
*
v
)
}
return
_c
}
// SetValidityDays sets the "validity_days" field.
func
(
_c
*
SubscriptionPlanCreate
)
SetValidityDays
(
v
int
)
*
SubscriptionPlanCreate
{
_c
.
mutation
.
SetValidityDays
(
v
)
return
_c
}
// SetNillableValidityDays sets the "validity_days" field if the given value is not nil.
func
(
_c
*
SubscriptionPlanCreate
)
SetNillableValidityDays
(
v
*
int
)
*
SubscriptionPlanCreate
{
if
v
!=
nil
{
_c
.
SetValidityDays
(
*
v
)
}
return
_c
}
// SetValidityUnit sets the "validity_unit" field.
func
(
_c
*
SubscriptionPlanCreate
)
SetValidityUnit
(
v
string
)
*
SubscriptionPlanCreate
{
_c
.
mutation
.
SetValidityUnit
(
v
)
return
_c
}
// SetNillableValidityUnit sets the "validity_unit" field if the given value is not nil.
func
(
_c
*
SubscriptionPlanCreate
)
SetNillableValidityUnit
(
v
*
string
)
*
SubscriptionPlanCreate
{
if
v
!=
nil
{
_c
.
SetValidityUnit
(
*
v
)
}
return
_c
}
// SetFeatures sets the "features" field.
func
(
_c
*
SubscriptionPlanCreate
)
SetFeatures
(
v
string
)
*
SubscriptionPlanCreate
{
_c
.
mutation
.
SetFeatures
(
v
)
return
_c
}
// SetNillableFeatures sets the "features" field if the given value is not nil.
func
(
_c
*
SubscriptionPlanCreate
)
SetNillableFeatures
(
v
*
string
)
*
SubscriptionPlanCreate
{
if
v
!=
nil
{
_c
.
SetFeatures
(
*
v
)
}
return
_c
}
// SetProductName sets the "product_name" field.
func
(
_c
*
SubscriptionPlanCreate
)
SetProductName
(
v
string
)
*
SubscriptionPlanCreate
{
_c
.
mutation
.
SetProductName
(
v
)
return
_c
}
// SetNillableProductName sets the "product_name" field if the given value is not nil.
func
(
_c
*
SubscriptionPlanCreate
)
SetNillableProductName
(
v
*
string
)
*
SubscriptionPlanCreate
{
if
v
!=
nil
{
_c
.
SetProductName
(
*
v
)
}
return
_c
}
// SetForSale sets the "for_sale" field.
func
(
_c
*
SubscriptionPlanCreate
)
SetForSale
(
v
bool
)
*
SubscriptionPlanCreate
{
_c
.
mutation
.
SetForSale
(
v
)
return
_c
}
// SetNillableForSale sets the "for_sale" field if the given value is not nil.
func
(
_c
*
SubscriptionPlanCreate
)
SetNillableForSale
(
v
*
bool
)
*
SubscriptionPlanCreate
{
if
v
!=
nil
{
_c
.
SetForSale
(
*
v
)
}
return
_c
}
// SetSortOrder sets the "sort_order" field.
func
(
_c
*
SubscriptionPlanCreate
)
SetSortOrder
(
v
int
)
*
SubscriptionPlanCreate
{
_c
.
mutation
.
SetSortOrder
(
v
)
return
_c
}
// SetNillableSortOrder sets the "sort_order" field if the given value is not nil.
func
(
_c
*
SubscriptionPlanCreate
)
SetNillableSortOrder
(
v
*
int
)
*
SubscriptionPlanCreate
{
if
v
!=
nil
{
_c
.
SetSortOrder
(
*
v
)
}
return
_c
}
// SetCreatedAt sets the "created_at" field.
func
(
_c
*
SubscriptionPlanCreate
)
SetCreatedAt
(
v
time
.
Time
)
*
SubscriptionPlanCreate
{
_c
.
mutation
.
SetCreatedAt
(
v
)
return
_c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func
(
_c
*
SubscriptionPlanCreate
)
SetNillableCreatedAt
(
v
*
time
.
Time
)
*
SubscriptionPlanCreate
{
if
v
!=
nil
{
_c
.
SetCreatedAt
(
*
v
)
}
return
_c
}
// SetUpdatedAt sets the "updated_at" field.
func
(
_c
*
SubscriptionPlanCreate
)
SetUpdatedAt
(
v
time
.
Time
)
*
SubscriptionPlanCreate
{
_c
.
mutation
.
SetUpdatedAt
(
v
)
return
_c
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func
(
_c
*
SubscriptionPlanCreate
)
SetNillableUpdatedAt
(
v
*
time
.
Time
)
*
SubscriptionPlanCreate
{
if
v
!=
nil
{
_c
.
SetUpdatedAt
(
*
v
)
}
return
_c
}
// Mutation returns the SubscriptionPlanMutation object of the builder.
func
(
_c
*
SubscriptionPlanCreate
)
Mutation
()
*
SubscriptionPlanMutation
{
return
_c
.
mutation
}
// Save creates the SubscriptionPlan in the database.
func
(
_c
*
SubscriptionPlanCreate
)
Save
(
ctx
context
.
Context
)
(
*
SubscriptionPlan
,
error
)
{
_c
.
defaults
()
return
withHooks
(
ctx
,
_c
.
sqlSave
,
_c
.
mutation
,
_c
.
hooks
)
}
// SaveX calls Save and panics if Save returns an error.
func
(
_c
*
SubscriptionPlanCreate
)
SaveX
(
ctx
context
.
Context
)
*
SubscriptionPlan
{
v
,
err
:=
_c
.
Save
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
v
}
// Exec executes the query.
func
(
_c
*
SubscriptionPlanCreate
)
Exec
(
ctx
context
.
Context
)
error
{
_
,
err
:=
_c
.
Save
(
ctx
)
return
err
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_c
*
SubscriptionPlanCreate
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
_c
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
// defaults sets the default values of the builder before save.
func
(
_c
*
SubscriptionPlanCreate
)
defaults
()
{
if
_
,
ok
:=
_c
.
mutation
.
Description
();
!
ok
{
v
:=
subscriptionplan
.
DefaultDescription
_c
.
mutation
.
SetDescription
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
ValidityDays
();
!
ok
{
v
:=
subscriptionplan
.
DefaultValidityDays
_c
.
mutation
.
SetValidityDays
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
ValidityUnit
();
!
ok
{
v
:=
subscriptionplan
.
DefaultValidityUnit
_c
.
mutation
.
SetValidityUnit
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
Features
();
!
ok
{
v
:=
subscriptionplan
.
DefaultFeatures
_c
.
mutation
.
SetFeatures
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
ProductName
();
!
ok
{
v
:=
subscriptionplan
.
DefaultProductName
_c
.
mutation
.
SetProductName
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
ForSale
();
!
ok
{
v
:=
subscriptionplan
.
DefaultForSale
_c
.
mutation
.
SetForSale
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
SortOrder
();
!
ok
{
v
:=
subscriptionplan
.
DefaultSortOrder
_c
.
mutation
.
SetSortOrder
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
CreatedAt
();
!
ok
{
v
:=
subscriptionplan
.
DefaultCreatedAt
()
_c
.
mutation
.
SetCreatedAt
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
UpdatedAt
();
!
ok
{
v
:=
subscriptionplan
.
DefaultUpdatedAt
()
_c
.
mutation
.
SetUpdatedAt
(
v
)
}
}
// check runs all checks and user-defined validators on the builder.
func
(
_c
*
SubscriptionPlanCreate
)
check
()
error
{
if
_
,
ok
:=
_c
.
mutation
.
GroupID
();
!
ok
{
return
&
ValidationError
{
Name
:
"group_id"
,
err
:
errors
.
New
(
`ent: missing required field "SubscriptionPlan.group_id"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
Name
();
!
ok
{
return
&
ValidationError
{
Name
:
"name"
,
err
:
errors
.
New
(
`ent: missing required field "SubscriptionPlan.name"`
)}
}
if
v
,
ok
:=
_c
.
mutation
.
Name
();
ok
{
if
err
:=
subscriptionplan
.
NameValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"name"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "SubscriptionPlan.name": %w`
,
err
)}
}
}
if
_
,
ok
:=
_c
.
mutation
.
Description
();
!
ok
{
return
&
ValidationError
{
Name
:
"description"
,
err
:
errors
.
New
(
`ent: missing required field "SubscriptionPlan.description"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
Price
();
!
ok
{
return
&
ValidationError
{
Name
:
"price"
,
err
:
errors
.
New
(
`ent: missing required field "SubscriptionPlan.price"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
ValidityDays
();
!
ok
{
return
&
ValidationError
{
Name
:
"validity_days"
,
err
:
errors
.
New
(
`ent: missing required field "SubscriptionPlan.validity_days"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
ValidityUnit
();
!
ok
{
return
&
ValidationError
{
Name
:
"validity_unit"
,
err
:
errors
.
New
(
`ent: missing required field "SubscriptionPlan.validity_unit"`
)}
}
if
v
,
ok
:=
_c
.
mutation
.
ValidityUnit
();
ok
{
if
err
:=
subscriptionplan
.
ValidityUnitValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"validity_unit"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "SubscriptionPlan.validity_unit": %w`
,
err
)}
}
}
if
_
,
ok
:=
_c
.
mutation
.
Features
();
!
ok
{
return
&
ValidationError
{
Name
:
"features"
,
err
:
errors
.
New
(
`ent: missing required field "SubscriptionPlan.features"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
ProductName
();
!
ok
{
return
&
ValidationError
{
Name
:
"product_name"
,
err
:
errors
.
New
(
`ent: missing required field "SubscriptionPlan.product_name"`
)}
}
if
v
,
ok
:=
_c
.
mutation
.
ProductName
();
ok
{
if
err
:=
subscriptionplan
.
ProductNameValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"product_name"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "SubscriptionPlan.product_name": %w`
,
err
)}
}
}
if
_
,
ok
:=
_c
.
mutation
.
ForSale
();
!
ok
{
return
&
ValidationError
{
Name
:
"for_sale"
,
err
:
errors
.
New
(
`ent: missing required field "SubscriptionPlan.for_sale"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
SortOrder
();
!
ok
{
return
&
ValidationError
{
Name
:
"sort_order"
,
err
:
errors
.
New
(
`ent: missing required field "SubscriptionPlan.sort_order"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
CreatedAt
();
!
ok
{
return
&
ValidationError
{
Name
:
"created_at"
,
err
:
errors
.
New
(
`ent: missing required field "SubscriptionPlan.created_at"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
UpdatedAt
();
!
ok
{
return
&
ValidationError
{
Name
:
"updated_at"
,
err
:
errors
.
New
(
`ent: missing required field "SubscriptionPlan.updated_at"`
)}
}
return
nil
}
func
(
_c
*
SubscriptionPlanCreate
)
sqlSave
(
ctx
context
.
Context
)
(
*
SubscriptionPlan
,
error
)
{
if
err
:=
_c
.
check
();
err
!=
nil
{
return
nil
,
err
}
_node
,
_spec
:=
_c
.
createSpec
()
if
err
:=
sqlgraph
.
CreateNode
(
ctx
,
_c
.
driver
,
_spec
);
err
!=
nil
{
if
sqlgraph
.
IsConstraintError
(
err
)
{
err
=
&
ConstraintError
{
msg
:
err
.
Error
(),
wrap
:
err
}
}
return
nil
,
err
}
id
:=
_spec
.
ID
.
Value
.
(
int64
)
_node
.
ID
=
int64
(
id
)
_c
.
mutation
.
id
=
&
_node
.
ID
_c
.
mutation
.
done
=
true
return
_node
,
nil
}
func
(
_c
*
SubscriptionPlanCreate
)
createSpec
()
(
*
SubscriptionPlan
,
*
sqlgraph
.
CreateSpec
)
{
var
(
_node
=
&
SubscriptionPlan
{
config
:
_c
.
config
}
_spec
=
sqlgraph
.
NewCreateSpec
(
subscriptionplan
.
Table
,
sqlgraph
.
NewFieldSpec
(
subscriptionplan
.
FieldID
,
field
.
TypeInt64
))
)
_spec
.
OnConflict
=
_c
.
conflict
if
value
,
ok
:=
_c
.
mutation
.
GroupID
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldGroupID
,
field
.
TypeInt64
,
value
)
_node
.
GroupID
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
Name
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldName
,
field
.
TypeString
,
value
)
_node
.
Name
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
Description
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldDescription
,
field
.
TypeString
,
value
)
_node
.
Description
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
Price
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldPrice
,
field
.
TypeFloat64
,
value
)
_node
.
Price
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
OriginalPrice
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldOriginalPrice
,
field
.
TypeFloat64
,
value
)
_node
.
OriginalPrice
=
&
value
}
if
value
,
ok
:=
_c
.
mutation
.
ValidityDays
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldValidityDays
,
field
.
TypeInt
,
value
)
_node
.
ValidityDays
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
ValidityUnit
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldValidityUnit
,
field
.
TypeString
,
value
)
_node
.
ValidityUnit
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
Features
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldFeatures
,
field
.
TypeString
,
value
)
_node
.
Features
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
ProductName
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldProductName
,
field
.
TypeString
,
value
)
_node
.
ProductName
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
ForSale
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldForSale
,
field
.
TypeBool
,
value
)
_node
.
ForSale
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
SortOrder
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldSortOrder
,
field
.
TypeInt
,
value
)
_node
.
SortOrder
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
CreatedAt
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldCreatedAt
,
field
.
TypeTime
,
value
)
_node
.
CreatedAt
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
UpdatedAt
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldUpdatedAt
,
field
.
TypeTime
,
value
)
_node
.
UpdatedAt
=
value
}
return
_node
,
_spec
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.SubscriptionPlan.Create().
// SetGroupID(v).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.SubscriptionPlanUpsert) {
// SetGroupID(v+v).
// }).
// Exec(ctx)
func
(
_c
*
SubscriptionPlanCreate
)
OnConflict
(
opts
...
sql
.
ConflictOption
)
*
SubscriptionPlanUpsertOne
{
_c
.
conflict
=
opts
return
&
SubscriptionPlanUpsertOne
{
create
:
_c
,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.SubscriptionPlan.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func
(
_c
*
SubscriptionPlanCreate
)
OnConflictColumns
(
columns
...
string
)
*
SubscriptionPlanUpsertOne
{
_c
.
conflict
=
append
(
_c
.
conflict
,
sql
.
ConflictColumns
(
columns
...
))
return
&
SubscriptionPlanUpsertOne
{
create
:
_c
,
}
}
type
(
// SubscriptionPlanUpsertOne is the builder for "upsert"-ing
// one SubscriptionPlan node.
SubscriptionPlanUpsertOne
struct
{
create
*
SubscriptionPlanCreate
}
// SubscriptionPlanUpsert is the "OnConflict" setter.
SubscriptionPlanUpsert
struct
{
*
sql
.
UpdateSet
}
)
// SetGroupID sets the "group_id" field.
func
(
u
*
SubscriptionPlanUpsert
)
SetGroupID
(
v
int64
)
*
SubscriptionPlanUpsert
{
u
.
Set
(
subscriptionplan
.
FieldGroupID
,
v
)
return
u
}
// UpdateGroupID sets the "group_id" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsert
)
UpdateGroupID
()
*
SubscriptionPlanUpsert
{
u
.
SetExcluded
(
subscriptionplan
.
FieldGroupID
)
return
u
}
// AddGroupID adds v to the "group_id" field.
func
(
u
*
SubscriptionPlanUpsert
)
AddGroupID
(
v
int64
)
*
SubscriptionPlanUpsert
{
u
.
Add
(
subscriptionplan
.
FieldGroupID
,
v
)
return
u
}
// SetName sets the "name" field.
func
(
u
*
SubscriptionPlanUpsert
)
SetName
(
v
string
)
*
SubscriptionPlanUpsert
{
u
.
Set
(
subscriptionplan
.
FieldName
,
v
)
return
u
}
// UpdateName sets the "name" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsert
)
UpdateName
()
*
SubscriptionPlanUpsert
{
u
.
SetExcluded
(
subscriptionplan
.
FieldName
)
return
u
}
// SetDescription sets the "description" field.
func
(
u
*
SubscriptionPlanUpsert
)
SetDescription
(
v
string
)
*
SubscriptionPlanUpsert
{
u
.
Set
(
subscriptionplan
.
FieldDescription
,
v
)
return
u
}
// UpdateDescription sets the "description" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsert
)
UpdateDescription
()
*
SubscriptionPlanUpsert
{
u
.
SetExcluded
(
subscriptionplan
.
FieldDescription
)
return
u
}
// SetPrice sets the "price" field.
func
(
u
*
SubscriptionPlanUpsert
)
SetPrice
(
v
float64
)
*
SubscriptionPlanUpsert
{
u
.
Set
(
subscriptionplan
.
FieldPrice
,
v
)
return
u
}
// UpdatePrice sets the "price" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsert
)
UpdatePrice
()
*
SubscriptionPlanUpsert
{
u
.
SetExcluded
(
subscriptionplan
.
FieldPrice
)
return
u
}
// AddPrice adds v to the "price" field.
func
(
u
*
SubscriptionPlanUpsert
)
AddPrice
(
v
float64
)
*
SubscriptionPlanUpsert
{
u
.
Add
(
subscriptionplan
.
FieldPrice
,
v
)
return
u
}
// SetOriginalPrice sets the "original_price" field.
func
(
u
*
SubscriptionPlanUpsert
)
SetOriginalPrice
(
v
float64
)
*
SubscriptionPlanUpsert
{
u
.
Set
(
subscriptionplan
.
FieldOriginalPrice
,
v
)
return
u
}
// UpdateOriginalPrice sets the "original_price" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsert
)
UpdateOriginalPrice
()
*
SubscriptionPlanUpsert
{
u
.
SetExcluded
(
subscriptionplan
.
FieldOriginalPrice
)
return
u
}
// AddOriginalPrice adds v to the "original_price" field.
func
(
u
*
SubscriptionPlanUpsert
)
AddOriginalPrice
(
v
float64
)
*
SubscriptionPlanUpsert
{
u
.
Add
(
subscriptionplan
.
FieldOriginalPrice
,
v
)
return
u
}
// ClearOriginalPrice clears the value of the "original_price" field.
func
(
u
*
SubscriptionPlanUpsert
)
ClearOriginalPrice
()
*
SubscriptionPlanUpsert
{
u
.
SetNull
(
subscriptionplan
.
FieldOriginalPrice
)
return
u
}
// SetValidityDays sets the "validity_days" field.
func
(
u
*
SubscriptionPlanUpsert
)
SetValidityDays
(
v
int
)
*
SubscriptionPlanUpsert
{
u
.
Set
(
subscriptionplan
.
FieldValidityDays
,
v
)
return
u
}
// UpdateValidityDays sets the "validity_days" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsert
)
UpdateValidityDays
()
*
SubscriptionPlanUpsert
{
u
.
SetExcluded
(
subscriptionplan
.
FieldValidityDays
)
return
u
}
// AddValidityDays adds v to the "validity_days" field.
func
(
u
*
SubscriptionPlanUpsert
)
AddValidityDays
(
v
int
)
*
SubscriptionPlanUpsert
{
u
.
Add
(
subscriptionplan
.
FieldValidityDays
,
v
)
return
u
}
// SetValidityUnit sets the "validity_unit" field.
func
(
u
*
SubscriptionPlanUpsert
)
SetValidityUnit
(
v
string
)
*
SubscriptionPlanUpsert
{
u
.
Set
(
subscriptionplan
.
FieldValidityUnit
,
v
)
return
u
}
// UpdateValidityUnit sets the "validity_unit" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsert
)
UpdateValidityUnit
()
*
SubscriptionPlanUpsert
{
u
.
SetExcluded
(
subscriptionplan
.
FieldValidityUnit
)
return
u
}
// SetFeatures sets the "features" field.
func
(
u
*
SubscriptionPlanUpsert
)
SetFeatures
(
v
string
)
*
SubscriptionPlanUpsert
{
u
.
Set
(
subscriptionplan
.
FieldFeatures
,
v
)
return
u
}
// UpdateFeatures sets the "features" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsert
)
UpdateFeatures
()
*
SubscriptionPlanUpsert
{
u
.
SetExcluded
(
subscriptionplan
.
FieldFeatures
)
return
u
}
// SetProductName sets the "product_name" field.
func
(
u
*
SubscriptionPlanUpsert
)
SetProductName
(
v
string
)
*
SubscriptionPlanUpsert
{
u
.
Set
(
subscriptionplan
.
FieldProductName
,
v
)
return
u
}
// UpdateProductName sets the "product_name" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsert
)
UpdateProductName
()
*
SubscriptionPlanUpsert
{
u
.
SetExcluded
(
subscriptionplan
.
FieldProductName
)
return
u
}
// SetForSale sets the "for_sale" field.
func
(
u
*
SubscriptionPlanUpsert
)
SetForSale
(
v
bool
)
*
SubscriptionPlanUpsert
{
u
.
Set
(
subscriptionplan
.
FieldForSale
,
v
)
return
u
}
// UpdateForSale sets the "for_sale" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsert
)
UpdateForSale
()
*
SubscriptionPlanUpsert
{
u
.
SetExcluded
(
subscriptionplan
.
FieldForSale
)
return
u
}
// SetSortOrder sets the "sort_order" field.
func
(
u
*
SubscriptionPlanUpsert
)
SetSortOrder
(
v
int
)
*
SubscriptionPlanUpsert
{
u
.
Set
(
subscriptionplan
.
FieldSortOrder
,
v
)
return
u
}
// UpdateSortOrder sets the "sort_order" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsert
)
UpdateSortOrder
()
*
SubscriptionPlanUpsert
{
u
.
SetExcluded
(
subscriptionplan
.
FieldSortOrder
)
return
u
}
// AddSortOrder adds v to the "sort_order" field.
func
(
u
*
SubscriptionPlanUpsert
)
AddSortOrder
(
v
int
)
*
SubscriptionPlanUpsert
{
u
.
Add
(
subscriptionplan
.
FieldSortOrder
,
v
)
return
u
}
// SetUpdatedAt sets the "updated_at" field.
func
(
u
*
SubscriptionPlanUpsert
)
SetUpdatedAt
(
v
time
.
Time
)
*
SubscriptionPlanUpsert
{
u
.
Set
(
subscriptionplan
.
FieldUpdatedAt
,
v
)
return
u
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsert
)
UpdateUpdatedAt
()
*
SubscriptionPlanUpsert
{
u
.
SetExcluded
(
subscriptionplan
.
FieldUpdatedAt
)
return
u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
// client.SubscriptionPlan.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func
(
u
*
SubscriptionPlanUpsertOne
)
UpdateNewValues
()
*
SubscriptionPlanUpsertOne
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWithNewValues
())
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWith
(
func
(
s
*
sql
.
UpdateSet
)
{
if
_
,
exists
:=
u
.
create
.
mutation
.
CreatedAt
();
exists
{
s
.
SetIgnore
(
subscriptionplan
.
FieldCreatedAt
)
}
}))
return
u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.SubscriptionPlan.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func
(
u
*
SubscriptionPlanUpsertOne
)
Ignore
()
*
SubscriptionPlanUpsertOne
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWithIgnore
())
return
u
}
// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func
(
u
*
SubscriptionPlanUpsertOne
)
DoNothing
()
*
SubscriptionPlanUpsertOne
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
DoNothing
())
return
u
}
// Update allows overriding fields `UPDATE` values. See the SubscriptionPlanCreate.OnConflict
// documentation for more info.
func
(
u
*
SubscriptionPlanUpsertOne
)
Update
(
set
func
(
*
SubscriptionPlanUpsert
))
*
SubscriptionPlanUpsertOne
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWith
(
func
(
update
*
sql
.
UpdateSet
)
{
set
(
&
SubscriptionPlanUpsert
{
UpdateSet
:
update
})
}))
return
u
}
// SetGroupID sets the "group_id" field.
func
(
u
*
SubscriptionPlanUpsertOne
)
SetGroupID
(
v
int64
)
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
SetGroupID
(
v
)
})
}
// AddGroupID adds v to the "group_id" field.
func
(
u
*
SubscriptionPlanUpsertOne
)
AddGroupID
(
v
int64
)
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
AddGroupID
(
v
)
})
}
// UpdateGroupID sets the "group_id" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsertOne
)
UpdateGroupID
()
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
UpdateGroupID
()
})
}
// SetName sets the "name" field.
func
(
u
*
SubscriptionPlanUpsertOne
)
SetName
(
v
string
)
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
SetName
(
v
)
})
}
// UpdateName sets the "name" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsertOne
)
UpdateName
()
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
UpdateName
()
})
}
// SetDescription sets the "description" field.
func
(
u
*
SubscriptionPlanUpsertOne
)
SetDescription
(
v
string
)
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
SetDescription
(
v
)
})
}
// UpdateDescription sets the "description" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsertOne
)
UpdateDescription
()
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
UpdateDescription
()
})
}
// SetPrice sets the "price" field.
func
(
u
*
SubscriptionPlanUpsertOne
)
SetPrice
(
v
float64
)
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
SetPrice
(
v
)
})
}
// AddPrice adds v to the "price" field.
func
(
u
*
SubscriptionPlanUpsertOne
)
AddPrice
(
v
float64
)
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
AddPrice
(
v
)
})
}
// UpdatePrice sets the "price" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsertOne
)
UpdatePrice
()
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
UpdatePrice
()
})
}
// SetOriginalPrice sets the "original_price" field.
func
(
u
*
SubscriptionPlanUpsertOne
)
SetOriginalPrice
(
v
float64
)
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
SetOriginalPrice
(
v
)
})
}
// AddOriginalPrice adds v to the "original_price" field.
func
(
u
*
SubscriptionPlanUpsertOne
)
AddOriginalPrice
(
v
float64
)
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
AddOriginalPrice
(
v
)
})
}
// UpdateOriginalPrice sets the "original_price" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsertOne
)
UpdateOriginalPrice
()
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
UpdateOriginalPrice
()
})
}
// ClearOriginalPrice clears the value of the "original_price" field.
func
(
u
*
SubscriptionPlanUpsertOne
)
ClearOriginalPrice
()
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
ClearOriginalPrice
()
})
}
// SetValidityDays sets the "validity_days" field.
func
(
u
*
SubscriptionPlanUpsertOne
)
SetValidityDays
(
v
int
)
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
SetValidityDays
(
v
)
})
}
// AddValidityDays adds v to the "validity_days" field.
func
(
u
*
SubscriptionPlanUpsertOne
)
AddValidityDays
(
v
int
)
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
AddValidityDays
(
v
)
})
}
// UpdateValidityDays sets the "validity_days" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsertOne
)
UpdateValidityDays
()
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
UpdateValidityDays
()
})
}
// SetValidityUnit sets the "validity_unit" field.
func
(
u
*
SubscriptionPlanUpsertOne
)
SetValidityUnit
(
v
string
)
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
SetValidityUnit
(
v
)
})
}
// UpdateValidityUnit sets the "validity_unit" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsertOne
)
UpdateValidityUnit
()
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
UpdateValidityUnit
()
})
}
// SetFeatures sets the "features" field.
func
(
u
*
SubscriptionPlanUpsertOne
)
SetFeatures
(
v
string
)
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
SetFeatures
(
v
)
})
}
// UpdateFeatures sets the "features" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsertOne
)
UpdateFeatures
()
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
UpdateFeatures
()
})
}
// SetProductName sets the "product_name" field.
func
(
u
*
SubscriptionPlanUpsertOne
)
SetProductName
(
v
string
)
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
SetProductName
(
v
)
})
}
// UpdateProductName sets the "product_name" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsertOne
)
UpdateProductName
()
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
UpdateProductName
()
})
}
// SetForSale sets the "for_sale" field.
func
(
u
*
SubscriptionPlanUpsertOne
)
SetForSale
(
v
bool
)
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
SetForSale
(
v
)
})
}
// UpdateForSale sets the "for_sale" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsertOne
)
UpdateForSale
()
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
UpdateForSale
()
})
}
// SetSortOrder sets the "sort_order" field.
func
(
u
*
SubscriptionPlanUpsertOne
)
SetSortOrder
(
v
int
)
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
SetSortOrder
(
v
)
})
}
// AddSortOrder adds v to the "sort_order" field.
func
(
u
*
SubscriptionPlanUpsertOne
)
AddSortOrder
(
v
int
)
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
AddSortOrder
(
v
)
})
}
// UpdateSortOrder sets the "sort_order" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsertOne
)
UpdateSortOrder
()
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
UpdateSortOrder
()
})
}
// SetUpdatedAt sets the "updated_at" field.
func
(
u
*
SubscriptionPlanUpsertOne
)
SetUpdatedAt
(
v
time
.
Time
)
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
SetUpdatedAt
(
v
)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsertOne
)
UpdateUpdatedAt
()
*
SubscriptionPlanUpsertOne
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
UpdateUpdatedAt
()
})
}
// Exec executes the query.
func
(
u
*
SubscriptionPlanUpsertOne
)
Exec
(
ctx
context
.
Context
)
error
{
if
len
(
u
.
create
.
conflict
)
==
0
{
return
errors
.
New
(
"ent: missing options for SubscriptionPlanCreate.OnConflict"
)
}
return
u
.
create
.
Exec
(
ctx
)
}
// ExecX is like Exec, but panics if an error occurs.
func
(
u
*
SubscriptionPlanUpsertOne
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
u
.
create
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
// Exec executes the UPSERT query and returns the inserted/updated ID.
func
(
u
*
SubscriptionPlanUpsertOne
)
ID
(
ctx
context
.
Context
)
(
id
int64
,
err
error
)
{
node
,
err
:=
u
.
create
.
Save
(
ctx
)
if
err
!=
nil
{
return
id
,
err
}
return
node
.
ID
,
nil
}
// IDX is like ID, but panics if an error occurs.
func
(
u
*
SubscriptionPlanUpsertOne
)
IDX
(
ctx
context
.
Context
)
int64
{
id
,
err
:=
u
.
ID
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
id
}
// SubscriptionPlanCreateBulk is the builder for creating many SubscriptionPlan entities in bulk.
type
SubscriptionPlanCreateBulk
struct
{
config
err
error
builders
[]
*
SubscriptionPlanCreate
conflict
[]
sql
.
ConflictOption
}
// Save creates the SubscriptionPlan entities in the database.
func
(
_c
*
SubscriptionPlanCreateBulk
)
Save
(
ctx
context
.
Context
)
([]
*
SubscriptionPlan
,
error
)
{
if
_c
.
err
!=
nil
{
return
nil
,
_c
.
err
}
specs
:=
make
([]
*
sqlgraph
.
CreateSpec
,
len
(
_c
.
builders
))
nodes
:=
make
([]
*
SubscriptionPlan
,
len
(
_c
.
builders
))
mutators
:=
make
([]
Mutator
,
len
(
_c
.
builders
))
for
i
:=
range
_c
.
builders
{
func
(
i
int
,
root
context
.
Context
)
{
builder
:=
_c
.
builders
[
i
]
builder
.
defaults
()
var
mut
Mutator
=
MutateFunc
(
func
(
ctx
context
.
Context
,
m
Mutation
)
(
Value
,
error
)
{
mutation
,
ok
:=
m
.
(
*
SubscriptionPlanMutation
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"unexpected mutation type %T"
,
m
)
}
if
err
:=
builder
.
check
();
err
!=
nil
{
return
nil
,
err
}
builder
.
mutation
=
mutation
var
err
error
nodes
[
i
],
specs
[
i
]
=
builder
.
createSpec
()
if
i
<
len
(
mutators
)
-
1
{
_
,
err
=
mutators
[
i
+
1
]
.
Mutate
(
root
,
_c
.
builders
[
i
+
1
]
.
mutation
)
}
else
{
spec
:=
&
sqlgraph
.
BatchCreateSpec
{
Nodes
:
specs
}
spec
.
OnConflict
=
_c
.
conflict
// Invoke the actual operation on the latest mutation in the chain.
if
err
=
sqlgraph
.
BatchCreate
(
ctx
,
_c
.
driver
,
spec
);
err
!=
nil
{
if
sqlgraph
.
IsConstraintError
(
err
)
{
err
=
&
ConstraintError
{
msg
:
err
.
Error
(),
wrap
:
err
}
}
}
}
if
err
!=
nil
{
return
nil
,
err
}
mutation
.
id
=
&
nodes
[
i
]
.
ID
if
specs
[
i
]
.
ID
.
Value
!=
nil
{
id
:=
specs
[
i
]
.
ID
.
Value
.
(
int64
)
nodes
[
i
]
.
ID
=
int64
(
id
)
}
mutation
.
done
=
true
return
nodes
[
i
],
nil
})
for
i
:=
len
(
builder
.
hooks
)
-
1
;
i
>=
0
;
i
--
{
mut
=
builder
.
hooks
[
i
](
mut
)
}
mutators
[
i
]
=
mut
}(
i
,
ctx
)
}
if
len
(
mutators
)
>
0
{
if
_
,
err
:=
mutators
[
0
]
.
Mutate
(
ctx
,
_c
.
builders
[
0
]
.
mutation
);
err
!=
nil
{
return
nil
,
err
}
}
return
nodes
,
nil
}
// SaveX is like Save, but panics if an error occurs.
func
(
_c
*
SubscriptionPlanCreateBulk
)
SaveX
(
ctx
context
.
Context
)
[]
*
SubscriptionPlan
{
v
,
err
:=
_c
.
Save
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
v
}
// Exec executes the query.
func
(
_c
*
SubscriptionPlanCreateBulk
)
Exec
(
ctx
context
.
Context
)
error
{
_
,
err
:=
_c
.
Save
(
ctx
)
return
err
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_c
*
SubscriptionPlanCreateBulk
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
_c
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.SubscriptionPlan.CreateBulk(builders...).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.SubscriptionPlanUpsert) {
// SetGroupID(v+v).
// }).
// Exec(ctx)
func
(
_c
*
SubscriptionPlanCreateBulk
)
OnConflict
(
opts
...
sql
.
ConflictOption
)
*
SubscriptionPlanUpsertBulk
{
_c
.
conflict
=
opts
return
&
SubscriptionPlanUpsertBulk
{
create
:
_c
,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.SubscriptionPlan.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func
(
_c
*
SubscriptionPlanCreateBulk
)
OnConflictColumns
(
columns
...
string
)
*
SubscriptionPlanUpsertBulk
{
_c
.
conflict
=
append
(
_c
.
conflict
,
sql
.
ConflictColumns
(
columns
...
))
return
&
SubscriptionPlanUpsertBulk
{
create
:
_c
,
}
}
// SubscriptionPlanUpsertBulk is the builder for "upsert"-ing
// a bulk of SubscriptionPlan nodes.
type
SubscriptionPlanUpsertBulk
struct
{
create
*
SubscriptionPlanCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.SubscriptionPlan.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func
(
u
*
SubscriptionPlanUpsertBulk
)
UpdateNewValues
()
*
SubscriptionPlanUpsertBulk
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWithNewValues
())
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWith
(
func
(
s
*
sql
.
UpdateSet
)
{
for
_
,
b
:=
range
u
.
create
.
builders
{
if
_
,
exists
:=
b
.
mutation
.
CreatedAt
();
exists
{
s
.
SetIgnore
(
subscriptionplan
.
FieldCreatedAt
)
}
}
}))
return
u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.SubscriptionPlan.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func
(
u
*
SubscriptionPlanUpsertBulk
)
Ignore
()
*
SubscriptionPlanUpsertBulk
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWithIgnore
())
return
u
}
// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func
(
u
*
SubscriptionPlanUpsertBulk
)
DoNothing
()
*
SubscriptionPlanUpsertBulk
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
DoNothing
())
return
u
}
// Update allows overriding fields `UPDATE` values. See the SubscriptionPlanCreateBulk.OnConflict
// documentation for more info.
func
(
u
*
SubscriptionPlanUpsertBulk
)
Update
(
set
func
(
*
SubscriptionPlanUpsert
))
*
SubscriptionPlanUpsertBulk
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWith
(
func
(
update
*
sql
.
UpdateSet
)
{
set
(
&
SubscriptionPlanUpsert
{
UpdateSet
:
update
})
}))
return
u
}
// SetGroupID sets the "group_id" field.
func
(
u
*
SubscriptionPlanUpsertBulk
)
SetGroupID
(
v
int64
)
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
SetGroupID
(
v
)
})
}
// AddGroupID adds v to the "group_id" field.
func
(
u
*
SubscriptionPlanUpsertBulk
)
AddGroupID
(
v
int64
)
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
AddGroupID
(
v
)
})
}
// UpdateGroupID sets the "group_id" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsertBulk
)
UpdateGroupID
()
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
UpdateGroupID
()
})
}
// SetName sets the "name" field.
func
(
u
*
SubscriptionPlanUpsertBulk
)
SetName
(
v
string
)
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
SetName
(
v
)
})
}
// UpdateName sets the "name" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsertBulk
)
UpdateName
()
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
UpdateName
()
})
}
// SetDescription sets the "description" field.
func
(
u
*
SubscriptionPlanUpsertBulk
)
SetDescription
(
v
string
)
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
SetDescription
(
v
)
})
}
// UpdateDescription sets the "description" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsertBulk
)
UpdateDescription
()
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
UpdateDescription
()
})
}
// SetPrice sets the "price" field.
func
(
u
*
SubscriptionPlanUpsertBulk
)
SetPrice
(
v
float64
)
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
SetPrice
(
v
)
})
}
// AddPrice adds v to the "price" field.
func
(
u
*
SubscriptionPlanUpsertBulk
)
AddPrice
(
v
float64
)
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
AddPrice
(
v
)
})
}
// UpdatePrice sets the "price" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsertBulk
)
UpdatePrice
()
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
UpdatePrice
()
})
}
// SetOriginalPrice sets the "original_price" field.
func
(
u
*
SubscriptionPlanUpsertBulk
)
SetOriginalPrice
(
v
float64
)
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
SetOriginalPrice
(
v
)
})
}
// AddOriginalPrice adds v to the "original_price" field.
func
(
u
*
SubscriptionPlanUpsertBulk
)
AddOriginalPrice
(
v
float64
)
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
AddOriginalPrice
(
v
)
})
}
// UpdateOriginalPrice sets the "original_price" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsertBulk
)
UpdateOriginalPrice
()
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
UpdateOriginalPrice
()
})
}
// ClearOriginalPrice clears the value of the "original_price" field.
func
(
u
*
SubscriptionPlanUpsertBulk
)
ClearOriginalPrice
()
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
ClearOriginalPrice
()
})
}
// SetValidityDays sets the "validity_days" field.
func
(
u
*
SubscriptionPlanUpsertBulk
)
SetValidityDays
(
v
int
)
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
SetValidityDays
(
v
)
})
}
// AddValidityDays adds v to the "validity_days" field.
func
(
u
*
SubscriptionPlanUpsertBulk
)
AddValidityDays
(
v
int
)
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
AddValidityDays
(
v
)
})
}
// UpdateValidityDays sets the "validity_days" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsertBulk
)
UpdateValidityDays
()
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
UpdateValidityDays
()
})
}
// SetValidityUnit sets the "validity_unit" field.
func
(
u
*
SubscriptionPlanUpsertBulk
)
SetValidityUnit
(
v
string
)
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
SetValidityUnit
(
v
)
})
}
// UpdateValidityUnit sets the "validity_unit" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsertBulk
)
UpdateValidityUnit
()
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
UpdateValidityUnit
()
})
}
// SetFeatures sets the "features" field.
func
(
u
*
SubscriptionPlanUpsertBulk
)
SetFeatures
(
v
string
)
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
SetFeatures
(
v
)
})
}
// UpdateFeatures sets the "features" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsertBulk
)
UpdateFeatures
()
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
UpdateFeatures
()
})
}
// SetProductName sets the "product_name" field.
func
(
u
*
SubscriptionPlanUpsertBulk
)
SetProductName
(
v
string
)
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
SetProductName
(
v
)
})
}
// UpdateProductName sets the "product_name" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsertBulk
)
UpdateProductName
()
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
UpdateProductName
()
})
}
// SetForSale sets the "for_sale" field.
func
(
u
*
SubscriptionPlanUpsertBulk
)
SetForSale
(
v
bool
)
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
SetForSale
(
v
)
})
}
// UpdateForSale sets the "for_sale" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsertBulk
)
UpdateForSale
()
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
UpdateForSale
()
})
}
// SetSortOrder sets the "sort_order" field.
func
(
u
*
SubscriptionPlanUpsertBulk
)
SetSortOrder
(
v
int
)
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
SetSortOrder
(
v
)
})
}
// AddSortOrder adds v to the "sort_order" field.
func
(
u
*
SubscriptionPlanUpsertBulk
)
AddSortOrder
(
v
int
)
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
AddSortOrder
(
v
)
})
}
// UpdateSortOrder sets the "sort_order" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsertBulk
)
UpdateSortOrder
()
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
UpdateSortOrder
()
})
}
// SetUpdatedAt sets the "updated_at" field.
func
(
u
*
SubscriptionPlanUpsertBulk
)
SetUpdatedAt
(
v
time
.
Time
)
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
SetUpdatedAt
(
v
)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func
(
u
*
SubscriptionPlanUpsertBulk
)
UpdateUpdatedAt
()
*
SubscriptionPlanUpsertBulk
{
return
u
.
Update
(
func
(
s
*
SubscriptionPlanUpsert
)
{
s
.
UpdateUpdatedAt
()
})
}
// Exec executes the query.
func
(
u
*
SubscriptionPlanUpsertBulk
)
Exec
(
ctx
context
.
Context
)
error
{
if
u
.
create
.
err
!=
nil
{
return
u
.
create
.
err
}
for
i
,
b
:=
range
u
.
create
.
builders
{
if
len
(
b
.
conflict
)
!=
0
{
return
fmt
.
Errorf
(
"ent: OnConflict was set for builder %d. Set it on the SubscriptionPlanCreateBulk instead"
,
i
)
}
}
if
len
(
u
.
create
.
conflict
)
==
0
{
return
errors
.
New
(
"ent: missing options for SubscriptionPlanCreateBulk.OnConflict"
)
}
return
u
.
create
.
Exec
(
ctx
)
}
// ExecX is like Exec, but panics if an error occurs.
func
(
u
*
SubscriptionPlanUpsertBulk
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
u
.
create
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
backend/ent/subscriptionplan_delete.go
0 → 100644
View file @
97f14b7a
// Code generated by ent, DO NOT EDIT.
package
ent
import
(
"context"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/subscriptionplan"
)
// SubscriptionPlanDelete is the builder for deleting a SubscriptionPlan entity.
type
SubscriptionPlanDelete
struct
{
config
hooks
[]
Hook
mutation
*
SubscriptionPlanMutation
}
// Where appends a list predicates to the SubscriptionPlanDelete builder.
func
(
_d
*
SubscriptionPlanDelete
)
Where
(
ps
...
predicate
.
SubscriptionPlan
)
*
SubscriptionPlanDelete
{
_d
.
mutation
.
Where
(
ps
...
)
return
_d
}
// Exec executes the deletion query and returns how many vertices were deleted.
func
(
_d
*
SubscriptionPlanDelete
)
Exec
(
ctx
context
.
Context
)
(
int
,
error
)
{
return
withHooks
(
ctx
,
_d
.
sqlExec
,
_d
.
mutation
,
_d
.
hooks
)
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_d
*
SubscriptionPlanDelete
)
ExecX
(
ctx
context
.
Context
)
int
{
n
,
err
:=
_d
.
Exec
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
n
}
func
(
_d
*
SubscriptionPlanDelete
)
sqlExec
(
ctx
context
.
Context
)
(
int
,
error
)
{
_spec
:=
sqlgraph
.
NewDeleteSpec
(
subscriptionplan
.
Table
,
sqlgraph
.
NewFieldSpec
(
subscriptionplan
.
FieldID
,
field
.
TypeInt64
))
if
ps
:=
_d
.
mutation
.
predicates
;
len
(
ps
)
>
0
{
_spec
.
Predicate
=
func
(
selector
*
sql
.
Selector
)
{
for
i
:=
range
ps
{
ps
[
i
](
selector
)
}
}
}
affected
,
err
:=
sqlgraph
.
DeleteNodes
(
ctx
,
_d
.
driver
,
_spec
)
if
err
!=
nil
&&
sqlgraph
.
IsConstraintError
(
err
)
{
err
=
&
ConstraintError
{
msg
:
err
.
Error
(),
wrap
:
err
}
}
_d
.
mutation
.
done
=
true
return
affected
,
err
}
// SubscriptionPlanDeleteOne is the builder for deleting a single SubscriptionPlan entity.
type
SubscriptionPlanDeleteOne
struct
{
_d
*
SubscriptionPlanDelete
}
// Where appends a list predicates to the SubscriptionPlanDelete builder.
func
(
_d
*
SubscriptionPlanDeleteOne
)
Where
(
ps
...
predicate
.
SubscriptionPlan
)
*
SubscriptionPlanDeleteOne
{
_d
.
_d
.
mutation
.
Where
(
ps
...
)
return
_d
}
// Exec executes the deletion query.
func
(
_d
*
SubscriptionPlanDeleteOne
)
Exec
(
ctx
context
.
Context
)
error
{
n
,
err
:=
_d
.
_d
.
Exec
(
ctx
)
switch
{
case
err
!=
nil
:
return
err
case
n
==
0
:
return
&
NotFoundError
{
subscriptionplan
.
Label
}
default
:
return
nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_d
*
SubscriptionPlanDeleteOne
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
_d
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
backend/ent/subscriptionplan_query.go
0 → 100644
View file @
97f14b7a
// Code generated by ent, DO NOT EDIT.
package
ent
import
(
"context"
"fmt"
"math"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/subscriptionplan"
)
// SubscriptionPlanQuery is the builder for querying SubscriptionPlan entities.
type
SubscriptionPlanQuery
struct
{
config
ctx
*
QueryContext
order
[]
subscriptionplan
.
OrderOption
inters
[]
Interceptor
predicates
[]
predicate
.
SubscriptionPlan
modifiers
[]
func
(
*
sql
.
Selector
)
// intermediate query (i.e. traversal path).
sql
*
sql
.
Selector
path
func
(
context
.
Context
)
(
*
sql
.
Selector
,
error
)
}
// Where adds a new predicate for the SubscriptionPlanQuery builder.
func
(
_q
*
SubscriptionPlanQuery
)
Where
(
ps
...
predicate
.
SubscriptionPlan
)
*
SubscriptionPlanQuery
{
_q
.
predicates
=
append
(
_q
.
predicates
,
ps
...
)
return
_q
}
// Limit the number of records to be returned by this query.
func
(
_q
*
SubscriptionPlanQuery
)
Limit
(
limit
int
)
*
SubscriptionPlanQuery
{
_q
.
ctx
.
Limit
=
&
limit
return
_q
}
// Offset to start from.
func
(
_q
*
SubscriptionPlanQuery
)
Offset
(
offset
int
)
*
SubscriptionPlanQuery
{
_q
.
ctx
.
Offset
=
&
offset
return
_q
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func
(
_q
*
SubscriptionPlanQuery
)
Unique
(
unique
bool
)
*
SubscriptionPlanQuery
{
_q
.
ctx
.
Unique
=
&
unique
return
_q
}
// Order specifies how the records should be ordered.
func
(
_q
*
SubscriptionPlanQuery
)
Order
(
o
...
subscriptionplan
.
OrderOption
)
*
SubscriptionPlanQuery
{
_q
.
order
=
append
(
_q
.
order
,
o
...
)
return
_q
}
// First returns the first SubscriptionPlan entity from the query.
// Returns a *NotFoundError when no SubscriptionPlan was found.
func
(
_q
*
SubscriptionPlanQuery
)
First
(
ctx
context
.
Context
)
(
*
SubscriptionPlan
,
error
)
{
nodes
,
err
:=
_q
.
Limit
(
1
)
.
All
(
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryFirst
))
if
err
!=
nil
{
return
nil
,
err
}
if
len
(
nodes
)
==
0
{
return
nil
,
&
NotFoundError
{
subscriptionplan
.
Label
}
}
return
nodes
[
0
],
nil
}
// FirstX is like First, but panics if an error occurs.
func
(
_q
*
SubscriptionPlanQuery
)
FirstX
(
ctx
context
.
Context
)
*
SubscriptionPlan
{
node
,
err
:=
_q
.
First
(
ctx
)
if
err
!=
nil
&&
!
IsNotFound
(
err
)
{
panic
(
err
)
}
return
node
}
// FirstID returns the first SubscriptionPlan ID from the query.
// Returns a *NotFoundError when no SubscriptionPlan ID was found.
func
(
_q
*
SubscriptionPlanQuery
)
FirstID
(
ctx
context
.
Context
)
(
id
int64
,
err
error
)
{
var
ids
[]
int64
if
ids
,
err
=
_q
.
Limit
(
1
)
.
IDs
(
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryFirstID
));
err
!=
nil
{
return
}
if
len
(
ids
)
==
0
{
err
=
&
NotFoundError
{
subscriptionplan
.
Label
}
return
}
return
ids
[
0
],
nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func
(
_q
*
SubscriptionPlanQuery
)
FirstIDX
(
ctx
context
.
Context
)
int64
{
id
,
err
:=
_q
.
FirstID
(
ctx
)
if
err
!=
nil
&&
!
IsNotFound
(
err
)
{
panic
(
err
)
}
return
id
}
// Only returns a single SubscriptionPlan entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one SubscriptionPlan entity is found.
// Returns a *NotFoundError when no SubscriptionPlan entities are found.
func
(
_q
*
SubscriptionPlanQuery
)
Only
(
ctx
context
.
Context
)
(
*
SubscriptionPlan
,
error
)
{
nodes
,
err
:=
_q
.
Limit
(
2
)
.
All
(
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryOnly
))
if
err
!=
nil
{
return
nil
,
err
}
switch
len
(
nodes
)
{
case
1
:
return
nodes
[
0
],
nil
case
0
:
return
nil
,
&
NotFoundError
{
subscriptionplan
.
Label
}
default
:
return
nil
,
&
NotSingularError
{
subscriptionplan
.
Label
}
}
}
// OnlyX is like Only, but panics if an error occurs.
func
(
_q
*
SubscriptionPlanQuery
)
OnlyX
(
ctx
context
.
Context
)
*
SubscriptionPlan
{
node
,
err
:=
_q
.
Only
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
node
}
// OnlyID is like Only, but returns the only SubscriptionPlan ID in the query.
// Returns a *NotSingularError when more than one SubscriptionPlan ID is found.
// Returns a *NotFoundError when no entities are found.
func
(
_q
*
SubscriptionPlanQuery
)
OnlyID
(
ctx
context
.
Context
)
(
id
int64
,
err
error
)
{
var
ids
[]
int64
if
ids
,
err
=
_q
.
Limit
(
2
)
.
IDs
(
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryOnlyID
));
err
!=
nil
{
return
}
switch
len
(
ids
)
{
case
1
:
id
=
ids
[
0
]
case
0
:
err
=
&
NotFoundError
{
subscriptionplan
.
Label
}
default
:
err
=
&
NotSingularError
{
subscriptionplan
.
Label
}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func
(
_q
*
SubscriptionPlanQuery
)
OnlyIDX
(
ctx
context
.
Context
)
int64
{
id
,
err
:=
_q
.
OnlyID
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
id
}
// All executes the query and returns a list of SubscriptionPlans.
func
(
_q
*
SubscriptionPlanQuery
)
All
(
ctx
context
.
Context
)
([]
*
SubscriptionPlan
,
error
)
{
ctx
=
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryAll
)
if
err
:=
_q
.
prepareQuery
(
ctx
);
err
!=
nil
{
return
nil
,
err
}
qr
:=
querierAll
[[]
*
SubscriptionPlan
,
*
SubscriptionPlanQuery
]()
return
withInterceptors
[[]
*
SubscriptionPlan
](
ctx
,
_q
,
qr
,
_q
.
inters
)
}
// AllX is like All, but panics if an error occurs.
func
(
_q
*
SubscriptionPlanQuery
)
AllX
(
ctx
context
.
Context
)
[]
*
SubscriptionPlan
{
nodes
,
err
:=
_q
.
All
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
nodes
}
// IDs executes the query and returns a list of SubscriptionPlan IDs.
func
(
_q
*
SubscriptionPlanQuery
)
IDs
(
ctx
context
.
Context
)
(
ids
[]
int64
,
err
error
)
{
if
_q
.
ctx
.
Unique
==
nil
&&
_q
.
path
!=
nil
{
_q
.
Unique
(
true
)
}
ctx
=
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryIDs
)
if
err
=
_q
.
Select
(
subscriptionplan
.
FieldID
)
.
Scan
(
ctx
,
&
ids
);
err
!=
nil
{
return
nil
,
err
}
return
ids
,
nil
}
// IDsX is like IDs, but panics if an error occurs.
func
(
_q
*
SubscriptionPlanQuery
)
IDsX
(
ctx
context
.
Context
)
[]
int64
{
ids
,
err
:=
_q
.
IDs
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
ids
}
// Count returns the count of the given query.
func
(
_q
*
SubscriptionPlanQuery
)
Count
(
ctx
context
.
Context
)
(
int
,
error
)
{
ctx
=
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryCount
)
if
err
:=
_q
.
prepareQuery
(
ctx
);
err
!=
nil
{
return
0
,
err
}
return
withInterceptors
[
int
](
ctx
,
_q
,
querierCount
[
*
SubscriptionPlanQuery
](),
_q
.
inters
)
}
// CountX is like Count, but panics if an error occurs.
func
(
_q
*
SubscriptionPlanQuery
)
CountX
(
ctx
context
.
Context
)
int
{
count
,
err
:=
_q
.
Count
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
count
}
// Exist returns true if the query has elements in the graph.
func
(
_q
*
SubscriptionPlanQuery
)
Exist
(
ctx
context
.
Context
)
(
bool
,
error
)
{
ctx
=
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryExist
)
switch
_
,
err
:=
_q
.
FirstID
(
ctx
);
{
case
IsNotFound
(
err
)
:
return
false
,
nil
case
err
!=
nil
:
return
false
,
fmt
.
Errorf
(
"ent: check existence: %w"
,
err
)
default
:
return
true
,
nil
}
}
// ExistX is like Exist, but panics if an error occurs.
func
(
_q
*
SubscriptionPlanQuery
)
ExistX
(
ctx
context
.
Context
)
bool
{
exist
,
err
:=
_q
.
Exist
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
exist
}
// Clone returns a duplicate of the SubscriptionPlanQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func
(
_q
*
SubscriptionPlanQuery
)
Clone
()
*
SubscriptionPlanQuery
{
if
_q
==
nil
{
return
nil
}
return
&
SubscriptionPlanQuery
{
config
:
_q
.
config
,
ctx
:
_q
.
ctx
.
Clone
(),
order
:
append
([]
subscriptionplan
.
OrderOption
{},
_q
.
order
...
),
inters
:
append
([]
Interceptor
{},
_q
.
inters
...
),
predicates
:
append
([]
predicate
.
SubscriptionPlan
{},
_q
.
predicates
...
),
// clone intermediate query.
sql
:
_q
.
sql
.
Clone
(),
path
:
_q
.
path
,
}
}
// GroupBy is used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
//
// Example:
//
// var v []struct {
// GroupID int64 `json:"group_id,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.SubscriptionPlan.Query().
// GroupBy(subscriptionplan.FieldGroupID).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func
(
_q
*
SubscriptionPlanQuery
)
GroupBy
(
field
string
,
fields
...
string
)
*
SubscriptionPlanGroupBy
{
_q
.
ctx
.
Fields
=
append
([]
string
{
field
},
fields
...
)
grbuild
:=
&
SubscriptionPlanGroupBy
{
build
:
_q
}
grbuild
.
flds
=
&
_q
.
ctx
.
Fields
grbuild
.
label
=
subscriptionplan
.
Label
grbuild
.
scan
=
grbuild
.
Scan
return
grbuild
}
// Select allows the selection one or more fields/columns for the given query,
// instead of selecting all fields in the entity.
//
// Example:
//
// var v []struct {
// GroupID int64 `json:"group_id,omitempty"`
// }
//
// client.SubscriptionPlan.Query().
// Select(subscriptionplan.FieldGroupID).
// Scan(ctx, &v)
func
(
_q
*
SubscriptionPlanQuery
)
Select
(
fields
...
string
)
*
SubscriptionPlanSelect
{
_q
.
ctx
.
Fields
=
append
(
_q
.
ctx
.
Fields
,
fields
...
)
sbuild
:=
&
SubscriptionPlanSelect
{
SubscriptionPlanQuery
:
_q
}
sbuild
.
label
=
subscriptionplan
.
Label
sbuild
.
flds
,
sbuild
.
scan
=
&
_q
.
ctx
.
Fields
,
sbuild
.
Scan
return
sbuild
}
// Aggregate returns a SubscriptionPlanSelect configured with the given aggregations.
func
(
_q
*
SubscriptionPlanQuery
)
Aggregate
(
fns
...
AggregateFunc
)
*
SubscriptionPlanSelect
{
return
_q
.
Select
()
.
Aggregate
(
fns
...
)
}
func
(
_q
*
SubscriptionPlanQuery
)
prepareQuery
(
ctx
context
.
Context
)
error
{
for
_
,
inter
:=
range
_q
.
inters
{
if
inter
==
nil
{
return
fmt
.
Errorf
(
"ent: uninitialized interceptor (forgotten import ent/runtime?)"
)
}
if
trv
,
ok
:=
inter
.
(
Traverser
);
ok
{
if
err
:=
trv
.
Traverse
(
ctx
,
_q
);
err
!=
nil
{
return
err
}
}
}
for
_
,
f
:=
range
_q
.
ctx
.
Fields
{
if
!
subscriptionplan
.
ValidColumn
(
f
)
{
return
&
ValidationError
{
Name
:
f
,
err
:
fmt
.
Errorf
(
"ent: invalid field %q for query"
,
f
)}
}
}
if
_q
.
path
!=
nil
{
prev
,
err
:=
_q
.
path
(
ctx
)
if
err
!=
nil
{
return
err
}
_q
.
sql
=
prev
}
return
nil
}
func
(
_q
*
SubscriptionPlanQuery
)
sqlAll
(
ctx
context
.
Context
,
hooks
...
queryHook
)
([]
*
SubscriptionPlan
,
error
)
{
var
(
nodes
=
[]
*
SubscriptionPlan
{}
_spec
=
_q
.
querySpec
()
)
_spec
.
ScanValues
=
func
(
columns
[]
string
)
([]
any
,
error
)
{
return
(
*
SubscriptionPlan
)
.
scanValues
(
nil
,
columns
)
}
_spec
.
Assign
=
func
(
columns
[]
string
,
values
[]
any
)
error
{
node
:=
&
SubscriptionPlan
{
config
:
_q
.
config
}
nodes
=
append
(
nodes
,
node
)
return
node
.
assignValues
(
columns
,
values
)
}
if
len
(
_q
.
modifiers
)
>
0
{
_spec
.
Modifiers
=
_q
.
modifiers
}
for
i
:=
range
hooks
{
hooks
[
i
](
ctx
,
_spec
)
}
if
err
:=
sqlgraph
.
QueryNodes
(
ctx
,
_q
.
driver
,
_spec
);
err
!=
nil
{
return
nil
,
err
}
if
len
(
nodes
)
==
0
{
return
nodes
,
nil
}
return
nodes
,
nil
}
func
(
_q
*
SubscriptionPlanQuery
)
sqlCount
(
ctx
context
.
Context
)
(
int
,
error
)
{
_spec
:=
_q
.
querySpec
()
if
len
(
_q
.
modifiers
)
>
0
{
_spec
.
Modifiers
=
_q
.
modifiers
}
_spec
.
Node
.
Columns
=
_q
.
ctx
.
Fields
if
len
(
_q
.
ctx
.
Fields
)
>
0
{
_spec
.
Unique
=
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
}
return
sqlgraph
.
CountNodes
(
ctx
,
_q
.
driver
,
_spec
)
}
func
(
_q
*
SubscriptionPlanQuery
)
querySpec
()
*
sqlgraph
.
QuerySpec
{
_spec
:=
sqlgraph
.
NewQuerySpec
(
subscriptionplan
.
Table
,
subscriptionplan
.
Columns
,
sqlgraph
.
NewFieldSpec
(
subscriptionplan
.
FieldID
,
field
.
TypeInt64
))
_spec
.
From
=
_q
.
sql
if
unique
:=
_q
.
ctx
.
Unique
;
unique
!=
nil
{
_spec
.
Unique
=
*
unique
}
else
if
_q
.
path
!=
nil
{
_spec
.
Unique
=
true
}
if
fields
:=
_q
.
ctx
.
Fields
;
len
(
fields
)
>
0
{
_spec
.
Node
.
Columns
=
make
([]
string
,
0
,
len
(
fields
))
_spec
.
Node
.
Columns
=
append
(
_spec
.
Node
.
Columns
,
subscriptionplan
.
FieldID
)
for
i
:=
range
fields
{
if
fields
[
i
]
!=
subscriptionplan
.
FieldID
{
_spec
.
Node
.
Columns
=
append
(
_spec
.
Node
.
Columns
,
fields
[
i
])
}
}
}
if
ps
:=
_q
.
predicates
;
len
(
ps
)
>
0
{
_spec
.
Predicate
=
func
(
selector
*
sql
.
Selector
)
{
for
i
:=
range
ps
{
ps
[
i
](
selector
)
}
}
}
if
limit
:=
_q
.
ctx
.
Limit
;
limit
!=
nil
{
_spec
.
Limit
=
*
limit
}
if
offset
:=
_q
.
ctx
.
Offset
;
offset
!=
nil
{
_spec
.
Offset
=
*
offset
}
if
ps
:=
_q
.
order
;
len
(
ps
)
>
0
{
_spec
.
Order
=
func
(
selector
*
sql
.
Selector
)
{
for
i
:=
range
ps
{
ps
[
i
](
selector
)
}
}
}
return
_spec
}
func
(
_q
*
SubscriptionPlanQuery
)
sqlQuery
(
ctx
context
.
Context
)
*
sql
.
Selector
{
builder
:=
sql
.
Dialect
(
_q
.
driver
.
Dialect
())
t1
:=
builder
.
Table
(
subscriptionplan
.
Table
)
columns
:=
_q
.
ctx
.
Fields
if
len
(
columns
)
==
0
{
columns
=
subscriptionplan
.
Columns
}
selector
:=
builder
.
Select
(
t1
.
Columns
(
columns
...
)
...
)
.
From
(
t1
)
if
_q
.
sql
!=
nil
{
selector
=
_q
.
sql
selector
.
Select
(
selector
.
Columns
(
columns
...
)
...
)
}
if
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
{
selector
.
Distinct
()
}
for
_
,
m
:=
range
_q
.
modifiers
{
m
(
selector
)
}
for
_
,
p
:=
range
_q
.
predicates
{
p
(
selector
)
}
for
_
,
p
:=
range
_q
.
order
{
p
(
selector
)
}
if
offset
:=
_q
.
ctx
.
Offset
;
offset
!=
nil
{
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector
.
Offset
(
*
offset
)
.
Limit
(
math
.
MaxInt32
)
}
if
limit
:=
_q
.
ctx
.
Limit
;
limit
!=
nil
{
selector
.
Limit
(
*
limit
)
}
return
selector
}
// ForUpdate locks the selected rows against concurrent updates, and prevent them from being
// updated, deleted or "selected ... for update" by other sessions, until the transaction is
// either committed or rolled-back.
func
(
_q
*
SubscriptionPlanQuery
)
ForUpdate
(
opts
...
sql
.
LockOption
)
*
SubscriptionPlanQuery
{
if
_q
.
driver
.
Dialect
()
==
dialect
.
Postgres
{
_q
.
Unique
(
false
)
}
_q
.
modifiers
=
append
(
_q
.
modifiers
,
func
(
s
*
sql
.
Selector
)
{
s
.
ForUpdate
(
opts
...
)
})
return
_q
}
// ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock
// on any rows that are read. Other sessions can read the rows, but cannot modify them
// until your transaction commits.
func
(
_q
*
SubscriptionPlanQuery
)
ForShare
(
opts
...
sql
.
LockOption
)
*
SubscriptionPlanQuery
{
if
_q
.
driver
.
Dialect
()
==
dialect
.
Postgres
{
_q
.
Unique
(
false
)
}
_q
.
modifiers
=
append
(
_q
.
modifiers
,
func
(
s
*
sql
.
Selector
)
{
s
.
ForShare
(
opts
...
)
})
return
_q
}
// SubscriptionPlanGroupBy is the group-by builder for SubscriptionPlan entities.
type
SubscriptionPlanGroupBy
struct
{
selector
build
*
SubscriptionPlanQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func
(
_g
*
SubscriptionPlanGroupBy
)
Aggregate
(
fns
...
AggregateFunc
)
*
SubscriptionPlanGroupBy
{
_g
.
fns
=
append
(
_g
.
fns
,
fns
...
)
return
_g
}
// Scan applies the selector query and scans the result into the given value.
func
(
_g
*
SubscriptionPlanGroupBy
)
Scan
(
ctx
context
.
Context
,
v
any
)
error
{
ctx
=
setContextOp
(
ctx
,
_g
.
build
.
ctx
,
ent
.
OpQueryGroupBy
)
if
err
:=
_g
.
build
.
prepareQuery
(
ctx
);
err
!=
nil
{
return
err
}
return
scanWithInterceptors
[
*
SubscriptionPlanQuery
,
*
SubscriptionPlanGroupBy
](
ctx
,
_g
.
build
,
_g
,
_g
.
build
.
inters
,
v
)
}
func
(
_g
*
SubscriptionPlanGroupBy
)
sqlScan
(
ctx
context
.
Context
,
root
*
SubscriptionPlanQuery
,
v
any
)
error
{
selector
:=
root
.
sqlQuery
(
ctx
)
.
Select
()
aggregation
:=
make
([]
string
,
0
,
len
(
_g
.
fns
))
for
_
,
fn
:=
range
_g
.
fns
{
aggregation
=
append
(
aggregation
,
fn
(
selector
))
}
if
len
(
selector
.
SelectedColumns
())
==
0
{
columns
:=
make
([]
string
,
0
,
len
(
*
_g
.
flds
)
+
len
(
_g
.
fns
))
for
_
,
f
:=
range
*
_g
.
flds
{
columns
=
append
(
columns
,
selector
.
C
(
f
))
}
columns
=
append
(
columns
,
aggregation
...
)
selector
.
Select
(
columns
...
)
}
selector
.
GroupBy
(
selector
.
Columns
(
*
_g
.
flds
...
)
...
)
if
err
:=
selector
.
Err
();
err
!=
nil
{
return
err
}
rows
:=
&
sql
.
Rows
{}
query
,
args
:=
selector
.
Query
()
if
err
:=
_g
.
build
.
driver
.
Query
(
ctx
,
query
,
args
,
rows
);
err
!=
nil
{
return
err
}
defer
rows
.
Close
()
return
sql
.
ScanSlice
(
rows
,
v
)
}
// SubscriptionPlanSelect is the builder for selecting fields of SubscriptionPlan entities.
type
SubscriptionPlanSelect
struct
{
*
SubscriptionPlanQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func
(
_s
*
SubscriptionPlanSelect
)
Aggregate
(
fns
...
AggregateFunc
)
*
SubscriptionPlanSelect
{
_s
.
fns
=
append
(
_s
.
fns
,
fns
...
)
return
_s
}
// Scan applies the selector query and scans the result into the given value.
func
(
_s
*
SubscriptionPlanSelect
)
Scan
(
ctx
context
.
Context
,
v
any
)
error
{
ctx
=
setContextOp
(
ctx
,
_s
.
ctx
,
ent
.
OpQuerySelect
)
if
err
:=
_s
.
prepareQuery
(
ctx
);
err
!=
nil
{
return
err
}
return
scanWithInterceptors
[
*
SubscriptionPlanQuery
,
*
SubscriptionPlanSelect
](
ctx
,
_s
.
SubscriptionPlanQuery
,
_s
,
_s
.
inters
,
v
)
}
func
(
_s
*
SubscriptionPlanSelect
)
sqlScan
(
ctx
context
.
Context
,
root
*
SubscriptionPlanQuery
,
v
any
)
error
{
selector
:=
root
.
sqlQuery
(
ctx
)
aggregation
:=
make
([]
string
,
0
,
len
(
_s
.
fns
))
for
_
,
fn
:=
range
_s
.
fns
{
aggregation
=
append
(
aggregation
,
fn
(
selector
))
}
switch
n
:=
len
(
*
_s
.
selector
.
flds
);
{
case
n
==
0
&&
len
(
aggregation
)
>
0
:
selector
.
Select
(
aggregation
...
)
case
n
!=
0
&&
len
(
aggregation
)
>
0
:
selector
.
AppendSelect
(
aggregation
...
)
}
rows
:=
&
sql
.
Rows
{}
query
,
args
:=
selector
.
Query
()
if
err
:=
_s
.
driver
.
Query
(
ctx
,
query
,
args
,
rows
);
err
!=
nil
{
return
err
}
defer
rows
.
Close
()
return
sql
.
ScanSlice
(
rows
,
v
)
}
backend/ent/subscriptionplan_update.go
0 → 100644
View file @
97f14b7a
// Code generated by ent, DO NOT EDIT.
package
ent
import
(
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/subscriptionplan"
)
// SubscriptionPlanUpdate is the builder for updating SubscriptionPlan entities.
type
SubscriptionPlanUpdate
struct
{
config
hooks
[]
Hook
mutation
*
SubscriptionPlanMutation
}
// Where appends a list predicates to the SubscriptionPlanUpdate builder.
func
(
_u
*
SubscriptionPlanUpdate
)
Where
(
ps
...
predicate
.
SubscriptionPlan
)
*
SubscriptionPlanUpdate
{
_u
.
mutation
.
Where
(
ps
...
)
return
_u
}
// SetGroupID sets the "group_id" field.
func
(
_u
*
SubscriptionPlanUpdate
)
SetGroupID
(
v
int64
)
*
SubscriptionPlanUpdate
{
_u
.
mutation
.
ResetGroupID
()
_u
.
mutation
.
SetGroupID
(
v
)
return
_u
}
// SetNillableGroupID sets the "group_id" field if the given value is not nil.
func
(
_u
*
SubscriptionPlanUpdate
)
SetNillableGroupID
(
v
*
int64
)
*
SubscriptionPlanUpdate
{
if
v
!=
nil
{
_u
.
SetGroupID
(
*
v
)
}
return
_u
}
// AddGroupID adds value to the "group_id" field.
func
(
_u
*
SubscriptionPlanUpdate
)
AddGroupID
(
v
int64
)
*
SubscriptionPlanUpdate
{
_u
.
mutation
.
AddGroupID
(
v
)
return
_u
}
// SetName sets the "name" field.
func
(
_u
*
SubscriptionPlanUpdate
)
SetName
(
v
string
)
*
SubscriptionPlanUpdate
{
_u
.
mutation
.
SetName
(
v
)
return
_u
}
// SetNillableName sets the "name" field if the given value is not nil.
func
(
_u
*
SubscriptionPlanUpdate
)
SetNillableName
(
v
*
string
)
*
SubscriptionPlanUpdate
{
if
v
!=
nil
{
_u
.
SetName
(
*
v
)
}
return
_u
}
// SetDescription sets the "description" field.
func
(
_u
*
SubscriptionPlanUpdate
)
SetDescription
(
v
string
)
*
SubscriptionPlanUpdate
{
_u
.
mutation
.
SetDescription
(
v
)
return
_u
}
// SetNillableDescription sets the "description" field if the given value is not nil.
func
(
_u
*
SubscriptionPlanUpdate
)
SetNillableDescription
(
v
*
string
)
*
SubscriptionPlanUpdate
{
if
v
!=
nil
{
_u
.
SetDescription
(
*
v
)
}
return
_u
}
// SetPrice sets the "price" field.
func
(
_u
*
SubscriptionPlanUpdate
)
SetPrice
(
v
float64
)
*
SubscriptionPlanUpdate
{
_u
.
mutation
.
ResetPrice
()
_u
.
mutation
.
SetPrice
(
v
)
return
_u
}
// SetNillablePrice sets the "price" field if the given value is not nil.
func
(
_u
*
SubscriptionPlanUpdate
)
SetNillablePrice
(
v
*
float64
)
*
SubscriptionPlanUpdate
{
if
v
!=
nil
{
_u
.
SetPrice
(
*
v
)
}
return
_u
}
// AddPrice adds value to the "price" field.
func
(
_u
*
SubscriptionPlanUpdate
)
AddPrice
(
v
float64
)
*
SubscriptionPlanUpdate
{
_u
.
mutation
.
AddPrice
(
v
)
return
_u
}
// SetOriginalPrice sets the "original_price" field.
func
(
_u
*
SubscriptionPlanUpdate
)
SetOriginalPrice
(
v
float64
)
*
SubscriptionPlanUpdate
{
_u
.
mutation
.
ResetOriginalPrice
()
_u
.
mutation
.
SetOriginalPrice
(
v
)
return
_u
}
// SetNillableOriginalPrice sets the "original_price" field if the given value is not nil.
func
(
_u
*
SubscriptionPlanUpdate
)
SetNillableOriginalPrice
(
v
*
float64
)
*
SubscriptionPlanUpdate
{
if
v
!=
nil
{
_u
.
SetOriginalPrice
(
*
v
)
}
return
_u
}
// AddOriginalPrice adds value to the "original_price" field.
func
(
_u
*
SubscriptionPlanUpdate
)
AddOriginalPrice
(
v
float64
)
*
SubscriptionPlanUpdate
{
_u
.
mutation
.
AddOriginalPrice
(
v
)
return
_u
}
// ClearOriginalPrice clears the value of the "original_price" field.
func
(
_u
*
SubscriptionPlanUpdate
)
ClearOriginalPrice
()
*
SubscriptionPlanUpdate
{
_u
.
mutation
.
ClearOriginalPrice
()
return
_u
}
// SetValidityDays sets the "validity_days" field.
func
(
_u
*
SubscriptionPlanUpdate
)
SetValidityDays
(
v
int
)
*
SubscriptionPlanUpdate
{
_u
.
mutation
.
ResetValidityDays
()
_u
.
mutation
.
SetValidityDays
(
v
)
return
_u
}
// SetNillableValidityDays sets the "validity_days" field if the given value is not nil.
func
(
_u
*
SubscriptionPlanUpdate
)
SetNillableValidityDays
(
v
*
int
)
*
SubscriptionPlanUpdate
{
if
v
!=
nil
{
_u
.
SetValidityDays
(
*
v
)
}
return
_u
}
// AddValidityDays adds value to the "validity_days" field.
func
(
_u
*
SubscriptionPlanUpdate
)
AddValidityDays
(
v
int
)
*
SubscriptionPlanUpdate
{
_u
.
mutation
.
AddValidityDays
(
v
)
return
_u
}
// SetValidityUnit sets the "validity_unit" field.
func
(
_u
*
SubscriptionPlanUpdate
)
SetValidityUnit
(
v
string
)
*
SubscriptionPlanUpdate
{
_u
.
mutation
.
SetValidityUnit
(
v
)
return
_u
}
// SetNillableValidityUnit sets the "validity_unit" field if the given value is not nil.
func
(
_u
*
SubscriptionPlanUpdate
)
SetNillableValidityUnit
(
v
*
string
)
*
SubscriptionPlanUpdate
{
if
v
!=
nil
{
_u
.
SetValidityUnit
(
*
v
)
}
return
_u
}
// SetFeatures sets the "features" field.
func
(
_u
*
SubscriptionPlanUpdate
)
SetFeatures
(
v
string
)
*
SubscriptionPlanUpdate
{
_u
.
mutation
.
SetFeatures
(
v
)
return
_u
}
// SetNillableFeatures sets the "features" field if the given value is not nil.
func
(
_u
*
SubscriptionPlanUpdate
)
SetNillableFeatures
(
v
*
string
)
*
SubscriptionPlanUpdate
{
if
v
!=
nil
{
_u
.
SetFeatures
(
*
v
)
}
return
_u
}
// SetProductName sets the "product_name" field.
func
(
_u
*
SubscriptionPlanUpdate
)
SetProductName
(
v
string
)
*
SubscriptionPlanUpdate
{
_u
.
mutation
.
SetProductName
(
v
)
return
_u
}
// SetNillableProductName sets the "product_name" field if the given value is not nil.
func
(
_u
*
SubscriptionPlanUpdate
)
SetNillableProductName
(
v
*
string
)
*
SubscriptionPlanUpdate
{
if
v
!=
nil
{
_u
.
SetProductName
(
*
v
)
}
return
_u
}
// SetForSale sets the "for_sale" field.
func
(
_u
*
SubscriptionPlanUpdate
)
SetForSale
(
v
bool
)
*
SubscriptionPlanUpdate
{
_u
.
mutation
.
SetForSale
(
v
)
return
_u
}
// SetNillableForSale sets the "for_sale" field if the given value is not nil.
func
(
_u
*
SubscriptionPlanUpdate
)
SetNillableForSale
(
v
*
bool
)
*
SubscriptionPlanUpdate
{
if
v
!=
nil
{
_u
.
SetForSale
(
*
v
)
}
return
_u
}
// SetSortOrder sets the "sort_order" field.
func
(
_u
*
SubscriptionPlanUpdate
)
SetSortOrder
(
v
int
)
*
SubscriptionPlanUpdate
{
_u
.
mutation
.
ResetSortOrder
()
_u
.
mutation
.
SetSortOrder
(
v
)
return
_u
}
// SetNillableSortOrder sets the "sort_order" field if the given value is not nil.
func
(
_u
*
SubscriptionPlanUpdate
)
SetNillableSortOrder
(
v
*
int
)
*
SubscriptionPlanUpdate
{
if
v
!=
nil
{
_u
.
SetSortOrder
(
*
v
)
}
return
_u
}
// AddSortOrder adds value to the "sort_order" field.
func
(
_u
*
SubscriptionPlanUpdate
)
AddSortOrder
(
v
int
)
*
SubscriptionPlanUpdate
{
_u
.
mutation
.
AddSortOrder
(
v
)
return
_u
}
// SetUpdatedAt sets the "updated_at" field.
func
(
_u
*
SubscriptionPlanUpdate
)
SetUpdatedAt
(
v
time
.
Time
)
*
SubscriptionPlanUpdate
{
_u
.
mutation
.
SetUpdatedAt
(
v
)
return
_u
}
// Mutation returns the SubscriptionPlanMutation object of the builder.
func
(
_u
*
SubscriptionPlanUpdate
)
Mutation
()
*
SubscriptionPlanMutation
{
return
_u
.
mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func
(
_u
*
SubscriptionPlanUpdate
)
Save
(
ctx
context
.
Context
)
(
int
,
error
)
{
_u
.
defaults
()
return
withHooks
(
ctx
,
_u
.
sqlSave
,
_u
.
mutation
,
_u
.
hooks
)
}
// SaveX is like Save, but panics if an error occurs.
func
(
_u
*
SubscriptionPlanUpdate
)
SaveX
(
ctx
context
.
Context
)
int
{
affected
,
err
:=
_u
.
Save
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
affected
}
// Exec executes the query.
func
(
_u
*
SubscriptionPlanUpdate
)
Exec
(
ctx
context
.
Context
)
error
{
_
,
err
:=
_u
.
Save
(
ctx
)
return
err
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_u
*
SubscriptionPlanUpdate
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
_u
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
// defaults sets the default values of the builder before save.
func
(
_u
*
SubscriptionPlanUpdate
)
defaults
()
{
if
_
,
ok
:=
_u
.
mutation
.
UpdatedAt
();
!
ok
{
v
:=
subscriptionplan
.
UpdateDefaultUpdatedAt
()
_u
.
mutation
.
SetUpdatedAt
(
v
)
}
}
// check runs all checks and user-defined validators on the builder.
func
(
_u
*
SubscriptionPlanUpdate
)
check
()
error
{
if
v
,
ok
:=
_u
.
mutation
.
Name
();
ok
{
if
err
:=
subscriptionplan
.
NameValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"name"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "SubscriptionPlan.name": %w`
,
err
)}
}
}
if
v
,
ok
:=
_u
.
mutation
.
ValidityUnit
();
ok
{
if
err
:=
subscriptionplan
.
ValidityUnitValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"validity_unit"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "SubscriptionPlan.validity_unit": %w`
,
err
)}
}
}
if
v
,
ok
:=
_u
.
mutation
.
ProductName
();
ok
{
if
err
:=
subscriptionplan
.
ProductNameValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"product_name"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "SubscriptionPlan.product_name": %w`
,
err
)}
}
}
return
nil
}
func
(
_u
*
SubscriptionPlanUpdate
)
sqlSave
(
ctx
context
.
Context
)
(
_node
int
,
err
error
)
{
if
err
:=
_u
.
check
();
err
!=
nil
{
return
_node
,
err
}
_spec
:=
sqlgraph
.
NewUpdateSpec
(
subscriptionplan
.
Table
,
subscriptionplan
.
Columns
,
sqlgraph
.
NewFieldSpec
(
subscriptionplan
.
FieldID
,
field
.
TypeInt64
))
if
ps
:=
_u
.
mutation
.
predicates
;
len
(
ps
)
>
0
{
_spec
.
Predicate
=
func
(
selector
*
sql
.
Selector
)
{
for
i
:=
range
ps
{
ps
[
i
](
selector
)
}
}
}
if
value
,
ok
:=
_u
.
mutation
.
GroupID
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldGroupID
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedGroupID
();
ok
{
_spec
.
AddField
(
subscriptionplan
.
FieldGroupID
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
Name
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldName
,
field
.
TypeString
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
Description
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldDescription
,
field
.
TypeString
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
Price
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldPrice
,
field
.
TypeFloat64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedPrice
();
ok
{
_spec
.
AddField
(
subscriptionplan
.
FieldPrice
,
field
.
TypeFloat64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
OriginalPrice
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldOriginalPrice
,
field
.
TypeFloat64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedOriginalPrice
();
ok
{
_spec
.
AddField
(
subscriptionplan
.
FieldOriginalPrice
,
field
.
TypeFloat64
,
value
)
}
if
_u
.
mutation
.
OriginalPriceCleared
()
{
_spec
.
ClearField
(
subscriptionplan
.
FieldOriginalPrice
,
field
.
TypeFloat64
)
}
if
value
,
ok
:=
_u
.
mutation
.
ValidityDays
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldValidityDays
,
field
.
TypeInt
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedValidityDays
();
ok
{
_spec
.
AddField
(
subscriptionplan
.
FieldValidityDays
,
field
.
TypeInt
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
ValidityUnit
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldValidityUnit
,
field
.
TypeString
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
Features
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldFeatures
,
field
.
TypeString
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
ProductName
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldProductName
,
field
.
TypeString
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
ForSale
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldForSale
,
field
.
TypeBool
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
SortOrder
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldSortOrder
,
field
.
TypeInt
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedSortOrder
();
ok
{
_spec
.
AddField
(
subscriptionplan
.
FieldSortOrder
,
field
.
TypeInt
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
UpdatedAt
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldUpdatedAt
,
field
.
TypeTime
,
value
)
}
if
_node
,
err
=
sqlgraph
.
UpdateNodes
(
ctx
,
_u
.
driver
,
_spec
);
err
!=
nil
{
if
_
,
ok
:=
err
.
(
*
sqlgraph
.
NotFoundError
);
ok
{
err
=
&
NotFoundError
{
subscriptionplan
.
Label
}
}
else
if
sqlgraph
.
IsConstraintError
(
err
)
{
err
=
&
ConstraintError
{
msg
:
err
.
Error
(),
wrap
:
err
}
}
return
0
,
err
}
_u
.
mutation
.
done
=
true
return
_node
,
nil
}
// SubscriptionPlanUpdateOne is the builder for updating a single SubscriptionPlan entity.
type
SubscriptionPlanUpdateOne
struct
{
config
fields
[]
string
hooks
[]
Hook
mutation
*
SubscriptionPlanMutation
}
// SetGroupID sets the "group_id" field.
func
(
_u
*
SubscriptionPlanUpdateOne
)
SetGroupID
(
v
int64
)
*
SubscriptionPlanUpdateOne
{
_u
.
mutation
.
ResetGroupID
()
_u
.
mutation
.
SetGroupID
(
v
)
return
_u
}
// SetNillableGroupID sets the "group_id" field if the given value is not nil.
func
(
_u
*
SubscriptionPlanUpdateOne
)
SetNillableGroupID
(
v
*
int64
)
*
SubscriptionPlanUpdateOne
{
if
v
!=
nil
{
_u
.
SetGroupID
(
*
v
)
}
return
_u
}
// AddGroupID adds value to the "group_id" field.
func
(
_u
*
SubscriptionPlanUpdateOne
)
AddGroupID
(
v
int64
)
*
SubscriptionPlanUpdateOne
{
_u
.
mutation
.
AddGroupID
(
v
)
return
_u
}
// SetName sets the "name" field.
func
(
_u
*
SubscriptionPlanUpdateOne
)
SetName
(
v
string
)
*
SubscriptionPlanUpdateOne
{
_u
.
mutation
.
SetName
(
v
)
return
_u
}
// SetNillableName sets the "name" field if the given value is not nil.
func
(
_u
*
SubscriptionPlanUpdateOne
)
SetNillableName
(
v
*
string
)
*
SubscriptionPlanUpdateOne
{
if
v
!=
nil
{
_u
.
SetName
(
*
v
)
}
return
_u
}
// SetDescription sets the "description" field.
func
(
_u
*
SubscriptionPlanUpdateOne
)
SetDescription
(
v
string
)
*
SubscriptionPlanUpdateOne
{
_u
.
mutation
.
SetDescription
(
v
)
return
_u
}
// SetNillableDescription sets the "description" field if the given value is not nil.
func
(
_u
*
SubscriptionPlanUpdateOne
)
SetNillableDescription
(
v
*
string
)
*
SubscriptionPlanUpdateOne
{
if
v
!=
nil
{
_u
.
SetDescription
(
*
v
)
}
return
_u
}
// SetPrice sets the "price" field.
func
(
_u
*
SubscriptionPlanUpdateOne
)
SetPrice
(
v
float64
)
*
SubscriptionPlanUpdateOne
{
_u
.
mutation
.
ResetPrice
()
_u
.
mutation
.
SetPrice
(
v
)
return
_u
}
// SetNillablePrice sets the "price" field if the given value is not nil.
func
(
_u
*
SubscriptionPlanUpdateOne
)
SetNillablePrice
(
v
*
float64
)
*
SubscriptionPlanUpdateOne
{
if
v
!=
nil
{
_u
.
SetPrice
(
*
v
)
}
return
_u
}
// AddPrice adds value to the "price" field.
func
(
_u
*
SubscriptionPlanUpdateOne
)
AddPrice
(
v
float64
)
*
SubscriptionPlanUpdateOne
{
_u
.
mutation
.
AddPrice
(
v
)
return
_u
}
// SetOriginalPrice sets the "original_price" field.
func
(
_u
*
SubscriptionPlanUpdateOne
)
SetOriginalPrice
(
v
float64
)
*
SubscriptionPlanUpdateOne
{
_u
.
mutation
.
ResetOriginalPrice
()
_u
.
mutation
.
SetOriginalPrice
(
v
)
return
_u
}
// SetNillableOriginalPrice sets the "original_price" field if the given value is not nil.
func
(
_u
*
SubscriptionPlanUpdateOne
)
SetNillableOriginalPrice
(
v
*
float64
)
*
SubscriptionPlanUpdateOne
{
if
v
!=
nil
{
_u
.
SetOriginalPrice
(
*
v
)
}
return
_u
}
// AddOriginalPrice adds value to the "original_price" field.
func
(
_u
*
SubscriptionPlanUpdateOne
)
AddOriginalPrice
(
v
float64
)
*
SubscriptionPlanUpdateOne
{
_u
.
mutation
.
AddOriginalPrice
(
v
)
return
_u
}
// ClearOriginalPrice clears the value of the "original_price" field.
func
(
_u
*
SubscriptionPlanUpdateOne
)
ClearOriginalPrice
()
*
SubscriptionPlanUpdateOne
{
_u
.
mutation
.
ClearOriginalPrice
()
return
_u
}
// SetValidityDays sets the "validity_days" field.
func
(
_u
*
SubscriptionPlanUpdateOne
)
SetValidityDays
(
v
int
)
*
SubscriptionPlanUpdateOne
{
_u
.
mutation
.
ResetValidityDays
()
_u
.
mutation
.
SetValidityDays
(
v
)
return
_u
}
// SetNillableValidityDays sets the "validity_days" field if the given value is not nil.
func
(
_u
*
SubscriptionPlanUpdateOne
)
SetNillableValidityDays
(
v
*
int
)
*
SubscriptionPlanUpdateOne
{
if
v
!=
nil
{
_u
.
SetValidityDays
(
*
v
)
}
return
_u
}
// AddValidityDays adds value to the "validity_days" field.
func
(
_u
*
SubscriptionPlanUpdateOne
)
AddValidityDays
(
v
int
)
*
SubscriptionPlanUpdateOne
{
_u
.
mutation
.
AddValidityDays
(
v
)
return
_u
}
// SetValidityUnit sets the "validity_unit" field.
func
(
_u
*
SubscriptionPlanUpdateOne
)
SetValidityUnit
(
v
string
)
*
SubscriptionPlanUpdateOne
{
_u
.
mutation
.
SetValidityUnit
(
v
)
return
_u
}
// SetNillableValidityUnit sets the "validity_unit" field if the given value is not nil.
func
(
_u
*
SubscriptionPlanUpdateOne
)
SetNillableValidityUnit
(
v
*
string
)
*
SubscriptionPlanUpdateOne
{
if
v
!=
nil
{
_u
.
SetValidityUnit
(
*
v
)
}
return
_u
}
// SetFeatures sets the "features" field.
func
(
_u
*
SubscriptionPlanUpdateOne
)
SetFeatures
(
v
string
)
*
SubscriptionPlanUpdateOne
{
_u
.
mutation
.
SetFeatures
(
v
)
return
_u
}
// SetNillableFeatures sets the "features" field if the given value is not nil.
func
(
_u
*
SubscriptionPlanUpdateOne
)
SetNillableFeatures
(
v
*
string
)
*
SubscriptionPlanUpdateOne
{
if
v
!=
nil
{
_u
.
SetFeatures
(
*
v
)
}
return
_u
}
// SetProductName sets the "product_name" field.
func
(
_u
*
SubscriptionPlanUpdateOne
)
SetProductName
(
v
string
)
*
SubscriptionPlanUpdateOne
{
_u
.
mutation
.
SetProductName
(
v
)
return
_u
}
// SetNillableProductName sets the "product_name" field if the given value is not nil.
func
(
_u
*
SubscriptionPlanUpdateOne
)
SetNillableProductName
(
v
*
string
)
*
SubscriptionPlanUpdateOne
{
if
v
!=
nil
{
_u
.
SetProductName
(
*
v
)
}
return
_u
}
// SetForSale sets the "for_sale" field.
func
(
_u
*
SubscriptionPlanUpdateOne
)
SetForSale
(
v
bool
)
*
SubscriptionPlanUpdateOne
{
_u
.
mutation
.
SetForSale
(
v
)
return
_u
}
// SetNillableForSale sets the "for_sale" field if the given value is not nil.
func
(
_u
*
SubscriptionPlanUpdateOne
)
SetNillableForSale
(
v
*
bool
)
*
SubscriptionPlanUpdateOne
{
if
v
!=
nil
{
_u
.
SetForSale
(
*
v
)
}
return
_u
}
// SetSortOrder sets the "sort_order" field.
func
(
_u
*
SubscriptionPlanUpdateOne
)
SetSortOrder
(
v
int
)
*
SubscriptionPlanUpdateOne
{
_u
.
mutation
.
ResetSortOrder
()
_u
.
mutation
.
SetSortOrder
(
v
)
return
_u
}
// SetNillableSortOrder sets the "sort_order" field if the given value is not nil.
func
(
_u
*
SubscriptionPlanUpdateOne
)
SetNillableSortOrder
(
v
*
int
)
*
SubscriptionPlanUpdateOne
{
if
v
!=
nil
{
_u
.
SetSortOrder
(
*
v
)
}
return
_u
}
// AddSortOrder adds value to the "sort_order" field.
func
(
_u
*
SubscriptionPlanUpdateOne
)
AddSortOrder
(
v
int
)
*
SubscriptionPlanUpdateOne
{
_u
.
mutation
.
AddSortOrder
(
v
)
return
_u
}
// SetUpdatedAt sets the "updated_at" field.
func
(
_u
*
SubscriptionPlanUpdateOne
)
SetUpdatedAt
(
v
time
.
Time
)
*
SubscriptionPlanUpdateOne
{
_u
.
mutation
.
SetUpdatedAt
(
v
)
return
_u
}
// Mutation returns the SubscriptionPlanMutation object of the builder.
func
(
_u
*
SubscriptionPlanUpdateOne
)
Mutation
()
*
SubscriptionPlanMutation
{
return
_u
.
mutation
}
// Where appends a list predicates to the SubscriptionPlanUpdate builder.
func
(
_u
*
SubscriptionPlanUpdateOne
)
Where
(
ps
...
predicate
.
SubscriptionPlan
)
*
SubscriptionPlanUpdateOne
{
_u
.
mutation
.
Where
(
ps
...
)
return
_u
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func
(
_u
*
SubscriptionPlanUpdateOne
)
Select
(
field
string
,
fields
...
string
)
*
SubscriptionPlanUpdateOne
{
_u
.
fields
=
append
([]
string
{
field
},
fields
...
)
return
_u
}
// Save executes the query and returns the updated SubscriptionPlan entity.
func
(
_u
*
SubscriptionPlanUpdateOne
)
Save
(
ctx
context
.
Context
)
(
*
SubscriptionPlan
,
error
)
{
_u
.
defaults
()
return
withHooks
(
ctx
,
_u
.
sqlSave
,
_u
.
mutation
,
_u
.
hooks
)
}
// SaveX is like Save, but panics if an error occurs.
func
(
_u
*
SubscriptionPlanUpdateOne
)
SaveX
(
ctx
context
.
Context
)
*
SubscriptionPlan
{
node
,
err
:=
_u
.
Save
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
node
}
// Exec executes the query on the entity.
func
(
_u
*
SubscriptionPlanUpdateOne
)
Exec
(
ctx
context
.
Context
)
error
{
_
,
err
:=
_u
.
Save
(
ctx
)
return
err
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_u
*
SubscriptionPlanUpdateOne
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
_u
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
// defaults sets the default values of the builder before save.
func
(
_u
*
SubscriptionPlanUpdateOne
)
defaults
()
{
if
_
,
ok
:=
_u
.
mutation
.
UpdatedAt
();
!
ok
{
v
:=
subscriptionplan
.
UpdateDefaultUpdatedAt
()
_u
.
mutation
.
SetUpdatedAt
(
v
)
}
}
// check runs all checks and user-defined validators on the builder.
func
(
_u
*
SubscriptionPlanUpdateOne
)
check
()
error
{
if
v
,
ok
:=
_u
.
mutation
.
Name
();
ok
{
if
err
:=
subscriptionplan
.
NameValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"name"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "SubscriptionPlan.name": %w`
,
err
)}
}
}
if
v
,
ok
:=
_u
.
mutation
.
ValidityUnit
();
ok
{
if
err
:=
subscriptionplan
.
ValidityUnitValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"validity_unit"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "SubscriptionPlan.validity_unit": %w`
,
err
)}
}
}
if
v
,
ok
:=
_u
.
mutation
.
ProductName
();
ok
{
if
err
:=
subscriptionplan
.
ProductNameValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"product_name"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "SubscriptionPlan.product_name": %w`
,
err
)}
}
}
return
nil
}
func
(
_u
*
SubscriptionPlanUpdateOne
)
sqlSave
(
ctx
context
.
Context
)
(
_node
*
SubscriptionPlan
,
err
error
)
{
if
err
:=
_u
.
check
();
err
!=
nil
{
return
_node
,
err
}
_spec
:=
sqlgraph
.
NewUpdateSpec
(
subscriptionplan
.
Table
,
subscriptionplan
.
Columns
,
sqlgraph
.
NewFieldSpec
(
subscriptionplan
.
FieldID
,
field
.
TypeInt64
))
id
,
ok
:=
_u
.
mutation
.
ID
()
if
!
ok
{
return
nil
,
&
ValidationError
{
Name
:
"id"
,
err
:
errors
.
New
(
`ent: missing "SubscriptionPlan.id" for update`
)}
}
_spec
.
Node
.
ID
.
Value
=
id
if
fields
:=
_u
.
fields
;
len
(
fields
)
>
0
{
_spec
.
Node
.
Columns
=
make
([]
string
,
0
,
len
(
fields
))
_spec
.
Node
.
Columns
=
append
(
_spec
.
Node
.
Columns
,
subscriptionplan
.
FieldID
)
for
_
,
f
:=
range
fields
{
if
!
subscriptionplan
.
ValidColumn
(
f
)
{
return
nil
,
&
ValidationError
{
Name
:
f
,
err
:
fmt
.
Errorf
(
"ent: invalid field %q for query"
,
f
)}
}
if
f
!=
subscriptionplan
.
FieldID
{
_spec
.
Node
.
Columns
=
append
(
_spec
.
Node
.
Columns
,
f
)
}
}
}
if
ps
:=
_u
.
mutation
.
predicates
;
len
(
ps
)
>
0
{
_spec
.
Predicate
=
func
(
selector
*
sql
.
Selector
)
{
for
i
:=
range
ps
{
ps
[
i
](
selector
)
}
}
}
if
value
,
ok
:=
_u
.
mutation
.
GroupID
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldGroupID
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedGroupID
();
ok
{
_spec
.
AddField
(
subscriptionplan
.
FieldGroupID
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
Name
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldName
,
field
.
TypeString
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
Description
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldDescription
,
field
.
TypeString
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
Price
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldPrice
,
field
.
TypeFloat64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedPrice
();
ok
{
_spec
.
AddField
(
subscriptionplan
.
FieldPrice
,
field
.
TypeFloat64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
OriginalPrice
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldOriginalPrice
,
field
.
TypeFloat64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedOriginalPrice
();
ok
{
_spec
.
AddField
(
subscriptionplan
.
FieldOriginalPrice
,
field
.
TypeFloat64
,
value
)
}
if
_u
.
mutation
.
OriginalPriceCleared
()
{
_spec
.
ClearField
(
subscriptionplan
.
FieldOriginalPrice
,
field
.
TypeFloat64
)
}
if
value
,
ok
:=
_u
.
mutation
.
ValidityDays
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldValidityDays
,
field
.
TypeInt
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedValidityDays
();
ok
{
_spec
.
AddField
(
subscriptionplan
.
FieldValidityDays
,
field
.
TypeInt
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
ValidityUnit
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldValidityUnit
,
field
.
TypeString
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
Features
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldFeatures
,
field
.
TypeString
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
ProductName
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldProductName
,
field
.
TypeString
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
ForSale
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldForSale
,
field
.
TypeBool
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
SortOrder
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldSortOrder
,
field
.
TypeInt
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedSortOrder
();
ok
{
_spec
.
AddField
(
subscriptionplan
.
FieldSortOrder
,
field
.
TypeInt
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
UpdatedAt
();
ok
{
_spec
.
SetField
(
subscriptionplan
.
FieldUpdatedAt
,
field
.
TypeTime
,
value
)
}
_node
=
&
SubscriptionPlan
{
config
:
_u
.
config
}
_spec
.
Assign
=
_node
.
assignValues
_spec
.
ScanValues
=
_node
.
scanValues
if
err
=
sqlgraph
.
UpdateNode
(
ctx
,
_u
.
driver
,
_spec
);
err
!=
nil
{
if
_
,
ok
:=
err
.
(
*
sqlgraph
.
NotFoundError
);
ok
{
err
=
&
NotFoundError
{
subscriptionplan
.
Label
}
}
else
if
sqlgraph
.
IsConstraintError
(
err
)
{
err
=
&
ConstraintError
{
msg
:
err
.
Error
(),
wrap
:
err
}
}
return
nil
,
err
}
_u
.
mutation
.
done
=
true
return
_node
,
nil
}
backend/ent/tx.go
View file @
97f14b7a
...
...
@@ -30,6 +30,12 @@ type Tx struct {
Group
*
GroupClient
// IdempotencyRecord is the client for interacting with the IdempotencyRecord builders.
IdempotencyRecord
*
IdempotencyRecordClient
// PaymentAuditLog is the client for interacting with the PaymentAuditLog builders.
PaymentAuditLog
*
PaymentAuditLogClient
// PaymentOrder is the client for interacting with the PaymentOrder builders.
PaymentOrder
*
PaymentOrderClient
// PaymentProviderInstance is the client for interacting with the PaymentProviderInstance builders.
PaymentProviderInstance
*
PaymentProviderInstanceClient
// PromoCode is the client for interacting with the PromoCode builders.
PromoCode
*
PromoCodeClient
// PromoCodeUsage is the client for interacting with the PromoCodeUsage builders.
...
...
@@ -42,6 +48,8 @@ type Tx struct {
SecuritySecret
*
SecuritySecretClient
// Setting is the client for interacting with the Setting builders.
Setting
*
SettingClient
// SubscriptionPlan is the client for interacting with the SubscriptionPlan builders.
SubscriptionPlan
*
SubscriptionPlanClient
// TLSFingerprintProfile is the client for interacting with the TLSFingerprintProfile builders.
TLSFingerprintProfile
*
TLSFingerprintProfileClient
// UsageCleanupTask is the client for interacting with the UsageCleanupTask builders.
...
...
@@ -197,12 +205,16 @@ func (tx *Tx) init() {
tx
.
ErrorPassthroughRule
=
NewErrorPassthroughRuleClient
(
tx
.
config
)
tx
.
Group
=
NewGroupClient
(
tx
.
config
)
tx
.
IdempotencyRecord
=
NewIdempotencyRecordClient
(
tx
.
config
)
tx
.
PaymentAuditLog
=
NewPaymentAuditLogClient
(
tx
.
config
)
tx
.
PaymentOrder
=
NewPaymentOrderClient
(
tx
.
config
)
tx
.
PaymentProviderInstance
=
NewPaymentProviderInstanceClient
(
tx
.
config
)
tx
.
PromoCode
=
NewPromoCodeClient
(
tx
.
config
)
tx
.
PromoCodeUsage
=
NewPromoCodeUsageClient
(
tx
.
config
)
tx
.
Proxy
=
NewProxyClient
(
tx
.
config
)
tx
.
RedeemCode
=
NewRedeemCodeClient
(
tx
.
config
)
tx
.
SecuritySecret
=
NewSecuritySecretClient
(
tx
.
config
)
tx
.
Setting
=
NewSettingClient
(
tx
.
config
)
tx
.
SubscriptionPlan
=
NewSubscriptionPlanClient
(
tx
.
config
)
tx
.
TLSFingerprintProfile
=
NewTLSFingerprintProfileClient
(
tx
.
config
)
tx
.
UsageCleanupTask
=
NewUsageCleanupTaskClient
(
tx
.
config
)
tx
.
UsageLog
=
NewUsageLogClient
(
tx
.
config
)
...
...
backend/ent/user.go
View file @
97f14b7a
...
...
@@ -71,11 +71,13 @@ type UserEdges struct {
AttributeValues
[]
*
UserAttributeValue
`json:"attribute_values,omitempty"`
// PromoCodeUsages holds the value of the promo_code_usages edge.
PromoCodeUsages
[]
*
PromoCodeUsage
`json:"promo_code_usages,omitempty"`
// PaymentOrders holds the value of the payment_orders edge.
PaymentOrders
[]
*
PaymentOrder
`json:"payment_orders,omitempty"`
// UserAllowedGroups holds the value of the user_allowed_groups edge.
UserAllowedGroups
[]
*
UserAllowedGroup
`json:"user_allowed_groups,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes
[
1
0
]
bool
loadedTypes
[
1
1
]
bool
}
// APIKeysOrErr returns the APIKeys value or an error if the edge
...
...
@@ -159,10 +161,19 @@ func (e UserEdges) PromoCodeUsagesOrErr() ([]*PromoCodeUsage, error) {
return
nil
,
&
NotLoadedError
{
edge
:
"promo_code_usages"
}
}
// PaymentOrdersOrErr returns the PaymentOrders value or an error if the edge
// was not loaded in eager-loading.
func
(
e
UserEdges
)
PaymentOrdersOrErr
()
([]
*
PaymentOrder
,
error
)
{
if
e
.
loadedTypes
[
9
]
{
return
e
.
PaymentOrders
,
nil
}
return
nil
,
&
NotLoadedError
{
edge
:
"payment_orders"
}
}
// UserAllowedGroupsOrErr returns the UserAllowedGroups value or an error if the edge
// was not loaded in eager-loading.
func
(
e
UserEdges
)
UserAllowedGroupsOrErr
()
([]
*
UserAllowedGroup
,
error
)
{
if
e
.
loadedTypes
[
9
]
{
if
e
.
loadedTypes
[
10
]
{
return
e
.
UserAllowedGroups
,
nil
}
return
nil
,
&
NotLoadedError
{
edge
:
"user_allowed_groups"
}
...
...
@@ -349,6 +360,11 @@ func (_m *User) QueryPromoCodeUsages() *PromoCodeUsageQuery {
return
NewUserClient
(
_m
.
config
)
.
QueryPromoCodeUsages
(
_m
)
}
// QueryPaymentOrders queries the "payment_orders" edge of the User entity.
func
(
_m
*
User
)
QueryPaymentOrders
()
*
PaymentOrderQuery
{
return
NewUserClient
(
_m
.
config
)
.
QueryPaymentOrders
(
_m
)
}
// QueryUserAllowedGroups queries the "user_allowed_groups" edge of the User entity.
func
(
_m
*
User
)
QueryUserAllowedGroups
()
*
UserAllowedGroupQuery
{
return
NewUserClient
(
_m
.
config
)
.
QueryUserAllowedGroups
(
_m
)
...
...
backend/ent/user/user.go
View file @
97f14b7a
...
...
@@ -61,6 +61,8 @@ const (
EdgeAttributeValues
=
"attribute_values"
// EdgePromoCodeUsages holds the string denoting the promo_code_usages edge name in mutations.
EdgePromoCodeUsages
=
"promo_code_usages"
// EdgePaymentOrders holds the string denoting the payment_orders edge name in mutations.
EdgePaymentOrders
=
"payment_orders"
// EdgeUserAllowedGroups holds the string denoting the user_allowed_groups edge name in mutations.
EdgeUserAllowedGroups
=
"user_allowed_groups"
// Table holds the table name of the user in the database.
...
...
@@ -126,6 +128,13 @@ const (
PromoCodeUsagesInverseTable
=
"promo_code_usages"
// PromoCodeUsagesColumn is the table column denoting the promo_code_usages relation/edge.
PromoCodeUsagesColumn
=
"user_id"
// PaymentOrdersTable is the table that holds the payment_orders relation/edge.
PaymentOrdersTable
=
"payment_orders"
// PaymentOrdersInverseTable is the table name for the PaymentOrder entity.
// It exists in this package in order to avoid circular dependency with the "paymentorder" package.
PaymentOrdersInverseTable
=
"payment_orders"
// PaymentOrdersColumn is the table column denoting the payment_orders relation/edge.
PaymentOrdersColumn
=
"user_id"
// UserAllowedGroupsTable is the table that holds the user_allowed_groups relation/edge.
UserAllowedGroupsTable
=
"user_allowed_groups"
// UserAllowedGroupsInverseTable is the table name for the UserAllowedGroup entity.
...
...
@@ -414,6 +423,20 @@ func ByPromoCodeUsages(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
}
}
// ByPaymentOrdersCount orders the results by payment_orders count.
func
ByPaymentOrdersCount
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
func
(
s
*
sql
.
Selector
)
{
sqlgraph
.
OrderByNeighborsCount
(
s
,
newPaymentOrdersStep
(),
opts
...
)
}
}
// ByPaymentOrders orders the results by payment_orders terms.
func
ByPaymentOrders
(
term
sql
.
OrderTerm
,
terms
...
sql
.
OrderTerm
)
OrderOption
{
return
func
(
s
*
sql
.
Selector
)
{
sqlgraph
.
OrderByNeighborTerms
(
s
,
newPaymentOrdersStep
(),
append
([]
sql
.
OrderTerm
{
term
},
terms
...
)
...
)
}
}
// ByUserAllowedGroupsCount orders the results by user_allowed_groups count.
func
ByUserAllowedGroupsCount
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
func
(
s
*
sql
.
Selector
)
{
...
...
@@ -490,6 +513,13 @@ func newPromoCodeUsagesStep() *sqlgraph.Step {
sqlgraph
.
Edge
(
sqlgraph
.
O2M
,
false
,
PromoCodeUsagesTable
,
PromoCodeUsagesColumn
),
)
}
func
newPaymentOrdersStep
()
*
sqlgraph
.
Step
{
return
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
Table
,
FieldID
),
sqlgraph
.
To
(
PaymentOrdersInverseTable
,
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
O2M
,
false
,
PaymentOrdersTable
,
PaymentOrdersColumn
),
)
}
func
newUserAllowedGroupsStep
()
*
sqlgraph
.
Step
{
return
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
Table
,
FieldID
),
...
...
backend/ent/user/where.go
View file @
97f14b7a
...
...
@@ -1067,6 +1067,29 @@ func HasPromoCodeUsagesWith(preds ...predicate.PromoCodeUsage) predicate.User {
})
}
// HasPaymentOrders applies the HasEdge predicate on the "payment_orders" edge.
func
HasPaymentOrders
()
predicate
.
User
{
return
predicate
.
User
(
func
(
s
*
sql
.
Selector
)
{
step
:=
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
Table
,
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
O2M
,
false
,
PaymentOrdersTable
,
PaymentOrdersColumn
),
)
sqlgraph
.
HasNeighbors
(
s
,
step
)
})
}
// HasPaymentOrdersWith applies the HasEdge predicate on the "payment_orders" edge with a given conditions (other predicates).
func
HasPaymentOrdersWith
(
preds
...
predicate
.
PaymentOrder
)
predicate
.
User
{
return
predicate
.
User
(
func
(
s
*
sql
.
Selector
)
{
step
:=
newPaymentOrdersStep
()
sqlgraph
.
HasNeighborsWith
(
s
,
step
,
func
(
s
*
sql
.
Selector
)
{
for
_
,
p
:=
range
preds
{
p
(
s
)
}
})
})
}
// HasUserAllowedGroups applies the HasEdge predicate on the "user_allowed_groups" edge.
func
HasUserAllowedGroups
()
predicate
.
User
{
return
predicate
.
User
(
func
(
s
*
sql
.
Selector
)
{
...
...
backend/ent/user_create.go
View file @
97f14b7a
...
...
@@ -14,6 +14,7 @@ import (
"github.com/Wei-Shaw/sub2api/ent/announcementread"
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/paymentorder"
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/usagelog"
...
...
@@ -345,6 +346,21 @@ func (_c *UserCreate) AddPromoCodeUsages(v ...*PromoCodeUsage) *UserCreate {
return
_c
.
AddPromoCodeUsageIDs
(
ids
...
)
}
// AddPaymentOrderIDs adds the "payment_orders" edge to the PaymentOrder entity by IDs.
func
(
_c
*
UserCreate
)
AddPaymentOrderIDs
(
ids
...
int64
)
*
UserCreate
{
_c
.
mutation
.
AddPaymentOrderIDs
(
ids
...
)
return
_c
}
// AddPaymentOrders adds the "payment_orders" edges to the PaymentOrder entity.
func
(
_c
*
UserCreate
)
AddPaymentOrders
(
v
...*
PaymentOrder
)
*
UserCreate
{
ids
:=
make
([]
int64
,
len
(
v
))
for
i
:=
range
v
{
ids
[
i
]
=
v
[
i
]
.
ID
}
return
_c
.
AddPaymentOrderIDs
(
ids
...
)
}
// Mutation returns the UserMutation object of the builder.
func
(
_c
*
UserCreate
)
Mutation
()
*
UserMutation
{
return
_c
.
mutation
...
...
@@ -718,6 +734,22 @@ func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
}
_spec
.
Edges
=
append
(
_spec
.
Edges
,
edge
)
}
if
nodes
:=
_c
.
mutation
.
PaymentOrdersIDs
();
len
(
nodes
)
>
0
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
user
.
PaymentOrdersTable
,
Columns
:
[]
string
{
user
.
PaymentOrdersColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
paymentorder
.
FieldID
,
field
.
TypeInt64
),
},
}
for
_
,
k
:=
range
nodes
{
edge
.
Target
.
Nodes
=
append
(
edge
.
Target
.
Nodes
,
k
)
}
_spec
.
Edges
=
append
(
_spec
.
Edges
,
edge
)
}
return
_node
,
_spec
}
...
...
backend/ent/user_query.go
View file @
97f14b7a
...
...
@@ -16,6 +16,7 @@ import (
"github.com/Wei-Shaw/sub2api/ent/announcementread"
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/paymentorder"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
...
...
@@ -42,6 +43,7 @@ type UserQuery struct {
withUsageLogs
*
UsageLogQuery
withAttributeValues
*
UserAttributeValueQuery
withPromoCodeUsages
*
PromoCodeUsageQuery
withPaymentOrders
*
PaymentOrderQuery
withUserAllowedGroups
*
UserAllowedGroupQuery
modifiers
[]
func
(
*
sql
.
Selector
)
// intermediate query (i.e. traversal path).
...
...
@@ -278,6 +280,28 @@ func (_q *UserQuery) QueryPromoCodeUsages() *PromoCodeUsageQuery {
return
query
}
// QueryPaymentOrders chains the current query on the "payment_orders" edge.
func
(
_q
*
UserQuery
)
QueryPaymentOrders
()
*
PaymentOrderQuery
{
query
:=
(
&
PaymentOrderClient
{
config
:
_q
.
config
})
.
Query
()
query
.
path
=
func
(
ctx
context
.
Context
)
(
fromU
*
sql
.
Selector
,
err
error
)
{
if
err
:=
_q
.
prepareQuery
(
ctx
);
err
!=
nil
{
return
nil
,
err
}
selector
:=
_q
.
sqlQuery
(
ctx
)
if
err
:=
selector
.
Err
();
err
!=
nil
{
return
nil
,
err
}
step
:=
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
user
.
Table
,
user
.
FieldID
,
selector
),
sqlgraph
.
To
(
paymentorder
.
Table
,
paymentorder
.
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
O2M
,
false
,
user
.
PaymentOrdersTable
,
user
.
PaymentOrdersColumn
),
)
fromU
=
sqlgraph
.
SetNeighbors
(
_q
.
driver
.
Dialect
(),
step
)
return
fromU
,
nil
}
return
query
}
// QueryUserAllowedGroups chains the current query on the "user_allowed_groups" edge.
func
(
_q
*
UserQuery
)
QueryUserAllowedGroups
()
*
UserAllowedGroupQuery
{
query
:=
(
&
UserAllowedGroupClient
{
config
:
_q
.
config
})
.
Query
()
...
...
@@ -501,6 +525,7 @@ func (_q *UserQuery) Clone() *UserQuery {
withUsageLogs
:
_q
.
withUsageLogs
.
Clone
(),
withAttributeValues
:
_q
.
withAttributeValues
.
Clone
(),
withPromoCodeUsages
:
_q
.
withPromoCodeUsages
.
Clone
(),
withPaymentOrders
:
_q
.
withPaymentOrders
.
Clone
(),
withUserAllowedGroups
:
_q
.
withUserAllowedGroups
.
Clone
(),
// clone intermediate query.
sql
:
_q
.
sql
.
Clone
(),
...
...
@@ -607,6 +632,17 @@ func (_q *UserQuery) WithPromoCodeUsages(opts ...func(*PromoCodeUsageQuery)) *Us
return
_q
}
// WithPaymentOrders tells the query-builder to eager-load the nodes that are connected to
// the "payment_orders" edge. The optional arguments are used to configure the query builder of the edge.
func
(
_q
*
UserQuery
)
WithPaymentOrders
(
opts
...
func
(
*
PaymentOrderQuery
))
*
UserQuery
{
query
:=
(
&
PaymentOrderClient
{
config
:
_q
.
config
})
.
Query
()
for
_
,
opt
:=
range
opts
{
opt
(
query
)
}
_q
.
withPaymentOrders
=
query
return
_q
}
// WithUserAllowedGroups tells the query-builder to eager-load the nodes that are connected to
// the "user_allowed_groups" edge. The optional arguments are used to configure the query builder of the edge.
func
(
_q
*
UserQuery
)
WithUserAllowedGroups
(
opts
...
func
(
*
UserAllowedGroupQuery
))
*
UserQuery
{
...
...
@@ -696,7 +732,7 @@ func (_q *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e
var
(
nodes
=
[]
*
User
{}
_spec
=
_q
.
querySpec
()
loadedTypes
=
[
1
0
]
bool
{
loadedTypes
=
[
1
1
]
bool
{
_q
.
withAPIKeys
!=
nil
,
_q
.
withRedeemCodes
!=
nil
,
_q
.
withSubscriptions
!=
nil
,
...
...
@@ -706,6 +742,7 @@ func (_q *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e
_q
.
withUsageLogs
!=
nil
,
_q
.
withAttributeValues
!=
nil
,
_q
.
withPromoCodeUsages
!=
nil
,
_q
.
withPaymentOrders
!=
nil
,
_q
.
withUserAllowedGroups
!=
nil
,
}
)
...
...
@@ -795,6 +832,13 @@ func (_q *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e
return
nil
,
err
}
}
if
query
:=
_q
.
withPaymentOrders
;
query
!=
nil
{
if
err
:=
_q
.
loadPaymentOrders
(
ctx
,
query
,
nodes
,
func
(
n
*
User
)
{
n
.
Edges
.
PaymentOrders
=
[]
*
PaymentOrder
{}
},
func
(
n
*
User
,
e
*
PaymentOrder
)
{
n
.
Edges
.
PaymentOrders
=
append
(
n
.
Edges
.
PaymentOrders
,
e
)
});
err
!=
nil
{
return
nil
,
err
}
}
if
query
:=
_q
.
withUserAllowedGroups
;
query
!=
nil
{
if
err
:=
_q
.
loadUserAllowedGroups
(
ctx
,
query
,
nodes
,
func
(
n
*
User
)
{
n
.
Edges
.
UserAllowedGroups
=
[]
*
UserAllowedGroup
{}
},
...
...
@@ -1112,6 +1156,36 @@ func (_q *UserQuery) loadPromoCodeUsages(ctx context.Context, query *PromoCodeUs
}
return
nil
}
func
(
_q
*
UserQuery
)
loadPaymentOrders
(
ctx
context
.
Context
,
query
*
PaymentOrderQuery
,
nodes
[]
*
User
,
init
func
(
*
User
),
assign
func
(
*
User
,
*
PaymentOrder
))
error
{
fks
:=
make
([]
driver
.
Value
,
0
,
len
(
nodes
))
nodeids
:=
make
(
map
[
int64
]
*
User
)
for
i
:=
range
nodes
{
fks
=
append
(
fks
,
nodes
[
i
]
.
ID
)
nodeids
[
nodes
[
i
]
.
ID
]
=
nodes
[
i
]
if
init
!=
nil
{
init
(
nodes
[
i
])
}
}
if
len
(
query
.
ctx
.
Fields
)
>
0
{
query
.
ctx
.
AppendFieldOnce
(
paymentorder
.
FieldUserID
)
}
query
.
Where
(
predicate
.
PaymentOrder
(
func
(
s
*
sql
.
Selector
)
{
s
.
Where
(
sql
.
InValues
(
s
.
C
(
user
.
PaymentOrdersColumn
),
fks
...
))
}))
neighbors
,
err
:=
query
.
All
(
ctx
)
if
err
!=
nil
{
return
err
}
for
_
,
n
:=
range
neighbors
{
fk
:=
n
.
UserID
node
,
ok
:=
nodeids
[
fk
]
if
!
ok
{
return
fmt
.
Errorf
(
`unexpected referenced foreign-key "user_id" returned %v for node %v`
,
fk
,
n
.
ID
)
}
assign
(
node
,
n
)
}
return
nil
}
func
(
_q
*
UserQuery
)
loadUserAllowedGroups
(
ctx
context
.
Context
,
query
*
UserAllowedGroupQuery
,
nodes
[]
*
User
,
init
func
(
*
User
),
assign
func
(
*
User
,
*
UserAllowedGroup
))
error
{
fks
:=
make
([]
driver
.
Value
,
0
,
len
(
nodes
))
nodeids
:=
make
(
map
[
int64
]
*
User
)
...
...
backend/ent/user_update.go
View file @
97f14b7a
...
...
@@ -14,6 +14,7 @@ import (
"github.com/Wei-Shaw/sub2api/ent/announcementread"
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/paymentorder"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
...
...
@@ -377,6 +378,21 @@ func (_u *UserUpdate) AddPromoCodeUsages(v ...*PromoCodeUsage) *UserUpdate {
return
_u
.
AddPromoCodeUsageIDs
(
ids
...
)
}
// AddPaymentOrderIDs adds the "payment_orders" edge to the PaymentOrder entity by IDs.
func
(
_u
*
UserUpdate
)
AddPaymentOrderIDs
(
ids
...
int64
)
*
UserUpdate
{
_u
.
mutation
.
AddPaymentOrderIDs
(
ids
...
)
return
_u
}
// AddPaymentOrders adds the "payment_orders" edges to the PaymentOrder entity.
func
(
_u
*
UserUpdate
)
AddPaymentOrders
(
v
...*
PaymentOrder
)
*
UserUpdate
{
ids
:=
make
([]
int64
,
len
(
v
))
for
i
:=
range
v
{
ids
[
i
]
=
v
[
i
]
.
ID
}
return
_u
.
AddPaymentOrderIDs
(
ids
...
)
}
// Mutation returns the UserMutation object of the builder.
func
(
_u
*
UserUpdate
)
Mutation
()
*
UserMutation
{
return
_u
.
mutation
...
...
@@ -571,6 +587,27 @@ func (_u *UserUpdate) RemovePromoCodeUsages(v ...*PromoCodeUsage) *UserUpdate {
return
_u
.
RemovePromoCodeUsageIDs
(
ids
...
)
}
// ClearPaymentOrders clears all "payment_orders" edges to the PaymentOrder entity.
func
(
_u
*
UserUpdate
)
ClearPaymentOrders
()
*
UserUpdate
{
_u
.
mutation
.
ClearPaymentOrders
()
return
_u
}
// RemovePaymentOrderIDs removes the "payment_orders" edge to PaymentOrder entities by IDs.
func
(
_u
*
UserUpdate
)
RemovePaymentOrderIDs
(
ids
...
int64
)
*
UserUpdate
{
_u
.
mutation
.
RemovePaymentOrderIDs
(
ids
...
)
return
_u
}
// RemovePaymentOrders removes "payment_orders" edges to PaymentOrder entities.
func
(
_u
*
UserUpdate
)
RemovePaymentOrders
(
v
...*
PaymentOrder
)
*
UserUpdate
{
ids
:=
make
([]
int64
,
len
(
v
))
for
i
:=
range
v
{
ids
[
i
]
=
v
[
i
]
.
ID
}
return
_u
.
RemovePaymentOrderIDs
(
ids
...
)
}
// Save executes the query and returns the number of nodes affected by the update operation.
func
(
_u
*
UserUpdate
)
Save
(
ctx
context
.
Context
)
(
int
,
error
)
{
if
err
:=
_u
.
defaults
();
err
!=
nil
{
...
...
@@ -1126,6 +1163,51 @@ func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
}
_spec
.
Edges
.
Add
=
append
(
_spec
.
Edges
.
Add
,
edge
)
}
if
_u
.
mutation
.
PaymentOrdersCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
user
.
PaymentOrdersTable
,
Columns
:
[]
string
{
user
.
PaymentOrdersColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
paymentorder
.
FieldID
,
field
.
TypeInt64
),
},
}
_spec
.
Edges
.
Clear
=
append
(
_spec
.
Edges
.
Clear
,
edge
)
}
if
nodes
:=
_u
.
mutation
.
RemovedPaymentOrdersIDs
();
len
(
nodes
)
>
0
&&
!
_u
.
mutation
.
PaymentOrdersCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
user
.
PaymentOrdersTable
,
Columns
:
[]
string
{
user
.
PaymentOrdersColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
paymentorder
.
FieldID
,
field
.
TypeInt64
),
},
}
for
_
,
k
:=
range
nodes
{
edge
.
Target
.
Nodes
=
append
(
edge
.
Target
.
Nodes
,
k
)
}
_spec
.
Edges
.
Clear
=
append
(
_spec
.
Edges
.
Clear
,
edge
)
}
if
nodes
:=
_u
.
mutation
.
PaymentOrdersIDs
();
len
(
nodes
)
>
0
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
user
.
PaymentOrdersTable
,
Columns
:
[]
string
{
user
.
PaymentOrdersColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
paymentorder
.
FieldID
,
field
.
TypeInt64
),
},
}
for
_
,
k
:=
range
nodes
{
edge
.
Target
.
Nodes
=
append
(
edge
.
Target
.
Nodes
,
k
)
}
_spec
.
Edges
.
Add
=
append
(
_spec
.
Edges
.
Add
,
edge
)
}
if
_node
,
err
=
sqlgraph
.
UpdateNodes
(
ctx
,
_u
.
driver
,
_spec
);
err
!=
nil
{
if
_
,
ok
:=
err
.
(
*
sqlgraph
.
NotFoundError
);
ok
{
err
=
&
NotFoundError
{
user
.
Label
}
...
...
@@ -1487,6 +1569,21 @@ func (_u *UserUpdateOne) AddPromoCodeUsages(v ...*PromoCodeUsage) *UserUpdateOne
return
_u
.
AddPromoCodeUsageIDs
(
ids
...
)
}
// AddPaymentOrderIDs adds the "payment_orders" edge to the PaymentOrder entity by IDs.
func
(
_u
*
UserUpdateOne
)
AddPaymentOrderIDs
(
ids
...
int64
)
*
UserUpdateOne
{
_u
.
mutation
.
AddPaymentOrderIDs
(
ids
...
)
return
_u
}
// AddPaymentOrders adds the "payment_orders" edges to the PaymentOrder entity.
func
(
_u
*
UserUpdateOne
)
AddPaymentOrders
(
v
...*
PaymentOrder
)
*
UserUpdateOne
{
ids
:=
make
([]
int64
,
len
(
v
))
for
i
:=
range
v
{
ids
[
i
]
=
v
[
i
]
.
ID
}
return
_u
.
AddPaymentOrderIDs
(
ids
...
)
}
// Mutation returns the UserMutation object of the builder.
func
(
_u
*
UserUpdateOne
)
Mutation
()
*
UserMutation
{
return
_u
.
mutation
...
...
@@ -1681,6 +1778,27 @@ func (_u *UserUpdateOne) RemovePromoCodeUsages(v ...*PromoCodeUsage) *UserUpdate
return
_u
.
RemovePromoCodeUsageIDs
(
ids
...
)
}
// ClearPaymentOrders clears all "payment_orders" edges to the PaymentOrder entity.
func
(
_u
*
UserUpdateOne
)
ClearPaymentOrders
()
*
UserUpdateOne
{
_u
.
mutation
.
ClearPaymentOrders
()
return
_u
}
// RemovePaymentOrderIDs removes the "payment_orders" edge to PaymentOrder entities by IDs.
func
(
_u
*
UserUpdateOne
)
RemovePaymentOrderIDs
(
ids
...
int64
)
*
UserUpdateOne
{
_u
.
mutation
.
RemovePaymentOrderIDs
(
ids
...
)
return
_u
}
// RemovePaymentOrders removes "payment_orders" edges to PaymentOrder entities.
func
(
_u
*
UserUpdateOne
)
RemovePaymentOrders
(
v
...*
PaymentOrder
)
*
UserUpdateOne
{
ids
:=
make
([]
int64
,
len
(
v
))
for
i
:=
range
v
{
ids
[
i
]
=
v
[
i
]
.
ID
}
return
_u
.
RemovePaymentOrderIDs
(
ids
...
)
}
// Where appends a list predicates to the UserUpdate builder.
func
(
_u
*
UserUpdateOne
)
Where
(
ps
...
predicate
.
User
)
*
UserUpdateOne
{
_u
.
mutation
.
Where
(
ps
...
)
...
...
@@ -2266,6 +2384,51 @@ func (_u *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
}
_spec
.
Edges
.
Add
=
append
(
_spec
.
Edges
.
Add
,
edge
)
}
if
_u
.
mutation
.
PaymentOrdersCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
user
.
PaymentOrdersTable
,
Columns
:
[]
string
{
user
.
PaymentOrdersColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
paymentorder
.
FieldID
,
field
.
TypeInt64
),
},
}
_spec
.
Edges
.
Clear
=
append
(
_spec
.
Edges
.
Clear
,
edge
)
}
if
nodes
:=
_u
.
mutation
.
RemovedPaymentOrdersIDs
();
len
(
nodes
)
>
0
&&
!
_u
.
mutation
.
PaymentOrdersCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
user
.
PaymentOrdersTable
,
Columns
:
[]
string
{
user
.
PaymentOrdersColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
paymentorder
.
FieldID
,
field
.
TypeInt64
),
},
}
for
_
,
k
:=
range
nodes
{
edge
.
Target
.
Nodes
=
append
(
edge
.
Target
.
Nodes
,
k
)
}
_spec
.
Edges
.
Clear
=
append
(
_spec
.
Edges
.
Clear
,
edge
)
}
if
nodes
:=
_u
.
mutation
.
PaymentOrdersIDs
();
len
(
nodes
)
>
0
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
user
.
PaymentOrdersTable
,
Columns
:
[]
string
{
user
.
PaymentOrdersColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
paymentorder
.
FieldID
,
field
.
TypeInt64
),
},
}
for
_
,
k
:=
range
nodes
{
edge
.
Target
.
Nodes
=
append
(
edge
.
Target
.
Nodes
,
k
)
}
_spec
.
Edges
.
Add
=
append
(
_spec
.
Edges
.
Add
,
edge
)
}
_node
=
&
User
{
config
:
_u
.
config
}
_spec
.
Assign
=
_node
.
assignValues
_spec
.
ScanValues
=
_node
.
scanValues
...
...
backend/go.mod
View file @
97f14b7a
...
...
@@ -27,12 +27,16 @@ require (
github.com/refraction-networking/utls v1.8.2
github.com/robfig/cron/v3 v3.0.1
github.com/shirou/gopsutil/v4 v4.25.6
github.com/shopspring/decimal v1.4.0
github.com/smartwalle/alipay/v3 v3.2.29
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.11.1
github.com/stripe/stripe-go/v85 v85.0.0
github.com/testcontainers/testcontainers-go/modules/postgres v0.40.0
github.com/testcontainers/testcontainers-go/modules/redis v0.40.0
github.com/tidwall/gjson v1.18.0
github.com/tidwall/sjson v1.2.5
github.com/wechatpay-apiv3/wechatpay-go v0.2.21
github.com/zeromicro/go-zero v1.9.4
go.uber.org/zap v1.24.0
golang.org/x/crypto v0.48.0
...
...
@@ -99,6 +103,7 @@ require (
github.com/goccy/go-json v0.10.2 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/subcommands v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/hcl/v2 v2.18.1 // indirect
...
...
@@ -137,6 +142,9 @@ require (
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/smartwalle/ncrypto v1.0.4 // indirect
github.com/smartwalle/ngx v1.1.0 // indirect
github.com/smartwalle/nsign v1.0.9 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
...
...
@@ -167,6 +175,7 @@ require (
golang.org/x/mod v0.32.0 // indirect
golang.org/x/sys v0.41.0 // indirect
golang.org/x/text v0.34.0 // indirect
golang.org/x/tools v0.41.0 // indirect
google.golang.org/grpc v1.75.1 // indirect
google.golang.org/protobuf v1.36.10 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
...
...
backend/go.sum
View file @
97f14b7a
...
...
@@ -14,6 +14,8 @@ github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERo
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo=
github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw=
github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw=
github.com/alitto/pond/v2 v2.6.2 h1:Sphe40g0ILeM1pA2c2K+Th0DGU+pt0A/Kprr+WB24Pw=
github.com/alitto/pond/v2 v2.6.2/go.mod h1:xkjYEgQ05RSpWdfSd1nM3OVv7TBhLdy7rMp3+2Nq+yE=
github.com/andybalholm/brotli v1.2.0 h1:ukwgCxwYrmACq68yiUqwIWnGY0cTPox/M94sVwToPjQ=
...
...
@@ -160,6 +162,8 @@ github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs=
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
github.com/google/subcommands v1.2.0 h1:vWQspBTo2nEqTUFita5/KeEWlUL8kQObDFbub/EN9oE=
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/wire v0.7.0 h1:JxUKI6+CVBgCO2WToKy/nQk0sS+amI9z9EjVmdaocj4=
...
...
@@ -288,8 +292,18 @@ github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
github.com/shirou/gopsutil/v4 v4.25.6 h1:kLysI2JsKorfaFPcYmcJqbzROzsBWEOAtw6A7dIfqXs=
github.com/shirou/gopsutil/v4 v4.25.6/go.mod h1:PfybzyydfZcN+JMMjkF6Zb8Mq1A/VcogFFg7hj50W9c=
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/smartwalle/alipay/v3 v3.2.29 h1:roGFqlml8hDa//0TpFmlyxZhndTYs7rbYLu/HlNFNJo=
github.com/smartwalle/alipay/v3 v3.2.29/go.mod h1:XarBLuAkwK3ah7mYjVtghRu+ysxzlex9sRkgqNMzMRU=
github.com/smartwalle/ncrypto v1.0.4 h1:P2rqQxDepJwgeO5ShoC+wGcK2wNJDmcdBOWAksuIgx8=
github.com/smartwalle/ncrypto v1.0.4/go.mod h1:Dwlp6sfeNaPMnOxMNayMTacvC5JGEVln3CVdiVDgbBk=
github.com/smartwalle/ngx v1.1.0 h1:q8nANgWSPRGeI/u+ixBoA4mf68DrUq6vZ+n9L5UKv9I=
github.com/smartwalle/ngx v1.1.0/go.mod h1:mx/nz2Pk5j+RBs7t6u6k22MPiBG/8CtOMpCnALIG8Y0=
github.com/smartwalle/nsign v1.0.9 h1:8poAgG7zBd8HkZy9RQDwasC6XZvJpDGQWSjzL2FZL6E=
github.com/smartwalle/nsign v1.0.9/go.mod h1:eY6I4CJlyNdVMP+t6z1H6Jpd4m5/V+8xi44ufSTxXgc=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
...
...
@@ -317,6 +331,8 @@ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/stripe/stripe-go/v85 v85.0.0 h1:HMlFJXW6I/9WvkeSAtj8V7dI5pzeDu4gS1TaqR1ccI4=
github.com/stripe/stripe-go/v85 v85.0.0/go.mod h1:5P+HGFenpWgak27T5Is6JMsmDfUC1yJnjhhmquz7kXw=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/testcontainers/testcontainers-go v0.40.0 h1:pSdJYLOVgLE8YdUY2FHQ1Fxu+aMnb6JfVz1mxk7OeMU=
...
...
@@ -342,6 +358,8 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/wechatpay-apiv3/wechatpay-go v0.2.21 h1:uIyMpzvcaHA33W/QPtHstccw+X52HO1gFdvVL9O6Lfs=
github.com/wechatpay-apiv3/wechatpay-go v0.2.21/go.mod h1:A254AUBVB6R+EqQFo3yTgeh7HtyqRRtN2w9hQSOrd4Q=
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
...
...
backend/internal/handler/admin/payment_handler.go
0 → 100644
View file @
97f14b7a
package
admin
import
(
"strconv"
"github.com/Wei-Shaw/sub2api/internal/pkg/response"
"github.com/Wei-Shaw/sub2api/internal/service"
"github.com/gin-gonic/gin"
)
// PaymentHandler handles admin payment management.
type
PaymentHandler
struct
{
paymentService
*
service
.
PaymentService
configService
*
service
.
PaymentConfigService
}
// NewPaymentHandler creates a new admin PaymentHandler.
func
NewPaymentHandler
(
paymentService
*
service
.
PaymentService
,
configService
*
service
.
PaymentConfigService
)
*
PaymentHandler
{
return
&
PaymentHandler
{
paymentService
:
paymentService
,
configService
:
configService
,
}
}
// --- Dashboard ---
// GetDashboard returns payment dashboard statistics.
// GET /api/v1/admin/payment/dashboard
func
(
h
*
PaymentHandler
)
GetDashboard
(
c
*
gin
.
Context
)
{
days
:=
30
if
d
:=
c
.
Query
(
"days"
);
d
!=
""
{
if
v
,
err
:=
strconv
.
Atoi
(
d
);
err
==
nil
&&
v
>
0
{
days
=
v
}
}
stats
,
err
:=
h
.
paymentService
.
GetDashboardStats
(
c
.
Request
.
Context
(),
days
)
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
response
.
Success
(
c
,
stats
)
}
// --- Orders ---
// ListOrders returns a paginated list of all payment orders.
// GET /api/v1/admin/payment/orders
func
(
h
*
PaymentHandler
)
ListOrders
(
c
*
gin
.
Context
)
{
page
,
pageSize
:=
response
.
ParsePagination
(
c
)
var
userID
int64
if
uid
:=
c
.
Query
(
"user_id"
);
uid
!=
""
{
if
v
,
err
:=
strconv
.
ParseInt
(
uid
,
10
,
64
);
err
==
nil
{
userID
=
v
}
}
orders
,
total
,
err
:=
h
.
paymentService
.
AdminListOrders
(
c
.
Request
.
Context
(),
userID
,
service
.
OrderListParams
{
Page
:
page
,
PageSize
:
pageSize
,
Status
:
c
.
Query
(
"status"
),
OrderType
:
c
.
Query
(
"order_type"
),
PaymentType
:
c
.
Query
(
"payment_type"
),
Keyword
:
c
.
Query
(
"keyword"
),
})
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
response
.
Paginated
(
c
,
orders
,
int64
(
total
),
page
,
pageSize
)
}
// GetOrderDetail returns detailed information about a single order.
// GET /api/v1/admin/payment/orders/:id
func
(
h
*
PaymentHandler
)
GetOrderDetail
(
c
*
gin
.
Context
)
{
orderID
,
ok
:=
parseIDParam
(
c
,
"id"
)
if
!
ok
{
return
}
order
,
err
:=
h
.
paymentService
.
GetOrderByID
(
c
.
Request
.
Context
(),
orderID
)
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
auditLogs
,
_
:=
h
.
paymentService
.
GetOrderAuditLogs
(
c
.
Request
.
Context
(),
orderID
)
response
.
Success
(
c
,
gin
.
H
{
"order"
:
order
,
"auditLogs"
:
auditLogs
})
}
// CancelOrder cancels a pending order (admin).
// POST /api/v1/admin/payment/orders/:id/cancel
func
(
h
*
PaymentHandler
)
CancelOrder
(
c
*
gin
.
Context
)
{
orderID
,
ok
:=
parseIDParam
(
c
,
"id"
)
if
!
ok
{
return
}
msg
,
err
:=
h
.
paymentService
.
AdminCancelOrder
(
c
.
Request
.
Context
(),
orderID
)
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
response
.
Success
(
c
,
gin
.
H
{
"message"
:
msg
})
}
// RetryFulfillment retries fulfillment for a paid order.
// POST /api/v1/admin/payment/orders/:id/retry
func
(
h
*
PaymentHandler
)
RetryFulfillment
(
c
*
gin
.
Context
)
{
orderID
,
ok
:=
parseIDParam
(
c
,
"id"
)
if
!
ok
{
return
}
if
err
:=
h
.
paymentService
.
RetryFulfillment
(
c
.
Request
.
Context
(),
orderID
);
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
response
.
Success
(
c
,
gin
.
H
{
"message"
:
"fulfillment retried"
})
}
// AdminProcessRefundRequest is the request body for admin refund processing.
type
AdminProcessRefundRequest
struct
{
Amount
float64
`json:"amount"`
Reason
string
`json:"reason"`
Force
bool
`json:"force"`
DeductBalance
bool
`json:"deduct_balance"`
}
// ProcessRefund processes a refund for an order (admin).
// POST /api/v1/admin/payment/orders/:id/refund
func
(
h
*
PaymentHandler
)
ProcessRefund
(
c
*
gin
.
Context
)
{
orderID
,
ok
:=
parseIDParam
(
c
,
"id"
)
if
!
ok
{
return
}
var
req
AdminProcessRefundRequest
if
err
:=
c
.
ShouldBindJSON
(
&
req
);
err
!=
nil
{
response
.
BadRequest
(
c
,
"Invalid request: "
+
err
.
Error
())
return
}
plan
,
earlyResult
,
err
:=
h
.
paymentService
.
PrepareRefund
(
c
.
Request
.
Context
(),
orderID
,
req
.
Amount
,
req
.
Reason
,
req
.
Force
,
req
.
DeductBalance
)
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
if
earlyResult
!=
nil
{
response
.
Success
(
c
,
earlyResult
)
return
}
result
,
err
:=
h
.
paymentService
.
ExecuteRefund
(
c
.
Request
.
Context
(),
plan
)
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
response
.
Success
(
c
,
result
)
}
// --- Subscription Plans ---
// ListPlans returns all subscription plans.
// GET /api/v1/admin/payment/plans
func
(
h
*
PaymentHandler
)
ListPlans
(
c
*
gin
.
Context
)
{
plans
,
err
:=
h
.
configService
.
ListPlans
(
c
.
Request
.
Context
())
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
response
.
Success
(
c
,
plans
)
}
// CreatePlan creates a new subscription plan.
// POST /api/v1/admin/payment/plans
func
(
h
*
PaymentHandler
)
CreatePlan
(
c
*
gin
.
Context
)
{
var
req
service
.
CreatePlanRequest
if
err
:=
c
.
ShouldBindJSON
(
&
req
);
err
!=
nil
{
response
.
BadRequest
(
c
,
"Invalid request: "
+
err
.
Error
())
return
}
plan
,
err
:=
h
.
configService
.
CreatePlan
(
c
.
Request
.
Context
(),
req
)
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
response
.
Created
(
c
,
plan
)
}
// UpdatePlan updates an existing subscription plan.
// PUT /api/v1/admin/payment/plans/:id
func
(
h
*
PaymentHandler
)
UpdatePlan
(
c
*
gin
.
Context
)
{
id
,
ok
:=
parseIDParam
(
c
,
"id"
)
if
!
ok
{
return
}
var
req
service
.
UpdatePlanRequest
if
err
:=
c
.
ShouldBindJSON
(
&
req
);
err
!=
nil
{
response
.
BadRequest
(
c
,
"Invalid request: "
+
err
.
Error
())
return
}
plan
,
err
:=
h
.
configService
.
UpdatePlan
(
c
.
Request
.
Context
(),
id
,
req
)
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
response
.
Success
(
c
,
plan
)
}
// DeletePlan deletes a subscription plan.
// DELETE /api/v1/admin/payment/plans/:id
func
(
h
*
PaymentHandler
)
DeletePlan
(
c
*
gin
.
Context
)
{
id
,
ok
:=
parseIDParam
(
c
,
"id"
)
if
!
ok
{
return
}
if
err
:=
h
.
configService
.
DeletePlan
(
c
.
Request
.
Context
(),
id
);
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
response
.
Success
(
c
,
gin
.
H
{
"message"
:
"deleted"
})
}
// --- Provider Instances ---
// ListProviders returns all payment provider instances.
// GET /api/v1/admin/payment/providers
func
(
h
*
PaymentHandler
)
ListProviders
(
c
*
gin
.
Context
)
{
providers
,
err
:=
h
.
configService
.
ListProviderInstancesWithConfig
(
c
.
Request
.
Context
())
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
response
.
Success
(
c
,
providers
)
}
// CreateProvider creates a new payment provider instance.
// POST /api/v1/admin/payment/providers
func
(
h
*
PaymentHandler
)
CreateProvider
(
c
*
gin
.
Context
)
{
var
req
service
.
CreateProviderInstanceRequest
if
err
:=
c
.
ShouldBindJSON
(
&
req
);
err
!=
nil
{
response
.
BadRequest
(
c
,
"Invalid request: "
+
err
.
Error
())
return
}
inst
,
err
:=
h
.
configService
.
CreateProviderInstance
(
c
.
Request
.
Context
(),
req
)
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
h
.
paymentService
.
RefreshProviders
(
c
.
Request
.
Context
())
response
.
Created
(
c
,
inst
)
}
// UpdateProvider updates an existing payment provider instance.
// PUT /api/v1/admin/payment/providers/:id
func
(
h
*
PaymentHandler
)
UpdateProvider
(
c
*
gin
.
Context
)
{
id
,
ok
:=
parseIDParam
(
c
,
"id"
)
if
!
ok
{
return
}
var
req
service
.
UpdateProviderInstanceRequest
if
err
:=
c
.
ShouldBindJSON
(
&
req
);
err
!=
nil
{
response
.
BadRequest
(
c
,
"Invalid request: "
+
err
.
Error
())
return
}
inst
,
err
:=
h
.
configService
.
UpdateProviderInstance
(
c
.
Request
.
Context
(),
id
,
req
)
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
h
.
paymentService
.
RefreshProviders
(
c
.
Request
.
Context
())
response
.
Success
(
c
,
inst
)
}
// DeleteProvider deletes a payment provider instance.
// DELETE /api/v1/admin/payment/providers/:id
func
(
h
*
PaymentHandler
)
DeleteProvider
(
c
*
gin
.
Context
)
{
id
,
ok
:=
parseIDParam
(
c
,
"id"
)
if
!
ok
{
return
}
if
err
:=
h
.
configService
.
DeleteProviderInstance
(
c
.
Request
.
Context
(),
id
);
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
h
.
paymentService
.
RefreshProviders
(
c
.
Request
.
Context
())
response
.
Success
(
c
,
gin
.
H
{
"message"
:
"deleted"
})
}
// parseIDParam parses an int64 path parameter.
// Returns the parsed ID and true on success; on failure it writes a BadRequest response and returns false.
func
parseIDParam
(
c
*
gin
.
Context
,
paramName
string
)
(
int64
,
bool
)
{
id
,
err
:=
strconv
.
ParseInt
(
c
.
Param
(
paramName
),
10
,
64
)
if
err
!=
nil
{
response
.
BadRequest
(
c
,
"Invalid "
+
paramName
)
return
0
,
false
}
return
id
,
true
}
// --- Config ---
// GetConfig returns the payment configuration (admin view).
// GET /api/v1/admin/payment/config
func
(
h
*
PaymentHandler
)
GetConfig
(
c
*
gin
.
Context
)
{
cfg
,
err
:=
h
.
configService
.
GetPaymentConfig
(
c
.
Request
.
Context
())
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
response
.
Success
(
c
,
cfg
)
}
// UpdateConfig updates the payment configuration.
// PUT /api/v1/admin/payment/config
func
(
h
*
PaymentHandler
)
UpdateConfig
(
c
*
gin
.
Context
)
{
var
req
service
.
UpdatePaymentConfigRequest
if
err
:=
c
.
ShouldBindJSON
(
&
req
);
err
!=
nil
{
response
.
BadRequest
(
c
,
"Invalid request: "
+
err
.
Error
())
return
}
if
err
:=
h
.
configService
.
UpdatePaymentConfig
(
c
.
Request
.
Context
(),
req
);
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
response
.
Success
(
c
,
gin
.
H
{
"message"
:
"updated"
})
}
backend/internal/handler/admin/setting_handler.go
View file @
97f14b7a
...
...
@@ -50,15 +50,19 @@ type SettingHandler struct {
emailService
*
service
.
EmailService
turnstileService
*
service
.
TurnstileService
opsService
*
service
.
OpsService
paymentConfigService
*
service
.
PaymentConfigService
paymentService
*
service
.
PaymentService
}
// NewSettingHandler 创建系统设置处理器
func
NewSettingHandler
(
settingService
*
service
.
SettingService
,
emailService
*
service
.
EmailService
,
turnstileService
*
service
.
TurnstileService
,
opsService
*
service
.
OpsService
)
*
SettingHandler
{
func
NewSettingHandler
(
settingService
*
service
.
SettingService
,
emailService
*
service
.
EmailService
,
turnstileService
*
service
.
TurnstileService
,
opsService
*
service
.
OpsService
,
paymentConfigService
*
service
.
PaymentConfigService
,
paymentService
*
service
.
PaymentService
)
*
SettingHandler
{
return
&
SettingHandler
{
settingService
:
settingService
,
emailService
:
emailService
,
turnstileService
:
turnstileService
,
opsService
:
opsService
,
paymentConfigService
:
paymentConfigService
,
paymentService
:
paymentService
,
}
}
...
...
@@ -81,6 +85,15 @@ func (h *SettingHandler) GetSettings(c *gin.Context) {
})
}
// Load payment config
var
paymentCfg
*
service
.
PaymentConfig
if
h
.
paymentConfigService
!=
nil
{
paymentCfg
,
_
=
h
.
paymentConfigService
.
GetPaymentConfig
(
c
.
Request
.
Context
())
}
if
paymentCfg
==
nil
{
paymentCfg
=
&
service
.
PaymentConfig
{}
}
response
.
Success
(
c
,
dto
.
SystemSettings
{
RegistrationEnabled
:
settings
.
RegistrationEnabled
,
EmailVerifyEnabled
:
settings
.
EmailVerifyEnabled
,
...
...
@@ -162,6 +175,24 @@ func (h *SettingHandler) GetSettings(c *gin.Context) {
EnableFingerprintUnification
:
settings
.
EnableFingerprintUnification
,
EnableMetadataPassthrough
:
settings
.
EnableMetadataPassthrough
,
EnableCCHSigning
:
settings
.
EnableCCHSigning
,
PaymentEnabled
:
paymentCfg
.
Enabled
,
PaymentMinAmount
:
paymentCfg
.
MinAmount
,
PaymentMaxAmount
:
paymentCfg
.
MaxAmount
,
PaymentDailyLimit
:
paymentCfg
.
DailyLimit
,
PaymentOrderTimeoutMin
:
paymentCfg
.
OrderTimeoutMin
,
PaymentMaxPendingOrders
:
paymentCfg
.
MaxPendingOrders
,
PaymentEnabledTypes
:
paymentCfg
.
EnabledTypes
,
PaymentBalanceDisabled
:
paymentCfg
.
BalanceDisabled
,
PaymentLoadBalanceStrat
:
paymentCfg
.
LoadBalanceStrategy
,
PaymentProductNamePrefix
:
paymentCfg
.
ProductNamePrefix
,
PaymentProductNameSuffix
:
paymentCfg
.
ProductNameSuffix
,
PaymentHelpImageURL
:
paymentCfg
.
HelpImageURL
,
PaymentHelpText
:
paymentCfg
.
HelpText
,
PaymentCancelRateLimitEnabled
:
paymentCfg
.
CancelRateLimitEnabled
,
PaymentCancelRateLimitMax
:
paymentCfg
.
CancelRateLimitMax
,
PaymentCancelRateLimitWindow
:
paymentCfg
.
CancelRateLimitWindow
,
PaymentCancelRateLimitUnit
:
paymentCfg
.
CancelRateLimitUnit
,
PaymentCancelRateLimitMode
:
paymentCfg
.
CancelRateLimitMode
,
})
}
...
...
@@ -272,6 +303,28 @@ type UpdateSettingsRequest struct {
EnableFingerprintUnification
*
bool
`json:"enable_fingerprint_unification"`
EnableMetadataPassthrough
*
bool
`json:"enable_metadata_passthrough"`
EnableCCHSigning
*
bool
`json:"enable_cch_signing"`
// Payment configuration (integrated into settings, full replace)
PaymentEnabled
*
bool
`json:"payment_enabled"`
PaymentMinAmount
*
float64
`json:"payment_min_amount"`
PaymentMaxAmount
*
float64
`json:"payment_max_amount"`
PaymentDailyLimit
*
float64
`json:"payment_daily_limit"`
PaymentOrderTimeoutMin
*
int
`json:"payment_order_timeout_minutes"`
PaymentMaxPendingOrders
*
int
`json:"payment_max_pending_orders"`
PaymentEnabledTypes
[]
string
`json:"payment_enabled_types"`
PaymentBalanceDisabled
*
bool
`json:"payment_balance_disabled"`
PaymentLoadBalanceStrat
*
string
`json:"payment_load_balance_strategy"`
PaymentProductNamePrefix
*
string
`json:"payment_product_name_prefix"`
PaymentProductNameSuffix
*
string
`json:"payment_product_name_suffix"`
PaymentHelpImageURL
*
string
`json:"payment_help_image_url"`
PaymentHelpText
*
string
`json:"payment_help_text"`
// Cancel rate limit
PaymentCancelRateLimitEnabled
*
bool
`json:"payment_cancel_rate_limit_enabled"`
PaymentCancelRateLimitMax
*
int
`json:"payment_cancel_rate_limit_max"`
PaymentCancelRateLimitWindow
*
int
`json:"payment_cancel_rate_limit_window"`
PaymentCancelRateLimitUnit
*
string
`json:"payment_cancel_rate_limit_unit"`
PaymentCancelRateLimitMode
*
string
`json:"payment_cancel_rate_limit_window_mode"`
}
// UpdateSettings 更新系统设置
...
...
@@ -835,6 +888,39 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
return
}
// Update payment configuration (integrated into system settings).
// Skip if no payment fields were provided (prevents accidental wipe).
if
h
.
paymentConfigService
!=
nil
&&
hasPaymentFields
(
req
)
{
paymentReq
:=
service
.
UpdatePaymentConfigRequest
{
Enabled
:
req
.
PaymentEnabled
,
MinAmount
:
req
.
PaymentMinAmount
,
MaxAmount
:
req
.
PaymentMaxAmount
,
DailyLimit
:
req
.
PaymentDailyLimit
,
OrderTimeoutMin
:
req
.
PaymentOrderTimeoutMin
,
MaxPendingOrders
:
req
.
PaymentMaxPendingOrders
,
EnabledTypes
:
req
.
PaymentEnabledTypes
,
BalanceDisabled
:
req
.
PaymentBalanceDisabled
,
LoadBalanceStrategy
:
req
.
PaymentLoadBalanceStrat
,
ProductNamePrefix
:
req
.
PaymentProductNamePrefix
,
ProductNameSuffix
:
req
.
PaymentProductNameSuffix
,
HelpImageURL
:
req
.
PaymentHelpImageURL
,
HelpText
:
req
.
PaymentHelpText
,
CancelRateLimitEnabled
:
req
.
PaymentCancelRateLimitEnabled
,
CancelRateLimitMax
:
req
.
PaymentCancelRateLimitMax
,
CancelRateLimitWindow
:
req
.
PaymentCancelRateLimitWindow
,
CancelRateLimitUnit
:
req
.
PaymentCancelRateLimitUnit
,
CancelRateLimitMode
:
req
.
PaymentCancelRateLimitMode
,
}
if
err
:=
h
.
paymentConfigService
.
UpdatePaymentConfig
(
c
.
Request
.
Context
(),
paymentReq
);
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
// Refresh in-memory provider registry so config changes take effect immediately
if
h
.
paymentService
!=
nil
{
h
.
paymentService
.
RefreshProviders
(
c
.
Request
.
Context
())
}
}
h
.
auditSettingsUpdate
(
c
,
previousSettings
,
settings
,
req
)
// 重新获取设置返回
...
...
@@ -851,6 +937,15 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
})
}
// Reload payment config for response
var
updatedPaymentCfg
*
service
.
PaymentConfig
if
h
.
paymentConfigService
!=
nil
{
updatedPaymentCfg
,
_
=
h
.
paymentConfigService
.
GetPaymentConfig
(
c
.
Request
.
Context
())
}
if
updatedPaymentCfg
==
nil
{
updatedPaymentCfg
=
&
service
.
PaymentConfig
{}
}
response
.
Success
(
c
,
dto
.
SystemSettings
{
RegistrationEnabled
:
updatedSettings
.
RegistrationEnabled
,
EmailVerifyEnabled
:
updatedSettings
.
EmailVerifyEnabled
,
...
...
@@ -932,9 +1027,40 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
EnableFingerprintUnification
:
updatedSettings
.
EnableFingerprintUnification
,
EnableMetadataPassthrough
:
updatedSettings
.
EnableMetadataPassthrough
,
EnableCCHSigning
:
updatedSettings
.
EnableCCHSigning
,
PaymentEnabled
:
updatedPaymentCfg
.
Enabled
,
PaymentMinAmount
:
updatedPaymentCfg
.
MinAmount
,
PaymentMaxAmount
:
updatedPaymentCfg
.
MaxAmount
,
PaymentDailyLimit
:
updatedPaymentCfg
.
DailyLimit
,
PaymentOrderTimeoutMin
:
updatedPaymentCfg
.
OrderTimeoutMin
,
PaymentMaxPendingOrders
:
updatedPaymentCfg
.
MaxPendingOrders
,
PaymentEnabledTypes
:
updatedPaymentCfg
.
EnabledTypes
,
PaymentBalanceDisabled
:
updatedPaymentCfg
.
BalanceDisabled
,
PaymentLoadBalanceStrat
:
updatedPaymentCfg
.
LoadBalanceStrategy
,
PaymentProductNamePrefix
:
updatedPaymentCfg
.
ProductNamePrefix
,
PaymentProductNameSuffix
:
updatedPaymentCfg
.
ProductNameSuffix
,
PaymentHelpImageURL
:
updatedPaymentCfg
.
HelpImageURL
,
PaymentHelpText
:
updatedPaymentCfg
.
HelpText
,
PaymentCancelRateLimitEnabled
:
updatedPaymentCfg
.
CancelRateLimitEnabled
,
PaymentCancelRateLimitMax
:
updatedPaymentCfg
.
CancelRateLimitMax
,
PaymentCancelRateLimitWindow
:
updatedPaymentCfg
.
CancelRateLimitWindow
,
PaymentCancelRateLimitUnit
:
updatedPaymentCfg
.
CancelRateLimitUnit
,
PaymentCancelRateLimitMode
:
updatedPaymentCfg
.
CancelRateLimitMode
,
})
}
// hasPaymentFields returns true if any payment-related field was explicitly provided.
func
hasPaymentFields
(
req
UpdateSettingsRequest
)
bool
{
return
req
.
PaymentEnabled
!=
nil
||
req
.
PaymentMinAmount
!=
nil
||
req
.
PaymentMaxAmount
!=
nil
||
req
.
PaymentDailyLimit
!=
nil
||
req
.
PaymentOrderTimeoutMin
!=
nil
||
req
.
PaymentMaxPendingOrders
!=
nil
||
req
.
PaymentEnabledTypes
!=
nil
||
req
.
PaymentBalanceDisabled
!=
nil
||
req
.
PaymentLoadBalanceStrat
!=
nil
||
req
.
PaymentProductNamePrefix
!=
nil
||
req
.
PaymentProductNameSuffix
!=
nil
||
req
.
PaymentHelpImageURL
!=
nil
||
req
.
PaymentHelpText
!=
nil
||
req
.
PaymentCancelRateLimitEnabled
!=
nil
||
req
.
PaymentCancelRateLimitMax
!=
nil
||
req
.
PaymentCancelRateLimitWindow
!=
nil
||
req
.
PaymentCancelRateLimitUnit
!=
nil
||
req
.
PaymentCancelRateLimitMode
!=
nil
}
func
(
h
*
SettingHandler
)
auditSettingsUpdate
(
c
*
gin
.
Context
,
before
*
service
.
SystemSettings
,
after
*
service
.
SystemSettings
,
req
UpdateSettingsRequest
)
{
if
before
==
nil
||
after
==
nil
{
return
...
...
backend/internal/handler/dto/settings.go
View file @
97f14b7a
...
...
@@ -123,6 +123,28 @@ type SystemSettings struct {
EnableFingerprintUnification
bool
`json:"enable_fingerprint_unification"`
EnableMetadataPassthrough
bool
`json:"enable_metadata_passthrough"`
EnableCCHSigning
bool
`json:"enable_cch_signing"`
// Payment configuration
PaymentEnabled
bool
`json:"payment_enabled"`
PaymentMinAmount
float64
`json:"payment_min_amount"`
PaymentMaxAmount
float64
`json:"payment_max_amount"`
PaymentDailyLimit
float64
`json:"payment_daily_limit"`
PaymentOrderTimeoutMin
int
`json:"payment_order_timeout_minutes"`
PaymentMaxPendingOrders
int
`json:"payment_max_pending_orders"`
PaymentEnabledTypes
[]
string
`json:"payment_enabled_types"`
PaymentBalanceDisabled
bool
`json:"payment_balance_disabled"`
PaymentLoadBalanceStrat
string
`json:"payment_load_balance_strategy"`
PaymentProductNamePrefix
string
`json:"payment_product_name_prefix"`
PaymentProductNameSuffix
string
`json:"payment_product_name_suffix"`
PaymentHelpImageURL
string
`json:"payment_help_image_url"`
PaymentHelpText
string
`json:"payment_help_text"`
// Cancel rate limit
PaymentCancelRateLimitEnabled
bool
`json:"payment_cancel_rate_limit_enabled"`
PaymentCancelRateLimitMax
int
`json:"payment_cancel_rate_limit_max"`
PaymentCancelRateLimitWindow
int
`json:"payment_cancel_rate_limit_window"`
PaymentCancelRateLimitUnit
string
`json:"payment_cancel_rate_limit_unit"`
PaymentCancelRateLimitMode
string
`json:"payment_cancel_rate_limit_window_mode"`
}
type
DefaultSubscriptionSetting
struct
{
...
...
@@ -159,6 +181,7 @@ type PublicSettings struct {
OIDCOAuthProviderName
string
`json:"oidc_oauth_provider_name"`
SoraClientEnabled
bool
`json:"sora_client_enabled"`
BackendModeEnabled
bool
`json:"backend_mode_enabled"`
PaymentEnabled
bool
`json:"payment_enabled"`
Version
string
`json:"version"`
}
...
...
backend/internal/handler/handler.go
View file @
97f14b7a
...
...
@@ -31,6 +31,7 @@ type AdminHandlers struct {
APIKey
*
admin
.
AdminAPIKeyHandler
ScheduledTest
*
admin
.
ScheduledTestHandler
Channel
*
admin
.
ChannelHandler
Payment
*
admin
.
PaymentHandler
}
// Handlers contains all HTTP handlers
...
...
@@ -47,6 +48,8 @@ type Handlers struct {
OpenAIGateway
*
OpenAIGatewayHandler
Setting
*
SettingHandler
Totp
*
TotpHandler
Payment
*
PaymentHandler
PaymentWebhook
*
PaymentWebhookHandler
}
// BuildInfo contains build-time information
...
...
backend/internal/handler/payment_handler.go
0 → 100644
View file @
97f14b7a
package
handler
import
(
"strconv"
"strings"
"github.com/Wei-Shaw/sub2api/internal/pkg/pagination"
"github.com/Wei-Shaw/sub2api/internal/pkg/response"
middleware2
"github.com/Wei-Shaw/sub2api/internal/server/middleware"
"github.com/Wei-Shaw/sub2api/internal/service"
"github.com/gin-gonic/gin"
)
// PaymentHandler handles user-facing payment requests.
type
PaymentHandler
struct
{
channelService
*
service
.
ChannelService
paymentService
*
service
.
PaymentService
configService
*
service
.
PaymentConfigService
}
// NewPaymentHandler creates a new PaymentHandler.
func
NewPaymentHandler
(
paymentService
*
service
.
PaymentService
,
configService
*
service
.
PaymentConfigService
,
channelService
*
service
.
ChannelService
)
*
PaymentHandler
{
return
&
PaymentHandler
{
channelService
:
channelService
,
paymentService
:
paymentService
,
configService
:
configService
,
}
}
// GetPaymentConfig returns the payment system configuration.
// GET /api/v1/payment/config
func
(
h
*
PaymentHandler
)
GetPaymentConfig
(
c
*
gin
.
Context
)
{
cfg
,
err
:=
h
.
configService
.
GetPaymentConfig
(
c
.
Request
.
Context
())
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
response
.
Success
(
c
,
cfg
)
}
// GetPlans returns subscription plans available for sale.
// GET /api/v1/payment/plans
func
(
h
*
PaymentHandler
)
GetPlans
(
c
*
gin
.
Context
)
{
plans
,
err
:=
h
.
configService
.
ListPlansForSale
(
c
.
Request
.
Context
())
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
// Enrich plans with group platform for frontend color coding
type
planWithPlatform
struct
{
ID
int64
`json:"id"`
GroupID
int64
`json:"group_id"`
GroupPlatform
string
`json:"group_platform"`
Name
string
`json:"name"`
Description
string
`json:"description"`
Price
float64
`json:"price"`
OriginalPrice
*
float64
`json:"original_price,omitempty"`
ValidityDays
int
`json:"validity_days"`
ValidityUnit
string
`json:"validity_unit"`
Features
string
`json:"features"`
ProductName
string
`json:"product_name"`
ForSale
bool
`json:"for_sale"`
SortOrder
int
`json:"sort_order"`
}
platformMap
:=
h
.
configService
.
GetGroupPlatformMap
(
c
.
Request
.
Context
(),
plans
)
result
:=
make
([]
planWithPlatform
,
0
,
len
(
plans
))
for
_
,
p
:=
range
plans
{
result
=
append
(
result
,
planWithPlatform
{
ID
:
int64
(
p
.
ID
),
GroupID
:
p
.
GroupID
,
GroupPlatform
:
platformMap
[
p
.
GroupID
],
Name
:
p
.
Name
,
Description
:
p
.
Description
,
Price
:
p
.
Price
,
OriginalPrice
:
p
.
OriginalPrice
,
ValidityDays
:
p
.
ValidityDays
,
ValidityUnit
:
p
.
ValidityUnit
,
Features
:
p
.
Features
,
ProductName
:
p
.
ProductName
,
ForSale
:
p
.
ForSale
,
SortOrder
:
p
.
SortOrder
,
})
}
response
.
Success
(
c
,
result
)
}
// GetChannels returns enabled payment channels.
// GET /api/v1/payment/channels
func
(
h
*
PaymentHandler
)
GetChannels
(
c
*
gin
.
Context
)
{
channels
,
_
,
err
:=
h
.
channelService
.
List
(
c
.
Request
.
Context
(),
pagination
.
PaginationParams
{
Page
:
1
,
PageSize
:
1000
},
"active"
,
""
)
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
response
.
Success
(
c
,
channels
)
}
// GetCheckoutInfo returns all data the payment page needs in a single call:
// payment methods with limits, subscription plans, and configuration.
// GET /api/v1/payment/checkout-info
func
(
h
*
PaymentHandler
)
GetCheckoutInfo
(
c
*
gin
.
Context
)
{
ctx
:=
c
.
Request
.
Context
()
// Fetch limits (methods + global range)
limitsResp
,
err
:=
h
.
configService
.
GetAvailableMethodLimits
(
ctx
)
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
// Fetch payment config
cfg
,
err
:=
h
.
configService
.
GetPaymentConfig
(
ctx
)
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
// Fetch plans with group info
plans
,
_
:=
h
.
configService
.
ListPlansForSale
(
ctx
)
groupInfo
:=
h
.
configService
.
GetGroupInfoMap
(
ctx
,
plans
)
planList
:=
make
([]
checkoutPlan
,
0
,
len
(
plans
))
for
_
,
p
:=
range
plans
{
gi
:=
groupInfo
[
p
.
GroupID
]
planList
=
append
(
planList
,
checkoutPlan
{
ID
:
int64
(
p
.
ID
),
GroupID
:
p
.
GroupID
,
GroupPlatform
:
gi
.
Platform
,
GroupName
:
gi
.
Name
,
RateMultiplier
:
gi
.
RateMultiplier
,
DailyLimitUSD
:
gi
.
DailyLimitUSD
,
WeeklyLimitUSD
:
gi
.
WeeklyLimitUSD
,
MonthlyLimitUSD
:
gi
.
MonthlyLimitUSD
,
ModelScopes
:
gi
.
ModelScopes
,
Name
:
p
.
Name
,
Description
:
p
.
Description
,
Price
:
p
.
Price
,
OriginalPrice
:
p
.
OriginalPrice
,
ValidityDays
:
p
.
ValidityDays
,
ValidityUnit
:
p
.
ValidityUnit
,
Features
:
parseFeatures
(
p
.
Features
),
ProductName
:
p
.
ProductName
,
})
}
response
.
Success
(
c
,
checkoutInfoResponse
{
Methods
:
limitsResp
.
Methods
,
GlobalMin
:
limitsResp
.
GlobalMin
,
GlobalMax
:
limitsResp
.
GlobalMax
,
Plans
:
planList
,
BalanceDisabled
:
cfg
.
BalanceDisabled
,
HelpText
:
cfg
.
HelpText
,
HelpImageURL
:
cfg
.
HelpImageURL
,
StripePublishableKey
:
cfg
.
StripePublishableKey
,
})
}
type
checkoutInfoResponse
struct
{
Methods
map
[
string
]
service
.
MethodLimits
`json:"methods"`
GlobalMin
float64
`json:"global_min"`
GlobalMax
float64
`json:"global_max"`
Plans
[]
checkoutPlan
`json:"plans"`
BalanceDisabled
bool
`json:"balance_disabled"`
HelpText
string
`json:"help_text"`
HelpImageURL
string
`json:"help_image_url"`
StripePublishableKey
string
`json:"stripe_publishable_key"`
}
type
checkoutPlan
struct
{
ID
int64
`json:"id"`
GroupID
int64
`json:"group_id"`
GroupPlatform
string
`json:"group_platform"`
GroupName
string
`json:"group_name"`
RateMultiplier
float64
`json:"rate_multiplier"`
DailyLimitUSD
*
float64
`json:"daily_limit_usd"`
WeeklyLimitUSD
*
float64
`json:"weekly_limit_usd"`
MonthlyLimitUSD
*
float64
`json:"monthly_limit_usd"`
ModelScopes
[]
string
`json:"supported_model_scopes"`
Name
string
`json:"name"`
Description
string
`json:"description"`
Price
float64
`json:"price"`
OriginalPrice
*
float64
`json:"original_price,omitempty"`
ValidityDays
int
`json:"validity_days"`
ValidityUnit
string
`json:"validity_unit"`
Features
[]
string
`json:"features"`
ProductName
string
`json:"product_name"`
}
// parseFeatures splits a newline-separated features string into a string slice.
func
parseFeatures
(
raw
string
)
[]
string
{
if
raw
==
""
{
return
[]
string
{}
}
var
out
[]
string
for
_
,
line
:=
range
strings
.
Split
(
raw
,
"
\n
"
)
{
if
s
:=
strings
.
TrimSpace
(
line
);
s
!=
""
{
out
=
append
(
out
,
s
)
}
}
if
out
==
nil
{
return
[]
string
{}
}
return
out
}
// GetLimits returns per-payment-type limits derived from enabled provider instances.
// GET /api/v1/payment/limits
func
(
h
*
PaymentHandler
)
GetLimits
(
c
*
gin
.
Context
)
{
resp
,
err
:=
h
.
configService
.
GetAvailableMethodLimits
(
c
.
Request
.
Context
())
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
response
.
Success
(
c
,
resp
)
}
// CreateOrderRequest is the request body for creating a payment order.
type
CreateOrderRequest
struct
{
Amount
float64
`json:"amount"`
PaymentType
string
`json:"payment_type" binding:"required"`
OrderType
string
`json:"order_type"`
PlanID
int64
`json:"plan_id"`
}
// CreateOrder creates a new payment order.
// POST /api/v1/payment/orders
func
(
h
*
PaymentHandler
)
CreateOrder
(
c
*
gin
.
Context
)
{
subject
,
ok
:=
requireAuth
(
c
)
if
!
ok
{
return
}
var
req
CreateOrderRequest
if
err
:=
c
.
ShouldBindJSON
(
&
req
);
err
!=
nil
{
response
.
BadRequest
(
c
,
"Invalid request: "
+
err
.
Error
())
return
}
result
,
err
:=
h
.
paymentService
.
CreateOrder
(
c
.
Request
.
Context
(),
service
.
CreateOrderRequest
{
UserID
:
subject
.
UserID
,
Amount
:
req
.
Amount
,
PaymentType
:
req
.
PaymentType
,
ClientIP
:
c
.
ClientIP
(),
IsMobile
:
isMobile
(
c
),
SrcHost
:
c
.
Request
.
Host
,
SrcURL
:
c
.
Request
.
Referer
(),
OrderType
:
req
.
OrderType
,
PlanID
:
req
.
PlanID
,
})
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
response
.
Success
(
c
,
result
)
}
// GetMyOrders returns the authenticated user's orders.
// GET /api/v1/payment/orders/my
func
(
h
*
PaymentHandler
)
GetMyOrders
(
c
*
gin
.
Context
)
{
subject
,
ok
:=
requireAuth
(
c
)
if
!
ok
{
return
}
page
,
pageSize
:=
response
.
ParsePagination
(
c
)
orders
,
total
,
err
:=
h
.
paymentService
.
GetUserOrders
(
c
.
Request
.
Context
(),
subject
.
UserID
,
service
.
OrderListParams
{
Page
:
page
,
PageSize
:
pageSize
,
Status
:
c
.
Query
(
"status"
),
OrderType
:
c
.
Query
(
"order_type"
),
PaymentType
:
c
.
Query
(
"payment_type"
),
})
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
response
.
Paginated
(
c
,
orders
,
int64
(
total
),
page
,
pageSize
)
}
// GetOrder returns a single order for the authenticated user.
// GET /api/v1/payment/orders/:id
func
(
h
*
PaymentHandler
)
GetOrder
(
c
*
gin
.
Context
)
{
subject
,
ok
:=
requireAuth
(
c
)
if
!
ok
{
return
}
orderID
,
err
:=
strconv
.
ParseInt
(
c
.
Param
(
"id"
),
10
,
64
)
if
err
!=
nil
{
response
.
BadRequest
(
c
,
"Invalid order ID"
)
return
}
order
,
err
:=
h
.
paymentService
.
GetOrder
(
c
.
Request
.
Context
(),
orderID
,
subject
.
UserID
)
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
response
.
Success
(
c
,
order
)
}
// CancelOrder cancels a pending order for the authenticated user.
// POST /api/v1/payment/orders/:id/cancel
func
(
h
*
PaymentHandler
)
CancelOrder
(
c
*
gin
.
Context
)
{
subject
,
ok
:=
requireAuth
(
c
)
if
!
ok
{
return
}
orderID
,
err
:=
strconv
.
ParseInt
(
c
.
Param
(
"id"
),
10
,
64
)
if
err
!=
nil
{
response
.
BadRequest
(
c
,
"Invalid order ID"
)
return
}
msg
,
err
:=
h
.
paymentService
.
CancelOrder
(
c
.
Request
.
Context
(),
orderID
,
subject
.
UserID
)
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
response
.
Success
(
c
,
gin
.
H
{
"message"
:
msg
})
}
// RefundRequestBody is the request body for requesting a refund.
type
RefundRequestBody
struct
{
Reason
string
`json:"reason"`
}
// RequestRefund submits a refund request for a completed order.
// POST /api/v1/payment/orders/:id/refund-request
func
(
h
*
PaymentHandler
)
RequestRefund
(
c
*
gin
.
Context
)
{
subject
,
ok
:=
requireAuth
(
c
)
if
!
ok
{
return
}
orderID
,
err
:=
strconv
.
ParseInt
(
c
.
Param
(
"id"
),
10
,
64
)
if
err
!=
nil
{
response
.
BadRequest
(
c
,
"Invalid order ID"
)
return
}
var
req
RefundRequestBody
if
err
:=
c
.
ShouldBindJSON
(
&
req
);
err
!=
nil
{
response
.
BadRequest
(
c
,
"Invalid request: "
+
err
.
Error
())
return
}
if
err
:=
h
.
paymentService
.
RequestRefund
(
c
.
Request
.
Context
(),
orderID
,
subject
.
UserID
,
req
.
Reason
);
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
response
.
Success
(
c
,
gin
.
H
{
"message"
:
"refund requested"
})
}
// VerifyOrderRequest is the request body for verifying a payment order.
type
VerifyOrderRequest
struct
{
OutTradeNo
string
`json:"out_trade_no" binding:"required"`
}
// VerifyOrder actively queries the upstream payment provider to check
// if payment was made, and processes it if so.
// POST /api/v1/payment/orders/verify
func
(
h
*
PaymentHandler
)
VerifyOrder
(
c
*
gin
.
Context
)
{
subject
,
ok
:=
requireAuth
(
c
)
if
!
ok
{
return
}
var
req
VerifyOrderRequest
if
err
:=
c
.
ShouldBindJSON
(
&
req
);
err
!=
nil
{
response
.
BadRequest
(
c
,
"Invalid request: "
+
err
.
Error
())
return
}
order
,
err
:=
h
.
paymentService
.
VerifyOrderByOutTradeNo
(
c
.
Request
.
Context
(),
req
.
OutTradeNo
,
subject
.
UserID
)
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
response
.
Success
(
c
,
order
)
}
// PublicOrderResult is the limited order info returned by the public verify endpoint.
// No user details are exposed — only payment status information.
type
PublicOrderResult
struct
{
ID
int64
`json:"id"`
OutTradeNo
string
`json:"out_trade_no"`
Amount
float64
`json:"amount"`
PayAmount
float64
`json:"pay_amount"`
PaymentType
string
`json:"payment_type"`
Status
string
`json:"status"`
}
// VerifyOrderPublic verifies payment status without requiring authentication.
// Returns limited order info (no user details) to prevent information leakage.
// POST /api/v1/payment/public/orders/verify
func
(
h
*
PaymentHandler
)
VerifyOrderPublic
(
c
*
gin
.
Context
)
{
var
req
VerifyOrderRequest
if
err
:=
c
.
ShouldBindJSON
(
&
req
);
err
!=
nil
{
response
.
BadRequest
(
c
,
"Invalid request: "
+
err
.
Error
())
return
}
order
,
err
:=
h
.
paymentService
.
VerifyOrderPublic
(
c
.
Request
.
Context
(),
req
.
OutTradeNo
)
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
response
.
Success
(
c
,
PublicOrderResult
{
ID
:
order
.
ID
,
OutTradeNo
:
order
.
OutTradeNo
,
Amount
:
order
.
Amount
,
PayAmount
:
order
.
PayAmount
,
PaymentType
:
order
.
PaymentType
,
Status
:
order
.
Status
,
})
}
// requireAuth extracts the authenticated subject from the context.
// Returns the subject and true on success; on failure it writes an Unauthorized response and returns false.
func
requireAuth
(
c
*
gin
.
Context
)
(
middleware2
.
AuthSubject
,
bool
)
{
subject
,
ok
:=
middleware2
.
GetAuthSubjectFromContext
(
c
)
if
!
ok
{
response
.
Unauthorized
(
c
,
"User not authenticated"
)
return
middleware2
.
AuthSubject
{},
false
}
return
subject
,
true
}
// isMobile detects mobile user agents.
func
isMobile
(
c
*
gin
.
Context
)
bool
{
ua
:=
strings
.
ToLower
(
c
.
GetHeader
(
"User-Agent"
))
for
_
,
kw
:=
range
[]
string
{
"mobile"
,
"android"
,
"iphone"
,
"ipad"
,
"ipod"
}
{
if
strings
.
Contains
(
ua
,
kw
)
{
return
true
}
}
return
false
}
backend/internal/handler/payment_webhook_handler.go
0 → 100644
View file @
97f14b7a
package
handler
import
(
"io"
"log/slog"
"net/http"
"net/url"
"strings"
"github.com/Wei-Shaw/sub2api/internal/payment"
"github.com/Wei-Shaw/sub2api/internal/service"
"github.com/gin-gonic/gin"
)
// PaymentWebhookHandler handles payment provider webhook callbacks.
type
PaymentWebhookHandler
struct
{
paymentService
*
service
.
PaymentService
registry
*
payment
.
Registry
}
// maxWebhookBodySize is the maximum allowed webhook request body size (1 MB).
const
maxWebhookBodySize
=
1
<<
20
// webhookLogTruncateLen is the maximum length of raw body logged on verify failure.
const
webhookLogTruncateLen
=
200
// NewPaymentWebhookHandler creates a new PaymentWebhookHandler.
func
NewPaymentWebhookHandler
(
paymentService
*
service
.
PaymentService
,
registry
*
payment
.
Registry
)
*
PaymentWebhookHandler
{
return
&
PaymentWebhookHandler
{
paymentService
:
paymentService
,
registry
:
registry
,
}
}
// EasyPayNotify handles EasyPay payment notifications.
// POST /api/v1/payment/webhook/easypay
func
(
h
*
PaymentWebhookHandler
)
EasyPayNotify
(
c
*
gin
.
Context
)
{
h
.
handleNotify
(
c
,
payment
.
TypeEasyPay
)
}
// AlipayNotify handles Alipay payment notifications.
// POST /api/v1/payment/webhook/alipay
func
(
h
*
PaymentWebhookHandler
)
AlipayNotify
(
c
*
gin
.
Context
)
{
h
.
handleNotify
(
c
,
payment
.
TypeAlipay
)
}
// WxpayNotify handles WeChat Pay payment notifications.
// POST /api/v1/payment/webhook/wxpay
func
(
h
*
PaymentWebhookHandler
)
WxpayNotify
(
c
*
gin
.
Context
)
{
h
.
handleNotify
(
c
,
payment
.
TypeWxpay
)
}
// StripeWebhook handles Stripe webhook events.
// POST /api/v1/payment/webhook/stripe
func
(
h
*
PaymentWebhookHandler
)
StripeWebhook
(
c
*
gin
.
Context
)
{
h
.
handleNotify
(
c
,
payment
.
TypeStripe
)
}
// handleNotify is the shared logic for all provider webhook handlers.
func
(
h
*
PaymentWebhookHandler
)
handleNotify
(
c
*
gin
.
Context
,
providerKey
string
)
{
var
rawBody
string
if
c
.
Request
.
Method
==
http
.
MethodGet
{
// GET callbacks (e.g. EasyPay) pass params as URL query string
rawBody
=
c
.
Request
.
URL
.
RawQuery
}
else
{
body
,
err
:=
io
.
ReadAll
(
io
.
LimitReader
(
c
.
Request
.
Body
,
maxWebhookBodySize
))
if
err
!=
nil
{
slog
.
Error
(
"[Payment Webhook] failed to read body"
,
"provider"
,
providerKey
,
"error"
,
err
)
c
.
String
(
http
.
StatusBadRequest
,
"failed to read body"
)
return
}
rawBody
=
string
(
body
)
}
// Extract out_trade_no to look up the order's specific provider instance.
// This is needed when multiple instances of the same provider exist (e.g. multiple EasyPay accounts).
outTradeNo
:=
extractOutTradeNo
(
rawBody
,
providerKey
)
provider
,
err
:=
h
.
paymentService
.
GetWebhookProvider
(
c
.
Request
.
Context
(),
providerKey
,
outTradeNo
)
if
err
!=
nil
{
slog
.
Warn
(
"[Payment Webhook] provider not found"
,
"provider"
,
providerKey
,
"outTradeNo"
,
outTradeNo
,
"error"
,
err
)
writeSuccessResponse
(
c
,
providerKey
)
return
}
headers
:=
make
(
map
[
string
]
string
)
for
k
:=
range
c
.
Request
.
Header
{
headers
[
strings
.
ToLower
(
k
)]
=
c
.
GetHeader
(
k
)
}
notification
,
err
:=
provider
.
VerifyNotification
(
c
.
Request
.
Context
(),
rawBody
,
headers
)
if
err
!=
nil
{
truncatedBody
:=
rawBody
if
len
(
truncatedBody
)
>
webhookLogTruncateLen
{
truncatedBody
=
truncatedBody
[
:
webhookLogTruncateLen
]
+
"...(truncated)"
}
slog
.
Error
(
"[Payment Webhook] verify failed"
,
"provider"
,
providerKey
,
"error"
,
err
,
"method"
,
c
.
Request
.
Method
,
"bodyLen"
,
len
(
rawBody
))
slog
.
Debug
(
"[Payment Webhook] verify failed body"
,
"provider"
,
providerKey
,
"rawBody"
,
truncatedBody
)
c
.
String
(
http
.
StatusBadRequest
,
"verify failed"
)
return
}
// nil notification means irrelevant event (e.g. Stripe non-payment event); return success.
if
notification
==
nil
{
writeSuccessResponse
(
c
,
providerKey
)
return
}
if
err
:=
h
.
paymentService
.
HandlePaymentNotification
(
c
.
Request
.
Context
(),
notification
,
providerKey
);
err
!=
nil
{
slog
.
Error
(
"[Payment Webhook] handle notification failed"
,
"provider"
,
providerKey
,
"error"
,
err
)
c
.
String
(
http
.
StatusInternalServerError
,
"handle failed"
)
return
}
writeSuccessResponse
(
c
,
providerKey
)
}
// extractOutTradeNo parses the webhook body to find the out_trade_no.
// This allows looking up the correct provider instance before verification.
func
extractOutTradeNo
(
rawBody
,
providerKey
string
)
string
{
switch
providerKey
{
case
payment
.
TypeEasyPay
:
values
,
err
:=
url
.
ParseQuery
(
rawBody
)
if
err
==
nil
{
return
values
.
Get
(
"out_trade_no"
)
}
}
// For other providers (Stripe, Alipay direct, WxPay direct), the registry
// typically has only one instance, so no instance lookup is needed.
return
""
}
// wxpaySuccessResponse is the JSON response expected by WeChat Pay webhook.
type
wxpaySuccessResponse
struct
{
Code
string
`json:"code"`
Message
string
`json:"message"`
}
// WeChat Pay webhook success response constants.
const
(
wxpaySuccessCode
=
"SUCCESS"
wxpaySuccessMessage
=
"成功"
)
// writeSuccessResponse sends the provider-specific success response.
// WeChat Pay requires JSON {"code":"SUCCESS","message":"成功"};
// Stripe expects an empty 200; others accept plain text "success".
func
writeSuccessResponse
(
c
*
gin
.
Context
,
providerKey
string
)
{
switch
providerKey
{
case
payment
.
TypeWxpay
:
c
.
JSON
(
http
.
StatusOK
,
wxpaySuccessResponse
{
Code
:
wxpaySuccessCode
,
Message
:
wxpaySuccessMessage
})
case
payment
.
TypeStripe
:
c
.
String
(
http
.
StatusOK
,
""
)
default
:
c
.
String
(
http
.
StatusOK
,
"success"
)
}
}
Prev
1
2
3
4
5
6
7
…
9
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment