- 支持创建/编辑/删除优惠码,设置赠送金额和使用限制 - 注册页面实时验证优惠码并显示赠送金额 - 支持 URL 参数自动填充 (?promo=CODE) - 添加优惠码验证接口速率限制 - 使用数据库行锁防止并发超限 - 新增后台优惠码管理页面,支持复制注册链接
376 lines
13 KiB
Go
376 lines
13 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect/sql"
|
|
"github.com/Wei-Shaw/sub2api/ent/user"
|
|
)
|
|
|
|
// User is the model entity for the User schema.
|
|
type User struct {
|
|
config `json:"-"`
|
|
// ID of the ent.
|
|
ID int64 `json:"id,omitempty"`
|
|
// CreatedAt holds the value of the "created_at" field.
|
|
CreatedAt time.Time `json:"created_at,omitempty"`
|
|
// UpdatedAt holds the value of the "updated_at" field.
|
|
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
|
// DeletedAt holds the value of the "deleted_at" field.
|
|
DeletedAt *time.Time `json:"deleted_at,omitempty"`
|
|
// Email holds the value of the "email" field.
|
|
Email string `json:"email,omitempty"`
|
|
// PasswordHash holds the value of the "password_hash" field.
|
|
PasswordHash string `json:"password_hash,omitempty"`
|
|
// Role holds the value of the "role" field.
|
|
Role string `json:"role,omitempty"`
|
|
// Balance holds the value of the "balance" field.
|
|
Balance float64 `json:"balance,omitempty"`
|
|
// Concurrency holds the value of the "concurrency" field.
|
|
Concurrency int `json:"concurrency,omitempty"`
|
|
// Status holds the value of the "status" field.
|
|
Status string `json:"status,omitempty"`
|
|
// Username holds the value of the "username" field.
|
|
Username string `json:"username,omitempty"`
|
|
// Notes holds the value of the "notes" field.
|
|
Notes string `json:"notes,omitempty"`
|
|
// Edges holds the relations/edges for other nodes in the graph.
|
|
// The values are being populated by the UserQuery when eager-loading is set.
|
|
Edges UserEdges `json:"edges"`
|
|
selectValues sql.SelectValues
|
|
}
|
|
|
|
// UserEdges holds the relations/edges for other nodes in the graph.
|
|
type UserEdges struct {
|
|
// APIKeys holds the value of the api_keys edge.
|
|
APIKeys []*APIKey `json:"api_keys,omitempty"`
|
|
// RedeemCodes holds the value of the redeem_codes edge.
|
|
RedeemCodes []*RedeemCode `json:"redeem_codes,omitempty"`
|
|
// Subscriptions holds the value of the subscriptions edge.
|
|
Subscriptions []*UserSubscription `json:"subscriptions,omitempty"`
|
|
// AssignedSubscriptions holds the value of the assigned_subscriptions edge.
|
|
AssignedSubscriptions []*UserSubscription `json:"assigned_subscriptions,omitempty"`
|
|
// AllowedGroups holds the value of the allowed_groups edge.
|
|
AllowedGroups []*Group `json:"allowed_groups,omitempty"`
|
|
// UsageLogs holds the value of the usage_logs edge.
|
|
UsageLogs []*UsageLog `json:"usage_logs,omitempty"`
|
|
// AttributeValues holds the value of the attribute_values edge.
|
|
AttributeValues []*UserAttributeValue `json:"attribute_values,omitempty"`
|
|
// PromoCodeUsages holds the value of the promo_code_usages edge.
|
|
PromoCodeUsages []*PromoCodeUsage `json:"promo_code_usages,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 [9]bool
|
|
}
|
|
|
|
// APIKeysOrErr returns the APIKeys value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e UserEdges) APIKeysOrErr() ([]*APIKey, error) {
|
|
if e.loadedTypes[0] {
|
|
return e.APIKeys, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "api_keys"}
|
|
}
|
|
|
|
// RedeemCodesOrErr returns the RedeemCodes value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e UserEdges) RedeemCodesOrErr() ([]*RedeemCode, error) {
|
|
if e.loadedTypes[1] {
|
|
return e.RedeemCodes, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "redeem_codes"}
|
|
}
|
|
|
|
// SubscriptionsOrErr returns the Subscriptions value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e UserEdges) SubscriptionsOrErr() ([]*UserSubscription, error) {
|
|
if e.loadedTypes[2] {
|
|
return e.Subscriptions, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "subscriptions"}
|
|
}
|
|
|
|
// AssignedSubscriptionsOrErr returns the AssignedSubscriptions value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e UserEdges) AssignedSubscriptionsOrErr() ([]*UserSubscription, error) {
|
|
if e.loadedTypes[3] {
|
|
return e.AssignedSubscriptions, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "assigned_subscriptions"}
|
|
}
|
|
|
|
// AllowedGroupsOrErr returns the AllowedGroups value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e UserEdges) AllowedGroupsOrErr() ([]*Group, error) {
|
|
if e.loadedTypes[4] {
|
|
return e.AllowedGroups, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "allowed_groups"}
|
|
}
|
|
|
|
// UsageLogsOrErr returns the UsageLogs value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e UserEdges) UsageLogsOrErr() ([]*UsageLog, error) {
|
|
if e.loadedTypes[5] {
|
|
return e.UsageLogs, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "usage_logs"}
|
|
}
|
|
|
|
// AttributeValuesOrErr returns the AttributeValues value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e UserEdges) AttributeValuesOrErr() ([]*UserAttributeValue, error) {
|
|
if e.loadedTypes[6] {
|
|
return e.AttributeValues, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "attribute_values"}
|
|
}
|
|
|
|
// PromoCodeUsagesOrErr returns the PromoCodeUsages value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e UserEdges) PromoCodeUsagesOrErr() ([]*PromoCodeUsage, error) {
|
|
if e.loadedTypes[7] {
|
|
return e.PromoCodeUsages, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "promo_code_usages"}
|
|
}
|
|
|
|
// 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[8] {
|
|
return e.UserAllowedGroups, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "user_allowed_groups"}
|
|
}
|
|
|
|
// scanValues returns the types for scanning values from sql.Rows.
|
|
func (*User) scanValues(columns []string) ([]any, error) {
|
|
values := make([]any, len(columns))
|
|
for i := range columns {
|
|
switch columns[i] {
|
|
case user.FieldBalance:
|
|
values[i] = new(sql.NullFloat64)
|
|
case user.FieldID, user.FieldConcurrency:
|
|
values[i] = new(sql.NullInt64)
|
|
case user.FieldEmail, user.FieldPasswordHash, user.FieldRole, user.FieldStatus, user.FieldUsername, user.FieldNotes:
|
|
values[i] = new(sql.NullString)
|
|
case user.FieldCreatedAt, user.FieldUpdatedAt, user.FieldDeletedAt:
|
|
values[i] = new(sql.NullTime)
|
|
default:
|
|
values[i] = new(sql.UnknownType)
|
|
}
|
|
}
|
|
return values, nil
|
|
}
|
|
|
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
|
// to the User fields.
|
|
func (_m *User) assignValues(columns []string, values []any) error {
|
|
if m, n := len(values), len(columns); m < n {
|
|
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
|
}
|
|
for i := range columns {
|
|
switch columns[i] {
|
|
case user.FieldID:
|
|
value, ok := values[i].(*sql.NullInt64)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field id", value)
|
|
}
|
|
_m.ID = int64(value.Int64)
|
|
case user.FieldCreatedAt:
|
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
|
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
|
} else if value.Valid {
|
|
_m.CreatedAt = value.Time
|
|
}
|
|
case user.FieldUpdatedAt:
|
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
|
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
|
} else if value.Valid {
|
|
_m.UpdatedAt = value.Time
|
|
}
|
|
case user.FieldDeletedAt:
|
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
|
return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
|
|
} else if value.Valid {
|
|
_m.DeletedAt = new(time.Time)
|
|
*_m.DeletedAt = value.Time
|
|
}
|
|
case user.FieldEmail:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field email", values[i])
|
|
} else if value.Valid {
|
|
_m.Email = value.String
|
|
}
|
|
case user.FieldPasswordHash:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field password_hash", values[i])
|
|
} else if value.Valid {
|
|
_m.PasswordHash = value.String
|
|
}
|
|
case user.FieldRole:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field role", values[i])
|
|
} else if value.Valid {
|
|
_m.Role = value.String
|
|
}
|
|
case user.FieldBalance:
|
|
if value, ok := values[i].(*sql.NullFloat64); !ok {
|
|
return fmt.Errorf("unexpected type %T for field balance", values[i])
|
|
} else if value.Valid {
|
|
_m.Balance = value.Float64
|
|
}
|
|
case user.FieldConcurrency:
|
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
|
return fmt.Errorf("unexpected type %T for field concurrency", values[i])
|
|
} else if value.Valid {
|
|
_m.Concurrency = int(value.Int64)
|
|
}
|
|
case user.FieldStatus:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field status", values[i])
|
|
} else if value.Valid {
|
|
_m.Status = value.String
|
|
}
|
|
case user.FieldUsername:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field username", values[i])
|
|
} else if value.Valid {
|
|
_m.Username = value.String
|
|
}
|
|
case user.FieldNotes:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field notes", values[i])
|
|
} else if value.Valid {
|
|
_m.Notes = value.String
|
|
}
|
|
default:
|
|
_m.selectValues.Set(columns[i], values[i])
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Value returns the ent.Value that was dynamically selected and assigned to the User.
|
|
// This includes values selected through modifiers, order, etc.
|
|
func (_m *User) Value(name string) (ent.Value, error) {
|
|
return _m.selectValues.Get(name)
|
|
}
|
|
|
|
// QueryAPIKeys queries the "api_keys" edge of the User entity.
|
|
func (_m *User) QueryAPIKeys() *APIKeyQuery {
|
|
return NewUserClient(_m.config).QueryAPIKeys(_m)
|
|
}
|
|
|
|
// QueryRedeemCodes queries the "redeem_codes" edge of the User entity.
|
|
func (_m *User) QueryRedeemCodes() *RedeemCodeQuery {
|
|
return NewUserClient(_m.config).QueryRedeemCodes(_m)
|
|
}
|
|
|
|
// QuerySubscriptions queries the "subscriptions" edge of the User entity.
|
|
func (_m *User) QuerySubscriptions() *UserSubscriptionQuery {
|
|
return NewUserClient(_m.config).QuerySubscriptions(_m)
|
|
}
|
|
|
|
// QueryAssignedSubscriptions queries the "assigned_subscriptions" edge of the User entity.
|
|
func (_m *User) QueryAssignedSubscriptions() *UserSubscriptionQuery {
|
|
return NewUserClient(_m.config).QueryAssignedSubscriptions(_m)
|
|
}
|
|
|
|
// QueryAllowedGroups queries the "allowed_groups" edge of the User entity.
|
|
func (_m *User) QueryAllowedGroups() *GroupQuery {
|
|
return NewUserClient(_m.config).QueryAllowedGroups(_m)
|
|
}
|
|
|
|
// QueryUsageLogs queries the "usage_logs" edge of the User entity.
|
|
func (_m *User) QueryUsageLogs() *UsageLogQuery {
|
|
return NewUserClient(_m.config).QueryUsageLogs(_m)
|
|
}
|
|
|
|
// QueryAttributeValues queries the "attribute_values" edge of the User entity.
|
|
func (_m *User) QueryAttributeValues() *UserAttributeValueQuery {
|
|
return NewUserClient(_m.config).QueryAttributeValues(_m)
|
|
}
|
|
|
|
// QueryPromoCodeUsages queries the "promo_code_usages" edge of the User entity.
|
|
func (_m *User) QueryPromoCodeUsages() *PromoCodeUsageQuery {
|
|
return NewUserClient(_m.config).QueryPromoCodeUsages(_m)
|
|
}
|
|
|
|
// QueryUserAllowedGroups queries the "user_allowed_groups" edge of the User entity.
|
|
func (_m *User) QueryUserAllowedGroups() *UserAllowedGroupQuery {
|
|
return NewUserClient(_m.config).QueryUserAllowedGroups(_m)
|
|
}
|
|
|
|
// Update returns a builder for updating this User.
|
|
// Note that you need to call User.Unwrap() before calling this method if this User
|
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
|
func (_m *User) Update() *UserUpdateOne {
|
|
return NewUserClient(_m.config).UpdateOne(_m)
|
|
}
|
|
|
|
// Unwrap unwraps the User entity that was returned from a transaction after it was closed,
|
|
// so that all future queries will be executed through the driver which created the transaction.
|
|
func (_m *User) Unwrap() *User {
|
|
_tx, ok := _m.config.driver.(*txDriver)
|
|
if !ok {
|
|
panic("ent: User is not a transactional entity")
|
|
}
|
|
_m.config.driver = _tx.drv
|
|
return _m
|
|
}
|
|
|
|
// String implements the fmt.Stringer.
|
|
func (_m *User) String() string {
|
|
var builder strings.Builder
|
|
builder.WriteString("User(")
|
|
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
|
builder.WriteString("created_at=")
|
|
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("updated_at=")
|
|
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
|
|
builder.WriteString(", ")
|
|
if v := _m.DeletedAt; v != nil {
|
|
builder.WriteString("deleted_at=")
|
|
builder.WriteString(v.Format(time.ANSIC))
|
|
}
|
|
builder.WriteString(", ")
|
|
builder.WriteString("email=")
|
|
builder.WriteString(_m.Email)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("password_hash=")
|
|
builder.WriteString(_m.PasswordHash)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("role=")
|
|
builder.WriteString(_m.Role)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("balance=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.Balance))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("concurrency=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.Concurrency))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("status=")
|
|
builder.WriteString(_m.Status)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("username=")
|
|
builder.WriteString(_m.Username)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("notes=")
|
|
builder.WriteString(_m.Notes)
|
|
builder.WriteByte(')')
|
|
return builder.String()
|
|
}
|
|
|
|
// Users is a parsable slice of User.
|
|
type Users []*User
|