Merge pull request #1785 from IanShaw027/rebuild/auth-identity-foundation
feat(auth,payment): 重构认证身份和支付系统及其他部分优化
This commit is contained in:
+1
-4
@@ -126,12 +126,9 @@ backend/cmd/server/server
|
|||||||
deploy/docker-compose.override.yml
|
deploy/docker-compose.override.yml
|
||||||
.gocache/
|
.gocache/
|
||||||
vite.config.js
|
vite.config.js
|
||||||
docs/*
|
docs/
|
||||||
!docs/PAYMENT.md
|
|
||||||
!docs/PAYMENT_CN.md
|
|
||||||
.serena/
|
.serena/
|
||||||
.codex/
|
.codex/
|
||||||
frontend/coverage/
|
frontend/coverage/
|
||||||
aicodex
|
aicodex
|
||||||
output/
|
output/
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
|||||||
totpCache := repository.NewTotpCache(redisClient)
|
totpCache := repository.NewTotpCache(redisClient)
|
||||||
totpService := service.NewTotpService(userRepository, secretEncryptor, totpCache, settingService, emailService, emailQueueService)
|
totpService := service.NewTotpService(userRepository, secretEncryptor, totpCache, settingService, emailService, emailQueueService)
|
||||||
authHandler := handler.NewAuthHandler(configConfig, authService, userService, settingService, promoService, redeemService, totpService)
|
authHandler := handler.NewAuthHandler(configConfig, authService, userService, settingService, promoService, redeemService, totpService)
|
||||||
userHandler := handler.NewUserHandler(userService, emailService, emailCache)
|
userHandler := handler.NewUserHandler(userService, authService, emailService, emailCache)
|
||||||
apiKeyHandler := handler.NewAPIKeyHandler(apiKeyService)
|
apiKeyHandler := handler.NewAPIKeyHandler(apiKeyService)
|
||||||
usageLogRepository := repository.NewUsageLogRepository(client, db)
|
usageLogRepository := repository.NewUsageLogRepository(client, db)
|
||||||
usageService := service.NewUsageService(usageLogRepository, userRepository, client, apiKeyAuthCacheInvalidator)
|
usageService := service.NewUsageService(usageLogRepository, userRepository, client, apiKeyAuthCacheInvalidator)
|
||||||
|
|||||||
@@ -0,0 +1,266 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/authidentity"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/user"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AuthIdentity is the model entity for the AuthIdentity schema.
|
||||||
|
type AuthIdentity 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"`
|
||||||
|
// UserID holds the value of the "user_id" field.
|
||||||
|
UserID int64 `json:"user_id,omitempty"`
|
||||||
|
// ProviderType holds the value of the "provider_type" field.
|
||||||
|
ProviderType string `json:"provider_type,omitempty"`
|
||||||
|
// ProviderKey holds the value of the "provider_key" field.
|
||||||
|
ProviderKey string `json:"provider_key,omitempty"`
|
||||||
|
// ProviderSubject holds the value of the "provider_subject" field.
|
||||||
|
ProviderSubject string `json:"provider_subject,omitempty"`
|
||||||
|
// VerifiedAt holds the value of the "verified_at" field.
|
||||||
|
VerifiedAt *time.Time `json:"verified_at,omitempty"`
|
||||||
|
// Issuer holds the value of the "issuer" field.
|
||||||
|
Issuer *string `json:"issuer,omitempty"`
|
||||||
|
// Metadata holds the value of the "metadata" field.
|
||||||
|
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
||||||
|
// Edges holds the relations/edges for other nodes in the graph.
|
||||||
|
// The values are being populated by the AuthIdentityQuery when eager-loading is set.
|
||||||
|
Edges AuthIdentityEdges `json:"edges"`
|
||||||
|
selectValues sql.SelectValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthIdentityEdges holds the relations/edges for other nodes in the graph.
|
||||||
|
type AuthIdentityEdges struct {
|
||||||
|
// User holds the value of the user edge.
|
||||||
|
User *User `json:"user,omitempty"`
|
||||||
|
// Channels holds the value of the channels edge.
|
||||||
|
Channels []*AuthIdentityChannel `json:"channels,omitempty"`
|
||||||
|
// AdoptionDecisions holds the value of the adoption_decisions edge.
|
||||||
|
AdoptionDecisions []*IdentityAdoptionDecision `json:"adoption_decisions,omitempty"`
|
||||||
|
// loadedTypes holds the information for reporting if a
|
||||||
|
// type was loaded (or requested) in eager-loading or not.
|
||||||
|
loadedTypes [3]bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserOrErr returns the User value or an error if the edge
|
||||||
|
// was not loaded in eager-loading, or loaded but was not found.
|
||||||
|
func (e AuthIdentityEdges) UserOrErr() (*User, error) {
|
||||||
|
if e.User != nil {
|
||||||
|
return e.User, nil
|
||||||
|
} else if e.loadedTypes[0] {
|
||||||
|
return nil, &NotFoundError{label: user.Label}
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "user"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelsOrErr returns the Channels value or an error if the edge
|
||||||
|
// was not loaded in eager-loading.
|
||||||
|
func (e AuthIdentityEdges) ChannelsOrErr() ([]*AuthIdentityChannel, error) {
|
||||||
|
if e.loadedTypes[1] {
|
||||||
|
return e.Channels, nil
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "channels"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdoptionDecisionsOrErr returns the AdoptionDecisions value or an error if the edge
|
||||||
|
// was not loaded in eager-loading.
|
||||||
|
func (e AuthIdentityEdges) AdoptionDecisionsOrErr() ([]*IdentityAdoptionDecision, error) {
|
||||||
|
if e.loadedTypes[2] {
|
||||||
|
return e.AdoptionDecisions, nil
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "adoption_decisions"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// scanValues returns the types for scanning values from sql.Rows.
|
||||||
|
func (*AuthIdentity) scanValues(columns []string) ([]any, error) {
|
||||||
|
values := make([]any, len(columns))
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case authidentity.FieldMetadata:
|
||||||
|
values[i] = new([]byte)
|
||||||
|
case authidentity.FieldID, authidentity.FieldUserID:
|
||||||
|
values[i] = new(sql.NullInt64)
|
||||||
|
case authidentity.FieldProviderType, authidentity.FieldProviderKey, authidentity.FieldProviderSubject, authidentity.FieldIssuer:
|
||||||
|
values[i] = new(sql.NullString)
|
||||||
|
case authidentity.FieldCreatedAt, authidentity.FieldUpdatedAt, authidentity.FieldVerifiedAt:
|
||||||
|
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 AuthIdentity fields.
|
||||||
|
func (_m *AuthIdentity) 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 authidentity.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 authidentity.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 authidentity.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 authidentity.FieldUserID:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field user_id", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.UserID = value.Int64
|
||||||
|
}
|
||||||
|
case authidentity.FieldProviderType:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field provider_type", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.ProviderType = value.String
|
||||||
|
}
|
||||||
|
case authidentity.FieldProviderKey:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field provider_key", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.ProviderKey = value.String
|
||||||
|
}
|
||||||
|
case authidentity.FieldProviderSubject:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field provider_subject", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.ProviderSubject = value.String
|
||||||
|
}
|
||||||
|
case authidentity.FieldVerifiedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field verified_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.VerifiedAt = new(time.Time)
|
||||||
|
*_m.VerifiedAt = value.Time
|
||||||
|
}
|
||||||
|
case authidentity.FieldIssuer:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field issuer", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.Issuer = new(string)
|
||||||
|
*_m.Issuer = value.String
|
||||||
|
}
|
||||||
|
case authidentity.FieldMetadata:
|
||||||
|
if value, ok := values[i].(*[]byte); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field metadata", values[i])
|
||||||
|
} else if value != nil && len(*value) > 0 {
|
||||||
|
if err := json.Unmarshal(*value, &_m.Metadata); err != nil {
|
||||||
|
return fmt.Errorf("unmarshal field metadata: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
_m.selectValues.Set(columns[i], values[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value returns the ent.Value that was dynamically selected and assigned to the AuthIdentity.
|
||||||
|
// This includes values selected through modifiers, order, etc.
|
||||||
|
func (_m *AuthIdentity) Value(name string) (ent.Value, error) {
|
||||||
|
return _m.selectValues.Get(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryUser queries the "user" edge of the AuthIdentity entity.
|
||||||
|
func (_m *AuthIdentity) QueryUser() *UserQuery {
|
||||||
|
return NewAuthIdentityClient(_m.config).QueryUser(_m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryChannels queries the "channels" edge of the AuthIdentity entity.
|
||||||
|
func (_m *AuthIdentity) QueryChannels() *AuthIdentityChannelQuery {
|
||||||
|
return NewAuthIdentityClient(_m.config).QueryChannels(_m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryAdoptionDecisions queries the "adoption_decisions" edge of the AuthIdentity entity.
|
||||||
|
func (_m *AuthIdentity) QueryAdoptionDecisions() *IdentityAdoptionDecisionQuery {
|
||||||
|
return NewAuthIdentityClient(_m.config).QueryAdoptionDecisions(_m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns a builder for updating this AuthIdentity.
|
||||||
|
// Note that you need to call AuthIdentity.Unwrap() before calling this method if this AuthIdentity
|
||||||
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||||
|
func (_m *AuthIdentity) Update() *AuthIdentityUpdateOne {
|
||||||
|
return NewAuthIdentityClient(_m.config).UpdateOne(_m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap unwraps the AuthIdentity 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 *AuthIdentity) Unwrap() *AuthIdentity {
|
||||||
|
_tx, ok := _m.config.driver.(*txDriver)
|
||||||
|
if !ok {
|
||||||
|
panic("ent: AuthIdentity is not a transactional entity")
|
||||||
|
}
|
||||||
|
_m.config.driver = _tx.drv
|
||||||
|
return _m
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements the fmt.Stringer.
|
||||||
|
func (_m *AuthIdentity) String() string {
|
||||||
|
var builder strings.Builder
|
||||||
|
builder.WriteString("AuthIdentity(")
|
||||||
|
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(", ")
|
||||||
|
builder.WriteString("user_id=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.UserID))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("provider_type=")
|
||||||
|
builder.WriteString(_m.ProviderType)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("provider_key=")
|
||||||
|
builder.WriteString(_m.ProviderKey)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("provider_subject=")
|
||||||
|
builder.WriteString(_m.ProviderSubject)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
if v := _m.VerifiedAt; v != nil {
|
||||||
|
builder.WriteString("verified_at=")
|
||||||
|
builder.WriteString(v.Format(time.ANSIC))
|
||||||
|
}
|
||||||
|
builder.WriteString(", ")
|
||||||
|
if v := _m.Issuer; v != nil {
|
||||||
|
builder.WriteString("issuer=")
|
||||||
|
builder.WriteString(*v)
|
||||||
|
}
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("metadata=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.Metadata))
|
||||||
|
builder.WriteByte(')')
|
||||||
|
return builder.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthIdentities is a parsable slice of AuthIdentity.
|
||||||
|
type AuthIdentities []*AuthIdentity
|
||||||
@@ -0,0 +1,209 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package authidentity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Label holds the string label denoting the authidentity type in the database.
|
||||||
|
Label = "auth_identity"
|
||||||
|
// FieldID holds the string denoting the id field in the database.
|
||||||
|
FieldID = "id"
|
||||||
|
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||||
|
FieldCreatedAt = "created_at"
|
||||||
|
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||||
|
FieldUpdatedAt = "updated_at"
|
||||||
|
// FieldUserID holds the string denoting the user_id field in the database.
|
||||||
|
FieldUserID = "user_id"
|
||||||
|
// FieldProviderType holds the string denoting the provider_type field in the database.
|
||||||
|
FieldProviderType = "provider_type"
|
||||||
|
// FieldProviderKey holds the string denoting the provider_key field in the database.
|
||||||
|
FieldProviderKey = "provider_key"
|
||||||
|
// FieldProviderSubject holds the string denoting the provider_subject field in the database.
|
||||||
|
FieldProviderSubject = "provider_subject"
|
||||||
|
// FieldVerifiedAt holds the string denoting the verified_at field in the database.
|
||||||
|
FieldVerifiedAt = "verified_at"
|
||||||
|
// FieldIssuer holds the string denoting the issuer field in the database.
|
||||||
|
FieldIssuer = "issuer"
|
||||||
|
// FieldMetadata holds the string denoting the metadata field in the database.
|
||||||
|
FieldMetadata = "metadata"
|
||||||
|
// EdgeUser holds the string denoting the user edge name in mutations.
|
||||||
|
EdgeUser = "user"
|
||||||
|
// EdgeChannels holds the string denoting the channels edge name in mutations.
|
||||||
|
EdgeChannels = "channels"
|
||||||
|
// EdgeAdoptionDecisions holds the string denoting the adoption_decisions edge name in mutations.
|
||||||
|
EdgeAdoptionDecisions = "adoption_decisions"
|
||||||
|
// Table holds the table name of the authidentity in the database.
|
||||||
|
Table = "auth_identities"
|
||||||
|
// UserTable is the table that holds the user relation/edge.
|
||||||
|
UserTable = "auth_identities"
|
||||||
|
// UserInverseTable is the table name for the User entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "user" package.
|
||||||
|
UserInverseTable = "users"
|
||||||
|
// UserColumn is the table column denoting the user relation/edge.
|
||||||
|
UserColumn = "user_id"
|
||||||
|
// ChannelsTable is the table that holds the channels relation/edge.
|
||||||
|
ChannelsTable = "auth_identity_channels"
|
||||||
|
// ChannelsInverseTable is the table name for the AuthIdentityChannel entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "authidentitychannel" package.
|
||||||
|
ChannelsInverseTable = "auth_identity_channels"
|
||||||
|
// ChannelsColumn is the table column denoting the channels relation/edge.
|
||||||
|
ChannelsColumn = "identity_id"
|
||||||
|
// AdoptionDecisionsTable is the table that holds the adoption_decisions relation/edge.
|
||||||
|
AdoptionDecisionsTable = "identity_adoption_decisions"
|
||||||
|
// AdoptionDecisionsInverseTable is the table name for the IdentityAdoptionDecision entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "identityadoptiondecision" package.
|
||||||
|
AdoptionDecisionsInverseTable = "identity_adoption_decisions"
|
||||||
|
// AdoptionDecisionsColumn is the table column denoting the adoption_decisions relation/edge.
|
||||||
|
AdoptionDecisionsColumn = "identity_id"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Columns holds all SQL columns for authidentity fields.
|
||||||
|
var Columns = []string{
|
||||||
|
FieldID,
|
||||||
|
FieldCreatedAt,
|
||||||
|
FieldUpdatedAt,
|
||||||
|
FieldUserID,
|
||||||
|
FieldProviderType,
|
||||||
|
FieldProviderKey,
|
||||||
|
FieldProviderSubject,
|
||||||
|
FieldVerifiedAt,
|
||||||
|
FieldIssuer,
|
||||||
|
FieldMetadata,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||||
|
func ValidColumn(column string) bool {
|
||||||
|
for i := range Columns {
|
||||||
|
if column == Columns[i] {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||||
|
DefaultCreatedAt func() time.Time
|
||||||
|
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||||
|
DefaultUpdatedAt func() time.Time
|
||||||
|
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||||
|
UpdateDefaultUpdatedAt func() time.Time
|
||||||
|
// ProviderTypeValidator is a validator for the "provider_type" field. It is called by the builders before save.
|
||||||
|
ProviderTypeValidator func(string) error
|
||||||
|
// ProviderKeyValidator is a validator for the "provider_key" field. It is called by the builders before save.
|
||||||
|
ProviderKeyValidator func(string) error
|
||||||
|
// ProviderSubjectValidator is a validator for the "provider_subject" field. It is called by the builders before save.
|
||||||
|
ProviderSubjectValidator func(string) error
|
||||||
|
// DefaultMetadata holds the default value on creation for the "metadata" field.
|
||||||
|
DefaultMetadata func() map[string]interface{}
|
||||||
|
)
|
||||||
|
|
||||||
|
// OrderOption defines the ordering options for the AuthIdentity queries.
|
||||||
|
type OrderOption func(*sql.Selector)
|
||||||
|
|
||||||
|
// ByID orders the results by the id field.
|
||||||
|
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByCreatedAt orders the results by the created_at field.
|
||||||
|
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByUpdatedAt orders the results by the updated_at field.
|
||||||
|
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByUserID orders the results by the user_id field.
|
||||||
|
func ByUserID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldUserID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByProviderType orders the results by the provider_type field.
|
||||||
|
func ByProviderType(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldProviderType, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByProviderKey orders the results by the provider_key field.
|
||||||
|
func ByProviderKey(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldProviderKey, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByProviderSubject orders the results by the provider_subject field.
|
||||||
|
func ByProviderSubject(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldProviderSubject, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByVerifiedAt orders the results by the verified_at field.
|
||||||
|
func ByVerifiedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldVerifiedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByIssuer orders the results by the issuer field.
|
||||||
|
func ByIssuer(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldIssuer, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByUserField orders the results by user field.
|
||||||
|
func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByChannelsCount orders the results by channels count.
|
||||||
|
func ByChannelsCount(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborsCount(s, newChannelsStep(), opts...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByChannels orders the results by channels terms.
|
||||||
|
func ByChannels(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborTerms(s, newChannelsStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByAdoptionDecisionsCount orders the results by adoption_decisions count.
|
||||||
|
func ByAdoptionDecisionsCount(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborsCount(s, newAdoptionDecisionsStep(), opts...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByAdoptionDecisions orders the results by adoption_decisions terms.
|
||||||
|
func ByAdoptionDecisions(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborTerms(s, newAdoptionDecisionsStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func newUserStep() *sqlgraph.Step {
|
||||||
|
return sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(UserInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
func newChannelsStep() *sqlgraph.Step {
|
||||||
|
return sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(ChannelsInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, ChannelsTable, ChannelsColumn),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
func newAdoptionDecisionsStep() *sqlgraph.Step {
|
||||||
|
return sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(AdoptionDecisionsInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, AdoptionDecisionsTable, AdoptionDecisionsColumn),
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,600 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package authidentity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/predicate"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ID filters vertices based on their ID field.
|
||||||
|
func ID(id int64) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDEQ applies the EQ predicate on the ID field.
|
||||||
|
func IDEQ(id int64) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNEQ applies the NEQ predicate on the ID field.
|
||||||
|
func IDNEQ(id int64) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldNEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDIn applies the In predicate on the ID field.
|
||||||
|
func IDIn(ids ...int64) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNotIn applies the NotIn predicate on the ID field.
|
||||||
|
func IDNotIn(ids ...int64) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldNotIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGT applies the GT predicate on the ID field.
|
||||||
|
func IDGT(id int64) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldGT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGTE applies the GTE predicate on the ID field.
|
||||||
|
func IDGTE(id int64) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldGTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLT applies the LT predicate on the ID field.
|
||||||
|
func IDLT(id int64) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldLT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLTE applies the LTE predicate on the ID field.
|
||||||
|
func IDLTE(id int64) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldLTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||||
|
func CreatedAt(v time.Time) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(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.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ.
|
||||||
|
func UserID(v int64) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldEQ(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderType applies equality check predicate on the "provider_type" field. It's identical to ProviderTypeEQ.
|
||||||
|
func ProviderType(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldEQ(FieldProviderType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKey applies equality check predicate on the "provider_key" field. It's identical to ProviderKeyEQ.
|
||||||
|
func ProviderKey(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldEQ(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderSubject applies equality check predicate on the "provider_subject" field. It's identical to ProviderSubjectEQ.
|
||||||
|
func ProviderSubject(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldEQ(FieldProviderSubject, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// VerifiedAt applies equality check predicate on the "verified_at" field. It's identical to VerifiedAtEQ.
|
||||||
|
func VerifiedAt(v time.Time) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldEQ(FieldVerifiedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Issuer applies equality check predicate on the "issuer" field. It's identical to IssuerEQ.
|
||||||
|
func Issuer(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldEQ(FieldIssuer, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtEQ(v time.Time) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtNEQ(v time.Time) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldNEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||||
|
func CreatedAtIn(vs ...time.Time) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||||
|
func CreatedAtNotIn(vs ...time.Time) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||||
|
func CreatedAtGT(v time.Time) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldGT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtGTE(v time.Time) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldGTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||||
|
func CreatedAtLT(v time.Time) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldLT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtLTE(v time.Time) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldLTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtEQ(v time.Time) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNEQ(v time.Time) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldNEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtIn(vs ...time.Time) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNotIn(vs ...time.Time) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldNotIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGT(v time.Time) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldGT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGTE(v time.Time) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldGTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLT(v time.Time) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldLT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLTE(v time.Time) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldLTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDEQ applies the EQ predicate on the "user_id" field.
|
||||||
|
func UserIDEQ(v int64) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldEQ(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDNEQ applies the NEQ predicate on the "user_id" field.
|
||||||
|
func UserIDNEQ(v int64) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldNEQ(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDIn applies the In predicate on the "user_id" field.
|
||||||
|
func UserIDIn(vs ...int64) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldIn(FieldUserID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDNotIn applies the NotIn predicate on the "user_id" field.
|
||||||
|
func UserIDNotIn(vs ...int64) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldNotIn(FieldUserID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderTypeEQ applies the EQ predicate on the "provider_type" field.
|
||||||
|
func ProviderTypeEQ(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldEQ(FieldProviderType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderTypeNEQ applies the NEQ predicate on the "provider_type" field.
|
||||||
|
func ProviderTypeNEQ(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldNEQ(FieldProviderType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderTypeIn applies the In predicate on the "provider_type" field.
|
||||||
|
func ProviderTypeIn(vs ...string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldIn(FieldProviderType, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderTypeNotIn applies the NotIn predicate on the "provider_type" field.
|
||||||
|
func ProviderTypeNotIn(vs ...string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldNotIn(FieldProviderType, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderTypeGT applies the GT predicate on the "provider_type" field.
|
||||||
|
func ProviderTypeGT(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldGT(FieldProviderType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderTypeGTE applies the GTE predicate on the "provider_type" field.
|
||||||
|
func ProviderTypeGTE(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldGTE(FieldProviderType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderTypeLT applies the LT predicate on the "provider_type" field.
|
||||||
|
func ProviderTypeLT(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldLT(FieldProviderType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderTypeLTE applies the LTE predicate on the "provider_type" field.
|
||||||
|
func ProviderTypeLTE(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldLTE(FieldProviderType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderTypeContains applies the Contains predicate on the "provider_type" field.
|
||||||
|
func ProviderTypeContains(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldContains(FieldProviderType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderTypeHasPrefix applies the HasPrefix predicate on the "provider_type" field.
|
||||||
|
func ProviderTypeHasPrefix(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldHasPrefix(FieldProviderType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderTypeHasSuffix applies the HasSuffix predicate on the "provider_type" field.
|
||||||
|
func ProviderTypeHasSuffix(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldHasSuffix(FieldProviderType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderTypeEqualFold applies the EqualFold predicate on the "provider_type" field.
|
||||||
|
func ProviderTypeEqualFold(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldEqualFold(FieldProviderType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderTypeContainsFold applies the ContainsFold predicate on the "provider_type" field.
|
||||||
|
func ProviderTypeContainsFold(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldContainsFold(FieldProviderType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyEQ applies the EQ predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyEQ(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldEQ(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyNEQ applies the NEQ predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyNEQ(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldNEQ(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyIn applies the In predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyIn(vs ...string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldIn(FieldProviderKey, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyNotIn applies the NotIn predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyNotIn(vs ...string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldNotIn(FieldProviderKey, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyGT applies the GT predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyGT(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldGT(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyGTE applies the GTE predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyGTE(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldGTE(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyLT applies the LT predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyLT(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldLT(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyLTE applies the LTE predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyLTE(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldLTE(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyContains applies the Contains predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyContains(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldContains(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyHasPrefix applies the HasPrefix predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyHasPrefix(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldHasPrefix(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyHasSuffix applies the HasSuffix predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyHasSuffix(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldHasSuffix(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyEqualFold applies the EqualFold predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyEqualFold(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldEqualFold(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyContainsFold applies the ContainsFold predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyContainsFold(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldContainsFold(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderSubjectEQ applies the EQ predicate on the "provider_subject" field.
|
||||||
|
func ProviderSubjectEQ(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldEQ(FieldProviderSubject, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderSubjectNEQ applies the NEQ predicate on the "provider_subject" field.
|
||||||
|
func ProviderSubjectNEQ(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldNEQ(FieldProviderSubject, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderSubjectIn applies the In predicate on the "provider_subject" field.
|
||||||
|
func ProviderSubjectIn(vs ...string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldIn(FieldProviderSubject, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderSubjectNotIn applies the NotIn predicate on the "provider_subject" field.
|
||||||
|
func ProviderSubjectNotIn(vs ...string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldNotIn(FieldProviderSubject, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderSubjectGT applies the GT predicate on the "provider_subject" field.
|
||||||
|
func ProviderSubjectGT(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldGT(FieldProviderSubject, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderSubjectGTE applies the GTE predicate on the "provider_subject" field.
|
||||||
|
func ProviderSubjectGTE(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldGTE(FieldProviderSubject, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderSubjectLT applies the LT predicate on the "provider_subject" field.
|
||||||
|
func ProviderSubjectLT(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldLT(FieldProviderSubject, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderSubjectLTE applies the LTE predicate on the "provider_subject" field.
|
||||||
|
func ProviderSubjectLTE(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldLTE(FieldProviderSubject, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderSubjectContains applies the Contains predicate on the "provider_subject" field.
|
||||||
|
func ProviderSubjectContains(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldContains(FieldProviderSubject, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderSubjectHasPrefix applies the HasPrefix predicate on the "provider_subject" field.
|
||||||
|
func ProviderSubjectHasPrefix(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldHasPrefix(FieldProviderSubject, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderSubjectHasSuffix applies the HasSuffix predicate on the "provider_subject" field.
|
||||||
|
func ProviderSubjectHasSuffix(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldHasSuffix(FieldProviderSubject, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderSubjectEqualFold applies the EqualFold predicate on the "provider_subject" field.
|
||||||
|
func ProviderSubjectEqualFold(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldEqualFold(FieldProviderSubject, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderSubjectContainsFold applies the ContainsFold predicate on the "provider_subject" field.
|
||||||
|
func ProviderSubjectContainsFold(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldContainsFold(FieldProviderSubject, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// VerifiedAtEQ applies the EQ predicate on the "verified_at" field.
|
||||||
|
func VerifiedAtEQ(v time.Time) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldEQ(FieldVerifiedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// VerifiedAtNEQ applies the NEQ predicate on the "verified_at" field.
|
||||||
|
func VerifiedAtNEQ(v time.Time) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldNEQ(FieldVerifiedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// VerifiedAtIn applies the In predicate on the "verified_at" field.
|
||||||
|
func VerifiedAtIn(vs ...time.Time) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldIn(FieldVerifiedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// VerifiedAtNotIn applies the NotIn predicate on the "verified_at" field.
|
||||||
|
func VerifiedAtNotIn(vs ...time.Time) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldNotIn(FieldVerifiedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// VerifiedAtGT applies the GT predicate on the "verified_at" field.
|
||||||
|
func VerifiedAtGT(v time.Time) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldGT(FieldVerifiedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// VerifiedAtGTE applies the GTE predicate on the "verified_at" field.
|
||||||
|
func VerifiedAtGTE(v time.Time) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldGTE(FieldVerifiedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// VerifiedAtLT applies the LT predicate on the "verified_at" field.
|
||||||
|
func VerifiedAtLT(v time.Time) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldLT(FieldVerifiedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// VerifiedAtLTE applies the LTE predicate on the "verified_at" field.
|
||||||
|
func VerifiedAtLTE(v time.Time) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldLTE(FieldVerifiedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// VerifiedAtIsNil applies the IsNil predicate on the "verified_at" field.
|
||||||
|
func VerifiedAtIsNil() predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldIsNull(FieldVerifiedAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// VerifiedAtNotNil applies the NotNil predicate on the "verified_at" field.
|
||||||
|
func VerifiedAtNotNil() predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldNotNull(FieldVerifiedAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssuerEQ applies the EQ predicate on the "issuer" field.
|
||||||
|
func IssuerEQ(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldEQ(FieldIssuer, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssuerNEQ applies the NEQ predicate on the "issuer" field.
|
||||||
|
func IssuerNEQ(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldNEQ(FieldIssuer, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssuerIn applies the In predicate on the "issuer" field.
|
||||||
|
func IssuerIn(vs ...string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldIn(FieldIssuer, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssuerNotIn applies the NotIn predicate on the "issuer" field.
|
||||||
|
func IssuerNotIn(vs ...string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldNotIn(FieldIssuer, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssuerGT applies the GT predicate on the "issuer" field.
|
||||||
|
func IssuerGT(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldGT(FieldIssuer, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssuerGTE applies the GTE predicate on the "issuer" field.
|
||||||
|
func IssuerGTE(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldGTE(FieldIssuer, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssuerLT applies the LT predicate on the "issuer" field.
|
||||||
|
func IssuerLT(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldLT(FieldIssuer, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssuerLTE applies the LTE predicate on the "issuer" field.
|
||||||
|
func IssuerLTE(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldLTE(FieldIssuer, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssuerContains applies the Contains predicate on the "issuer" field.
|
||||||
|
func IssuerContains(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldContains(FieldIssuer, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssuerHasPrefix applies the HasPrefix predicate on the "issuer" field.
|
||||||
|
func IssuerHasPrefix(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldHasPrefix(FieldIssuer, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssuerHasSuffix applies the HasSuffix predicate on the "issuer" field.
|
||||||
|
func IssuerHasSuffix(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldHasSuffix(FieldIssuer, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssuerIsNil applies the IsNil predicate on the "issuer" field.
|
||||||
|
func IssuerIsNil() predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldIsNull(FieldIssuer))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssuerNotNil applies the NotNil predicate on the "issuer" field.
|
||||||
|
func IssuerNotNil() predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldNotNull(FieldIssuer))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssuerEqualFold applies the EqualFold predicate on the "issuer" field.
|
||||||
|
func IssuerEqualFold(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldEqualFold(FieldIssuer, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssuerContainsFold applies the ContainsFold predicate on the "issuer" field.
|
||||||
|
func IssuerContainsFold(v string) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.FieldContainsFold(FieldIssuer, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasUser applies the HasEdge predicate on the "user" edge.
|
||||||
|
func HasUser() predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates).
|
||||||
|
func HasUserWith(preds ...predicate.User) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(func(s *sql.Selector) {
|
||||||
|
step := newUserStep()
|
||||||
|
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasChannels applies the HasEdge predicate on the "channels" edge.
|
||||||
|
func HasChannels() predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, ChannelsTable, ChannelsColumn),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasChannelsWith applies the HasEdge predicate on the "channels" edge with a given conditions (other predicates).
|
||||||
|
func HasChannelsWith(preds ...predicate.AuthIdentityChannel) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(func(s *sql.Selector) {
|
||||||
|
step := newChannelsStep()
|
||||||
|
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasAdoptionDecisions applies the HasEdge predicate on the "adoption_decisions" edge.
|
||||||
|
func HasAdoptionDecisions() predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, AdoptionDecisionsTable, AdoptionDecisionsColumn),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasAdoptionDecisionsWith applies the HasEdge predicate on the "adoption_decisions" edge with a given conditions (other predicates).
|
||||||
|
func HasAdoptionDecisionsWith(preds ...predicate.IdentityAdoptionDecision) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(func(s *sql.Selector) {
|
||||||
|
step := newAdoptionDecisionsStep()
|
||||||
|
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// And groups predicates with the AND operator between them.
|
||||||
|
func And(predicates ...predicate.AuthIdentity) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.AndPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or groups predicates with the OR operator between them.
|
||||||
|
func Or(predicates ...predicate.AuthIdentity) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.OrPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not applies the not operator on the given predicate.
|
||||||
|
func Not(p predicate.AuthIdentity) predicate.AuthIdentity {
|
||||||
|
return predicate.AuthIdentity(sql.NotPredicates(p))
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,88 @@
|
|||||||
|
// 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/authidentity"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/predicate"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AuthIdentityDelete is the builder for deleting a AuthIdentity entity.
|
||||||
|
type AuthIdentityDelete struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *AuthIdentityMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the AuthIdentityDelete builder.
|
||||||
|
func (_d *AuthIdentityDelete) Where(ps ...predicate.AuthIdentity) *AuthIdentityDelete {
|
||||||
|
_d.mutation.Where(ps...)
|
||||||
|
return _d
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||||
|
func (_d *AuthIdentityDelete) 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 *AuthIdentityDelete) ExecX(ctx context.Context) int {
|
||||||
|
n, err := _d.Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_d *AuthIdentityDelete) sqlExec(ctx context.Context) (int, error) {
|
||||||
|
_spec := sqlgraph.NewDeleteSpec(authidentity.Table, sqlgraph.NewFieldSpec(authidentity.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
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthIdentityDeleteOne is the builder for deleting a single AuthIdentity entity.
|
||||||
|
type AuthIdentityDeleteOne struct {
|
||||||
|
_d *AuthIdentityDelete
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the AuthIdentityDelete builder.
|
||||||
|
func (_d *AuthIdentityDeleteOne) Where(ps ...predicate.AuthIdentity) *AuthIdentityDeleteOne {
|
||||||
|
_d._d.mutation.Where(ps...)
|
||||||
|
return _d
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query.
|
||||||
|
func (_d *AuthIdentityDeleteOne) Exec(ctx context.Context) error {
|
||||||
|
n, err := _d._d.Exec(ctx)
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
|
case n == 0:
|
||||||
|
return &NotFoundError{authidentity.Label}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_d *AuthIdentityDeleteOne) ExecX(ctx context.Context) {
|
||||||
|
if err := _d.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,797 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql/driver"
|
||||||
|
"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/authidentity"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/authidentitychannel"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/identityadoptiondecision"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/predicate"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/user"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AuthIdentityQuery is the builder for querying AuthIdentity entities.
|
||||||
|
type AuthIdentityQuery struct {
|
||||||
|
config
|
||||||
|
ctx *QueryContext
|
||||||
|
order []authidentity.OrderOption
|
||||||
|
inters []Interceptor
|
||||||
|
predicates []predicate.AuthIdentity
|
||||||
|
withUser *UserQuery
|
||||||
|
withChannels *AuthIdentityChannelQuery
|
||||||
|
withAdoptionDecisions *IdentityAdoptionDecisionQuery
|
||||||
|
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 AuthIdentityQuery builder.
|
||||||
|
func (_q *AuthIdentityQuery) Where(ps ...predicate.AuthIdentity) *AuthIdentityQuery {
|
||||||
|
_q.predicates = append(_q.predicates, ps...)
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit the number of records to be returned by this query.
|
||||||
|
func (_q *AuthIdentityQuery) Limit(limit int) *AuthIdentityQuery {
|
||||||
|
_q.ctx.Limit = &limit
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Offset to start from.
|
||||||
|
func (_q *AuthIdentityQuery) Offset(offset int) *AuthIdentityQuery {
|
||||||
|
_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 *AuthIdentityQuery) Unique(unique bool) *AuthIdentityQuery {
|
||||||
|
_q.ctx.Unique = &unique
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Order specifies how the records should be ordered.
|
||||||
|
func (_q *AuthIdentityQuery) Order(o ...authidentity.OrderOption) *AuthIdentityQuery {
|
||||||
|
_q.order = append(_q.order, o...)
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryUser chains the current query on the "user" edge.
|
||||||
|
func (_q *AuthIdentityQuery) QueryUser() *UserQuery {
|
||||||
|
query := (&UserClient{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(authidentity.Table, authidentity.FieldID, selector),
|
||||||
|
sqlgraph.To(user.Table, user.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, authidentity.UserTable, authidentity.UserColumn),
|
||||||
|
)
|
||||||
|
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||||
|
return fromU, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryChannels chains the current query on the "channels" edge.
|
||||||
|
func (_q *AuthIdentityQuery) QueryChannels() *AuthIdentityChannelQuery {
|
||||||
|
query := (&AuthIdentityChannelClient{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(authidentity.Table, authidentity.FieldID, selector),
|
||||||
|
sqlgraph.To(authidentitychannel.Table, authidentitychannel.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, authidentity.ChannelsTable, authidentity.ChannelsColumn),
|
||||||
|
)
|
||||||
|
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||||
|
return fromU, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryAdoptionDecisions chains the current query on the "adoption_decisions" edge.
|
||||||
|
func (_q *AuthIdentityQuery) QueryAdoptionDecisions() *IdentityAdoptionDecisionQuery {
|
||||||
|
query := (&IdentityAdoptionDecisionClient{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(authidentity.Table, authidentity.FieldID, selector),
|
||||||
|
sqlgraph.To(identityadoptiondecision.Table, identityadoptiondecision.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, authidentity.AdoptionDecisionsTable, authidentity.AdoptionDecisionsColumn),
|
||||||
|
)
|
||||||
|
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||||
|
return fromU, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// First returns the first AuthIdentity entity from the query.
|
||||||
|
// Returns a *NotFoundError when no AuthIdentity was found.
|
||||||
|
func (_q *AuthIdentityQuery) First(ctx context.Context) (*AuthIdentity, 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{authidentity.Label}
|
||||||
|
}
|
||||||
|
return nodes[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstX is like First, but panics if an error occurs.
|
||||||
|
func (_q *AuthIdentityQuery) FirstX(ctx context.Context) *AuthIdentity {
|
||||||
|
node, err := _q.First(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstID returns the first AuthIdentity ID from the query.
|
||||||
|
// Returns a *NotFoundError when no AuthIdentity ID was found.
|
||||||
|
func (_q *AuthIdentityQuery) 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{authidentity.Label}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return ids[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||||
|
func (_q *AuthIdentityQuery) FirstIDX(ctx context.Context) int64 {
|
||||||
|
id, err := _q.FirstID(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only returns a single AuthIdentity entity found by the query, ensuring it only returns one.
|
||||||
|
// Returns a *NotSingularError when more than one AuthIdentity entity is found.
|
||||||
|
// Returns a *NotFoundError when no AuthIdentity entities are found.
|
||||||
|
func (_q *AuthIdentityQuery) Only(ctx context.Context) (*AuthIdentity, 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{authidentity.Label}
|
||||||
|
default:
|
||||||
|
return nil, &NotSingularError{authidentity.Label}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyX is like Only, but panics if an error occurs.
|
||||||
|
func (_q *AuthIdentityQuery) OnlyX(ctx context.Context) *AuthIdentity {
|
||||||
|
node, err := _q.Only(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyID is like Only, but returns the only AuthIdentity ID in the query.
|
||||||
|
// Returns a *NotSingularError when more than one AuthIdentity ID is found.
|
||||||
|
// Returns a *NotFoundError when no entities are found.
|
||||||
|
func (_q *AuthIdentityQuery) 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{authidentity.Label}
|
||||||
|
default:
|
||||||
|
err = &NotSingularError{authidentity.Label}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||||
|
func (_q *AuthIdentityQuery) 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 AuthIdentities.
|
||||||
|
func (_q *AuthIdentityQuery) All(ctx context.Context) ([]*AuthIdentity, error) {
|
||||||
|
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||||
|
if err := _q.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
qr := querierAll[[]*AuthIdentity, *AuthIdentityQuery]()
|
||||||
|
return withInterceptors[[]*AuthIdentity](ctx, _q, qr, _q.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllX is like All, but panics if an error occurs.
|
||||||
|
func (_q *AuthIdentityQuery) AllX(ctx context.Context) []*AuthIdentity {
|
||||||
|
nodes, err := _q.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return nodes
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDs executes the query and returns a list of AuthIdentity IDs.
|
||||||
|
func (_q *AuthIdentityQuery) 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(authidentity.FieldID).Scan(ctx, &ids); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ids, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDsX is like IDs, but panics if an error occurs.
|
||||||
|
func (_q *AuthIdentityQuery) 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 *AuthIdentityQuery) 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[*AuthIdentityQuery](), _q.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountX is like Count, but panics if an error occurs.
|
||||||
|
func (_q *AuthIdentityQuery) 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 *AuthIdentityQuery) 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 *AuthIdentityQuery) ExistX(ctx context.Context) bool {
|
||||||
|
exist, err := _q.Exist(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return exist
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone returns a duplicate of the AuthIdentityQuery 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 *AuthIdentityQuery) Clone() *AuthIdentityQuery {
|
||||||
|
if _q == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &AuthIdentityQuery{
|
||||||
|
config: _q.config,
|
||||||
|
ctx: _q.ctx.Clone(),
|
||||||
|
order: append([]authidentity.OrderOption{}, _q.order...),
|
||||||
|
inters: append([]Interceptor{}, _q.inters...),
|
||||||
|
predicates: append([]predicate.AuthIdentity{}, _q.predicates...),
|
||||||
|
withUser: _q.withUser.Clone(),
|
||||||
|
withChannels: _q.withChannels.Clone(),
|
||||||
|
withAdoptionDecisions: _q.withAdoptionDecisions.Clone(),
|
||||||
|
// clone intermediate query.
|
||||||
|
sql: _q.sql.Clone(),
|
||||||
|
path: _q.path,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithUser tells the query-builder to eager-load the nodes that are connected to
|
||||||
|
// the "user" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (_q *AuthIdentityQuery) WithUser(opts ...func(*UserQuery)) *AuthIdentityQuery {
|
||||||
|
query := (&UserClient{config: _q.config}).Query()
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
_q.withUser = query
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithChannels tells the query-builder to eager-load the nodes that are connected to
|
||||||
|
// the "channels" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (_q *AuthIdentityQuery) WithChannels(opts ...func(*AuthIdentityChannelQuery)) *AuthIdentityQuery {
|
||||||
|
query := (&AuthIdentityChannelClient{config: _q.config}).Query()
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
_q.withChannels = query
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithAdoptionDecisions tells the query-builder to eager-load the nodes that are connected to
|
||||||
|
// the "adoption_decisions" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (_q *AuthIdentityQuery) WithAdoptionDecisions(opts ...func(*IdentityAdoptionDecisionQuery)) *AuthIdentityQuery {
|
||||||
|
query := (&IdentityAdoptionDecisionClient{config: _q.config}).Query()
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
_q.withAdoptionDecisions = query
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// Count int `json:"count,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.AuthIdentity.Query().
|
||||||
|
// GroupBy(authidentity.FieldCreatedAt).
|
||||||
|
// Aggregate(ent.Count()).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (_q *AuthIdentityQuery) GroupBy(field string, fields ...string) *AuthIdentityGroupBy {
|
||||||
|
_q.ctx.Fields = append([]string{field}, fields...)
|
||||||
|
grbuild := &AuthIdentityGroupBy{build: _q}
|
||||||
|
grbuild.flds = &_q.ctx.Fields
|
||||||
|
grbuild.label = authidentity.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 {
|
||||||
|
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.AuthIdentity.Query().
|
||||||
|
// Select(authidentity.FieldCreatedAt).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (_q *AuthIdentityQuery) Select(fields ...string) *AuthIdentitySelect {
|
||||||
|
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||||
|
sbuild := &AuthIdentitySelect{AuthIdentityQuery: _q}
|
||||||
|
sbuild.label = authidentity.Label
|
||||||
|
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||||
|
return sbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate returns a AuthIdentitySelect configured with the given aggregations.
|
||||||
|
func (_q *AuthIdentityQuery) Aggregate(fns ...AggregateFunc) *AuthIdentitySelect {
|
||||||
|
return _q.Select().Aggregate(fns...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *AuthIdentityQuery) 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 !authidentity.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 *AuthIdentityQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*AuthIdentity, error) {
|
||||||
|
var (
|
||||||
|
nodes = []*AuthIdentity{}
|
||||||
|
_spec = _q.querySpec()
|
||||||
|
loadedTypes = [3]bool{
|
||||||
|
_q.withUser != nil,
|
||||||
|
_q.withChannels != nil,
|
||||||
|
_q.withAdoptionDecisions != nil,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||||
|
return (*AuthIdentity).scanValues(nil, columns)
|
||||||
|
}
|
||||||
|
_spec.Assign = func(columns []string, values []any) error {
|
||||||
|
node := &AuthIdentity{config: _q.config}
|
||||||
|
nodes = append(nodes, node)
|
||||||
|
node.Edges.loadedTypes = loadedTypes
|
||||||
|
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
|
||||||
|
}
|
||||||
|
if query := _q.withUser; query != nil {
|
||||||
|
if err := _q.loadUser(ctx, query, nodes, nil,
|
||||||
|
func(n *AuthIdentity, e *User) { n.Edges.User = e }); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if query := _q.withChannels; query != nil {
|
||||||
|
if err := _q.loadChannels(ctx, query, nodes,
|
||||||
|
func(n *AuthIdentity) { n.Edges.Channels = []*AuthIdentityChannel{} },
|
||||||
|
func(n *AuthIdentity, e *AuthIdentityChannel) { n.Edges.Channels = append(n.Edges.Channels, e) }); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if query := _q.withAdoptionDecisions; query != nil {
|
||||||
|
if err := _q.loadAdoptionDecisions(ctx, query, nodes,
|
||||||
|
func(n *AuthIdentity) { n.Edges.AdoptionDecisions = []*IdentityAdoptionDecision{} },
|
||||||
|
func(n *AuthIdentity, e *IdentityAdoptionDecision) {
|
||||||
|
n.Edges.AdoptionDecisions = append(n.Edges.AdoptionDecisions, e)
|
||||||
|
}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *AuthIdentityQuery) loadUser(ctx context.Context, query *UserQuery, nodes []*AuthIdentity, init func(*AuthIdentity), assign func(*AuthIdentity, *User)) error {
|
||||||
|
ids := make([]int64, 0, len(nodes))
|
||||||
|
nodeids := make(map[int64][]*AuthIdentity)
|
||||||
|
for i := range nodes {
|
||||||
|
fk := nodes[i].UserID
|
||||||
|
if _, ok := nodeids[fk]; !ok {
|
||||||
|
ids = append(ids, fk)
|
||||||
|
}
|
||||||
|
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
query.Where(user.IDIn(ids...))
|
||||||
|
neighbors, err := query.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, n := range neighbors {
|
||||||
|
nodes, ok := nodeids[n.ID]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(`unexpected foreign-key "user_id" returned %v`, n.ID)
|
||||||
|
}
|
||||||
|
for i := range nodes {
|
||||||
|
assign(nodes[i], n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (_q *AuthIdentityQuery) loadChannels(ctx context.Context, query *AuthIdentityChannelQuery, nodes []*AuthIdentity, init func(*AuthIdentity), assign func(*AuthIdentity, *AuthIdentityChannel)) error {
|
||||||
|
fks := make([]driver.Value, 0, len(nodes))
|
||||||
|
nodeids := make(map[int64]*AuthIdentity)
|
||||||
|
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(authidentitychannel.FieldIdentityID)
|
||||||
|
}
|
||||||
|
query.Where(predicate.AuthIdentityChannel(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.InValues(s.C(authidentity.ChannelsColumn), fks...))
|
||||||
|
}))
|
||||||
|
neighbors, err := query.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, n := range neighbors {
|
||||||
|
fk := n.IdentityID
|
||||||
|
node, ok := nodeids[fk]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(`unexpected referenced foreign-key "identity_id" returned %v for node %v`, fk, n.ID)
|
||||||
|
}
|
||||||
|
assign(node, n)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (_q *AuthIdentityQuery) loadAdoptionDecisions(ctx context.Context, query *IdentityAdoptionDecisionQuery, nodes []*AuthIdentity, init func(*AuthIdentity), assign func(*AuthIdentity, *IdentityAdoptionDecision)) error {
|
||||||
|
fks := make([]driver.Value, 0, len(nodes))
|
||||||
|
nodeids := make(map[int64]*AuthIdentity)
|
||||||
|
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(identityadoptiondecision.FieldIdentityID)
|
||||||
|
}
|
||||||
|
query.Where(predicate.IdentityAdoptionDecision(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.InValues(s.C(authidentity.AdoptionDecisionsColumn), fks...))
|
||||||
|
}))
|
||||||
|
neighbors, err := query.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, n := range neighbors {
|
||||||
|
fk := n.IdentityID
|
||||||
|
if fk == nil {
|
||||||
|
return fmt.Errorf(`foreign-key "identity_id" is nil for node %v`, n.ID)
|
||||||
|
}
|
||||||
|
node, ok := nodeids[*fk]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(`unexpected referenced foreign-key "identity_id" returned %v for node %v`, *fk, n.ID)
|
||||||
|
}
|
||||||
|
assign(node, n)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *AuthIdentityQuery) 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 *AuthIdentityQuery) querySpec() *sqlgraph.QuerySpec {
|
||||||
|
_spec := sqlgraph.NewQuerySpec(authidentity.Table, authidentity.Columns, sqlgraph.NewFieldSpec(authidentity.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, authidentity.FieldID)
|
||||||
|
for i := range fields {
|
||||||
|
if fields[i] != authidentity.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _q.withUser != nil {
|
||||||
|
_spec.Node.AddColumnOnce(authidentity.FieldUserID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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 *AuthIdentityQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||||
|
builder := sql.Dialect(_q.driver.Dialect())
|
||||||
|
t1 := builder.Table(authidentity.Table)
|
||||||
|
columns := _q.ctx.Fields
|
||||||
|
if len(columns) == 0 {
|
||||||
|
columns = authidentity.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 *AuthIdentityQuery) ForUpdate(opts ...sql.LockOption) *AuthIdentityQuery {
|
||||||
|
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 *AuthIdentityQuery) ForShare(opts ...sql.LockOption) *AuthIdentityQuery {
|
||||||
|
if _q.driver.Dialect() == dialect.Postgres {
|
||||||
|
_q.Unique(false)
|
||||||
|
}
|
||||||
|
_q.modifiers = append(_q.modifiers, func(s *sql.Selector) {
|
||||||
|
s.ForShare(opts...)
|
||||||
|
})
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthIdentityGroupBy is the group-by builder for AuthIdentity entities.
|
||||||
|
type AuthIdentityGroupBy struct {
|
||||||
|
selector
|
||||||
|
build *AuthIdentityQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the group-by query.
|
||||||
|
func (_g *AuthIdentityGroupBy) Aggregate(fns ...AggregateFunc) *AuthIdentityGroupBy {
|
||||||
|
_g.fns = append(_g.fns, fns...)
|
||||||
|
return _g
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (_g *AuthIdentityGroupBy) 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[*AuthIdentityQuery, *AuthIdentityGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_g *AuthIdentityGroupBy) sqlScan(ctx context.Context, root *AuthIdentityQuery, 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthIdentitySelect is the builder for selecting fields of AuthIdentity entities.
|
||||||
|
type AuthIdentitySelect struct {
|
||||||
|
*AuthIdentityQuery
|
||||||
|
selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the selector query.
|
||||||
|
func (_s *AuthIdentitySelect) Aggregate(fns ...AggregateFunc) *AuthIdentitySelect {
|
||||||
|
_s.fns = append(_s.fns, fns...)
|
||||||
|
return _s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (_s *AuthIdentitySelect) 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[*AuthIdentityQuery, *AuthIdentitySelect](ctx, _s.AuthIdentityQuery, _s, _s.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_s *AuthIdentitySelect) sqlScan(ctx context.Context, root *AuthIdentityQuery, 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)
|
||||||
|
}
|
||||||
@@ -0,0 +1,923 @@
|
|||||||
|
// 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/authidentity"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/authidentitychannel"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/identityadoptiondecision"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/predicate"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/user"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AuthIdentityUpdate is the builder for updating AuthIdentity entities.
|
||||||
|
type AuthIdentityUpdate struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *AuthIdentityMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the AuthIdentityUpdate builder.
|
||||||
|
func (_u *AuthIdentityUpdate) Where(ps ...predicate.AuthIdentity) *AuthIdentityUpdate {
|
||||||
|
_u.mutation.Where(ps...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (_u *AuthIdentityUpdate) SetUpdatedAt(v time.Time) *AuthIdentityUpdate {
|
||||||
|
_u.mutation.SetUpdatedAt(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUserID sets the "user_id" field.
|
||||||
|
func (_u *AuthIdentityUpdate) SetUserID(v int64) *AuthIdentityUpdate {
|
||||||
|
_u.mutation.SetUserID(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
||||||
|
func (_u *AuthIdentityUpdate) SetNillableUserID(v *int64) *AuthIdentityUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetUserID(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProviderType sets the "provider_type" field.
|
||||||
|
func (_u *AuthIdentityUpdate) SetProviderType(v string) *AuthIdentityUpdate {
|
||||||
|
_u.mutation.SetProviderType(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableProviderType sets the "provider_type" field if the given value is not nil.
|
||||||
|
func (_u *AuthIdentityUpdate) SetNillableProviderType(v *string) *AuthIdentityUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetProviderType(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProviderKey sets the "provider_key" field.
|
||||||
|
func (_u *AuthIdentityUpdate) SetProviderKey(v string) *AuthIdentityUpdate {
|
||||||
|
_u.mutation.SetProviderKey(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableProviderKey sets the "provider_key" field if the given value is not nil.
|
||||||
|
func (_u *AuthIdentityUpdate) SetNillableProviderKey(v *string) *AuthIdentityUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetProviderKey(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProviderSubject sets the "provider_subject" field.
|
||||||
|
func (_u *AuthIdentityUpdate) SetProviderSubject(v string) *AuthIdentityUpdate {
|
||||||
|
_u.mutation.SetProviderSubject(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableProviderSubject sets the "provider_subject" field if the given value is not nil.
|
||||||
|
func (_u *AuthIdentityUpdate) SetNillableProviderSubject(v *string) *AuthIdentityUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetProviderSubject(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetVerifiedAt sets the "verified_at" field.
|
||||||
|
func (_u *AuthIdentityUpdate) SetVerifiedAt(v time.Time) *AuthIdentityUpdate {
|
||||||
|
_u.mutation.SetVerifiedAt(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableVerifiedAt sets the "verified_at" field if the given value is not nil.
|
||||||
|
func (_u *AuthIdentityUpdate) SetNillableVerifiedAt(v *time.Time) *AuthIdentityUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetVerifiedAt(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearVerifiedAt clears the value of the "verified_at" field.
|
||||||
|
func (_u *AuthIdentityUpdate) ClearVerifiedAt() *AuthIdentityUpdate {
|
||||||
|
_u.mutation.ClearVerifiedAt()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIssuer sets the "issuer" field.
|
||||||
|
func (_u *AuthIdentityUpdate) SetIssuer(v string) *AuthIdentityUpdate {
|
||||||
|
_u.mutation.SetIssuer(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableIssuer sets the "issuer" field if the given value is not nil.
|
||||||
|
func (_u *AuthIdentityUpdate) SetNillableIssuer(v *string) *AuthIdentityUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetIssuer(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearIssuer clears the value of the "issuer" field.
|
||||||
|
func (_u *AuthIdentityUpdate) ClearIssuer() *AuthIdentityUpdate {
|
||||||
|
_u.mutation.ClearIssuer()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMetadata sets the "metadata" field.
|
||||||
|
func (_u *AuthIdentityUpdate) SetMetadata(v map[string]interface{}) *AuthIdentityUpdate {
|
||||||
|
_u.mutation.SetMetadata(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUser sets the "user" edge to the User entity.
|
||||||
|
func (_u *AuthIdentityUpdate) SetUser(v *User) *AuthIdentityUpdate {
|
||||||
|
return _u.SetUserID(v.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddChannelIDs adds the "channels" edge to the AuthIdentityChannel entity by IDs.
|
||||||
|
func (_u *AuthIdentityUpdate) AddChannelIDs(ids ...int64) *AuthIdentityUpdate {
|
||||||
|
_u.mutation.AddChannelIDs(ids...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddChannels adds the "channels" edges to the AuthIdentityChannel entity.
|
||||||
|
func (_u *AuthIdentityUpdate) AddChannels(v ...*AuthIdentityChannel) *AuthIdentityUpdate {
|
||||||
|
ids := make([]int64, len(v))
|
||||||
|
for i := range v {
|
||||||
|
ids[i] = v[i].ID
|
||||||
|
}
|
||||||
|
return _u.AddChannelIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddAdoptionDecisionIDs adds the "adoption_decisions" edge to the IdentityAdoptionDecision entity by IDs.
|
||||||
|
func (_u *AuthIdentityUpdate) AddAdoptionDecisionIDs(ids ...int64) *AuthIdentityUpdate {
|
||||||
|
_u.mutation.AddAdoptionDecisionIDs(ids...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddAdoptionDecisions adds the "adoption_decisions" edges to the IdentityAdoptionDecision entity.
|
||||||
|
func (_u *AuthIdentityUpdate) AddAdoptionDecisions(v ...*IdentityAdoptionDecision) *AuthIdentityUpdate {
|
||||||
|
ids := make([]int64, len(v))
|
||||||
|
for i := range v {
|
||||||
|
ids[i] = v[i].ID
|
||||||
|
}
|
||||||
|
return _u.AddAdoptionDecisionIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the AuthIdentityMutation object of the builder.
|
||||||
|
func (_u *AuthIdentityUpdate) Mutation() *AuthIdentityMutation {
|
||||||
|
return _u.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearUser clears the "user" edge to the User entity.
|
||||||
|
func (_u *AuthIdentityUpdate) ClearUser() *AuthIdentityUpdate {
|
||||||
|
_u.mutation.ClearUser()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearChannels clears all "channels" edges to the AuthIdentityChannel entity.
|
||||||
|
func (_u *AuthIdentityUpdate) ClearChannels() *AuthIdentityUpdate {
|
||||||
|
_u.mutation.ClearChannels()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveChannelIDs removes the "channels" edge to AuthIdentityChannel entities by IDs.
|
||||||
|
func (_u *AuthIdentityUpdate) RemoveChannelIDs(ids ...int64) *AuthIdentityUpdate {
|
||||||
|
_u.mutation.RemoveChannelIDs(ids...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveChannels removes "channels" edges to AuthIdentityChannel entities.
|
||||||
|
func (_u *AuthIdentityUpdate) RemoveChannels(v ...*AuthIdentityChannel) *AuthIdentityUpdate {
|
||||||
|
ids := make([]int64, len(v))
|
||||||
|
for i := range v {
|
||||||
|
ids[i] = v[i].ID
|
||||||
|
}
|
||||||
|
return _u.RemoveChannelIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearAdoptionDecisions clears all "adoption_decisions" edges to the IdentityAdoptionDecision entity.
|
||||||
|
func (_u *AuthIdentityUpdate) ClearAdoptionDecisions() *AuthIdentityUpdate {
|
||||||
|
_u.mutation.ClearAdoptionDecisions()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveAdoptionDecisionIDs removes the "adoption_decisions" edge to IdentityAdoptionDecision entities by IDs.
|
||||||
|
func (_u *AuthIdentityUpdate) RemoveAdoptionDecisionIDs(ids ...int64) *AuthIdentityUpdate {
|
||||||
|
_u.mutation.RemoveAdoptionDecisionIDs(ids...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveAdoptionDecisions removes "adoption_decisions" edges to IdentityAdoptionDecision entities.
|
||||||
|
func (_u *AuthIdentityUpdate) RemoveAdoptionDecisions(v ...*IdentityAdoptionDecision) *AuthIdentityUpdate {
|
||||||
|
ids := make([]int64, len(v))
|
||||||
|
for i := range v {
|
||||||
|
ids[i] = v[i].ID
|
||||||
|
}
|
||||||
|
return _u.RemoveAdoptionDecisionIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||||
|
func (_u *AuthIdentityUpdate) 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 *AuthIdentityUpdate) SaveX(ctx context.Context) int {
|
||||||
|
affected, err := _u.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return affected
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (_u *AuthIdentityUpdate) Exec(ctx context.Context) error {
|
||||||
|
_, err := _u.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_u *AuthIdentityUpdate) 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 *AuthIdentityUpdate) defaults() {
|
||||||
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
||||||
|
v := authidentity.UpdateDefaultUpdatedAt()
|
||||||
|
_u.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (_u *AuthIdentityUpdate) check() error {
|
||||||
|
if v, ok := _u.mutation.ProviderType(); ok {
|
||||||
|
if err := authidentity.ProviderTypeValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "provider_type", err: fmt.Errorf(`ent: validator failed for field "AuthIdentity.provider_type": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := _u.mutation.ProviderKey(); ok {
|
||||||
|
if err := authidentity.ProviderKeyValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "provider_key", err: fmt.Errorf(`ent: validator failed for field "AuthIdentity.provider_key": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := _u.mutation.ProviderSubject(); ok {
|
||||||
|
if err := authidentity.ProviderSubjectValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "provider_subject", err: fmt.Errorf(`ent: validator failed for field "AuthIdentity.provider_subject": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
|
||||||
|
return errors.New(`ent: clearing a required unique edge "AuthIdentity.user"`)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_u *AuthIdentityUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||||
|
if err := _u.check(); err != nil {
|
||||||
|
return _node, err
|
||||||
|
}
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(authidentity.Table, authidentity.Columns, sqlgraph.NewFieldSpec(authidentity.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.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(authidentity.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.ProviderType(); ok {
|
||||||
|
_spec.SetField(authidentity.FieldProviderType, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.ProviderKey(); ok {
|
||||||
|
_spec.SetField(authidentity.FieldProviderKey, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.ProviderSubject(); ok {
|
||||||
|
_spec.SetField(authidentity.FieldProviderSubject, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.VerifiedAt(); ok {
|
||||||
|
_spec.SetField(authidentity.FieldVerifiedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.VerifiedAtCleared() {
|
||||||
|
_spec.ClearField(authidentity.FieldVerifiedAt, field.TypeTime)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Issuer(); ok {
|
||||||
|
_spec.SetField(authidentity.FieldIssuer, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.IssuerCleared() {
|
||||||
|
_spec.ClearField(authidentity.FieldIssuer, field.TypeString)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Metadata(); ok {
|
||||||
|
_spec.SetField(authidentity.FieldMetadata, field.TypeJSON, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.UserCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: authidentity.UserTable,
|
||||||
|
Columns: []string{authidentity.UserColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: authidentity.UserTable,
|
||||||
|
Columns: []string{authidentity.UserColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if _u.mutation.ChannelsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: authidentity.ChannelsTable,
|
||||||
|
Columns: []string{authidentity.ChannelsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(authidentitychannel.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := _u.mutation.RemovedChannelsIDs(); len(nodes) > 0 && !_u.mutation.ChannelsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: authidentity.ChannelsTable,
|
||||||
|
Columns: []string{authidentity.ChannelsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(authidentitychannel.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.ChannelsIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: authidentity.ChannelsTable,
|
||||||
|
Columns: []string{authidentity.ChannelsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(authidentitychannel.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if _u.mutation.AdoptionDecisionsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: authidentity.AdoptionDecisionsTable,
|
||||||
|
Columns: []string{authidentity.AdoptionDecisionsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(identityadoptiondecision.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := _u.mutation.RemovedAdoptionDecisionsIDs(); len(nodes) > 0 && !_u.mutation.AdoptionDecisionsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: authidentity.AdoptionDecisionsTable,
|
||||||
|
Columns: []string{authidentity.AdoptionDecisionsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(identityadoptiondecision.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.AdoptionDecisionsIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: authidentity.AdoptionDecisionsTable,
|
||||||
|
Columns: []string{authidentity.AdoptionDecisionsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(identityadoptiondecision.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{authidentity.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
_u.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthIdentityUpdateOne is the builder for updating a single AuthIdentity entity.
|
||||||
|
type AuthIdentityUpdateOne struct {
|
||||||
|
config
|
||||||
|
fields []string
|
||||||
|
hooks []Hook
|
||||||
|
mutation *AuthIdentityMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (_u *AuthIdentityUpdateOne) SetUpdatedAt(v time.Time) *AuthIdentityUpdateOne {
|
||||||
|
_u.mutation.SetUpdatedAt(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUserID sets the "user_id" field.
|
||||||
|
func (_u *AuthIdentityUpdateOne) SetUserID(v int64) *AuthIdentityUpdateOne {
|
||||||
|
_u.mutation.SetUserID(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
||||||
|
func (_u *AuthIdentityUpdateOne) SetNillableUserID(v *int64) *AuthIdentityUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetUserID(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProviderType sets the "provider_type" field.
|
||||||
|
func (_u *AuthIdentityUpdateOne) SetProviderType(v string) *AuthIdentityUpdateOne {
|
||||||
|
_u.mutation.SetProviderType(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableProviderType sets the "provider_type" field if the given value is not nil.
|
||||||
|
func (_u *AuthIdentityUpdateOne) SetNillableProviderType(v *string) *AuthIdentityUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetProviderType(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProviderKey sets the "provider_key" field.
|
||||||
|
func (_u *AuthIdentityUpdateOne) SetProviderKey(v string) *AuthIdentityUpdateOne {
|
||||||
|
_u.mutation.SetProviderKey(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableProviderKey sets the "provider_key" field if the given value is not nil.
|
||||||
|
func (_u *AuthIdentityUpdateOne) SetNillableProviderKey(v *string) *AuthIdentityUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetProviderKey(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProviderSubject sets the "provider_subject" field.
|
||||||
|
func (_u *AuthIdentityUpdateOne) SetProviderSubject(v string) *AuthIdentityUpdateOne {
|
||||||
|
_u.mutation.SetProviderSubject(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableProviderSubject sets the "provider_subject" field if the given value is not nil.
|
||||||
|
func (_u *AuthIdentityUpdateOne) SetNillableProviderSubject(v *string) *AuthIdentityUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetProviderSubject(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetVerifiedAt sets the "verified_at" field.
|
||||||
|
func (_u *AuthIdentityUpdateOne) SetVerifiedAt(v time.Time) *AuthIdentityUpdateOne {
|
||||||
|
_u.mutation.SetVerifiedAt(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableVerifiedAt sets the "verified_at" field if the given value is not nil.
|
||||||
|
func (_u *AuthIdentityUpdateOne) SetNillableVerifiedAt(v *time.Time) *AuthIdentityUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetVerifiedAt(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearVerifiedAt clears the value of the "verified_at" field.
|
||||||
|
func (_u *AuthIdentityUpdateOne) ClearVerifiedAt() *AuthIdentityUpdateOne {
|
||||||
|
_u.mutation.ClearVerifiedAt()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIssuer sets the "issuer" field.
|
||||||
|
func (_u *AuthIdentityUpdateOne) SetIssuer(v string) *AuthIdentityUpdateOne {
|
||||||
|
_u.mutation.SetIssuer(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableIssuer sets the "issuer" field if the given value is not nil.
|
||||||
|
func (_u *AuthIdentityUpdateOne) SetNillableIssuer(v *string) *AuthIdentityUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetIssuer(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearIssuer clears the value of the "issuer" field.
|
||||||
|
func (_u *AuthIdentityUpdateOne) ClearIssuer() *AuthIdentityUpdateOne {
|
||||||
|
_u.mutation.ClearIssuer()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMetadata sets the "metadata" field.
|
||||||
|
func (_u *AuthIdentityUpdateOne) SetMetadata(v map[string]interface{}) *AuthIdentityUpdateOne {
|
||||||
|
_u.mutation.SetMetadata(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUser sets the "user" edge to the User entity.
|
||||||
|
func (_u *AuthIdentityUpdateOne) SetUser(v *User) *AuthIdentityUpdateOne {
|
||||||
|
return _u.SetUserID(v.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddChannelIDs adds the "channels" edge to the AuthIdentityChannel entity by IDs.
|
||||||
|
func (_u *AuthIdentityUpdateOne) AddChannelIDs(ids ...int64) *AuthIdentityUpdateOne {
|
||||||
|
_u.mutation.AddChannelIDs(ids...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddChannels adds the "channels" edges to the AuthIdentityChannel entity.
|
||||||
|
func (_u *AuthIdentityUpdateOne) AddChannels(v ...*AuthIdentityChannel) *AuthIdentityUpdateOne {
|
||||||
|
ids := make([]int64, len(v))
|
||||||
|
for i := range v {
|
||||||
|
ids[i] = v[i].ID
|
||||||
|
}
|
||||||
|
return _u.AddChannelIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddAdoptionDecisionIDs adds the "adoption_decisions" edge to the IdentityAdoptionDecision entity by IDs.
|
||||||
|
func (_u *AuthIdentityUpdateOne) AddAdoptionDecisionIDs(ids ...int64) *AuthIdentityUpdateOne {
|
||||||
|
_u.mutation.AddAdoptionDecisionIDs(ids...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddAdoptionDecisions adds the "adoption_decisions" edges to the IdentityAdoptionDecision entity.
|
||||||
|
func (_u *AuthIdentityUpdateOne) AddAdoptionDecisions(v ...*IdentityAdoptionDecision) *AuthIdentityUpdateOne {
|
||||||
|
ids := make([]int64, len(v))
|
||||||
|
for i := range v {
|
||||||
|
ids[i] = v[i].ID
|
||||||
|
}
|
||||||
|
return _u.AddAdoptionDecisionIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the AuthIdentityMutation object of the builder.
|
||||||
|
func (_u *AuthIdentityUpdateOne) Mutation() *AuthIdentityMutation {
|
||||||
|
return _u.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearUser clears the "user" edge to the User entity.
|
||||||
|
func (_u *AuthIdentityUpdateOne) ClearUser() *AuthIdentityUpdateOne {
|
||||||
|
_u.mutation.ClearUser()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearChannels clears all "channels" edges to the AuthIdentityChannel entity.
|
||||||
|
func (_u *AuthIdentityUpdateOne) ClearChannels() *AuthIdentityUpdateOne {
|
||||||
|
_u.mutation.ClearChannels()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveChannelIDs removes the "channels" edge to AuthIdentityChannel entities by IDs.
|
||||||
|
func (_u *AuthIdentityUpdateOne) RemoveChannelIDs(ids ...int64) *AuthIdentityUpdateOne {
|
||||||
|
_u.mutation.RemoveChannelIDs(ids...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveChannels removes "channels" edges to AuthIdentityChannel entities.
|
||||||
|
func (_u *AuthIdentityUpdateOne) RemoveChannels(v ...*AuthIdentityChannel) *AuthIdentityUpdateOne {
|
||||||
|
ids := make([]int64, len(v))
|
||||||
|
for i := range v {
|
||||||
|
ids[i] = v[i].ID
|
||||||
|
}
|
||||||
|
return _u.RemoveChannelIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearAdoptionDecisions clears all "adoption_decisions" edges to the IdentityAdoptionDecision entity.
|
||||||
|
func (_u *AuthIdentityUpdateOne) ClearAdoptionDecisions() *AuthIdentityUpdateOne {
|
||||||
|
_u.mutation.ClearAdoptionDecisions()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveAdoptionDecisionIDs removes the "adoption_decisions" edge to IdentityAdoptionDecision entities by IDs.
|
||||||
|
func (_u *AuthIdentityUpdateOne) RemoveAdoptionDecisionIDs(ids ...int64) *AuthIdentityUpdateOne {
|
||||||
|
_u.mutation.RemoveAdoptionDecisionIDs(ids...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveAdoptionDecisions removes "adoption_decisions" edges to IdentityAdoptionDecision entities.
|
||||||
|
func (_u *AuthIdentityUpdateOne) RemoveAdoptionDecisions(v ...*IdentityAdoptionDecision) *AuthIdentityUpdateOne {
|
||||||
|
ids := make([]int64, len(v))
|
||||||
|
for i := range v {
|
||||||
|
ids[i] = v[i].ID
|
||||||
|
}
|
||||||
|
return _u.RemoveAdoptionDecisionIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the AuthIdentityUpdate builder.
|
||||||
|
func (_u *AuthIdentityUpdateOne) Where(ps ...predicate.AuthIdentity) *AuthIdentityUpdateOne {
|
||||||
|
_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 *AuthIdentityUpdateOne) Select(field string, fields ...string) *AuthIdentityUpdateOne {
|
||||||
|
_u.fields = append([]string{field}, fields...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the updated AuthIdentity entity.
|
||||||
|
func (_u *AuthIdentityUpdateOne) Save(ctx context.Context) (*AuthIdentity, error) {
|
||||||
|
_u.defaults()
|
||||||
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (_u *AuthIdentityUpdateOne) SaveX(ctx context.Context) *AuthIdentity {
|
||||||
|
node, err := _u.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query on the entity.
|
||||||
|
func (_u *AuthIdentityUpdateOne) Exec(ctx context.Context) error {
|
||||||
|
_, err := _u.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_u *AuthIdentityUpdateOne) 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 *AuthIdentityUpdateOne) defaults() {
|
||||||
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
||||||
|
v := authidentity.UpdateDefaultUpdatedAt()
|
||||||
|
_u.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (_u *AuthIdentityUpdateOne) check() error {
|
||||||
|
if v, ok := _u.mutation.ProviderType(); ok {
|
||||||
|
if err := authidentity.ProviderTypeValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "provider_type", err: fmt.Errorf(`ent: validator failed for field "AuthIdentity.provider_type": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := _u.mutation.ProviderKey(); ok {
|
||||||
|
if err := authidentity.ProviderKeyValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "provider_key", err: fmt.Errorf(`ent: validator failed for field "AuthIdentity.provider_key": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := _u.mutation.ProviderSubject(); ok {
|
||||||
|
if err := authidentity.ProviderSubjectValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "provider_subject", err: fmt.Errorf(`ent: validator failed for field "AuthIdentity.provider_subject": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
|
||||||
|
return errors.New(`ent: clearing a required unique edge "AuthIdentity.user"`)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_u *AuthIdentityUpdateOne) sqlSave(ctx context.Context) (_node *AuthIdentity, err error) {
|
||||||
|
if err := _u.check(); err != nil {
|
||||||
|
return _node, err
|
||||||
|
}
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(authidentity.Table, authidentity.Columns, sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64))
|
||||||
|
id, ok := _u.mutation.ID()
|
||||||
|
if !ok {
|
||||||
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "AuthIdentity.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, authidentity.FieldID)
|
||||||
|
for _, f := range fields {
|
||||||
|
if !authidentity.ValidColumn(f) {
|
||||||
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
if f != authidentity.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.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(authidentity.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.ProviderType(); ok {
|
||||||
|
_spec.SetField(authidentity.FieldProviderType, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.ProviderKey(); ok {
|
||||||
|
_spec.SetField(authidentity.FieldProviderKey, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.ProviderSubject(); ok {
|
||||||
|
_spec.SetField(authidentity.FieldProviderSubject, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.VerifiedAt(); ok {
|
||||||
|
_spec.SetField(authidentity.FieldVerifiedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.VerifiedAtCleared() {
|
||||||
|
_spec.ClearField(authidentity.FieldVerifiedAt, field.TypeTime)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Issuer(); ok {
|
||||||
|
_spec.SetField(authidentity.FieldIssuer, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.IssuerCleared() {
|
||||||
|
_spec.ClearField(authidentity.FieldIssuer, field.TypeString)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Metadata(); ok {
|
||||||
|
_spec.SetField(authidentity.FieldMetadata, field.TypeJSON, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.UserCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: authidentity.UserTable,
|
||||||
|
Columns: []string{authidentity.UserColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: authidentity.UserTable,
|
||||||
|
Columns: []string{authidentity.UserColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if _u.mutation.ChannelsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: authidentity.ChannelsTable,
|
||||||
|
Columns: []string{authidentity.ChannelsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(authidentitychannel.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := _u.mutation.RemovedChannelsIDs(); len(nodes) > 0 && !_u.mutation.ChannelsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: authidentity.ChannelsTable,
|
||||||
|
Columns: []string{authidentity.ChannelsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(authidentitychannel.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.ChannelsIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: authidentity.ChannelsTable,
|
||||||
|
Columns: []string{authidentity.ChannelsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(authidentitychannel.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if _u.mutation.AdoptionDecisionsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: authidentity.AdoptionDecisionsTable,
|
||||||
|
Columns: []string{authidentity.AdoptionDecisionsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(identityadoptiondecision.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := _u.mutation.RemovedAdoptionDecisionsIDs(); len(nodes) > 0 && !_u.mutation.AdoptionDecisionsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: authidentity.AdoptionDecisionsTable,
|
||||||
|
Columns: []string{authidentity.AdoptionDecisionsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(identityadoptiondecision.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.AdoptionDecisionsIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: authidentity.AdoptionDecisionsTable,
|
||||||
|
Columns: []string{authidentity.AdoptionDecisionsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(identityadoptiondecision.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
_node = &AuthIdentity{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{authidentity.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_u.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,228 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/authidentity"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/authidentitychannel"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AuthIdentityChannel is the model entity for the AuthIdentityChannel schema.
|
||||||
|
type AuthIdentityChannel 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"`
|
||||||
|
// IdentityID holds the value of the "identity_id" field.
|
||||||
|
IdentityID int64 `json:"identity_id,omitempty"`
|
||||||
|
// ProviderType holds the value of the "provider_type" field.
|
||||||
|
ProviderType string `json:"provider_type,omitempty"`
|
||||||
|
// ProviderKey holds the value of the "provider_key" field.
|
||||||
|
ProviderKey string `json:"provider_key,omitempty"`
|
||||||
|
// Channel holds the value of the "channel" field.
|
||||||
|
Channel string `json:"channel,omitempty"`
|
||||||
|
// ChannelAppID holds the value of the "channel_app_id" field.
|
||||||
|
ChannelAppID string `json:"channel_app_id,omitempty"`
|
||||||
|
// ChannelSubject holds the value of the "channel_subject" field.
|
||||||
|
ChannelSubject string `json:"channel_subject,omitempty"`
|
||||||
|
// Metadata holds the value of the "metadata" field.
|
||||||
|
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
||||||
|
// Edges holds the relations/edges for other nodes in the graph.
|
||||||
|
// The values are being populated by the AuthIdentityChannelQuery when eager-loading is set.
|
||||||
|
Edges AuthIdentityChannelEdges `json:"edges"`
|
||||||
|
selectValues sql.SelectValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthIdentityChannelEdges holds the relations/edges for other nodes in the graph.
|
||||||
|
type AuthIdentityChannelEdges struct {
|
||||||
|
// Identity holds the value of the identity edge.
|
||||||
|
Identity *AuthIdentity `json:"identity,omitempty"`
|
||||||
|
// loadedTypes holds the information for reporting if a
|
||||||
|
// type was loaded (or requested) in eager-loading or not.
|
||||||
|
loadedTypes [1]bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// IdentityOrErr returns the Identity value or an error if the edge
|
||||||
|
// was not loaded in eager-loading, or loaded but was not found.
|
||||||
|
func (e AuthIdentityChannelEdges) IdentityOrErr() (*AuthIdentity, error) {
|
||||||
|
if e.Identity != nil {
|
||||||
|
return e.Identity, nil
|
||||||
|
} else if e.loadedTypes[0] {
|
||||||
|
return nil, &NotFoundError{label: authidentity.Label}
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "identity"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// scanValues returns the types for scanning values from sql.Rows.
|
||||||
|
func (*AuthIdentityChannel) scanValues(columns []string) ([]any, error) {
|
||||||
|
values := make([]any, len(columns))
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case authidentitychannel.FieldMetadata:
|
||||||
|
values[i] = new([]byte)
|
||||||
|
case authidentitychannel.FieldID, authidentitychannel.FieldIdentityID:
|
||||||
|
values[i] = new(sql.NullInt64)
|
||||||
|
case authidentitychannel.FieldProviderType, authidentitychannel.FieldProviderKey, authidentitychannel.FieldChannel, authidentitychannel.FieldChannelAppID, authidentitychannel.FieldChannelSubject:
|
||||||
|
values[i] = new(sql.NullString)
|
||||||
|
case authidentitychannel.FieldCreatedAt, authidentitychannel.FieldUpdatedAt:
|
||||||
|
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 AuthIdentityChannel fields.
|
||||||
|
func (_m *AuthIdentityChannel) 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 authidentitychannel.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 authidentitychannel.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 authidentitychannel.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 authidentitychannel.FieldIdentityID:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field identity_id", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.IdentityID = value.Int64
|
||||||
|
}
|
||||||
|
case authidentitychannel.FieldProviderType:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field provider_type", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.ProviderType = value.String
|
||||||
|
}
|
||||||
|
case authidentitychannel.FieldProviderKey:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field provider_key", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.ProviderKey = value.String
|
||||||
|
}
|
||||||
|
case authidentitychannel.FieldChannel:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field channel", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.Channel = value.String
|
||||||
|
}
|
||||||
|
case authidentitychannel.FieldChannelAppID:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field channel_app_id", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.ChannelAppID = value.String
|
||||||
|
}
|
||||||
|
case authidentitychannel.FieldChannelSubject:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field channel_subject", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.ChannelSubject = value.String
|
||||||
|
}
|
||||||
|
case authidentitychannel.FieldMetadata:
|
||||||
|
if value, ok := values[i].(*[]byte); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field metadata", values[i])
|
||||||
|
} else if value != nil && len(*value) > 0 {
|
||||||
|
if err := json.Unmarshal(*value, &_m.Metadata); err != nil {
|
||||||
|
return fmt.Errorf("unmarshal field metadata: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
_m.selectValues.Set(columns[i], values[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value returns the ent.Value that was dynamically selected and assigned to the AuthIdentityChannel.
|
||||||
|
// This includes values selected through modifiers, order, etc.
|
||||||
|
func (_m *AuthIdentityChannel) Value(name string) (ent.Value, error) {
|
||||||
|
return _m.selectValues.Get(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryIdentity queries the "identity" edge of the AuthIdentityChannel entity.
|
||||||
|
func (_m *AuthIdentityChannel) QueryIdentity() *AuthIdentityQuery {
|
||||||
|
return NewAuthIdentityChannelClient(_m.config).QueryIdentity(_m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns a builder for updating this AuthIdentityChannel.
|
||||||
|
// Note that you need to call AuthIdentityChannel.Unwrap() before calling this method if this AuthIdentityChannel
|
||||||
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||||
|
func (_m *AuthIdentityChannel) Update() *AuthIdentityChannelUpdateOne {
|
||||||
|
return NewAuthIdentityChannelClient(_m.config).UpdateOne(_m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap unwraps the AuthIdentityChannel 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 *AuthIdentityChannel) Unwrap() *AuthIdentityChannel {
|
||||||
|
_tx, ok := _m.config.driver.(*txDriver)
|
||||||
|
if !ok {
|
||||||
|
panic("ent: AuthIdentityChannel is not a transactional entity")
|
||||||
|
}
|
||||||
|
_m.config.driver = _tx.drv
|
||||||
|
return _m
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements the fmt.Stringer.
|
||||||
|
func (_m *AuthIdentityChannel) String() string {
|
||||||
|
var builder strings.Builder
|
||||||
|
builder.WriteString("AuthIdentityChannel(")
|
||||||
|
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(", ")
|
||||||
|
builder.WriteString("identity_id=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.IdentityID))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("provider_type=")
|
||||||
|
builder.WriteString(_m.ProviderType)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("provider_key=")
|
||||||
|
builder.WriteString(_m.ProviderKey)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("channel=")
|
||||||
|
builder.WriteString(_m.Channel)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("channel_app_id=")
|
||||||
|
builder.WriteString(_m.ChannelAppID)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("channel_subject=")
|
||||||
|
builder.WriteString(_m.ChannelSubject)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("metadata=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.Metadata))
|
||||||
|
builder.WriteByte(')')
|
||||||
|
return builder.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthIdentityChannels is a parsable slice of AuthIdentityChannel.
|
||||||
|
type AuthIdentityChannels []*AuthIdentityChannel
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package authidentitychannel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Label holds the string label denoting the authidentitychannel type in the database.
|
||||||
|
Label = "auth_identity_channel"
|
||||||
|
// FieldID holds the string denoting the id field in the database.
|
||||||
|
FieldID = "id"
|
||||||
|
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||||
|
FieldCreatedAt = "created_at"
|
||||||
|
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||||
|
FieldUpdatedAt = "updated_at"
|
||||||
|
// FieldIdentityID holds the string denoting the identity_id field in the database.
|
||||||
|
FieldIdentityID = "identity_id"
|
||||||
|
// FieldProviderType holds the string denoting the provider_type field in the database.
|
||||||
|
FieldProviderType = "provider_type"
|
||||||
|
// FieldProviderKey holds the string denoting the provider_key field in the database.
|
||||||
|
FieldProviderKey = "provider_key"
|
||||||
|
// FieldChannel holds the string denoting the channel field in the database.
|
||||||
|
FieldChannel = "channel"
|
||||||
|
// FieldChannelAppID holds the string denoting the channel_app_id field in the database.
|
||||||
|
FieldChannelAppID = "channel_app_id"
|
||||||
|
// FieldChannelSubject holds the string denoting the channel_subject field in the database.
|
||||||
|
FieldChannelSubject = "channel_subject"
|
||||||
|
// FieldMetadata holds the string denoting the metadata field in the database.
|
||||||
|
FieldMetadata = "metadata"
|
||||||
|
// EdgeIdentity holds the string denoting the identity edge name in mutations.
|
||||||
|
EdgeIdentity = "identity"
|
||||||
|
// Table holds the table name of the authidentitychannel in the database.
|
||||||
|
Table = "auth_identity_channels"
|
||||||
|
// IdentityTable is the table that holds the identity relation/edge.
|
||||||
|
IdentityTable = "auth_identity_channels"
|
||||||
|
// IdentityInverseTable is the table name for the AuthIdentity entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "authidentity" package.
|
||||||
|
IdentityInverseTable = "auth_identities"
|
||||||
|
// IdentityColumn is the table column denoting the identity relation/edge.
|
||||||
|
IdentityColumn = "identity_id"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Columns holds all SQL columns for authidentitychannel fields.
|
||||||
|
var Columns = []string{
|
||||||
|
FieldID,
|
||||||
|
FieldCreatedAt,
|
||||||
|
FieldUpdatedAt,
|
||||||
|
FieldIdentityID,
|
||||||
|
FieldProviderType,
|
||||||
|
FieldProviderKey,
|
||||||
|
FieldChannel,
|
||||||
|
FieldChannelAppID,
|
||||||
|
FieldChannelSubject,
|
||||||
|
FieldMetadata,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||||
|
func ValidColumn(column string) bool {
|
||||||
|
for i := range Columns {
|
||||||
|
if column == Columns[i] {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||||
|
DefaultCreatedAt func() time.Time
|
||||||
|
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||||
|
DefaultUpdatedAt func() time.Time
|
||||||
|
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||||
|
UpdateDefaultUpdatedAt func() time.Time
|
||||||
|
// ProviderTypeValidator is a validator for the "provider_type" field. It is called by the builders before save.
|
||||||
|
ProviderTypeValidator func(string) error
|
||||||
|
// ProviderKeyValidator is a validator for the "provider_key" field. It is called by the builders before save.
|
||||||
|
ProviderKeyValidator func(string) error
|
||||||
|
// ChannelValidator is a validator for the "channel" field. It is called by the builders before save.
|
||||||
|
ChannelValidator func(string) error
|
||||||
|
// ChannelAppIDValidator is a validator for the "channel_app_id" field. It is called by the builders before save.
|
||||||
|
ChannelAppIDValidator func(string) error
|
||||||
|
// ChannelSubjectValidator is a validator for the "channel_subject" field. It is called by the builders before save.
|
||||||
|
ChannelSubjectValidator func(string) error
|
||||||
|
// DefaultMetadata holds the default value on creation for the "metadata" field.
|
||||||
|
DefaultMetadata func() map[string]interface{}
|
||||||
|
)
|
||||||
|
|
||||||
|
// OrderOption defines the ordering options for the AuthIdentityChannel queries.
|
||||||
|
type OrderOption func(*sql.Selector)
|
||||||
|
|
||||||
|
// ByID orders the results by the id field.
|
||||||
|
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByCreatedAt orders the results by the created_at field.
|
||||||
|
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByUpdatedAt orders the results by the updated_at field.
|
||||||
|
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByIdentityID orders the results by the identity_id field.
|
||||||
|
func ByIdentityID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldIdentityID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByProviderType orders the results by the provider_type field.
|
||||||
|
func ByProviderType(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldProviderType, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByProviderKey orders the results by the provider_key field.
|
||||||
|
func ByProviderKey(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldProviderKey, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByChannel orders the results by the channel field.
|
||||||
|
func ByChannel(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldChannel, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByChannelAppID orders the results by the channel_app_id field.
|
||||||
|
func ByChannelAppID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldChannelAppID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByChannelSubject orders the results by the channel_subject field.
|
||||||
|
func ByChannelSubject(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldChannelSubject, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByIdentityField orders the results by identity field.
|
||||||
|
func ByIdentityField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborTerms(s, newIdentityStep(), sql.OrderByField(field, opts...))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func newIdentityStep() *sqlgraph.Step {
|
||||||
|
return sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(IdentityInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, IdentityTable, IdentityColumn),
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,559 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package authidentitychannel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/predicate"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ID filters vertices based on their ID field.
|
||||||
|
func ID(id int64) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDEQ applies the EQ predicate on the ID field.
|
||||||
|
func IDEQ(id int64) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNEQ applies the NEQ predicate on the ID field.
|
||||||
|
func IDNEQ(id int64) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldNEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDIn applies the In predicate on the ID field.
|
||||||
|
func IDIn(ids ...int64) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNotIn applies the NotIn predicate on the ID field.
|
||||||
|
func IDNotIn(ids ...int64) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldNotIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGT applies the GT predicate on the ID field.
|
||||||
|
func IDGT(id int64) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldGT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGTE applies the GTE predicate on the ID field.
|
||||||
|
func IDGTE(id int64) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldGTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLT applies the LT predicate on the ID field.
|
||||||
|
func IDLT(id int64) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldLT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLTE applies the LTE predicate on the ID field.
|
||||||
|
func IDLTE(id int64) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldLTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||||
|
func CreatedAt(v time.Time) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(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.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IdentityID applies equality check predicate on the "identity_id" field. It's identical to IdentityIDEQ.
|
||||||
|
func IdentityID(v int64) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldEQ(FieldIdentityID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderType applies equality check predicate on the "provider_type" field. It's identical to ProviderTypeEQ.
|
||||||
|
func ProviderType(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldEQ(FieldProviderType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKey applies equality check predicate on the "provider_key" field. It's identical to ProviderKeyEQ.
|
||||||
|
func ProviderKey(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldEQ(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Channel applies equality check predicate on the "channel" field. It's identical to ChannelEQ.
|
||||||
|
func Channel(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldEQ(FieldChannel, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelAppID applies equality check predicate on the "channel_app_id" field. It's identical to ChannelAppIDEQ.
|
||||||
|
func ChannelAppID(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldEQ(FieldChannelAppID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelSubject applies equality check predicate on the "channel_subject" field. It's identical to ChannelSubjectEQ.
|
||||||
|
func ChannelSubject(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldEQ(FieldChannelSubject, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtEQ(v time.Time) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtNEQ(v time.Time) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldNEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||||
|
func CreatedAtIn(vs ...time.Time) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||||
|
func CreatedAtNotIn(vs ...time.Time) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||||
|
func CreatedAtGT(v time.Time) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldGT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtGTE(v time.Time) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldGTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||||
|
func CreatedAtLT(v time.Time) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldLT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtLTE(v time.Time) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldLTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtEQ(v time.Time) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNEQ(v time.Time) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldNEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtIn(vs ...time.Time) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNotIn(vs ...time.Time) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldNotIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGT(v time.Time) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldGT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGTE(v time.Time) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldGTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLT(v time.Time) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldLT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLTE(v time.Time) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldLTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IdentityIDEQ applies the EQ predicate on the "identity_id" field.
|
||||||
|
func IdentityIDEQ(v int64) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldEQ(FieldIdentityID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IdentityIDNEQ applies the NEQ predicate on the "identity_id" field.
|
||||||
|
func IdentityIDNEQ(v int64) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldNEQ(FieldIdentityID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IdentityIDIn applies the In predicate on the "identity_id" field.
|
||||||
|
func IdentityIDIn(vs ...int64) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldIn(FieldIdentityID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IdentityIDNotIn applies the NotIn predicate on the "identity_id" field.
|
||||||
|
func IdentityIDNotIn(vs ...int64) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldNotIn(FieldIdentityID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderTypeEQ applies the EQ predicate on the "provider_type" field.
|
||||||
|
func ProviderTypeEQ(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldEQ(FieldProviderType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderTypeNEQ applies the NEQ predicate on the "provider_type" field.
|
||||||
|
func ProviderTypeNEQ(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldNEQ(FieldProviderType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderTypeIn applies the In predicate on the "provider_type" field.
|
||||||
|
func ProviderTypeIn(vs ...string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldIn(FieldProviderType, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderTypeNotIn applies the NotIn predicate on the "provider_type" field.
|
||||||
|
func ProviderTypeNotIn(vs ...string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldNotIn(FieldProviderType, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderTypeGT applies the GT predicate on the "provider_type" field.
|
||||||
|
func ProviderTypeGT(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldGT(FieldProviderType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderTypeGTE applies the GTE predicate on the "provider_type" field.
|
||||||
|
func ProviderTypeGTE(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldGTE(FieldProviderType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderTypeLT applies the LT predicate on the "provider_type" field.
|
||||||
|
func ProviderTypeLT(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldLT(FieldProviderType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderTypeLTE applies the LTE predicate on the "provider_type" field.
|
||||||
|
func ProviderTypeLTE(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldLTE(FieldProviderType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderTypeContains applies the Contains predicate on the "provider_type" field.
|
||||||
|
func ProviderTypeContains(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldContains(FieldProviderType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderTypeHasPrefix applies the HasPrefix predicate on the "provider_type" field.
|
||||||
|
func ProviderTypeHasPrefix(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldHasPrefix(FieldProviderType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderTypeHasSuffix applies the HasSuffix predicate on the "provider_type" field.
|
||||||
|
func ProviderTypeHasSuffix(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldHasSuffix(FieldProviderType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderTypeEqualFold applies the EqualFold predicate on the "provider_type" field.
|
||||||
|
func ProviderTypeEqualFold(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldEqualFold(FieldProviderType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderTypeContainsFold applies the ContainsFold predicate on the "provider_type" field.
|
||||||
|
func ProviderTypeContainsFold(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldContainsFold(FieldProviderType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyEQ applies the EQ predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyEQ(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldEQ(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyNEQ applies the NEQ predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyNEQ(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldNEQ(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyIn applies the In predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyIn(vs ...string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldIn(FieldProviderKey, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyNotIn applies the NotIn predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyNotIn(vs ...string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldNotIn(FieldProviderKey, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyGT applies the GT predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyGT(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldGT(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyGTE applies the GTE predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyGTE(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldGTE(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyLT applies the LT predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyLT(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldLT(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyLTE applies the LTE predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyLTE(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldLTE(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyContains applies the Contains predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyContains(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldContains(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyHasPrefix applies the HasPrefix predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyHasPrefix(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldHasPrefix(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyHasSuffix applies the HasSuffix predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyHasSuffix(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldHasSuffix(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyEqualFold applies the EqualFold predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyEqualFold(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldEqualFold(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyContainsFold applies the ContainsFold predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyContainsFold(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldContainsFold(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelEQ applies the EQ predicate on the "channel" field.
|
||||||
|
func ChannelEQ(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldEQ(FieldChannel, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelNEQ applies the NEQ predicate on the "channel" field.
|
||||||
|
func ChannelNEQ(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldNEQ(FieldChannel, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelIn applies the In predicate on the "channel" field.
|
||||||
|
func ChannelIn(vs ...string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldIn(FieldChannel, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelNotIn applies the NotIn predicate on the "channel" field.
|
||||||
|
func ChannelNotIn(vs ...string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldNotIn(FieldChannel, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelGT applies the GT predicate on the "channel" field.
|
||||||
|
func ChannelGT(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldGT(FieldChannel, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelGTE applies the GTE predicate on the "channel" field.
|
||||||
|
func ChannelGTE(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldGTE(FieldChannel, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelLT applies the LT predicate on the "channel" field.
|
||||||
|
func ChannelLT(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldLT(FieldChannel, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelLTE applies the LTE predicate on the "channel" field.
|
||||||
|
func ChannelLTE(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldLTE(FieldChannel, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelContains applies the Contains predicate on the "channel" field.
|
||||||
|
func ChannelContains(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldContains(FieldChannel, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelHasPrefix applies the HasPrefix predicate on the "channel" field.
|
||||||
|
func ChannelHasPrefix(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldHasPrefix(FieldChannel, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelHasSuffix applies the HasSuffix predicate on the "channel" field.
|
||||||
|
func ChannelHasSuffix(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldHasSuffix(FieldChannel, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelEqualFold applies the EqualFold predicate on the "channel" field.
|
||||||
|
func ChannelEqualFold(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldEqualFold(FieldChannel, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelContainsFold applies the ContainsFold predicate on the "channel" field.
|
||||||
|
func ChannelContainsFold(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldContainsFold(FieldChannel, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelAppIDEQ applies the EQ predicate on the "channel_app_id" field.
|
||||||
|
func ChannelAppIDEQ(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldEQ(FieldChannelAppID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelAppIDNEQ applies the NEQ predicate on the "channel_app_id" field.
|
||||||
|
func ChannelAppIDNEQ(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldNEQ(FieldChannelAppID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelAppIDIn applies the In predicate on the "channel_app_id" field.
|
||||||
|
func ChannelAppIDIn(vs ...string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldIn(FieldChannelAppID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelAppIDNotIn applies the NotIn predicate on the "channel_app_id" field.
|
||||||
|
func ChannelAppIDNotIn(vs ...string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldNotIn(FieldChannelAppID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelAppIDGT applies the GT predicate on the "channel_app_id" field.
|
||||||
|
func ChannelAppIDGT(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldGT(FieldChannelAppID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelAppIDGTE applies the GTE predicate on the "channel_app_id" field.
|
||||||
|
func ChannelAppIDGTE(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldGTE(FieldChannelAppID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelAppIDLT applies the LT predicate on the "channel_app_id" field.
|
||||||
|
func ChannelAppIDLT(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldLT(FieldChannelAppID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelAppIDLTE applies the LTE predicate on the "channel_app_id" field.
|
||||||
|
func ChannelAppIDLTE(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldLTE(FieldChannelAppID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelAppIDContains applies the Contains predicate on the "channel_app_id" field.
|
||||||
|
func ChannelAppIDContains(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldContains(FieldChannelAppID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelAppIDHasPrefix applies the HasPrefix predicate on the "channel_app_id" field.
|
||||||
|
func ChannelAppIDHasPrefix(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldHasPrefix(FieldChannelAppID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelAppIDHasSuffix applies the HasSuffix predicate on the "channel_app_id" field.
|
||||||
|
func ChannelAppIDHasSuffix(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldHasSuffix(FieldChannelAppID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelAppIDEqualFold applies the EqualFold predicate on the "channel_app_id" field.
|
||||||
|
func ChannelAppIDEqualFold(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldEqualFold(FieldChannelAppID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelAppIDContainsFold applies the ContainsFold predicate on the "channel_app_id" field.
|
||||||
|
func ChannelAppIDContainsFold(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldContainsFold(FieldChannelAppID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelSubjectEQ applies the EQ predicate on the "channel_subject" field.
|
||||||
|
func ChannelSubjectEQ(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldEQ(FieldChannelSubject, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelSubjectNEQ applies the NEQ predicate on the "channel_subject" field.
|
||||||
|
func ChannelSubjectNEQ(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldNEQ(FieldChannelSubject, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelSubjectIn applies the In predicate on the "channel_subject" field.
|
||||||
|
func ChannelSubjectIn(vs ...string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldIn(FieldChannelSubject, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelSubjectNotIn applies the NotIn predicate on the "channel_subject" field.
|
||||||
|
func ChannelSubjectNotIn(vs ...string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldNotIn(FieldChannelSubject, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelSubjectGT applies the GT predicate on the "channel_subject" field.
|
||||||
|
func ChannelSubjectGT(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldGT(FieldChannelSubject, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelSubjectGTE applies the GTE predicate on the "channel_subject" field.
|
||||||
|
func ChannelSubjectGTE(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldGTE(FieldChannelSubject, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelSubjectLT applies the LT predicate on the "channel_subject" field.
|
||||||
|
func ChannelSubjectLT(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldLT(FieldChannelSubject, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelSubjectLTE applies the LTE predicate on the "channel_subject" field.
|
||||||
|
func ChannelSubjectLTE(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldLTE(FieldChannelSubject, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelSubjectContains applies the Contains predicate on the "channel_subject" field.
|
||||||
|
func ChannelSubjectContains(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldContains(FieldChannelSubject, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelSubjectHasPrefix applies the HasPrefix predicate on the "channel_subject" field.
|
||||||
|
func ChannelSubjectHasPrefix(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldHasPrefix(FieldChannelSubject, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelSubjectHasSuffix applies the HasSuffix predicate on the "channel_subject" field.
|
||||||
|
func ChannelSubjectHasSuffix(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldHasSuffix(FieldChannelSubject, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelSubjectEqualFold applies the EqualFold predicate on the "channel_subject" field.
|
||||||
|
func ChannelSubjectEqualFold(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldEqualFold(FieldChannelSubject, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelSubjectContainsFold applies the ContainsFold predicate on the "channel_subject" field.
|
||||||
|
func ChannelSubjectContainsFold(v string) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.FieldContainsFold(FieldChannelSubject, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasIdentity applies the HasEdge predicate on the "identity" edge.
|
||||||
|
func HasIdentity() predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, IdentityTable, IdentityColumn),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasIdentityWith applies the HasEdge predicate on the "identity" edge with a given conditions (other predicates).
|
||||||
|
func HasIdentityWith(preds ...predicate.AuthIdentity) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(func(s *sql.Selector) {
|
||||||
|
step := newIdentityStep()
|
||||||
|
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// And groups predicates with the AND operator between them.
|
||||||
|
func And(predicates ...predicate.AuthIdentityChannel) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.AndPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or groups predicates with the OR operator between them.
|
||||||
|
func Or(predicates ...predicate.AuthIdentityChannel) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.OrPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not applies the not operator on the given predicate.
|
||||||
|
func Not(p predicate.AuthIdentityChannel) predicate.AuthIdentityChannel {
|
||||||
|
return predicate.AuthIdentityChannel(sql.NotPredicates(p))
|
||||||
|
}
|
||||||
@@ -0,0 +1,932 @@
|
|||||||
|
// 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/authidentity"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/authidentitychannel"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AuthIdentityChannelCreate is the builder for creating a AuthIdentityChannel entity.
|
||||||
|
type AuthIdentityChannelCreate struct {
|
||||||
|
config
|
||||||
|
mutation *AuthIdentityChannelMutation
|
||||||
|
hooks []Hook
|
||||||
|
conflict []sql.ConflictOption
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreatedAt sets the "created_at" field.
|
||||||
|
func (_c *AuthIdentityChannelCreate) SetCreatedAt(v time.Time) *AuthIdentityChannelCreate {
|
||||||
|
_c.mutation.SetCreatedAt(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||||
|
func (_c *AuthIdentityChannelCreate) SetNillableCreatedAt(v *time.Time) *AuthIdentityChannelCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetCreatedAt(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (_c *AuthIdentityChannelCreate) SetUpdatedAt(v time.Time) *AuthIdentityChannelCreate {
|
||||||
|
_c.mutation.SetUpdatedAt(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||||
|
func (_c *AuthIdentityChannelCreate) SetNillableUpdatedAt(v *time.Time) *AuthIdentityChannelCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetUpdatedAt(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIdentityID sets the "identity_id" field.
|
||||||
|
func (_c *AuthIdentityChannelCreate) SetIdentityID(v int64) *AuthIdentityChannelCreate {
|
||||||
|
_c.mutation.SetIdentityID(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProviderType sets the "provider_type" field.
|
||||||
|
func (_c *AuthIdentityChannelCreate) SetProviderType(v string) *AuthIdentityChannelCreate {
|
||||||
|
_c.mutation.SetProviderType(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProviderKey sets the "provider_key" field.
|
||||||
|
func (_c *AuthIdentityChannelCreate) SetProviderKey(v string) *AuthIdentityChannelCreate {
|
||||||
|
_c.mutation.SetProviderKey(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetChannel sets the "channel" field.
|
||||||
|
func (_c *AuthIdentityChannelCreate) SetChannel(v string) *AuthIdentityChannelCreate {
|
||||||
|
_c.mutation.SetChannel(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetChannelAppID sets the "channel_app_id" field.
|
||||||
|
func (_c *AuthIdentityChannelCreate) SetChannelAppID(v string) *AuthIdentityChannelCreate {
|
||||||
|
_c.mutation.SetChannelAppID(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetChannelSubject sets the "channel_subject" field.
|
||||||
|
func (_c *AuthIdentityChannelCreate) SetChannelSubject(v string) *AuthIdentityChannelCreate {
|
||||||
|
_c.mutation.SetChannelSubject(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMetadata sets the "metadata" field.
|
||||||
|
func (_c *AuthIdentityChannelCreate) SetMetadata(v map[string]interface{}) *AuthIdentityChannelCreate {
|
||||||
|
_c.mutation.SetMetadata(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIdentity sets the "identity" edge to the AuthIdentity entity.
|
||||||
|
func (_c *AuthIdentityChannelCreate) SetIdentity(v *AuthIdentity) *AuthIdentityChannelCreate {
|
||||||
|
return _c.SetIdentityID(v.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the AuthIdentityChannelMutation object of the builder.
|
||||||
|
func (_c *AuthIdentityChannelCreate) Mutation() *AuthIdentityChannelMutation {
|
||||||
|
return _c.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the AuthIdentityChannel in the database.
|
||||||
|
func (_c *AuthIdentityChannelCreate) Save(ctx context.Context) (*AuthIdentityChannel, error) {
|
||||||
|
_c.defaults()
|
||||||
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX calls Save and panics if Save returns an error.
|
||||||
|
func (_c *AuthIdentityChannelCreate) SaveX(ctx context.Context) *AuthIdentityChannel {
|
||||||
|
v, err := _c.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (_c *AuthIdentityChannelCreate) Exec(ctx context.Context) error {
|
||||||
|
_, err := _c.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_c *AuthIdentityChannelCreate) 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 *AuthIdentityChannelCreate) defaults() {
|
||||||
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||||
|
v := authidentitychannel.DefaultCreatedAt()
|
||||||
|
_c.mutation.SetCreatedAt(v)
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||||||
|
v := authidentitychannel.DefaultUpdatedAt()
|
||||||
|
_c.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.Metadata(); !ok {
|
||||||
|
v := authidentitychannel.DefaultMetadata()
|
||||||
|
_c.mutation.SetMetadata(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (_c *AuthIdentityChannelCreate) check() error {
|
||||||
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||||
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "AuthIdentityChannel.created_at"`)}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||||||
|
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "AuthIdentityChannel.updated_at"`)}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.IdentityID(); !ok {
|
||||||
|
return &ValidationError{Name: "identity_id", err: errors.New(`ent: missing required field "AuthIdentityChannel.identity_id"`)}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.ProviderType(); !ok {
|
||||||
|
return &ValidationError{Name: "provider_type", err: errors.New(`ent: missing required field "AuthIdentityChannel.provider_type"`)}
|
||||||
|
}
|
||||||
|
if v, ok := _c.mutation.ProviderType(); ok {
|
||||||
|
if err := authidentitychannel.ProviderTypeValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "provider_type", err: fmt.Errorf(`ent: validator failed for field "AuthIdentityChannel.provider_type": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.ProviderKey(); !ok {
|
||||||
|
return &ValidationError{Name: "provider_key", err: errors.New(`ent: missing required field "AuthIdentityChannel.provider_key"`)}
|
||||||
|
}
|
||||||
|
if v, ok := _c.mutation.ProviderKey(); ok {
|
||||||
|
if err := authidentitychannel.ProviderKeyValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "provider_key", err: fmt.Errorf(`ent: validator failed for field "AuthIdentityChannel.provider_key": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.Channel(); !ok {
|
||||||
|
return &ValidationError{Name: "channel", err: errors.New(`ent: missing required field "AuthIdentityChannel.channel"`)}
|
||||||
|
}
|
||||||
|
if v, ok := _c.mutation.Channel(); ok {
|
||||||
|
if err := authidentitychannel.ChannelValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "channel", err: fmt.Errorf(`ent: validator failed for field "AuthIdentityChannel.channel": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.ChannelAppID(); !ok {
|
||||||
|
return &ValidationError{Name: "channel_app_id", err: errors.New(`ent: missing required field "AuthIdentityChannel.channel_app_id"`)}
|
||||||
|
}
|
||||||
|
if v, ok := _c.mutation.ChannelAppID(); ok {
|
||||||
|
if err := authidentitychannel.ChannelAppIDValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "channel_app_id", err: fmt.Errorf(`ent: validator failed for field "AuthIdentityChannel.channel_app_id": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.ChannelSubject(); !ok {
|
||||||
|
return &ValidationError{Name: "channel_subject", err: errors.New(`ent: missing required field "AuthIdentityChannel.channel_subject"`)}
|
||||||
|
}
|
||||||
|
if v, ok := _c.mutation.ChannelSubject(); ok {
|
||||||
|
if err := authidentitychannel.ChannelSubjectValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "channel_subject", err: fmt.Errorf(`ent: validator failed for field "AuthIdentityChannel.channel_subject": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.Metadata(); !ok {
|
||||||
|
return &ValidationError{Name: "metadata", err: errors.New(`ent: missing required field "AuthIdentityChannel.metadata"`)}
|
||||||
|
}
|
||||||
|
if len(_c.mutation.IdentityIDs()) == 0 {
|
||||||
|
return &ValidationError{Name: "identity", err: errors.New(`ent: missing required edge "AuthIdentityChannel.identity"`)}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_c *AuthIdentityChannelCreate) sqlSave(ctx context.Context) (*AuthIdentityChannel, 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 *AuthIdentityChannelCreate) createSpec() (*AuthIdentityChannel, *sqlgraph.CreateSpec) {
|
||||||
|
var (
|
||||||
|
_node = &AuthIdentityChannel{config: _c.config}
|
||||||
|
_spec = sqlgraph.NewCreateSpec(authidentitychannel.Table, sqlgraph.NewFieldSpec(authidentitychannel.FieldID, field.TypeInt64))
|
||||||
|
)
|
||||||
|
_spec.OnConflict = _c.conflict
|
||||||
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
||||||
|
_spec.SetField(authidentitychannel.FieldCreatedAt, field.TypeTime, value)
|
||||||
|
_node.CreatedAt = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(authidentitychannel.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
_node.UpdatedAt = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.ProviderType(); ok {
|
||||||
|
_spec.SetField(authidentitychannel.FieldProviderType, field.TypeString, value)
|
||||||
|
_node.ProviderType = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.ProviderKey(); ok {
|
||||||
|
_spec.SetField(authidentitychannel.FieldProviderKey, field.TypeString, value)
|
||||||
|
_node.ProviderKey = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.Channel(); ok {
|
||||||
|
_spec.SetField(authidentitychannel.FieldChannel, field.TypeString, value)
|
||||||
|
_node.Channel = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.ChannelAppID(); ok {
|
||||||
|
_spec.SetField(authidentitychannel.FieldChannelAppID, field.TypeString, value)
|
||||||
|
_node.ChannelAppID = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.ChannelSubject(); ok {
|
||||||
|
_spec.SetField(authidentitychannel.FieldChannelSubject, field.TypeString, value)
|
||||||
|
_node.ChannelSubject = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.Metadata(); ok {
|
||||||
|
_spec.SetField(authidentitychannel.FieldMetadata, field.TypeJSON, value)
|
||||||
|
_node.Metadata = value
|
||||||
|
}
|
||||||
|
if nodes := _c.mutation.IdentityIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: authidentitychannel.IdentityTable,
|
||||||
|
Columns: []string{authidentitychannel.IdentityColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_node.IdentityID = nodes[0]
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
|
return _node, _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||||||
|
// of the `INSERT` statement. For example:
|
||||||
|
//
|
||||||
|
// client.AuthIdentityChannel.Create().
|
||||||
|
// SetCreatedAt(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.AuthIdentityChannelUpsert) {
|
||||||
|
// SetCreatedAt(v+v).
|
||||||
|
// }).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (_c *AuthIdentityChannelCreate) OnConflict(opts ...sql.ConflictOption) *AuthIdentityChannelUpsertOne {
|
||||||
|
_c.conflict = opts
|
||||||
|
return &AuthIdentityChannelUpsertOne{
|
||||||
|
create: _c,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
||||||
|
// as conflict target. Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.AuthIdentityChannel.Create().
|
||||||
|
// OnConflict(sql.ConflictColumns(columns...)).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (_c *AuthIdentityChannelCreate) OnConflictColumns(columns ...string) *AuthIdentityChannelUpsertOne {
|
||||||
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
||||||
|
return &AuthIdentityChannelUpsertOne{
|
||||||
|
create: _c,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// AuthIdentityChannelUpsertOne is the builder for "upsert"-ing
|
||||||
|
// one AuthIdentityChannel node.
|
||||||
|
AuthIdentityChannelUpsertOne struct {
|
||||||
|
create *AuthIdentityChannelCreate
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthIdentityChannelUpsert is the "OnConflict" setter.
|
||||||
|
AuthIdentityChannelUpsert struct {
|
||||||
|
*sql.UpdateSet
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (u *AuthIdentityChannelUpsert) SetUpdatedAt(v time.Time) *AuthIdentityChannelUpsert {
|
||||||
|
u.Set(authidentitychannel.FieldUpdatedAt, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
||||||
|
func (u *AuthIdentityChannelUpsert) UpdateUpdatedAt() *AuthIdentityChannelUpsert {
|
||||||
|
u.SetExcluded(authidentitychannel.FieldUpdatedAt)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIdentityID sets the "identity_id" field.
|
||||||
|
func (u *AuthIdentityChannelUpsert) SetIdentityID(v int64) *AuthIdentityChannelUpsert {
|
||||||
|
u.Set(authidentitychannel.FieldIdentityID, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateIdentityID sets the "identity_id" field to the value that was provided on create.
|
||||||
|
func (u *AuthIdentityChannelUpsert) UpdateIdentityID() *AuthIdentityChannelUpsert {
|
||||||
|
u.SetExcluded(authidentitychannel.FieldIdentityID)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProviderType sets the "provider_type" field.
|
||||||
|
func (u *AuthIdentityChannelUpsert) SetProviderType(v string) *AuthIdentityChannelUpsert {
|
||||||
|
u.Set(authidentitychannel.FieldProviderType, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateProviderType sets the "provider_type" field to the value that was provided on create.
|
||||||
|
func (u *AuthIdentityChannelUpsert) UpdateProviderType() *AuthIdentityChannelUpsert {
|
||||||
|
u.SetExcluded(authidentitychannel.FieldProviderType)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProviderKey sets the "provider_key" field.
|
||||||
|
func (u *AuthIdentityChannelUpsert) SetProviderKey(v string) *AuthIdentityChannelUpsert {
|
||||||
|
u.Set(authidentitychannel.FieldProviderKey, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateProviderKey sets the "provider_key" field to the value that was provided on create.
|
||||||
|
func (u *AuthIdentityChannelUpsert) UpdateProviderKey() *AuthIdentityChannelUpsert {
|
||||||
|
u.SetExcluded(authidentitychannel.FieldProviderKey)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetChannel sets the "channel" field.
|
||||||
|
func (u *AuthIdentityChannelUpsert) SetChannel(v string) *AuthIdentityChannelUpsert {
|
||||||
|
u.Set(authidentitychannel.FieldChannel, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateChannel sets the "channel" field to the value that was provided on create.
|
||||||
|
func (u *AuthIdentityChannelUpsert) UpdateChannel() *AuthIdentityChannelUpsert {
|
||||||
|
u.SetExcluded(authidentitychannel.FieldChannel)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetChannelAppID sets the "channel_app_id" field.
|
||||||
|
func (u *AuthIdentityChannelUpsert) SetChannelAppID(v string) *AuthIdentityChannelUpsert {
|
||||||
|
u.Set(authidentitychannel.FieldChannelAppID, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateChannelAppID sets the "channel_app_id" field to the value that was provided on create.
|
||||||
|
func (u *AuthIdentityChannelUpsert) UpdateChannelAppID() *AuthIdentityChannelUpsert {
|
||||||
|
u.SetExcluded(authidentitychannel.FieldChannelAppID)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetChannelSubject sets the "channel_subject" field.
|
||||||
|
func (u *AuthIdentityChannelUpsert) SetChannelSubject(v string) *AuthIdentityChannelUpsert {
|
||||||
|
u.Set(authidentitychannel.FieldChannelSubject, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateChannelSubject sets the "channel_subject" field to the value that was provided on create.
|
||||||
|
func (u *AuthIdentityChannelUpsert) UpdateChannelSubject() *AuthIdentityChannelUpsert {
|
||||||
|
u.SetExcluded(authidentitychannel.FieldChannelSubject)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMetadata sets the "metadata" field.
|
||||||
|
func (u *AuthIdentityChannelUpsert) SetMetadata(v map[string]interface{}) *AuthIdentityChannelUpsert {
|
||||||
|
u.Set(authidentitychannel.FieldMetadata, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateMetadata sets the "metadata" field to the value that was provided on create.
|
||||||
|
func (u *AuthIdentityChannelUpsert) UpdateMetadata() *AuthIdentityChannelUpsert {
|
||||||
|
u.SetExcluded(authidentitychannel.FieldMetadata)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
||||||
|
// Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.AuthIdentityChannel.Create().
|
||||||
|
// OnConflict(
|
||||||
|
// sql.ResolveWithNewValues(),
|
||||||
|
// ).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (u *AuthIdentityChannelUpsertOne) UpdateNewValues() *AuthIdentityChannelUpsertOne {
|
||||||
|
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(authidentitychannel.FieldCreatedAt)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ignore sets each column to itself in case of conflict.
|
||||||
|
// Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.AuthIdentityChannel.Create().
|
||||||
|
// OnConflict(sql.ResolveWithIgnore()).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (u *AuthIdentityChannelUpsertOne) Ignore() *AuthIdentityChannelUpsertOne {
|
||||||
|
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 *AuthIdentityChannelUpsertOne) DoNothing() *AuthIdentityChannelUpsertOne {
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update allows overriding fields `UPDATE` values. See the AuthIdentityChannelCreate.OnConflict
|
||||||
|
// documentation for more info.
|
||||||
|
func (u *AuthIdentityChannelUpsertOne) Update(set func(*AuthIdentityChannelUpsert)) *AuthIdentityChannelUpsertOne {
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||||||
|
set(&AuthIdentityChannelUpsert{UpdateSet: update})
|
||||||
|
}))
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (u *AuthIdentityChannelUpsertOne) SetUpdatedAt(v time.Time) *AuthIdentityChannelUpsertOne {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.SetUpdatedAt(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
||||||
|
func (u *AuthIdentityChannelUpsertOne) UpdateUpdatedAt() *AuthIdentityChannelUpsertOne {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.UpdateUpdatedAt()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIdentityID sets the "identity_id" field.
|
||||||
|
func (u *AuthIdentityChannelUpsertOne) SetIdentityID(v int64) *AuthIdentityChannelUpsertOne {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.SetIdentityID(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateIdentityID sets the "identity_id" field to the value that was provided on create.
|
||||||
|
func (u *AuthIdentityChannelUpsertOne) UpdateIdentityID() *AuthIdentityChannelUpsertOne {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.UpdateIdentityID()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProviderType sets the "provider_type" field.
|
||||||
|
func (u *AuthIdentityChannelUpsertOne) SetProviderType(v string) *AuthIdentityChannelUpsertOne {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.SetProviderType(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateProviderType sets the "provider_type" field to the value that was provided on create.
|
||||||
|
func (u *AuthIdentityChannelUpsertOne) UpdateProviderType() *AuthIdentityChannelUpsertOne {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.UpdateProviderType()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProviderKey sets the "provider_key" field.
|
||||||
|
func (u *AuthIdentityChannelUpsertOne) SetProviderKey(v string) *AuthIdentityChannelUpsertOne {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.SetProviderKey(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateProviderKey sets the "provider_key" field to the value that was provided on create.
|
||||||
|
func (u *AuthIdentityChannelUpsertOne) UpdateProviderKey() *AuthIdentityChannelUpsertOne {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.UpdateProviderKey()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetChannel sets the "channel" field.
|
||||||
|
func (u *AuthIdentityChannelUpsertOne) SetChannel(v string) *AuthIdentityChannelUpsertOne {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.SetChannel(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateChannel sets the "channel" field to the value that was provided on create.
|
||||||
|
func (u *AuthIdentityChannelUpsertOne) UpdateChannel() *AuthIdentityChannelUpsertOne {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.UpdateChannel()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetChannelAppID sets the "channel_app_id" field.
|
||||||
|
func (u *AuthIdentityChannelUpsertOne) SetChannelAppID(v string) *AuthIdentityChannelUpsertOne {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.SetChannelAppID(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateChannelAppID sets the "channel_app_id" field to the value that was provided on create.
|
||||||
|
func (u *AuthIdentityChannelUpsertOne) UpdateChannelAppID() *AuthIdentityChannelUpsertOne {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.UpdateChannelAppID()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetChannelSubject sets the "channel_subject" field.
|
||||||
|
func (u *AuthIdentityChannelUpsertOne) SetChannelSubject(v string) *AuthIdentityChannelUpsertOne {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.SetChannelSubject(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateChannelSubject sets the "channel_subject" field to the value that was provided on create.
|
||||||
|
func (u *AuthIdentityChannelUpsertOne) UpdateChannelSubject() *AuthIdentityChannelUpsertOne {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.UpdateChannelSubject()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMetadata sets the "metadata" field.
|
||||||
|
func (u *AuthIdentityChannelUpsertOne) SetMetadata(v map[string]interface{}) *AuthIdentityChannelUpsertOne {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.SetMetadata(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateMetadata sets the "metadata" field to the value that was provided on create.
|
||||||
|
func (u *AuthIdentityChannelUpsertOne) UpdateMetadata() *AuthIdentityChannelUpsertOne {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.UpdateMetadata()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (u *AuthIdentityChannelUpsertOne) Exec(ctx context.Context) error {
|
||||||
|
if len(u.create.conflict) == 0 {
|
||||||
|
return errors.New("ent: missing options for AuthIdentityChannelCreate.OnConflict")
|
||||||
|
}
|
||||||
|
return u.create.Exec(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (u *AuthIdentityChannelUpsertOne) 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 *AuthIdentityChannelUpsertOne) 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 *AuthIdentityChannelUpsertOne) IDX(ctx context.Context) int64 {
|
||||||
|
id, err := u.ID(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthIdentityChannelCreateBulk is the builder for creating many AuthIdentityChannel entities in bulk.
|
||||||
|
type AuthIdentityChannelCreateBulk struct {
|
||||||
|
config
|
||||||
|
err error
|
||||||
|
builders []*AuthIdentityChannelCreate
|
||||||
|
conflict []sql.ConflictOption
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the AuthIdentityChannel entities in the database.
|
||||||
|
func (_c *AuthIdentityChannelCreateBulk) Save(ctx context.Context) ([]*AuthIdentityChannel, error) {
|
||||||
|
if _c.err != nil {
|
||||||
|
return nil, _c.err
|
||||||
|
}
|
||||||
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||||
|
nodes := make([]*AuthIdentityChannel, 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.(*AuthIdentityChannelMutation)
|
||||||
|
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 *AuthIdentityChannelCreateBulk) SaveX(ctx context.Context) []*AuthIdentityChannel {
|
||||||
|
v, err := _c.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (_c *AuthIdentityChannelCreateBulk) Exec(ctx context.Context) error {
|
||||||
|
_, err := _c.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_c *AuthIdentityChannelCreateBulk) 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.AuthIdentityChannel.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.AuthIdentityChannelUpsert) {
|
||||||
|
// SetCreatedAt(v+v).
|
||||||
|
// }).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (_c *AuthIdentityChannelCreateBulk) OnConflict(opts ...sql.ConflictOption) *AuthIdentityChannelUpsertBulk {
|
||||||
|
_c.conflict = opts
|
||||||
|
return &AuthIdentityChannelUpsertBulk{
|
||||||
|
create: _c,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
||||||
|
// as conflict target. Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.AuthIdentityChannel.Create().
|
||||||
|
// OnConflict(sql.ConflictColumns(columns...)).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (_c *AuthIdentityChannelCreateBulk) OnConflictColumns(columns ...string) *AuthIdentityChannelUpsertBulk {
|
||||||
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
||||||
|
return &AuthIdentityChannelUpsertBulk{
|
||||||
|
create: _c,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthIdentityChannelUpsertBulk is the builder for "upsert"-ing
|
||||||
|
// a bulk of AuthIdentityChannel nodes.
|
||||||
|
type AuthIdentityChannelUpsertBulk struct {
|
||||||
|
create *AuthIdentityChannelCreateBulk
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateNewValues updates the mutable fields using the new values that
|
||||||
|
// were set on create. Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.AuthIdentityChannel.Create().
|
||||||
|
// OnConflict(
|
||||||
|
// sql.ResolveWithNewValues(),
|
||||||
|
// ).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (u *AuthIdentityChannelUpsertBulk) UpdateNewValues() *AuthIdentityChannelUpsertBulk {
|
||||||
|
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(authidentitychannel.FieldCreatedAt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ignore sets each column to itself in case of conflict.
|
||||||
|
// Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.AuthIdentityChannel.Create().
|
||||||
|
// OnConflict(sql.ResolveWithIgnore()).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (u *AuthIdentityChannelUpsertBulk) Ignore() *AuthIdentityChannelUpsertBulk {
|
||||||
|
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 *AuthIdentityChannelUpsertBulk) DoNothing() *AuthIdentityChannelUpsertBulk {
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update allows overriding fields `UPDATE` values. See the AuthIdentityChannelCreateBulk.OnConflict
|
||||||
|
// documentation for more info.
|
||||||
|
func (u *AuthIdentityChannelUpsertBulk) Update(set func(*AuthIdentityChannelUpsert)) *AuthIdentityChannelUpsertBulk {
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||||||
|
set(&AuthIdentityChannelUpsert{UpdateSet: update})
|
||||||
|
}))
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (u *AuthIdentityChannelUpsertBulk) SetUpdatedAt(v time.Time) *AuthIdentityChannelUpsertBulk {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.SetUpdatedAt(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
||||||
|
func (u *AuthIdentityChannelUpsertBulk) UpdateUpdatedAt() *AuthIdentityChannelUpsertBulk {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.UpdateUpdatedAt()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIdentityID sets the "identity_id" field.
|
||||||
|
func (u *AuthIdentityChannelUpsertBulk) SetIdentityID(v int64) *AuthIdentityChannelUpsertBulk {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.SetIdentityID(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateIdentityID sets the "identity_id" field to the value that was provided on create.
|
||||||
|
func (u *AuthIdentityChannelUpsertBulk) UpdateIdentityID() *AuthIdentityChannelUpsertBulk {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.UpdateIdentityID()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProviderType sets the "provider_type" field.
|
||||||
|
func (u *AuthIdentityChannelUpsertBulk) SetProviderType(v string) *AuthIdentityChannelUpsertBulk {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.SetProviderType(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateProviderType sets the "provider_type" field to the value that was provided on create.
|
||||||
|
func (u *AuthIdentityChannelUpsertBulk) UpdateProviderType() *AuthIdentityChannelUpsertBulk {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.UpdateProviderType()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProviderKey sets the "provider_key" field.
|
||||||
|
func (u *AuthIdentityChannelUpsertBulk) SetProviderKey(v string) *AuthIdentityChannelUpsertBulk {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.SetProviderKey(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateProviderKey sets the "provider_key" field to the value that was provided on create.
|
||||||
|
func (u *AuthIdentityChannelUpsertBulk) UpdateProviderKey() *AuthIdentityChannelUpsertBulk {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.UpdateProviderKey()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetChannel sets the "channel" field.
|
||||||
|
func (u *AuthIdentityChannelUpsertBulk) SetChannel(v string) *AuthIdentityChannelUpsertBulk {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.SetChannel(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateChannel sets the "channel" field to the value that was provided on create.
|
||||||
|
func (u *AuthIdentityChannelUpsertBulk) UpdateChannel() *AuthIdentityChannelUpsertBulk {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.UpdateChannel()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetChannelAppID sets the "channel_app_id" field.
|
||||||
|
func (u *AuthIdentityChannelUpsertBulk) SetChannelAppID(v string) *AuthIdentityChannelUpsertBulk {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.SetChannelAppID(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateChannelAppID sets the "channel_app_id" field to the value that was provided on create.
|
||||||
|
func (u *AuthIdentityChannelUpsertBulk) UpdateChannelAppID() *AuthIdentityChannelUpsertBulk {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.UpdateChannelAppID()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetChannelSubject sets the "channel_subject" field.
|
||||||
|
func (u *AuthIdentityChannelUpsertBulk) SetChannelSubject(v string) *AuthIdentityChannelUpsertBulk {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.SetChannelSubject(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateChannelSubject sets the "channel_subject" field to the value that was provided on create.
|
||||||
|
func (u *AuthIdentityChannelUpsertBulk) UpdateChannelSubject() *AuthIdentityChannelUpsertBulk {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.UpdateChannelSubject()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMetadata sets the "metadata" field.
|
||||||
|
func (u *AuthIdentityChannelUpsertBulk) SetMetadata(v map[string]interface{}) *AuthIdentityChannelUpsertBulk {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.SetMetadata(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateMetadata sets the "metadata" field to the value that was provided on create.
|
||||||
|
func (u *AuthIdentityChannelUpsertBulk) UpdateMetadata() *AuthIdentityChannelUpsertBulk {
|
||||||
|
return u.Update(func(s *AuthIdentityChannelUpsert) {
|
||||||
|
s.UpdateMetadata()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (u *AuthIdentityChannelUpsertBulk) 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 AuthIdentityChannelCreateBulk instead", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(u.create.conflict) == 0 {
|
||||||
|
return errors.New("ent: missing options for AuthIdentityChannelCreateBulk.OnConflict")
|
||||||
|
}
|
||||||
|
return u.create.Exec(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (u *AuthIdentityChannelUpsertBulk) ExecX(ctx context.Context) {
|
||||||
|
if err := u.create.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
// 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/authidentitychannel"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/predicate"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AuthIdentityChannelDelete is the builder for deleting a AuthIdentityChannel entity.
|
||||||
|
type AuthIdentityChannelDelete struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *AuthIdentityChannelMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the AuthIdentityChannelDelete builder.
|
||||||
|
func (_d *AuthIdentityChannelDelete) Where(ps ...predicate.AuthIdentityChannel) *AuthIdentityChannelDelete {
|
||||||
|
_d.mutation.Where(ps...)
|
||||||
|
return _d
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||||
|
func (_d *AuthIdentityChannelDelete) 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 *AuthIdentityChannelDelete) ExecX(ctx context.Context) int {
|
||||||
|
n, err := _d.Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_d *AuthIdentityChannelDelete) sqlExec(ctx context.Context) (int, error) {
|
||||||
|
_spec := sqlgraph.NewDeleteSpec(authidentitychannel.Table, sqlgraph.NewFieldSpec(authidentitychannel.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
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthIdentityChannelDeleteOne is the builder for deleting a single AuthIdentityChannel entity.
|
||||||
|
type AuthIdentityChannelDeleteOne struct {
|
||||||
|
_d *AuthIdentityChannelDelete
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the AuthIdentityChannelDelete builder.
|
||||||
|
func (_d *AuthIdentityChannelDeleteOne) Where(ps ...predicate.AuthIdentityChannel) *AuthIdentityChannelDeleteOne {
|
||||||
|
_d._d.mutation.Where(ps...)
|
||||||
|
return _d
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query.
|
||||||
|
func (_d *AuthIdentityChannelDeleteOne) Exec(ctx context.Context) error {
|
||||||
|
n, err := _d._d.Exec(ctx)
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
|
case n == 0:
|
||||||
|
return &NotFoundError{authidentitychannel.Label}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_d *AuthIdentityChannelDeleteOne) ExecX(ctx context.Context) {
|
||||||
|
if err := _d.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,643 @@
|
|||||||
|
// 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/authidentity"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/authidentitychannel"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/predicate"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AuthIdentityChannelQuery is the builder for querying AuthIdentityChannel entities.
|
||||||
|
type AuthIdentityChannelQuery struct {
|
||||||
|
config
|
||||||
|
ctx *QueryContext
|
||||||
|
order []authidentitychannel.OrderOption
|
||||||
|
inters []Interceptor
|
||||||
|
predicates []predicate.AuthIdentityChannel
|
||||||
|
withIdentity *AuthIdentityQuery
|
||||||
|
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 AuthIdentityChannelQuery builder.
|
||||||
|
func (_q *AuthIdentityChannelQuery) Where(ps ...predicate.AuthIdentityChannel) *AuthIdentityChannelQuery {
|
||||||
|
_q.predicates = append(_q.predicates, ps...)
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit the number of records to be returned by this query.
|
||||||
|
func (_q *AuthIdentityChannelQuery) Limit(limit int) *AuthIdentityChannelQuery {
|
||||||
|
_q.ctx.Limit = &limit
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Offset to start from.
|
||||||
|
func (_q *AuthIdentityChannelQuery) Offset(offset int) *AuthIdentityChannelQuery {
|
||||||
|
_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 *AuthIdentityChannelQuery) Unique(unique bool) *AuthIdentityChannelQuery {
|
||||||
|
_q.ctx.Unique = &unique
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Order specifies how the records should be ordered.
|
||||||
|
func (_q *AuthIdentityChannelQuery) Order(o ...authidentitychannel.OrderOption) *AuthIdentityChannelQuery {
|
||||||
|
_q.order = append(_q.order, o...)
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryIdentity chains the current query on the "identity" edge.
|
||||||
|
func (_q *AuthIdentityChannelQuery) QueryIdentity() *AuthIdentityQuery {
|
||||||
|
query := (&AuthIdentityClient{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(authidentitychannel.Table, authidentitychannel.FieldID, selector),
|
||||||
|
sqlgraph.To(authidentity.Table, authidentity.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, authidentitychannel.IdentityTable, authidentitychannel.IdentityColumn),
|
||||||
|
)
|
||||||
|
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||||
|
return fromU, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// First returns the first AuthIdentityChannel entity from the query.
|
||||||
|
// Returns a *NotFoundError when no AuthIdentityChannel was found.
|
||||||
|
func (_q *AuthIdentityChannelQuery) First(ctx context.Context) (*AuthIdentityChannel, 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{authidentitychannel.Label}
|
||||||
|
}
|
||||||
|
return nodes[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstX is like First, but panics if an error occurs.
|
||||||
|
func (_q *AuthIdentityChannelQuery) FirstX(ctx context.Context) *AuthIdentityChannel {
|
||||||
|
node, err := _q.First(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstID returns the first AuthIdentityChannel ID from the query.
|
||||||
|
// Returns a *NotFoundError when no AuthIdentityChannel ID was found.
|
||||||
|
func (_q *AuthIdentityChannelQuery) 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{authidentitychannel.Label}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return ids[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||||
|
func (_q *AuthIdentityChannelQuery) FirstIDX(ctx context.Context) int64 {
|
||||||
|
id, err := _q.FirstID(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only returns a single AuthIdentityChannel entity found by the query, ensuring it only returns one.
|
||||||
|
// Returns a *NotSingularError when more than one AuthIdentityChannel entity is found.
|
||||||
|
// Returns a *NotFoundError when no AuthIdentityChannel entities are found.
|
||||||
|
func (_q *AuthIdentityChannelQuery) Only(ctx context.Context) (*AuthIdentityChannel, 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{authidentitychannel.Label}
|
||||||
|
default:
|
||||||
|
return nil, &NotSingularError{authidentitychannel.Label}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyX is like Only, but panics if an error occurs.
|
||||||
|
func (_q *AuthIdentityChannelQuery) OnlyX(ctx context.Context) *AuthIdentityChannel {
|
||||||
|
node, err := _q.Only(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyID is like Only, but returns the only AuthIdentityChannel ID in the query.
|
||||||
|
// Returns a *NotSingularError when more than one AuthIdentityChannel ID is found.
|
||||||
|
// Returns a *NotFoundError when no entities are found.
|
||||||
|
func (_q *AuthIdentityChannelQuery) 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{authidentitychannel.Label}
|
||||||
|
default:
|
||||||
|
err = &NotSingularError{authidentitychannel.Label}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||||
|
func (_q *AuthIdentityChannelQuery) 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 AuthIdentityChannels.
|
||||||
|
func (_q *AuthIdentityChannelQuery) All(ctx context.Context) ([]*AuthIdentityChannel, error) {
|
||||||
|
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||||
|
if err := _q.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
qr := querierAll[[]*AuthIdentityChannel, *AuthIdentityChannelQuery]()
|
||||||
|
return withInterceptors[[]*AuthIdentityChannel](ctx, _q, qr, _q.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllX is like All, but panics if an error occurs.
|
||||||
|
func (_q *AuthIdentityChannelQuery) AllX(ctx context.Context) []*AuthIdentityChannel {
|
||||||
|
nodes, err := _q.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return nodes
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDs executes the query and returns a list of AuthIdentityChannel IDs.
|
||||||
|
func (_q *AuthIdentityChannelQuery) 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(authidentitychannel.FieldID).Scan(ctx, &ids); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ids, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDsX is like IDs, but panics if an error occurs.
|
||||||
|
func (_q *AuthIdentityChannelQuery) 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 *AuthIdentityChannelQuery) 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[*AuthIdentityChannelQuery](), _q.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountX is like Count, but panics if an error occurs.
|
||||||
|
func (_q *AuthIdentityChannelQuery) 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 *AuthIdentityChannelQuery) 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 *AuthIdentityChannelQuery) ExistX(ctx context.Context) bool {
|
||||||
|
exist, err := _q.Exist(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return exist
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone returns a duplicate of the AuthIdentityChannelQuery 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 *AuthIdentityChannelQuery) Clone() *AuthIdentityChannelQuery {
|
||||||
|
if _q == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &AuthIdentityChannelQuery{
|
||||||
|
config: _q.config,
|
||||||
|
ctx: _q.ctx.Clone(),
|
||||||
|
order: append([]authidentitychannel.OrderOption{}, _q.order...),
|
||||||
|
inters: append([]Interceptor{}, _q.inters...),
|
||||||
|
predicates: append([]predicate.AuthIdentityChannel{}, _q.predicates...),
|
||||||
|
withIdentity: _q.withIdentity.Clone(),
|
||||||
|
// clone intermediate query.
|
||||||
|
sql: _q.sql.Clone(),
|
||||||
|
path: _q.path,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithIdentity tells the query-builder to eager-load the nodes that are connected to
|
||||||
|
// the "identity" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (_q *AuthIdentityChannelQuery) WithIdentity(opts ...func(*AuthIdentityQuery)) *AuthIdentityChannelQuery {
|
||||||
|
query := (&AuthIdentityClient{config: _q.config}).Query()
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
_q.withIdentity = query
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// Count int `json:"count,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.AuthIdentityChannel.Query().
|
||||||
|
// GroupBy(authidentitychannel.FieldCreatedAt).
|
||||||
|
// Aggregate(ent.Count()).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (_q *AuthIdentityChannelQuery) GroupBy(field string, fields ...string) *AuthIdentityChannelGroupBy {
|
||||||
|
_q.ctx.Fields = append([]string{field}, fields...)
|
||||||
|
grbuild := &AuthIdentityChannelGroupBy{build: _q}
|
||||||
|
grbuild.flds = &_q.ctx.Fields
|
||||||
|
grbuild.label = authidentitychannel.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 {
|
||||||
|
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.AuthIdentityChannel.Query().
|
||||||
|
// Select(authidentitychannel.FieldCreatedAt).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (_q *AuthIdentityChannelQuery) Select(fields ...string) *AuthIdentityChannelSelect {
|
||||||
|
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||||
|
sbuild := &AuthIdentityChannelSelect{AuthIdentityChannelQuery: _q}
|
||||||
|
sbuild.label = authidentitychannel.Label
|
||||||
|
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||||
|
return sbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate returns a AuthIdentityChannelSelect configured with the given aggregations.
|
||||||
|
func (_q *AuthIdentityChannelQuery) Aggregate(fns ...AggregateFunc) *AuthIdentityChannelSelect {
|
||||||
|
return _q.Select().Aggregate(fns...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *AuthIdentityChannelQuery) 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 !authidentitychannel.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 *AuthIdentityChannelQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*AuthIdentityChannel, error) {
|
||||||
|
var (
|
||||||
|
nodes = []*AuthIdentityChannel{}
|
||||||
|
_spec = _q.querySpec()
|
||||||
|
loadedTypes = [1]bool{
|
||||||
|
_q.withIdentity != nil,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||||
|
return (*AuthIdentityChannel).scanValues(nil, columns)
|
||||||
|
}
|
||||||
|
_spec.Assign = func(columns []string, values []any) error {
|
||||||
|
node := &AuthIdentityChannel{config: _q.config}
|
||||||
|
nodes = append(nodes, node)
|
||||||
|
node.Edges.loadedTypes = loadedTypes
|
||||||
|
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
|
||||||
|
}
|
||||||
|
if query := _q.withIdentity; query != nil {
|
||||||
|
if err := _q.loadIdentity(ctx, query, nodes, nil,
|
||||||
|
func(n *AuthIdentityChannel, e *AuthIdentity) { n.Edges.Identity = e }); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *AuthIdentityChannelQuery) loadIdentity(ctx context.Context, query *AuthIdentityQuery, nodes []*AuthIdentityChannel, init func(*AuthIdentityChannel), assign func(*AuthIdentityChannel, *AuthIdentity)) error {
|
||||||
|
ids := make([]int64, 0, len(nodes))
|
||||||
|
nodeids := make(map[int64][]*AuthIdentityChannel)
|
||||||
|
for i := range nodes {
|
||||||
|
fk := nodes[i].IdentityID
|
||||||
|
if _, ok := nodeids[fk]; !ok {
|
||||||
|
ids = append(ids, fk)
|
||||||
|
}
|
||||||
|
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
query.Where(authidentity.IDIn(ids...))
|
||||||
|
neighbors, err := query.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, n := range neighbors {
|
||||||
|
nodes, ok := nodeids[n.ID]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(`unexpected foreign-key "identity_id" returned %v`, n.ID)
|
||||||
|
}
|
||||||
|
for i := range nodes {
|
||||||
|
assign(nodes[i], n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *AuthIdentityChannelQuery) 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 *AuthIdentityChannelQuery) querySpec() *sqlgraph.QuerySpec {
|
||||||
|
_spec := sqlgraph.NewQuerySpec(authidentitychannel.Table, authidentitychannel.Columns, sqlgraph.NewFieldSpec(authidentitychannel.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, authidentitychannel.FieldID)
|
||||||
|
for i := range fields {
|
||||||
|
if fields[i] != authidentitychannel.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _q.withIdentity != nil {
|
||||||
|
_spec.Node.AddColumnOnce(authidentitychannel.FieldIdentityID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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 *AuthIdentityChannelQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||||
|
builder := sql.Dialect(_q.driver.Dialect())
|
||||||
|
t1 := builder.Table(authidentitychannel.Table)
|
||||||
|
columns := _q.ctx.Fields
|
||||||
|
if len(columns) == 0 {
|
||||||
|
columns = authidentitychannel.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 *AuthIdentityChannelQuery) ForUpdate(opts ...sql.LockOption) *AuthIdentityChannelQuery {
|
||||||
|
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 *AuthIdentityChannelQuery) ForShare(opts ...sql.LockOption) *AuthIdentityChannelQuery {
|
||||||
|
if _q.driver.Dialect() == dialect.Postgres {
|
||||||
|
_q.Unique(false)
|
||||||
|
}
|
||||||
|
_q.modifiers = append(_q.modifiers, func(s *sql.Selector) {
|
||||||
|
s.ForShare(opts...)
|
||||||
|
})
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthIdentityChannelGroupBy is the group-by builder for AuthIdentityChannel entities.
|
||||||
|
type AuthIdentityChannelGroupBy struct {
|
||||||
|
selector
|
||||||
|
build *AuthIdentityChannelQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the group-by query.
|
||||||
|
func (_g *AuthIdentityChannelGroupBy) Aggregate(fns ...AggregateFunc) *AuthIdentityChannelGroupBy {
|
||||||
|
_g.fns = append(_g.fns, fns...)
|
||||||
|
return _g
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (_g *AuthIdentityChannelGroupBy) 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[*AuthIdentityChannelQuery, *AuthIdentityChannelGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_g *AuthIdentityChannelGroupBy) sqlScan(ctx context.Context, root *AuthIdentityChannelQuery, 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthIdentityChannelSelect is the builder for selecting fields of AuthIdentityChannel entities.
|
||||||
|
type AuthIdentityChannelSelect struct {
|
||||||
|
*AuthIdentityChannelQuery
|
||||||
|
selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the selector query.
|
||||||
|
func (_s *AuthIdentityChannelSelect) Aggregate(fns ...AggregateFunc) *AuthIdentityChannelSelect {
|
||||||
|
_s.fns = append(_s.fns, fns...)
|
||||||
|
return _s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (_s *AuthIdentityChannelSelect) 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[*AuthIdentityChannelQuery, *AuthIdentityChannelSelect](ctx, _s.AuthIdentityChannelQuery, _s, _s.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_s *AuthIdentityChannelSelect) sqlScan(ctx context.Context, root *AuthIdentityChannelQuery, 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)
|
||||||
|
}
|
||||||
@@ -0,0 +1,581 @@
|
|||||||
|
// 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/authidentity"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/authidentitychannel"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/predicate"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AuthIdentityChannelUpdate is the builder for updating AuthIdentityChannel entities.
|
||||||
|
type AuthIdentityChannelUpdate struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *AuthIdentityChannelMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the AuthIdentityChannelUpdate builder.
|
||||||
|
func (_u *AuthIdentityChannelUpdate) Where(ps ...predicate.AuthIdentityChannel) *AuthIdentityChannelUpdate {
|
||||||
|
_u.mutation.Where(ps...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (_u *AuthIdentityChannelUpdate) SetUpdatedAt(v time.Time) *AuthIdentityChannelUpdate {
|
||||||
|
_u.mutation.SetUpdatedAt(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIdentityID sets the "identity_id" field.
|
||||||
|
func (_u *AuthIdentityChannelUpdate) SetIdentityID(v int64) *AuthIdentityChannelUpdate {
|
||||||
|
_u.mutation.SetIdentityID(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableIdentityID sets the "identity_id" field if the given value is not nil.
|
||||||
|
func (_u *AuthIdentityChannelUpdate) SetNillableIdentityID(v *int64) *AuthIdentityChannelUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetIdentityID(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProviderType sets the "provider_type" field.
|
||||||
|
func (_u *AuthIdentityChannelUpdate) SetProviderType(v string) *AuthIdentityChannelUpdate {
|
||||||
|
_u.mutation.SetProviderType(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableProviderType sets the "provider_type" field if the given value is not nil.
|
||||||
|
func (_u *AuthIdentityChannelUpdate) SetNillableProviderType(v *string) *AuthIdentityChannelUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetProviderType(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProviderKey sets the "provider_key" field.
|
||||||
|
func (_u *AuthIdentityChannelUpdate) SetProviderKey(v string) *AuthIdentityChannelUpdate {
|
||||||
|
_u.mutation.SetProviderKey(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableProviderKey sets the "provider_key" field if the given value is not nil.
|
||||||
|
func (_u *AuthIdentityChannelUpdate) SetNillableProviderKey(v *string) *AuthIdentityChannelUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetProviderKey(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetChannel sets the "channel" field.
|
||||||
|
func (_u *AuthIdentityChannelUpdate) SetChannel(v string) *AuthIdentityChannelUpdate {
|
||||||
|
_u.mutation.SetChannel(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableChannel sets the "channel" field if the given value is not nil.
|
||||||
|
func (_u *AuthIdentityChannelUpdate) SetNillableChannel(v *string) *AuthIdentityChannelUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetChannel(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetChannelAppID sets the "channel_app_id" field.
|
||||||
|
func (_u *AuthIdentityChannelUpdate) SetChannelAppID(v string) *AuthIdentityChannelUpdate {
|
||||||
|
_u.mutation.SetChannelAppID(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableChannelAppID sets the "channel_app_id" field if the given value is not nil.
|
||||||
|
func (_u *AuthIdentityChannelUpdate) SetNillableChannelAppID(v *string) *AuthIdentityChannelUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetChannelAppID(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetChannelSubject sets the "channel_subject" field.
|
||||||
|
func (_u *AuthIdentityChannelUpdate) SetChannelSubject(v string) *AuthIdentityChannelUpdate {
|
||||||
|
_u.mutation.SetChannelSubject(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableChannelSubject sets the "channel_subject" field if the given value is not nil.
|
||||||
|
func (_u *AuthIdentityChannelUpdate) SetNillableChannelSubject(v *string) *AuthIdentityChannelUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetChannelSubject(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMetadata sets the "metadata" field.
|
||||||
|
func (_u *AuthIdentityChannelUpdate) SetMetadata(v map[string]interface{}) *AuthIdentityChannelUpdate {
|
||||||
|
_u.mutation.SetMetadata(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIdentity sets the "identity" edge to the AuthIdentity entity.
|
||||||
|
func (_u *AuthIdentityChannelUpdate) SetIdentity(v *AuthIdentity) *AuthIdentityChannelUpdate {
|
||||||
|
return _u.SetIdentityID(v.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the AuthIdentityChannelMutation object of the builder.
|
||||||
|
func (_u *AuthIdentityChannelUpdate) Mutation() *AuthIdentityChannelMutation {
|
||||||
|
return _u.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearIdentity clears the "identity" edge to the AuthIdentity entity.
|
||||||
|
func (_u *AuthIdentityChannelUpdate) ClearIdentity() *AuthIdentityChannelUpdate {
|
||||||
|
_u.mutation.ClearIdentity()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||||
|
func (_u *AuthIdentityChannelUpdate) 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 *AuthIdentityChannelUpdate) SaveX(ctx context.Context) int {
|
||||||
|
affected, err := _u.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return affected
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (_u *AuthIdentityChannelUpdate) Exec(ctx context.Context) error {
|
||||||
|
_, err := _u.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_u *AuthIdentityChannelUpdate) 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 *AuthIdentityChannelUpdate) defaults() {
|
||||||
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
||||||
|
v := authidentitychannel.UpdateDefaultUpdatedAt()
|
||||||
|
_u.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (_u *AuthIdentityChannelUpdate) check() error {
|
||||||
|
if v, ok := _u.mutation.ProviderType(); ok {
|
||||||
|
if err := authidentitychannel.ProviderTypeValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "provider_type", err: fmt.Errorf(`ent: validator failed for field "AuthIdentityChannel.provider_type": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := _u.mutation.ProviderKey(); ok {
|
||||||
|
if err := authidentitychannel.ProviderKeyValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "provider_key", err: fmt.Errorf(`ent: validator failed for field "AuthIdentityChannel.provider_key": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := _u.mutation.Channel(); ok {
|
||||||
|
if err := authidentitychannel.ChannelValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "channel", err: fmt.Errorf(`ent: validator failed for field "AuthIdentityChannel.channel": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := _u.mutation.ChannelAppID(); ok {
|
||||||
|
if err := authidentitychannel.ChannelAppIDValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "channel_app_id", err: fmt.Errorf(`ent: validator failed for field "AuthIdentityChannel.channel_app_id": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := _u.mutation.ChannelSubject(); ok {
|
||||||
|
if err := authidentitychannel.ChannelSubjectValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "channel_subject", err: fmt.Errorf(`ent: validator failed for field "AuthIdentityChannel.channel_subject": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _u.mutation.IdentityCleared() && len(_u.mutation.IdentityIDs()) > 0 {
|
||||||
|
return errors.New(`ent: clearing a required unique edge "AuthIdentityChannel.identity"`)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_u *AuthIdentityChannelUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||||
|
if err := _u.check(); err != nil {
|
||||||
|
return _node, err
|
||||||
|
}
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(authidentitychannel.Table, authidentitychannel.Columns, sqlgraph.NewFieldSpec(authidentitychannel.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.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(authidentitychannel.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.ProviderType(); ok {
|
||||||
|
_spec.SetField(authidentitychannel.FieldProviderType, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.ProviderKey(); ok {
|
||||||
|
_spec.SetField(authidentitychannel.FieldProviderKey, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Channel(); ok {
|
||||||
|
_spec.SetField(authidentitychannel.FieldChannel, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.ChannelAppID(); ok {
|
||||||
|
_spec.SetField(authidentitychannel.FieldChannelAppID, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.ChannelSubject(); ok {
|
||||||
|
_spec.SetField(authidentitychannel.FieldChannelSubject, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Metadata(); ok {
|
||||||
|
_spec.SetField(authidentitychannel.FieldMetadata, field.TypeJSON, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.IdentityCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: authidentitychannel.IdentityTable,
|
||||||
|
Columns: []string{authidentitychannel.IdentityColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := _u.mutation.IdentityIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: authidentitychannel.IdentityTable,
|
||||||
|
Columns: []string{authidentitychannel.IdentityColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(authidentity.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{authidentitychannel.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
_u.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthIdentityChannelUpdateOne is the builder for updating a single AuthIdentityChannel entity.
|
||||||
|
type AuthIdentityChannelUpdateOne struct {
|
||||||
|
config
|
||||||
|
fields []string
|
||||||
|
hooks []Hook
|
||||||
|
mutation *AuthIdentityChannelMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (_u *AuthIdentityChannelUpdateOne) SetUpdatedAt(v time.Time) *AuthIdentityChannelUpdateOne {
|
||||||
|
_u.mutation.SetUpdatedAt(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIdentityID sets the "identity_id" field.
|
||||||
|
func (_u *AuthIdentityChannelUpdateOne) SetIdentityID(v int64) *AuthIdentityChannelUpdateOne {
|
||||||
|
_u.mutation.SetIdentityID(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableIdentityID sets the "identity_id" field if the given value is not nil.
|
||||||
|
func (_u *AuthIdentityChannelUpdateOne) SetNillableIdentityID(v *int64) *AuthIdentityChannelUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetIdentityID(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProviderType sets the "provider_type" field.
|
||||||
|
func (_u *AuthIdentityChannelUpdateOne) SetProviderType(v string) *AuthIdentityChannelUpdateOne {
|
||||||
|
_u.mutation.SetProviderType(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableProviderType sets the "provider_type" field if the given value is not nil.
|
||||||
|
func (_u *AuthIdentityChannelUpdateOne) SetNillableProviderType(v *string) *AuthIdentityChannelUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetProviderType(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProviderKey sets the "provider_key" field.
|
||||||
|
func (_u *AuthIdentityChannelUpdateOne) SetProviderKey(v string) *AuthIdentityChannelUpdateOne {
|
||||||
|
_u.mutation.SetProviderKey(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableProviderKey sets the "provider_key" field if the given value is not nil.
|
||||||
|
func (_u *AuthIdentityChannelUpdateOne) SetNillableProviderKey(v *string) *AuthIdentityChannelUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetProviderKey(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetChannel sets the "channel" field.
|
||||||
|
func (_u *AuthIdentityChannelUpdateOne) SetChannel(v string) *AuthIdentityChannelUpdateOne {
|
||||||
|
_u.mutation.SetChannel(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableChannel sets the "channel" field if the given value is not nil.
|
||||||
|
func (_u *AuthIdentityChannelUpdateOne) SetNillableChannel(v *string) *AuthIdentityChannelUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetChannel(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetChannelAppID sets the "channel_app_id" field.
|
||||||
|
func (_u *AuthIdentityChannelUpdateOne) SetChannelAppID(v string) *AuthIdentityChannelUpdateOne {
|
||||||
|
_u.mutation.SetChannelAppID(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableChannelAppID sets the "channel_app_id" field if the given value is not nil.
|
||||||
|
func (_u *AuthIdentityChannelUpdateOne) SetNillableChannelAppID(v *string) *AuthIdentityChannelUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetChannelAppID(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetChannelSubject sets the "channel_subject" field.
|
||||||
|
func (_u *AuthIdentityChannelUpdateOne) SetChannelSubject(v string) *AuthIdentityChannelUpdateOne {
|
||||||
|
_u.mutation.SetChannelSubject(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableChannelSubject sets the "channel_subject" field if the given value is not nil.
|
||||||
|
func (_u *AuthIdentityChannelUpdateOne) SetNillableChannelSubject(v *string) *AuthIdentityChannelUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetChannelSubject(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMetadata sets the "metadata" field.
|
||||||
|
func (_u *AuthIdentityChannelUpdateOne) SetMetadata(v map[string]interface{}) *AuthIdentityChannelUpdateOne {
|
||||||
|
_u.mutation.SetMetadata(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIdentity sets the "identity" edge to the AuthIdentity entity.
|
||||||
|
func (_u *AuthIdentityChannelUpdateOne) SetIdentity(v *AuthIdentity) *AuthIdentityChannelUpdateOne {
|
||||||
|
return _u.SetIdentityID(v.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the AuthIdentityChannelMutation object of the builder.
|
||||||
|
func (_u *AuthIdentityChannelUpdateOne) Mutation() *AuthIdentityChannelMutation {
|
||||||
|
return _u.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearIdentity clears the "identity" edge to the AuthIdentity entity.
|
||||||
|
func (_u *AuthIdentityChannelUpdateOne) ClearIdentity() *AuthIdentityChannelUpdateOne {
|
||||||
|
_u.mutation.ClearIdentity()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the AuthIdentityChannelUpdate builder.
|
||||||
|
func (_u *AuthIdentityChannelUpdateOne) Where(ps ...predicate.AuthIdentityChannel) *AuthIdentityChannelUpdateOne {
|
||||||
|
_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 *AuthIdentityChannelUpdateOne) Select(field string, fields ...string) *AuthIdentityChannelUpdateOne {
|
||||||
|
_u.fields = append([]string{field}, fields...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the updated AuthIdentityChannel entity.
|
||||||
|
func (_u *AuthIdentityChannelUpdateOne) Save(ctx context.Context) (*AuthIdentityChannel, error) {
|
||||||
|
_u.defaults()
|
||||||
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (_u *AuthIdentityChannelUpdateOne) SaveX(ctx context.Context) *AuthIdentityChannel {
|
||||||
|
node, err := _u.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query on the entity.
|
||||||
|
func (_u *AuthIdentityChannelUpdateOne) Exec(ctx context.Context) error {
|
||||||
|
_, err := _u.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_u *AuthIdentityChannelUpdateOne) 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 *AuthIdentityChannelUpdateOne) defaults() {
|
||||||
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
||||||
|
v := authidentitychannel.UpdateDefaultUpdatedAt()
|
||||||
|
_u.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (_u *AuthIdentityChannelUpdateOne) check() error {
|
||||||
|
if v, ok := _u.mutation.ProviderType(); ok {
|
||||||
|
if err := authidentitychannel.ProviderTypeValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "provider_type", err: fmt.Errorf(`ent: validator failed for field "AuthIdentityChannel.provider_type": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := _u.mutation.ProviderKey(); ok {
|
||||||
|
if err := authidentitychannel.ProviderKeyValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "provider_key", err: fmt.Errorf(`ent: validator failed for field "AuthIdentityChannel.provider_key": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := _u.mutation.Channel(); ok {
|
||||||
|
if err := authidentitychannel.ChannelValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "channel", err: fmt.Errorf(`ent: validator failed for field "AuthIdentityChannel.channel": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := _u.mutation.ChannelAppID(); ok {
|
||||||
|
if err := authidentitychannel.ChannelAppIDValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "channel_app_id", err: fmt.Errorf(`ent: validator failed for field "AuthIdentityChannel.channel_app_id": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := _u.mutation.ChannelSubject(); ok {
|
||||||
|
if err := authidentitychannel.ChannelSubjectValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "channel_subject", err: fmt.Errorf(`ent: validator failed for field "AuthIdentityChannel.channel_subject": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _u.mutation.IdentityCleared() && len(_u.mutation.IdentityIDs()) > 0 {
|
||||||
|
return errors.New(`ent: clearing a required unique edge "AuthIdentityChannel.identity"`)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_u *AuthIdentityChannelUpdateOne) sqlSave(ctx context.Context) (_node *AuthIdentityChannel, err error) {
|
||||||
|
if err := _u.check(); err != nil {
|
||||||
|
return _node, err
|
||||||
|
}
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(authidentitychannel.Table, authidentitychannel.Columns, sqlgraph.NewFieldSpec(authidentitychannel.FieldID, field.TypeInt64))
|
||||||
|
id, ok := _u.mutation.ID()
|
||||||
|
if !ok {
|
||||||
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "AuthIdentityChannel.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, authidentitychannel.FieldID)
|
||||||
|
for _, f := range fields {
|
||||||
|
if !authidentitychannel.ValidColumn(f) {
|
||||||
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
if f != authidentitychannel.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.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(authidentitychannel.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.ProviderType(); ok {
|
||||||
|
_spec.SetField(authidentitychannel.FieldProviderType, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.ProviderKey(); ok {
|
||||||
|
_spec.SetField(authidentitychannel.FieldProviderKey, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Channel(); ok {
|
||||||
|
_spec.SetField(authidentitychannel.FieldChannel, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.ChannelAppID(); ok {
|
||||||
|
_spec.SetField(authidentitychannel.FieldChannelAppID, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.ChannelSubject(); ok {
|
||||||
|
_spec.SetField(authidentitychannel.FieldChannelSubject, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Metadata(); ok {
|
||||||
|
_spec.SetField(authidentitychannel.FieldMetadata, field.TypeJSON, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.IdentityCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: authidentitychannel.IdentityTable,
|
||||||
|
Columns: []string{authidentitychannel.IdentityColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := _u.mutation.IdentityIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: authidentitychannel.IdentityTable,
|
||||||
|
Columns: []string{authidentitychannel.IdentityColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
_node = &AuthIdentityChannel{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{authidentitychannel.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_u.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
+746
-18
@@ -20,12 +20,16 @@ import (
|
|||||||
"github.com/Wei-Shaw/sub2api/ent/announcement"
|
"github.com/Wei-Shaw/sub2api/ent/announcement"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/announcementread"
|
"github.com/Wei-Shaw/sub2api/ent/announcementread"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/apikey"
|
"github.com/Wei-Shaw/sub2api/ent/apikey"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/authidentity"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/authidentitychannel"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/errorpassthroughrule"
|
"github.com/Wei-Shaw/sub2api/ent/errorpassthroughrule"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/group"
|
"github.com/Wei-Shaw/sub2api/ent/group"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/idempotencyrecord"
|
"github.com/Wei-Shaw/sub2api/ent/idempotencyrecord"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/identityadoptiondecision"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/paymentauditlog"
|
"github.com/Wei-Shaw/sub2api/ent/paymentauditlog"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/paymentorder"
|
"github.com/Wei-Shaw/sub2api/ent/paymentorder"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/paymentproviderinstance"
|
"github.com/Wei-Shaw/sub2api/ent/paymentproviderinstance"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/pendingauthsession"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/promocode"
|
"github.com/Wei-Shaw/sub2api/ent/promocode"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
|
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/proxy"
|
"github.com/Wei-Shaw/sub2api/ent/proxy"
|
||||||
@@ -60,18 +64,26 @@ type Client struct {
|
|||||||
Announcement *AnnouncementClient
|
Announcement *AnnouncementClient
|
||||||
// AnnouncementRead is the client for interacting with the AnnouncementRead builders.
|
// AnnouncementRead is the client for interacting with the AnnouncementRead builders.
|
||||||
AnnouncementRead *AnnouncementReadClient
|
AnnouncementRead *AnnouncementReadClient
|
||||||
|
// AuthIdentity is the client for interacting with the AuthIdentity builders.
|
||||||
|
AuthIdentity *AuthIdentityClient
|
||||||
|
// AuthIdentityChannel is the client for interacting with the AuthIdentityChannel builders.
|
||||||
|
AuthIdentityChannel *AuthIdentityChannelClient
|
||||||
// ErrorPassthroughRule is the client for interacting with the ErrorPassthroughRule builders.
|
// ErrorPassthroughRule is the client for interacting with the ErrorPassthroughRule builders.
|
||||||
ErrorPassthroughRule *ErrorPassthroughRuleClient
|
ErrorPassthroughRule *ErrorPassthroughRuleClient
|
||||||
// Group is the client for interacting with the Group builders.
|
// Group is the client for interacting with the Group builders.
|
||||||
Group *GroupClient
|
Group *GroupClient
|
||||||
// IdempotencyRecord is the client for interacting with the IdempotencyRecord builders.
|
// IdempotencyRecord is the client for interacting with the IdempotencyRecord builders.
|
||||||
IdempotencyRecord *IdempotencyRecordClient
|
IdempotencyRecord *IdempotencyRecordClient
|
||||||
|
// IdentityAdoptionDecision is the client for interacting with the IdentityAdoptionDecision builders.
|
||||||
|
IdentityAdoptionDecision *IdentityAdoptionDecisionClient
|
||||||
// PaymentAuditLog is the client for interacting with the PaymentAuditLog builders.
|
// PaymentAuditLog is the client for interacting with the PaymentAuditLog builders.
|
||||||
PaymentAuditLog *PaymentAuditLogClient
|
PaymentAuditLog *PaymentAuditLogClient
|
||||||
// PaymentOrder is the client for interacting with the PaymentOrder builders.
|
// PaymentOrder is the client for interacting with the PaymentOrder builders.
|
||||||
PaymentOrder *PaymentOrderClient
|
PaymentOrder *PaymentOrderClient
|
||||||
// PaymentProviderInstance is the client for interacting with the PaymentProviderInstance builders.
|
// PaymentProviderInstance is the client for interacting with the PaymentProviderInstance builders.
|
||||||
PaymentProviderInstance *PaymentProviderInstanceClient
|
PaymentProviderInstance *PaymentProviderInstanceClient
|
||||||
|
// PendingAuthSession is the client for interacting with the PendingAuthSession builders.
|
||||||
|
PendingAuthSession *PendingAuthSessionClient
|
||||||
// PromoCode is the client for interacting with the PromoCode builders.
|
// PromoCode is the client for interacting with the PromoCode builders.
|
||||||
PromoCode *PromoCodeClient
|
PromoCode *PromoCodeClient
|
||||||
// PromoCodeUsage is the client for interacting with the PromoCodeUsage builders.
|
// PromoCodeUsage is the client for interacting with the PromoCodeUsage builders.
|
||||||
@@ -118,12 +130,16 @@ func (c *Client) init() {
|
|||||||
c.AccountGroup = NewAccountGroupClient(c.config)
|
c.AccountGroup = NewAccountGroupClient(c.config)
|
||||||
c.Announcement = NewAnnouncementClient(c.config)
|
c.Announcement = NewAnnouncementClient(c.config)
|
||||||
c.AnnouncementRead = NewAnnouncementReadClient(c.config)
|
c.AnnouncementRead = NewAnnouncementReadClient(c.config)
|
||||||
|
c.AuthIdentity = NewAuthIdentityClient(c.config)
|
||||||
|
c.AuthIdentityChannel = NewAuthIdentityChannelClient(c.config)
|
||||||
c.ErrorPassthroughRule = NewErrorPassthroughRuleClient(c.config)
|
c.ErrorPassthroughRule = NewErrorPassthroughRuleClient(c.config)
|
||||||
c.Group = NewGroupClient(c.config)
|
c.Group = NewGroupClient(c.config)
|
||||||
c.IdempotencyRecord = NewIdempotencyRecordClient(c.config)
|
c.IdempotencyRecord = NewIdempotencyRecordClient(c.config)
|
||||||
|
c.IdentityAdoptionDecision = NewIdentityAdoptionDecisionClient(c.config)
|
||||||
c.PaymentAuditLog = NewPaymentAuditLogClient(c.config)
|
c.PaymentAuditLog = NewPaymentAuditLogClient(c.config)
|
||||||
c.PaymentOrder = NewPaymentOrderClient(c.config)
|
c.PaymentOrder = NewPaymentOrderClient(c.config)
|
||||||
c.PaymentProviderInstance = NewPaymentProviderInstanceClient(c.config)
|
c.PaymentProviderInstance = NewPaymentProviderInstanceClient(c.config)
|
||||||
|
c.PendingAuthSession = NewPendingAuthSessionClient(c.config)
|
||||||
c.PromoCode = NewPromoCodeClient(c.config)
|
c.PromoCode = NewPromoCodeClient(c.config)
|
||||||
c.PromoCodeUsage = NewPromoCodeUsageClient(c.config)
|
c.PromoCodeUsage = NewPromoCodeUsageClient(c.config)
|
||||||
c.Proxy = NewProxyClient(c.config)
|
c.Proxy = NewProxyClient(c.config)
|
||||||
@@ -236,12 +252,16 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
|||||||
AccountGroup: NewAccountGroupClient(cfg),
|
AccountGroup: NewAccountGroupClient(cfg),
|
||||||
Announcement: NewAnnouncementClient(cfg),
|
Announcement: NewAnnouncementClient(cfg),
|
||||||
AnnouncementRead: NewAnnouncementReadClient(cfg),
|
AnnouncementRead: NewAnnouncementReadClient(cfg),
|
||||||
|
AuthIdentity: NewAuthIdentityClient(cfg),
|
||||||
|
AuthIdentityChannel: NewAuthIdentityChannelClient(cfg),
|
||||||
ErrorPassthroughRule: NewErrorPassthroughRuleClient(cfg),
|
ErrorPassthroughRule: NewErrorPassthroughRuleClient(cfg),
|
||||||
Group: NewGroupClient(cfg),
|
Group: NewGroupClient(cfg),
|
||||||
IdempotencyRecord: NewIdempotencyRecordClient(cfg),
|
IdempotencyRecord: NewIdempotencyRecordClient(cfg),
|
||||||
|
IdentityAdoptionDecision: NewIdentityAdoptionDecisionClient(cfg),
|
||||||
PaymentAuditLog: NewPaymentAuditLogClient(cfg),
|
PaymentAuditLog: NewPaymentAuditLogClient(cfg),
|
||||||
PaymentOrder: NewPaymentOrderClient(cfg),
|
PaymentOrder: NewPaymentOrderClient(cfg),
|
||||||
PaymentProviderInstance: NewPaymentProviderInstanceClient(cfg),
|
PaymentProviderInstance: NewPaymentProviderInstanceClient(cfg),
|
||||||
|
PendingAuthSession: NewPendingAuthSessionClient(cfg),
|
||||||
PromoCode: NewPromoCodeClient(cfg),
|
PromoCode: NewPromoCodeClient(cfg),
|
||||||
PromoCodeUsage: NewPromoCodeUsageClient(cfg),
|
PromoCodeUsage: NewPromoCodeUsageClient(cfg),
|
||||||
Proxy: NewProxyClient(cfg),
|
Proxy: NewProxyClient(cfg),
|
||||||
@@ -281,12 +301,16 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
|
|||||||
AccountGroup: NewAccountGroupClient(cfg),
|
AccountGroup: NewAccountGroupClient(cfg),
|
||||||
Announcement: NewAnnouncementClient(cfg),
|
Announcement: NewAnnouncementClient(cfg),
|
||||||
AnnouncementRead: NewAnnouncementReadClient(cfg),
|
AnnouncementRead: NewAnnouncementReadClient(cfg),
|
||||||
|
AuthIdentity: NewAuthIdentityClient(cfg),
|
||||||
|
AuthIdentityChannel: NewAuthIdentityChannelClient(cfg),
|
||||||
ErrorPassthroughRule: NewErrorPassthroughRuleClient(cfg),
|
ErrorPassthroughRule: NewErrorPassthroughRuleClient(cfg),
|
||||||
Group: NewGroupClient(cfg),
|
Group: NewGroupClient(cfg),
|
||||||
IdempotencyRecord: NewIdempotencyRecordClient(cfg),
|
IdempotencyRecord: NewIdempotencyRecordClient(cfg),
|
||||||
|
IdentityAdoptionDecision: NewIdentityAdoptionDecisionClient(cfg),
|
||||||
PaymentAuditLog: NewPaymentAuditLogClient(cfg),
|
PaymentAuditLog: NewPaymentAuditLogClient(cfg),
|
||||||
PaymentOrder: NewPaymentOrderClient(cfg),
|
PaymentOrder: NewPaymentOrderClient(cfg),
|
||||||
PaymentProviderInstance: NewPaymentProviderInstanceClient(cfg),
|
PaymentProviderInstance: NewPaymentProviderInstanceClient(cfg),
|
||||||
|
PendingAuthSession: NewPendingAuthSessionClient(cfg),
|
||||||
PromoCode: NewPromoCodeClient(cfg),
|
PromoCode: NewPromoCodeClient(cfg),
|
||||||
PromoCodeUsage: NewPromoCodeUsageClient(cfg),
|
PromoCodeUsage: NewPromoCodeUsageClient(cfg),
|
||||||
Proxy: NewProxyClient(cfg),
|
Proxy: NewProxyClient(cfg),
|
||||||
@@ -332,11 +356,12 @@ func (c *Client) Close() error {
|
|||||||
func (c *Client) Use(hooks ...Hook) {
|
func (c *Client) Use(hooks ...Hook) {
|
||||||
for _, n := range []interface{ Use(...Hook) }{
|
for _, n := range []interface{ Use(...Hook) }{
|
||||||
c.APIKey, c.Account, c.AccountGroup, c.Announcement, c.AnnouncementRead,
|
c.APIKey, c.Account, c.AccountGroup, c.Announcement, c.AnnouncementRead,
|
||||||
c.ErrorPassthroughRule, c.Group, c.IdempotencyRecord, c.PaymentAuditLog,
|
c.AuthIdentity, c.AuthIdentityChannel, c.ErrorPassthroughRule, c.Group,
|
||||||
c.PaymentOrder, c.PaymentProviderInstance, c.PromoCode, c.PromoCodeUsage,
|
c.IdempotencyRecord, c.IdentityAdoptionDecision, c.PaymentAuditLog,
|
||||||
c.Proxy, c.RedeemCode, c.SecuritySecret, c.Setting, c.SubscriptionPlan,
|
c.PaymentOrder, c.PaymentProviderInstance, c.PendingAuthSession, c.PromoCode,
|
||||||
c.TLSFingerprintProfile, c.UsageCleanupTask, c.UsageLog, c.User,
|
c.PromoCodeUsage, c.Proxy, c.RedeemCode, c.SecuritySecret, c.Setting,
|
||||||
c.UserAllowedGroup, c.UserAttributeDefinition, c.UserAttributeValue,
|
c.SubscriptionPlan, c.TLSFingerprintProfile, c.UsageCleanupTask, c.UsageLog,
|
||||||
|
c.User, c.UserAllowedGroup, c.UserAttributeDefinition, c.UserAttributeValue,
|
||||||
c.UserSubscription,
|
c.UserSubscription,
|
||||||
} {
|
} {
|
||||||
n.Use(hooks...)
|
n.Use(hooks...)
|
||||||
@@ -348,11 +373,12 @@ func (c *Client) Use(hooks ...Hook) {
|
|||||||
func (c *Client) Intercept(interceptors ...Interceptor) {
|
func (c *Client) Intercept(interceptors ...Interceptor) {
|
||||||
for _, n := range []interface{ Intercept(...Interceptor) }{
|
for _, n := range []interface{ Intercept(...Interceptor) }{
|
||||||
c.APIKey, c.Account, c.AccountGroup, c.Announcement, c.AnnouncementRead,
|
c.APIKey, c.Account, c.AccountGroup, c.Announcement, c.AnnouncementRead,
|
||||||
c.ErrorPassthroughRule, c.Group, c.IdempotencyRecord, c.PaymentAuditLog,
|
c.AuthIdentity, c.AuthIdentityChannel, c.ErrorPassthroughRule, c.Group,
|
||||||
c.PaymentOrder, c.PaymentProviderInstance, c.PromoCode, c.PromoCodeUsage,
|
c.IdempotencyRecord, c.IdentityAdoptionDecision, c.PaymentAuditLog,
|
||||||
c.Proxy, c.RedeemCode, c.SecuritySecret, c.Setting, c.SubscriptionPlan,
|
c.PaymentOrder, c.PaymentProviderInstance, c.PendingAuthSession, c.PromoCode,
|
||||||
c.TLSFingerprintProfile, c.UsageCleanupTask, c.UsageLog, c.User,
|
c.PromoCodeUsage, c.Proxy, c.RedeemCode, c.SecuritySecret, c.Setting,
|
||||||
c.UserAllowedGroup, c.UserAttributeDefinition, c.UserAttributeValue,
|
c.SubscriptionPlan, c.TLSFingerprintProfile, c.UsageCleanupTask, c.UsageLog,
|
||||||
|
c.User, c.UserAllowedGroup, c.UserAttributeDefinition, c.UserAttributeValue,
|
||||||
c.UserSubscription,
|
c.UserSubscription,
|
||||||
} {
|
} {
|
||||||
n.Intercept(interceptors...)
|
n.Intercept(interceptors...)
|
||||||
@@ -372,18 +398,26 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
|||||||
return c.Announcement.mutate(ctx, m)
|
return c.Announcement.mutate(ctx, m)
|
||||||
case *AnnouncementReadMutation:
|
case *AnnouncementReadMutation:
|
||||||
return c.AnnouncementRead.mutate(ctx, m)
|
return c.AnnouncementRead.mutate(ctx, m)
|
||||||
|
case *AuthIdentityMutation:
|
||||||
|
return c.AuthIdentity.mutate(ctx, m)
|
||||||
|
case *AuthIdentityChannelMutation:
|
||||||
|
return c.AuthIdentityChannel.mutate(ctx, m)
|
||||||
case *ErrorPassthroughRuleMutation:
|
case *ErrorPassthroughRuleMutation:
|
||||||
return c.ErrorPassthroughRule.mutate(ctx, m)
|
return c.ErrorPassthroughRule.mutate(ctx, m)
|
||||||
case *GroupMutation:
|
case *GroupMutation:
|
||||||
return c.Group.mutate(ctx, m)
|
return c.Group.mutate(ctx, m)
|
||||||
case *IdempotencyRecordMutation:
|
case *IdempotencyRecordMutation:
|
||||||
return c.IdempotencyRecord.mutate(ctx, m)
|
return c.IdempotencyRecord.mutate(ctx, m)
|
||||||
|
case *IdentityAdoptionDecisionMutation:
|
||||||
|
return c.IdentityAdoptionDecision.mutate(ctx, m)
|
||||||
case *PaymentAuditLogMutation:
|
case *PaymentAuditLogMutation:
|
||||||
return c.PaymentAuditLog.mutate(ctx, m)
|
return c.PaymentAuditLog.mutate(ctx, m)
|
||||||
case *PaymentOrderMutation:
|
case *PaymentOrderMutation:
|
||||||
return c.PaymentOrder.mutate(ctx, m)
|
return c.PaymentOrder.mutate(ctx, m)
|
||||||
case *PaymentProviderInstanceMutation:
|
case *PaymentProviderInstanceMutation:
|
||||||
return c.PaymentProviderInstance.mutate(ctx, m)
|
return c.PaymentProviderInstance.mutate(ctx, m)
|
||||||
|
case *PendingAuthSessionMutation:
|
||||||
|
return c.PendingAuthSession.mutate(ctx, m)
|
||||||
case *PromoCodeMutation:
|
case *PromoCodeMutation:
|
||||||
return c.PromoCode.mutate(ctx, m)
|
return c.PromoCode.mutate(ctx, m)
|
||||||
case *PromoCodeUsageMutation:
|
case *PromoCodeUsageMutation:
|
||||||
@@ -1231,6 +1265,336 @@ func (c *AnnouncementReadClient) mutate(ctx context.Context, m *AnnouncementRead
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AuthIdentityClient is a client for the AuthIdentity schema.
|
||||||
|
type AuthIdentityClient struct {
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewAuthIdentityClient returns a client for the AuthIdentity from the given config.
|
||||||
|
func NewAuthIdentityClient(c config) *AuthIdentityClient {
|
||||||
|
return &AuthIdentityClient{config: c}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||||||
|
// A call to `Use(f, g, h)` equals to `authidentity.Hooks(f(g(h())))`.
|
||||||
|
func (c *AuthIdentityClient) Use(hooks ...Hook) {
|
||||||
|
c.hooks.AuthIdentity = append(c.hooks.AuthIdentity, hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||||
|
// A call to `Intercept(f, g, h)` equals to `authidentity.Intercept(f(g(h())))`.
|
||||||
|
func (c *AuthIdentityClient) Intercept(interceptors ...Interceptor) {
|
||||||
|
c.inters.AuthIdentity = append(c.inters.AuthIdentity, interceptors...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create returns a builder for creating a AuthIdentity entity.
|
||||||
|
func (c *AuthIdentityClient) Create() *AuthIdentityCreate {
|
||||||
|
mutation := newAuthIdentityMutation(c.config, OpCreate)
|
||||||
|
return &AuthIdentityCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateBulk returns a builder for creating a bulk of AuthIdentity entities.
|
||||||
|
func (c *AuthIdentityClient) CreateBulk(builders ...*AuthIdentityCreate) *AuthIdentityCreateBulk {
|
||||||
|
return &AuthIdentityCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||||
|
// a builder and applies setFunc on it.
|
||||||
|
func (c *AuthIdentityClient) MapCreateBulk(slice any, setFunc func(*AuthIdentityCreate, int)) *AuthIdentityCreateBulk {
|
||||||
|
rv := reflect.ValueOf(slice)
|
||||||
|
if rv.Kind() != reflect.Slice {
|
||||||
|
return &AuthIdentityCreateBulk{err: fmt.Errorf("calling to AuthIdentityClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||||
|
}
|
||||||
|
builders := make([]*AuthIdentityCreate, rv.Len())
|
||||||
|
for i := 0; i < rv.Len(); i++ {
|
||||||
|
builders[i] = c.Create()
|
||||||
|
setFunc(builders[i], i)
|
||||||
|
}
|
||||||
|
return &AuthIdentityCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns an update builder for AuthIdentity.
|
||||||
|
func (c *AuthIdentityClient) Update() *AuthIdentityUpdate {
|
||||||
|
mutation := newAuthIdentityMutation(c.config, OpUpdate)
|
||||||
|
return &AuthIdentityUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOne returns an update builder for the given entity.
|
||||||
|
func (c *AuthIdentityClient) UpdateOne(_m *AuthIdentity) *AuthIdentityUpdateOne {
|
||||||
|
mutation := newAuthIdentityMutation(c.config, OpUpdateOne, withAuthIdentity(_m))
|
||||||
|
return &AuthIdentityUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOneID returns an update builder for the given id.
|
||||||
|
func (c *AuthIdentityClient) UpdateOneID(id int64) *AuthIdentityUpdateOne {
|
||||||
|
mutation := newAuthIdentityMutation(c.config, OpUpdateOne, withAuthIdentityID(id))
|
||||||
|
return &AuthIdentityUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete returns a delete builder for AuthIdentity.
|
||||||
|
func (c *AuthIdentityClient) Delete() *AuthIdentityDelete {
|
||||||
|
mutation := newAuthIdentityMutation(c.config, OpDelete)
|
||||||
|
return &AuthIdentityDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOne returns a builder for deleting the given entity.
|
||||||
|
func (c *AuthIdentityClient) DeleteOne(_m *AuthIdentity) *AuthIdentityDeleteOne {
|
||||||
|
return c.DeleteOneID(_m.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||||
|
func (c *AuthIdentityClient) DeleteOneID(id int64) *AuthIdentityDeleteOne {
|
||||||
|
builder := c.Delete().Where(authidentity.ID(id))
|
||||||
|
builder.mutation.id = &id
|
||||||
|
builder.mutation.op = OpDeleteOne
|
||||||
|
return &AuthIdentityDeleteOne{builder}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query returns a query builder for AuthIdentity.
|
||||||
|
func (c *AuthIdentityClient) Query() *AuthIdentityQuery {
|
||||||
|
return &AuthIdentityQuery{
|
||||||
|
config: c.config,
|
||||||
|
ctx: &QueryContext{Type: TypeAuthIdentity},
|
||||||
|
inters: c.Interceptors(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns a AuthIdentity entity by its id.
|
||||||
|
func (c *AuthIdentityClient) Get(ctx context.Context, id int64) (*AuthIdentity, error) {
|
||||||
|
return c.Query().Where(authidentity.ID(id)).Only(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetX is like Get, but panics if an error occurs.
|
||||||
|
func (c *AuthIdentityClient) GetX(ctx context.Context, id int64) *AuthIdentity {
|
||||||
|
obj, err := c.Get(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryUser queries the user edge of a AuthIdentity.
|
||||||
|
func (c *AuthIdentityClient) QueryUser(_m *AuthIdentity) *UserQuery {
|
||||||
|
query := (&UserClient{config: c.config}).Query()
|
||||||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := _m.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(authidentity.Table, authidentity.FieldID, id),
|
||||||
|
sqlgraph.To(user.Table, user.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, authidentity.UserTable, authidentity.UserColumn),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryChannels queries the channels edge of a AuthIdentity.
|
||||||
|
func (c *AuthIdentityClient) QueryChannels(_m *AuthIdentity) *AuthIdentityChannelQuery {
|
||||||
|
query := (&AuthIdentityChannelClient{config: c.config}).Query()
|
||||||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := _m.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(authidentity.Table, authidentity.FieldID, id),
|
||||||
|
sqlgraph.To(authidentitychannel.Table, authidentitychannel.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, authidentity.ChannelsTable, authidentity.ChannelsColumn),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryAdoptionDecisions queries the adoption_decisions edge of a AuthIdentity.
|
||||||
|
func (c *AuthIdentityClient) QueryAdoptionDecisions(_m *AuthIdentity) *IdentityAdoptionDecisionQuery {
|
||||||
|
query := (&IdentityAdoptionDecisionClient{config: c.config}).Query()
|
||||||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := _m.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(authidentity.Table, authidentity.FieldID, id),
|
||||||
|
sqlgraph.To(identityadoptiondecision.Table, identityadoptiondecision.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, authidentity.AdoptionDecisionsTable, authidentity.AdoptionDecisionsColumn),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hooks returns the client hooks.
|
||||||
|
func (c *AuthIdentityClient) Hooks() []Hook {
|
||||||
|
return c.hooks.AuthIdentity
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interceptors returns the client interceptors.
|
||||||
|
func (c *AuthIdentityClient) Interceptors() []Interceptor {
|
||||||
|
return c.inters.AuthIdentity
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *AuthIdentityClient) mutate(ctx context.Context, m *AuthIdentityMutation) (Value, error) {
|
||||||
|
switch m.Op() {
|
||||||
|
case OpCreate:
|
||||||
|
return (&AuthIdentityCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdate:
|
||||||
|
return (&AuthIdentityUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdateOne:
|
||||||
|
return (&AuthIdentityUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpDelete, OpDeleteOne:
|
||||||
|
return (&AuthIdentityDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("ent: unknown AuthIdentity mutation op: %q", m.Op())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthIdentityChannelClient is a client for the AuthIdentityChannel schema.
|
||||||
|
type AuthIdentityChannelClient struct {
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewAuthIdentityChannelClient returns a client for the AuthIdentityChannel from the given config.
|
||||||
|
func NewAuthIdentityChannelClient(c config) *AuthIdentityChannelClient {
|
||||||
|
return &AuthIdentityChannelClient{config: c}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||||||
|
// A call to `Use(f, g, h)` equals to `authidentitychannel.Hooks(f(g(h())))`.
|
||||||
|
func (c *AuthIdentityChannelClient) Use(hooks ...Hook) {
|
||||||
|
c.hooks.AuthIdentityChannel = append(c.hooks.AuthIdentityChannel, hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||||
|
// A call to `Intercept(f, g, h)` equals to `authidentitychannel.Intercept(f(g(h())))`.
|
||||||
|
func (c *AuthIdentityChannelClient) Intercept(interceptors ...Interceptor) {
|
||||||
|
c.inters.AuthIdentityChannel = append(c.inters.AuthIdentityChannel, interceptors...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create returns a builder for creating a AuthIdentityChannel entity.
|
||||||
|
func (c *AuthIdentityChannelClient) Create() *AuthIdentityChannelCreate {
|
||||||
|
mutation := newAuthIdentityChannelMutation(c.config, OpCreate)
|
||||||
|
return &AuthIdentityChannelCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateBulk returns a builder for creating a bulk of AuthIdentityChannel entities.
|
||||||
|
func (c *AuthIdentityChannelClient) CreateBulk(builders ...*AuthIdentityChannelCreate) *AuthIdentityChannelCreateBulk {
|
||||||
|
return &AuthIdentityChannelCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||||
|
// a builder and applies setFunc on it.
|
||||||
|
func (c *AuthIdentityChannelClient) MapCreateBulk(slice any, setFunc func(*AuthIdentityChannelCreate, int)) *AuthIdentityChannelCreateBulk {
|
||||||
|
rv := reflect.ValueOf(slice)
|
||||||
|
if rv.Kind() != reflect.Slice {
|
||||||
|
return &AuthIdentityChannelCreateBulk{err: fmt.Errorf("calling to AuthIdentityChannelClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||||
|
}
|
||||||
|
builders := make([]*AuthIdentityChannelCreate, rv.Len())
|
||||||
|
for i := 0; i < rv.Len(); i++ {
|
||||||
|
builders[i] = c.Create()
|
||||||
|
setFunc(builders[i], i)
|
||||||
|
}
|
||||||
|
return &AuthIdentityChannelCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns an update builder for AuthIdentityChannel.
|
||||||
|
func (c *AuthIdentityChannelClient) Update() *AuthIdentityChannelUpdate {
|
||||||
|
mutation := newAuthIdentityChannelMutation(c.config, OpUpdate)
|
||||||
|
return &AuthIdentityChannelUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOne returns an update builder for the given entity.
|
||||||
|
func (c *AuthIdentityChannelClient) UpdateOne(_m *AuthIdentityChannel) *AuthIdentityChannelUpdateOne {
|
||||||
|
mutation := newAuthIdentityChannelMutation(c.config, OpUpdateOne, withAuthIdentityChannel(_m))
|
||||||
|
return &AuthIdentityChannelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOneID returns an update builder for the given id.
|
||||||
|
func (c *AuthIdentityChannelClient) UpdateOneID(id int64) *AuthIdentityChannelUpdateOne {
|
||||||
|
mutation := newAuthIdentityChannelMutation(c.config, OpUpdateOne, withAuthIdentityChannelID(id))
|
||||||
|
return &AuthIdentityChannelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete returns a delete builder for AuthIdentityChannel.
|
||||||
|
func (c *AuthIdentityChannelClient) Delete() *AuthIdentityChannelDelete {
|
||||||
|
mutation := newAuthIdentityChannelMutation(c.config, OpDelete)
|
||||||
|
return &AuthIdentityChannelDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOne returns a builder for deleting the given entity.
|
||||||
|
func (c *AuthIdentityChannelClient) DeleteOne(_m *AuthIdentityChannel) *AuthIdentityChannelDeleteOne {
|
||||||
|
return c.DeleteOneID(_m.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||||
|
func (c *AuthIdentityChannelClient) DeleteOneID(id int64) *AuthIdentityChannelDeleteOne {
|
||||||
|
builder := c.Delete().Where(authidentitychannel.ID(id))
|
||||||
|
builder.mutation.id = &id
|
||||||
|
builder.mutation.op = OpDeleteOne
|
||||||
|
return &AuthIdentityChannelDeleteOne{builder}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query returns a query builder for AuthIdentityChannel.
|
||||||
|
func (c *AuthIdentityChannelClient) Query() *AuthIdentityChannelQuery {
|
||||||
|
return &AuthIdentityChannelQuery{
|
||||||
|
config: c.config,
|
||||||
|
ctx: &QueryContext{Type: TypeAuthIdentityChannel},
|
||||||
|
inters: c.Interceptors(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns a AuthIdentityChannel entity by its id.
|
||||||
|
func (c *AuthIdentityChannelClient) Get(ctx context.Context, id int64) (*AuthIdentityChannel, error) {
|
||||||
|
return c.Query().Where(authidentitychannel.ID(id)).Only(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetX is like Get, but panics if an error occurs.
|
||||||
|
func (c *AuthIdentityChannelClient) GetX(ctx context.Context, id int64) *AuthIdentityChannel {
|
||||||
|
obj, err := c.Get(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryIdentity queries the identity edge of a AuthIdentityChannel.
|
||||||
|
func (c *AuthIdentityChannelClient) QueryIdentity(_m *AuthIdentityChannel) *AuthIdentityQuery {
|
||||||
|
query := (&AuthIdentityClient{config: c.config}).Query()
|
||||||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := _m.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(authidentitychannel.Table, authidentitychannel.FieldID, id),
|
||||||
|
sqlgraph.To(authidentity.Table, authidentity.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, authidentitychannel.IdentityTable, authidentitychannel.IdentityColumn),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hooks returns the client hooks.
|
||||||
|
func (c *AuthIdentityChannelClient) Hooks() []Hook {
|
||||||
|
return c.hooks.AuthIdentityChannel
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interceptors returns the client interceptors.
|
||||||
|
func (c *AuthIdentityChannelClient) Interceptors() []Interceptor {
|
||||||
|
return c.inters.AuthIdentityChannel
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *AuthIdentityChannelClient) mutate(ctx context.Context, m *AuthIdentityChannelMutation) (Value, error) {
|
||||||
|
switch m.Op() {
|
||||||
|
case OpCreate:
|
||||||
|
return (&AuthIdentityChannelCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdate:
|
||||||
|
return (&AuthIdentityChannelUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdateOne:
|
||||||
|
return (&AuthIdentityChannelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpDelete, OpDeleteOne:
|
||||||
|
return (&AuthIdentityChannelDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("ent: unknown AuthIdentityChannel mutation op: %q", m.Op())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ErrorPassthroughRuleClient is a client for the ErrorPassthroughRule schema.
|
// ErrorPassthroughRuleClient is a client for the ErrorPassthroughRule schema.
|
||||||
type ErrorPassthroughRuleClient struct {
|
type ErrorPassthroughRuleClient struct {
|
||||||
config
|
config
|
||||||
@@ -1760,6 +2124,171 @@ func (c *IdempotencyRecordClient) mutate(ctx context.Context, m *IdempotencyReco
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IdentityAdoptionDecisionClient is a client for the IdentityAdoptionDecision schema.
|
||||||
|
type IdentityAdoptionDecisionClient struct {
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewIdentityAdoptionDecisionClient returns a client for the IdentityAdoptionDecision from the given config.
|
||||||
|
func NewIdentityAdoptionDecisionClient(c config) *IdentityAdoptionDecisionClient {
|
||||||
|
return &IdentityAdoptionDecisionClient{config: c}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||||||
|
// A call to `Use(f, g, h)` equals to `identityadoptiondecision.Hooks(f(g(h())))`.
|
||||||
|
func (c *IdentityAdoptionDecisionClient) Use(hooks ...Hook) {
|
||||||
|
c.hooks.IdentityAdoptionDecision = append(c.hooks.IdentityAdoptionDecision, hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||||
|
// A call to `Intercept(f, g, h)` equals to `identityadoptiondecision.Intercept(f(g(h())))`.
|
||||||
|
func (c *IdentityAdoptionDecisionClient) Intercept(interceptors ...Interceptor) {
|
||||||
|
c.inters.IdentityAdoptionDecision = append(c.inters.IdentityAdoptionDecision, interceptors...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create returns a builder for creating a IdentityAdoptionDecision entity.
|
||||||
|
func (c *IdentityAdoptionDecisionClient) Create() *IdentityAdoptionDecisionCreate {
|
||||||
|
mutation := newIdentityAdoptionDecisionMutation(c.config, OpCreate)
|
||||||
|
return &IdentityAdoptionDecisionCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateBulk returns a builder for creating a bulk of IdentityAdoptionDecision entities.
|
||||||
|
func (c *IdentityAdoptionDecisionClient) CreateBulk(builders ...*IdentityAdoptionDecisionCreate) *IdentityAdoptionDecisionCreateBulk {
|
||||||
|
return &IdentityAdoptionDecisionCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||||
|
// a builder and applies setFunc on it.
|
||||||
|
func (c *IdentityAdoptionDecisionClient) MapCreateBulk(slice any, setFunc func(*IdentityAdoptionDecisionCreate, int)) *IdentityAdoptionDecisionCreateBulk {
|
||||||
|
rv := reflect.ValueOf(slice)
|
||||||
|
if rv.Kind() != reflect.Slice {
|
||||||
|
return &IdentityAdoptionDecisionCreateBulk{err: fmt.Errorf("calling to IdentityAdoptionDecisionClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||||
|
}
|
||||||
|
builders := make([]*IdentityAdoptionDecisionCreate, rv.Len())
|
||||||
|
for i := 0; i < rv.Len(); i++ {
|
||||||
|
builders[i] = c.Create()
|
||||||
|
setFunc(builders[i], i)
|
||||||
|
}
|
||||||
|
return &IdentityAdoptionDecisionCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns an update builder for IdentityAdoptionDecision.
|
||||||
|
func (c *IdentityAdoptionDecisionClient) Update() *IdentityAdoptionDecisionUpdate {
|
||||||
|
mutation := newIdentityAdoptionDecisionMutation(c.config, OpUpdate)
|
||||||
|
return &IdentityAdoptionDecisionUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOne returns an update builder for the given entity.
|
||||||
|
func (c *IdentityAdoptionDecisionClient) UpdateOne(_m *IdentityAdoptionDecision) *IdentityAdoptionDecisionUpdateOne {
|
||||||
|
mutation := newIdentityAdoptionDecisionMutation(c.config, OpUpdateOne, withIdentityAdoptionDecision(_m))
|
||||||
|
return &IdentityAdoptionDecisionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOneID returns an update builder for the given id.
|
||||||
|
func (c *IdentityAdoptionDecisionClient) UpdateOneID(id int64) *IdentityAdoptionDecisionUpdateOne {
|
||||||
|
mutation := newIdentityAdoptionDecisionMutation(c.config, OpUpdateOne, withIdentityAdoptionDecisionID(id))
|
||||||
|
return &IdentityAdoptionDecisionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete returns a delete builder for IdentityAdoptionDecision.
|
||||||
|
func (c *IdentityAdoptionDecisionClient) Delete() *IdentityAdoptionDecisionDelete {
|
||||||
|
mutation := newIdentityAdoptionDecisionMutation(c.config, OpDelete)
|
||||||
|
return &IdentityAdoptionDecisionDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOne returns a builder for deleting the given entity.
|
||||||
|
func (c *IdentityAdoptionDecisionClient) DeleteOne(_m *IdentityAdoptionDecision) *IdentityAdoptionDecisionDeleteOne {
|
||||||
|
return c.DeleteOneID(_m.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||||
|
func (c *IdentityAdoptionDecisionClient) DeleteOneID(id int64) *IdentityAdoptionDecisionDeleteOne {
|
||||||
|
builder := c.Delete().Where(identityadoptiondecision.ID(id))
|
||||||
|
builder.mutation.id = &id
|
||||||
|
builder.mutation.op = OpDeleteOne
|
||||||
|
return &IdentityAdoptionDecisionDeleteOne{builder}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query returns a query builder for IdentityAdoptionDecision.
|
||||||
|
func (c *IdentityAdoptionDecisionClient) Query() *IdentityAdoptionDecisionQuery {
|
||||||
|
return &IdentityAdoptionDecisionQuery{
|
||||||
|
config: c.config,
|
||||||
|
ctx: &QueryContext{Type: TypeIdentityAdoptionDecision},
|
||||||
|
inters: c.Interceptors(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns a IdentityAdoptionDecision entity by its id.
|
||||||
|
func (c *IdentityAdoptionDecisionClient) Get(ctx context.Context, id int64) (*IdentityAdoptionDecision, error) {
|
||||||
|
return c.Query().Where(identityadoptiondecision.ID(id)).Only(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetX is like Get, but panics if an error occurs.
|
||||||
|
func (c *IdentityAdoptionDecisionClient) GetX(ctx context.Context, id int64) *IdentityAdoptionDecision {
|
||||||
|
obj, err := c.Get(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryPendingAuthSession queries the pending_auth_session edge of a IdentityAdoptionDecision.
|
||||||
|
func (c *IdentityAdoptionDecisionClient) QueryPendingAuthSession(_m *IdentityAdoptionDecision) *PendingAuthSessionQuery {
|
||||||
|
query := (&PendingAuthSessionClient{config: c.config}).Query()
|
||||||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := _m.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(identityadoptiondecision.Table, identityadoptiondecision.FieldID, id),
|
||||||
|
sqlgraph.To(pendingauthsession.Table, pendingauthsession.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2O, true, identityadoptiondecision.PendingAuthSessionTable, identityadoptiondecision.PendingAuthSessionColumn),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryIdentity queries the identity edge of a IdentityAdoptionDecision.
|
||||||
|
func (c *IdentityAdoptionDecisionClient) QueryIdentity(_m *IdentityAdoptionDecision) *AuthIdentityQuery {
|
||||||
|
query := (&AuthIdentityClient{config: c.config}).Query()
|
||||||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := _m.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(identityadoptiondecision.Table, identityadoptiondecision.FieldID, id),
|
||||||
|
sqlgraph.To(authidentity.Table, authidentity.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, identityadoptiondecision.IdentityTable, identityadoptiondecision.IdentityColumn),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hooks returns the client hooks.
|
||||||
|
func (c *IdentityAdoptionDecisionClient) Hooks() []Hook {
|
||||||
|
return c.hooks.IdentityAdoptionDecision
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interceptors returns the client interceptors.
|
||||||
|
func (c *IdentityAdoptionDecisionClient) Interceptors() []Interceptor {
|
||||||
|
return c.inters.IdentityAdoptionDecision
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *IdentityAdoptionDecisionClient) mutate(ctx context.Context, m *IdentityAdoptionDecisionMutation) (Value, error) {
|
||||||
|
switch m.Op() {
|
||||||
|
case OpCreate:
|
||||||
|
return (&IdentityAdoptionDecisionCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdate:
|
||||||
|
return (&IdentityAdoptionDecisionUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdateOne:
|
||||||
|
return (&IdentityAdoptionDecisionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpDelete, OpDeleteOne:
|
||||||
|
return (&IdentityAdoptionDecisionDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("ent: unknown IdentityAdoptionDecision mutation op: %q", m.Op())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// PaymentAuditLogClient is a client for the PaymentAuditLog schema.
|
// PaymentAuditLogClient is a client for the PaymentAuditLog schema.
|
||||||
type PaymentAuditLogClient struct {
|
type PaymentAuditLogClient struct {
|
||||||
config
|
config
|
||||||
@@ -2175,6 +2704,171 @@ func (c *PaymentProviderInstanceClient) mutate(ctx context.Context, m *PaymentPr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PendingAuthSessionClient is a client for the PendingAuthSession schema.
|
||||||
|
type PendingAuthSessionClient struct {
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewPendingAuthSessionClient returns a client for the PendingAuthSession from the given config.
|
||||||
|
func NewPendingAuthSessionClient(c config) *PendingAuthSessionClient {
|
||||||
|
return &PendingAuthSessionClient{config: c}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||||||
|
// A call to `Use(f, g, h)` equals to `pendingauthsession.Hooks(f(g(h())))`.
|
||||||
|
func (c *PendingAuthSessionClient) Use(hooks ...Hook) {
|
||||||
|
c.hooks.PendingAuthSession = append(c.hooks.PendingAuthSession, hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||||
|
// A call to `Intercept(f, g, h)` equals to `pendingauthsession.Intercept(f(g(h())))`.
|
||||||
|
func (c *PendingAuthSessionClient) Intercept(interceptors ...Interceptor) {
|
||||||
|
c.inters.PendingAuthSession = append(c.inters.PendingAuthSession, interceptors...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create returns a builder for creating a PendingAuthSession entity.
|
||||||
|
func (c *PendingAuthSessionClient) Create() *PendingAuthSessionCreate {
|
||||||
|
mutation := newPendingAuthSessionMutation(c.config, OpCreate)
|
||||||
|
return &PendingAuthSessionCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateBulk returns a builder for creating a bulk of PendingAuthSession entities.
|
||||||
|
func (c *PendingAuthSessionClient) CreateBulk(builders ...*PendingAuthSessionCreate) *PendingAuthSessionCreateBulk {
|
||||||
|
return &PendingAuthSessionCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||||
|
// a builder and applies setFunc on it.
|
||||||
|
func (c *PendingAuthSessionClient) MapCreateBulk(slice any, setFunc func(*PendingAuthSessionCreate, int)) *PendingAuthSessionCreateBulk {
|
||||||
|
rv := reflect.ValueOf(slice)
|
||||||
|
if rv.Kind() != reflect.Slice {
|
||||||
|
return &PendingAuthSessionCreateBulk{err: fmt.Errorf("calling to PendingAuthSessionClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||||
|
}
|
||||||
|
builders := make([]*PendingAuthSessionCreate, rv.Len())
|
||||||
|
for i := 0; i < rv.Len(); i++ {
|
||||||
|
builders[i] = c.Create()
|
||||||
|
setFunc(builders[i], i)
|
||||||
|
}
|
||||||
|
return &PendingAuthSessionCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns an update builder for PendingAuthSession.
|
||||||
|
func (c *PendingAuthSessionClient) Update() *PendingAuthSessionUpdate {
|
||||||
|
mutation := newPendingAuthSessionMutation(c.config, OpUpdate)
|
||||||
|
return &PendingAuthSessionUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOne returns an update builder for the given entity.
|
||||||
|
func (c *PendingAuthSessionClient) UpdateOne(_m *PendingAuthSession) *PendingAuthSessionUpdateOne {
|
||||||
|
mutation := newPendingAuthSessionMutation(c.config, OpUpdateOne, withPendingAuthSession(_m))
|
||||||
|
return &PendingAuthSessionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOneID returns an update builder for the given id.
|
||||||
|
func (c *PendingAuthSessionClient) UpdateOneID(id int64) *PendingAuthSessionUpdateOne {
|
||||||
|
mutation := newPendingAuthSessionMutation(c.config, OpUpdateOne, withPendingAuthSessionID(id))
|
||||||
|
return &PendingAuthSessionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete returns a delete builder for PendingAuthSession.
|
||||||
|
func (c *PendingAuthSessionClient) Delete() *PendingAuthSessionDelete {
|
||||||
|
mutation := newPendingAuthSessionMutation(c.config, OpDelete)
|
||||||
|
return &PendingAuthSessionDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOne returns a builder for deleting the given entity.
|
||||||
|
func (c *PendingAuthSessionClient) DeleteOne(_m *PendingAuthSession) *PendingAuthSessionDeleteOne {
|
||||||
|
return c.DeleteOneID(_m.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||||
|
func (c *PendingAuthSessionClient) DeleteOneID(id int64) *PendingAuthSessionDeleteOne {
|
||||||
|
builder := c.Delete().Where(pendingauthsession.ID(id))
|
||||||
|
builder.mutation.id = &id
|
||||||
|
builder.mutation.op = OpDeleteOne
|
||||||
|
return &PendingAuthSessionDeleteOne{builder}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query returns a query builder for PendingAuthSession.
|
||||||
|
func (c *PendingAuthSessionClient) Query() *PendingAuthSessionQuery {
|
||||||
|
return &PendingAuthSessionQuery{
|
||||||
|
config: c.config,
|
||||||
|
ctx: &QueryContext{Type: TypePendingAuthSession},
|
||||||
|
inters: c.Interceptors(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns a PendingAuthSession entity by its id.
|
||||||
|
func (c *PendingAuthSessionClient) Get(ctx context.Context, id int64) (*PendingAuthSession, error) {
|
||||||
|
return c.Query().Where(pendingauthsession.ID(id)).Only(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetX is like Get, but panics if an error occurs.
|
||||||
|
func (c *PendingAuthSessionClient) GetX(ctx context.Context, id int64) *PendingAuthSession {
|
||||||
|
obj, err := c.Get(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryTargetUser queries the target_user edge of a PendingAuthSession.
|
||||||
|
func (c *PendingAuthSessionClient) QueryTargetUser(_m *PendingAuthSession) *UserQuery {
|
||||||
|
query := (&UserClient{config: c.config}).Query()
|
||||||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := _m.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(pendingauthsession.Table, pendingauthsession.FieldID, id),
|
||||||
|
sqlgraph.To(user.Table, user.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, pendingauthsession.TargetUserTable, pendingauthsession.TargetUserColumn),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryAdoptionDecision queries the adoption_decision edge of a PendingAuthSession.
|
||||||
|
func (c *PendingAuthSessionClient) QueryAdoptionDecision(_m *PendingAuthSession) *IdentityAdoptionDecisionQuery {
|
||||||
|
query := (&IdentityAdoptionDecisionClient{config: c.config}).Query()
|
||||||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := _m.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(pendingauthsession.Table, pendingauthsession.FieldID, id),
|
||||||
|
sqlgraph.To(identityadoptiondecision.Table, identityadoptiondecision.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2O, false, pendingauthsession.AdoptionDecisionTable, pendingauthsession.AdoptionDecisionColumn),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hooks returns the client hooks.
|
||||||
|
func (c *PendingAuthSessionClient) Hooks() []Hook {
|
||||||
|
return c.hooks.PendingAuthSession
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interceptors returns the client interceptors.
|
||||||
|
func (c *PendingAuthSessionClient) Interceptors() []Interceptor {
|
||||||
|
return c.inters.PendingAuthSession
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *PendingAuthSessionClient) mutate(ctx context.Context, m *PendingAuthSessionMutation) (Value, error) {
|
||||||
|
switch m.Op() {
|
||||||
|
case OpCreate:
|
||||||
|
return (&PendingAuthSessionCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdate:
|
||||||
|
return (&PendingAuthSessionUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdateOne:
|
||||||
|
return (&PendingAuthSessionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpDelete, OpDeleteOne:
|
||||||
|
return (&PendingAuthSessionDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("ent: unknown PendingAuthSession mutation op: %q", m.Op())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// PromoCodeClient is a client for the PromoCode schema.
|
// PromoCodeClient is a client for the PromoCode schema.
|
||||||
type PromoCodeClient struct {
|
type PromoCodeClient struct {
|
||||||
config
|
config
|
||||||
@@ -3951,6 +4645,38 @@ func (c *UserClient) QueryPaymentOrders(_m *User) *PaymentOrderQuery {
|
|||||||
return query
|
return query
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QueryAuthIdentities queries the auth_identities edge of a User.
|
||||||
|
func (c *UserClient) QueryAuthIdentities(_m *User) *AuthIdentityQuery {
|
||||||
|
query := (&AuthIdentityClient{config: c.config}).Query()
|
||||||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := _m.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(user.Table, user.FieldID, id),
|
||||||
|
sqlgraph.To(authidentity.Table, authidentity.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, user.AuthIdentitiesTable, user.AuthIdentitiesColumn),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryPendingAuthSessions queries the pending_auth_sessions edge of a User.
|
||||||
|
func (c *UserClient) QueryPendingAuthSessions(_m *User) *PendingAuthSessionQuery {
|
||||||
|
query := (&PendingAuthSessionClient{config: c.config}).Query()
|
||||||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := _m.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(user.Table, user.FieldID, id),
|
||||||
|
sqlgraph.To(pendingauthsession.Table, pendingauthsession.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, user.PendingAuthSessionsTable, user.PendingAuthSessionsColumn),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
// QueryUserAllowedGroups queries the user_allowed_groups edge of a User.
|
// QueryUserAllowedGroups queries the user_allowed_groups edge of a User.
|
||||||
func (c *UserClient) QueryUserAllowedGroups(_m *User) *UserAllowedGroupQuery {
|
func (c *UserClient) QueryUserAllowedGroups(_m *User) *UserAllowedGroupQuery {
|
||||||
query := (&UserAllowedGroupClient{config: c.config}).Query()
|
query := (&UserAllowedGroupClient{config: c.config}).Query()
|
||||||
@@ -4628,18 +5354,20 @@ func (c *UserSubscriptionClient) mutate(ctx context.Context, m *UserSubscription
|
|||||||
// hooks and interceptors per client, for fast access.
|
// hooks and interceptors per client, for fast access.
|
||||||
type (
|
type (
|
||||||
hooks struct {
|
hooks struct {
|
||||||
APIKey, Account, AccountGroup, Announcement, AnnouncementRead,
|
APIKey, Account, AccountGroup, Announcement, AnnouncementRead, AuthIdentity,
|
||||||
ErrorPassthroughRule, Group, IdempotencyRecord, PaymentAuditLog, PaymentOrder,
|
AuthIdentityChannel, ErrorPassthroughRule, Group, IdempotencyRecord,
|
||||||
PaymentProviderInstance, PromoCode, PromoCodeUsage, Proxy, RedeemCode,
|
IdentityAdoptionDecision, PaymentAuditLog, PaymentOrder,
|
||||||
SecuritySecret, Setting, SubscriptionPlan, TLSFingerprintProfile,
|
PaymentProviderInstance, PendingAuthSession, PromoCode, PromoCodeUsage, Proxy,
|
||||||
|
RedeemCode, SecuritySecret, Setting, SubscriptionPlan, TLSFingerprintProfile,
|
||||||
UsageCleanupTask, UsageLog, User, UserAllowedGroup, UserAttributeDefinition,
|
UsageCleanupTask, UsageLog, User, UserAllowedGroup, UserAttributeDefinition,
|
||||||
UserAttributeValue, UserSubscription []ent.Hook
|
UserAttributeValue, UserSubscription []ent.Hook
|
||||||
}
|
}
|
||||||
inters struct {
|
inters struct {
|
||||||
APIKey, Account, AccountGroup, Announcement, AnnouncementRead,
|
APIKey, Account, AccountGroup, Announcement, AnnouncementRead, AuthIdentity,
|
||||||
ErrorPassthroughRule, Group, IdempotencyRecord, PaymentAuditLog, PaymentOrder,
|
AuthIdentityChannel, ErrorPassthroughRule, Group, IdempotencyRecord,
|
||||||
PaymentProviderInstance, PromoCode, PromoCodeUsage, Proxy, RedeemCode,
|
IdentityAdoptionDecision, PaymentAuditLog, PaymentOrder,
|
||||||
SecuritySecret, Setting, SubscriptionPlan, TLSFingerprintProfile,
|
PaymentProviderInstance, PendingAuthSession, PromoCode, PromoCodeUsage, Proxy,
|
||||||
|
RedeemCode, SecuritySecret, Setting, SubscriptionPlan, TLSFingerprintProfile,
|
||||||
UsageCleanupTask, UsageLog, User, UserAllowedGroup, UserAttributeDefinition,
|
UsageCleanupTask, UsageLog, User, UserAllowedGroup, UserAttributeDefinition,
|
||||||
UserAttributeValue, UserSubscription []ent.Interceptor
|
UserAttributeValue, UserSubscription []ent.Interceptor
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,12 +17,16 @@ import (
|
|||||||
"github.com/Wei-Shaw/sub2api/ent/announcement"
|
"github.com/Wei-Shaw/sub2api/ent/announcement"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/announcementread"
|
"github.com/Wei-Shaw/sub2api/ent/announcementread"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/apikey"
|
"github.com/Wei-Shaw/sub2api/ent/apikey"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/authidentity"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/authidentitychannel"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/errorpassthroughrule"
|
"github.com/Wei-Shaw/sub2api/ent/errorpassthroughrule"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/group"
|
"github.com/Wei-Shaw/sub2api/ent/group"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/idempotencyrecord"
|
"github.com/Wei-Shaw/sub2api/ent/idempotencyrecord"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/identityadoptiondecision"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/paymentauditlog"
|
"github.com/Wei-Shaw/sub2api/ent/paymentauditlog"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/paymentorder"
|
"github.com/Wei-Shaw/sub2api/ent/paymentorder"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/paymentproviderinstance"
|
"github.com/Wei-Shaw/sub2api/ent/paymentproviderinstance"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/pendingauthsession"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/promocode"
|
"github.com/Wei-Shaw/sub2api/ent/promocode"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
|
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/proxy"
|
"github.com/Wei-Shaw/sub2api/ent/proxy"
|
||||||
@@ -103,12 +107,16 @@ func checkColumn(t, c string) error {
|
|||||||
accountgroup.Table: accountgroup.ValidColumn,
|
accountgroup.Table: accountgroup.ValidColumn,
|
||||||
announcement.Table: announcement.ValidColumn,
|
announcement.Table: announcement.ValidColumn,
|
||||||
announcementread.Table: announcementread.ValidColumn,
|
announcementread.Table: announcementread.ValidColumn,
|
||||||
|
authidentity.Table: authidentity.ValidColumn,
|
||||||
|
authidentitychannel.Table: authidentitychannel.ValidColumn,
|
||||||
errorpassthroughrule.Table: errorpassthroughrule.ValidColumn,
|
errorpassthroughrule.Table: errorpassthroughrule.ValidColumn,
|
||||||
group.Table: group.ValidColumn,
|
group.Table: group.ValidColumn,
|
||||||
idempotencyrecord.Table: idempotencyrecord.ValidColumn,
|
idempotencyrecord.Table: idempotencyrecord.ValidColumn,
|
||||||
|
identityadoptiondecision.Table: identityadoptiondecision.ValidColumn,
|
||||||
paymentauditlog.Table: paymentauditlog.ValidColumn,
|
paymentauditlog.Table: paymentauditlog.ValidColumn,
|
||||||
paymentorder.Table: paymentorder.ValidColumn,
|
paymentorder.Table: paymentorder.ValidColumn,
|
||||||
paymentproviderinstance.Table: paymentproviderinstance.ValidColumn,
|
paymentproviderinstance.Table: paymentproviderinstance.ValidColumn,
|
||||||
|
pendingauthsession.Table: pendingauthsession.ValidColumn,
|
||||||
promocode.Table: promocode.ValidColumn,
|
promocode.Table: promocode.ValidColumn,
|
||||||
promocodeusage.Table: promocodeusage.ValidColumn,
|
promocodeusage.Table: promocodeusage.ValidColumn,
|
||||||
proxy.Table: proxy.ValidColumn,
|
proxy.Table: proxy.ValidColumn,
|
||||||
|
|||||||
@@ -69,6 +69,30 @@ func (f AnnouncementReadFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.V
|
|||||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AnnouncementReadMutation", m)
|
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AnnouncementReadMutation", m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The AuthIdentityFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as AuthIdentity mutator.
|
||||||
|
type AuthIdentityFunc func(context.Context, *ent.AuthIdentityMutation) (ent.Value, error)
|
||||||
|
|
||||||
|
// Mutate calls f(ctx, m).
|
||||||
|
func (f AuthIdentityFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||||
|
if mv, ok := m.(*ent.AuthIdentityMutation); ok {
|
||||||
|
return f(ctx, mv)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AuthIdentityMutation", m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The AuthIdentityChannelFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as AuthIdentityChannel mutator.
|
||||||
|
type AuthIdentityChannelFunc func(context.Context, *ent.AuthIdentityChannelMutation) (ent.Value, error)
|
||||||
|
|
||||||
|
// Mutate calls f(ctx, m).
|
||||||
|
func (f AuthIdentityChannelFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||||
|
if mv, ok := m.(*ent.AuthIdentityChannelMutation); ok {
|
||||||
|
return f(ctx, mv)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AuthIdentityChannelMutation", m)
|
||||||
|
}
|
||||||
|
|
||||||
// The ErrorPassthroughRuleFunc type is an adapter to allow the use of ordinary
|
// The ErrorPassthroughRuleFunc type is an adapter to allow the use of ordinary
|
||||||
// function as ErrorPassthroughRule mutator.
|
// function as ErrorPassthroughRule mutator.
|
||||||
type ErrorPassthroughRuleFunc func(context.Context, *ent.ErrorPassthroughRuleMutation) (ent.Value, error)
|
type ErrorPassthroughRuleFunc func(context.Context, *ent.ErrorPassthroughRuleMutation) (ent.Value, error)
|
||||||
@@ -105,6 +129,18 @@ func (f IdempotencyRecordFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.
|
|||||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.IdempotencyRecordMutation", m)
|
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.IdempotencyRecordMutation", m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The IdentityAdoptionDecisionFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as IdentityAdoptionDecision mutator.
|
||||||
|
type IdentityAdoptionDecisionFunc func(context.Context, *ent.IdentityAdoptionDecisionMutation) (ent.Value, error)
|
||||||
|
|
||||||
|
// Mutate calls f(ctx, m).
|
||||||
|
func (f IdentityAdoptionDecisionFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||||
|
if mv, ok := m.(*ent.IdentityAdoptionDecisionMutation); ok {
|
||||||
|
return f(ctx, mv)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.IdentityAdoptionDecisionMutation", m)
|
||||||
|
}
|
||||||
|
|
||||||
// The PaymentAuditLogFunc type is an adapter to allow the use of ordinary
|
// The PaymentAuditLogFunc type is an adapter to allow the use of ordinary
|
||||||
// function as PaymentAuditLog mutator.
|
// function as PaymentAuditLog mutator.
|
||||||
type PaymentAuditLogFunc func(context.Context, *ent.PaymentAuditLogMutation) (ent.Value, error)
|
type PaymentAuditLogFunc func(context.Context, *ent.PaymentAuditLogMutation) (ent.Value, error)
|
||||||
@@ -141,6 +177,18 @@ func (f PaymentProviderInstanceFunc) Mutate(ctx context.Context, m ent.Mutation)
|
|||||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.PaymentProviderInstanceMutation", m)
|
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.PaymentProviderInstanceMutation", m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The PendingAuthSessionFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as PendingAuthSession mutator.
|
||||||
|
type PendingAuthSessionFunc func(context.Context, *ent.PendingAuthSessionMutation) (ent.Value, error)
|
||||||
|
|
||||||
|
// Mutate calls f(ctx, m).
|
||||||
|
func (f PendingAuthSessionFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||||
|
if mv, ok := m.(*ent.PendingAuthSessionMutation); ok {
|
||||||
|
return f(ctx, mv)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.PendingAuthSessionMutation", m)
|
||||||
|
}
|
||||||
|
|
||||||
// The PromoCodeFunc type is an adapter to allow the use of ordinary
|
// The PromoCodeFunc type is an adapter to allow the use of ordinary
|
||||||
// function as PromoCode mutator.
|
// function as PromoCode mutator.
|
||||||
type PromoCodeFunc func(context.Context, *ent.PromoCodeMutation) (ent.Value, error)
|
type PromoCodeFunc func(context.Context, *ent.PromoCodeMutation) (ent.Value, error)
|
||||||
|
|||||||
@@ -0,0 +1,223 @@
|
|||||||
|
// 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/authidentity"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/identityadoptiondecision"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/pendingauthsession"
|
||||||
|
)
|
||||||
|
|
||||||
|
// IdentityAdoptionDecision is the model entity for the IdentityAdoptionDecision schema.
|
||||||
|
type IdentityAdoptionDecision 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"`
|
||||||
|
// PendingAuthSessionID holds the value of the "pending_auth_session_id" field.
|
||||||
|
PendingAuthSessionID int64 `json:"pending_auth_session_id,omitempty"`
|
||||||
|
// IdentityID holds the value of the "identity_id" field.
|
||||||
|
IdentityID *int64 `json:"identity_id,omitempty"`
|
||||||
|
// AdoptDisplayName holds the value of the "adopt_display_name" field.
|
||||||
|
AdoptDisplayName bool `json:"adopt_display_name,omitempty"`
|
||||||
|
// AdoptAvatar holds the value of the "adopt_avatar" field.
|
||||||
|
AdoptAvatar bool `json:"adopt_avatar,omitempty"`
|
||||||
|
// DecidedAt holds the value of the "decided_at" field.
|
||||||
|
DecidedAt time.Time `json:"decided_at,omitempty"`
|
||||||
|
// Edges holds the relations/edges for other nodes in the graph.
|
||||||
|
// The values are being populated by the IdentityAdoptionDecisionQuery when eager-loading is set.
|
||||||
|
Edges IdentityAdoptionDecisionEdges `json:"edges"`
|
||||||
|
selectValues sql.SelectValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// IdentityAdoptionDecisionEdges holds the relations/edges for other nodes in the graph.
|
||||||
|
type IdentityAdoptionDecisionEdges struct {
|
||||||
|
// PendingAuthSession holds the value of the pending_auth_session edge.
|
||||||
|
PendingAuthSession *PendingAuthSession `json:"pending_auth_session,omitempty"`
|
||||||
|
// Identity holds the value of the identity edge.
|
||||||
|
Identity *AuthIdentity `json:"identity,omitempty"`
|
||||||
|
// loadedTypes holds the information for reporting if a
|
||||||
|
// type was loaded (or requested) in eager-loading or not.
|
||||||
|
loadedTypes [2]bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// PendingAuthSessionOrErr returns the PendingAuthSession value or an error if the edge
|
||||||
|
// was not loaded in eager-loading, or loaded but was not found.
|
||||||
|
func (e IdentityAdoptionDecisionEdges) PendingAuthSessionOrErr() (*PendingAuthSession, error) {
|
||||||
|
if e.PendingAuthSession != nil {
|
||||||
|
return e.PendingAuthSession, nil
|
||||||
|
} else if e.loadedTypes[0] {
|
||||||
|
return nil, &NotFoundError{label: pendingauthsession.Label}
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "pending_auth_session"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// IdentityOrErr returns the Identity value or an error if the edge
|
||||||
|
// was not loaded in eager-loading, or loaded but was not found.
|
||||||
|
func (e IdentityAdoptionDecisionEdges) IdentityOrErr() (*AuthIdentity, error) {
|
||||||
|
if e.Identity != nil {
|
||||||
|
return e.Identity, nil
|
||||||
|
} else if e.loadedTypes[1] {
|
||||||
|
return nil, &NotFoundError{label: authidentity.Label}
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "identity"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// scanValues returns the types for scanning values from sql.Rows.
|
||||||
|
func (*IdentityAdoptionDecision) scanValues(columns []string) ([]any, error) {
|
||||||
|
values := make([]any, len(columns))
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case identityadoptiondecision.FieldAdoptDisplayName, identityadoptiondecision.FieldAdoptAvatar:
|
||||||
|
values[i] = new(sql.NullBool)
|
||||||
|
case identityadoptiondecision.FieldID, identityadoptiondecision.FieldPendingAuthSessionID, identityadoptiondecision.FieldIdentityID:
|
||||||
|
values[i] = new(sql.NullInt64)
|
||||||
|
case identityadoptiondecision.FieldCreatedAt, identityadoptiondecision.FieldUpdatedAt, identityadoptiondecision.FieldDecidedAt:
|
||||||
|
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 IdentityAdoptionDecision fields.
|
||||||
|
func (_m *IdentityAdoptionDecision) 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 identityadoptiondecision.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 identityadoptiondecision.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 identityadoptiondecision.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 identityadoptiondecision.FieldPendingAuthSessionID:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field pending_auth_session_id", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.PendingAuthSessionID = value.Int64
|
||||||
|
}
|
||||||
|
case identityadoptiondecision.FieldIdentityID:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field identity_id", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.IdentityID = new(int64)
|
||||||
|
*_m.IdentityID = value.Int64
|
||||||
|
}
|
||||||
|
case identityadoptiondecision.FieldAdoptDisplayName:
|
||||||
|
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field adopt_display_name", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.AdoptDisplayName = value.Bool
|
||||||
|
}
|
||||||
|
case identityadoptiondecision.FieldAdoptAvatar:
|
||||||
|
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field adopt_avatar", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.AdoptAvatar = value.Bool
|
||||||
|
}
|
||||||
|
case identityadoptiondecision.FieldDecidedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field decided_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.DecidedAt = value.Time
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
_m.selectValues.Set(columns[i], values[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value returns the ent.Value that was dynamically selected and assigned to the IdentityAdoptionDecision.
|
||||||
|
// This includes values selected through modifiers, order, etc.
|
||||||
|
func (_m *IdentityAdoptionDecision) Value(name string) (ent.Value, error) {
|
||||||
|
return _m.selectValues.Get(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryPendingAuthSession queries the "pending_auth_session" edge of the IdentityAdoptionDecision entity.
|
||||||
|
func (_m *IdentityAdoptionDecision) QueryPendingAuthSession() *PendingAuthSessionQuery {
|
||||||
|
return NewIdentityAdoptionDecisionClient(_m.config).QueryPendingAuthSession(_m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryIdentity queries the "identity" edge of the IdentityAdoptionDecision entity.
|
||||||
|
func (_m *IdentityAdoptionDecision) QueryIdentity() *AuthIdentityQuery {
|
||||||
|
return NewIdentityAdoptionDecisionClient(_m.config).QueryIdentity(_m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns a builder for updating this IdentityAdoptionDecision.
|
||||||
|
// Note that you need to call IdentityAdoptionDecision.Unwrap() before calling this method if this IdentityAdoptionDecision
|
||||||
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||||
|
func (_m *IdentityAdoptionDecision) Update() *IdentityAdoptionDecisionUpdateOne {
|
||||||
|
return NewIdentityAdoptionDecisionClient(_m.config).UpdateOne(_m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap unwraps the IdentityAdoptionDecision 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 *IdentityAdoptionDecision) Unwrap() *IdentityAdoptionDecision {
|
||||||
|
_tx, ok := _m.config.driver.(*txDriver)
|
||||||
|
if !ok {
|
||||||
|
panic("ent: IdentityAdoptionDecision is not a transactional entity")
|
||||||
|
}
|
||||||
|
_m.config.driver = _tx.drv
|
||||||
|
return _m
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements the fmt.Stringer.
|
||||||
|
func (_m *IdentityAdoptionDecision) String() string {
|
||||||
|
var builder strings.Builder
|
||||||
|
builder.WriteString("IdentityAdoptionDecision(")
|
||||||
|
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(", ")
|
||||||
|
builder.WriteString("pending_auth_session_id=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.PendingAuthSessionID))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
if v := _m.IdentityID; v != nil {
|
||||||
|
builder.WriteString("identity_id=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", *v))
|
||||||
|
}
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("adopt_display_name=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.AdoptDisplayName))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("adopt_avatar=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.AdoptAvatar))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("decided_at=")
|
||||||
|
builder.WriteString(_m.DecidedAt.Format(time.ANSIC))
|
||||||
|
builder.WriteByte(')')
|
||||||
|
return builder.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// IdentityAdoptionDecisions is a parsable slice of IdentityAdoptionDecision.
|
||||||
|
type IdentityAdoptionDecisions []*IdentityAdoptionDecision
|
||||||
@@ -0,0 +1,159 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package identityadoptiondecision
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Label holds the string label denoting the identityadoptiondecision type in the database.
|
||||||
|
Label = "identity_adoption_decision"
|
||||||
|
// FieldID holds the string denoting the id field in the database.
|
||||||
|
FieldID = "id"
|
||||||
|
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||||
|
FieldCreatedAt = "created_at"
|
||||||
|
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||||
|
FieldUpdatedAt = "updated_at"
|
||||||
|
// FieldPendingAuthSessionID holds the string denoting the pending_auth_session_id field in the database.
|
||||||
|
FieldPendingAuthSessionID = "pending_auth_session_id"
|
||||||
|
// FieldIdentityID holds the string denoting the identity_id field in the database.
|
||||||
|
FieldIdentityID = "identity_id"
|
||||||
|
// FieldAdoptDisplayName holds the string denoting the adopt_display_name field in the database.
|
||||||
|
FieldAdoptDisplayName = "adopt_display_name"
|
||||||
|
// FieldAdoptAvatar holds the string denoting the adopt_avatar field in the database.
|
||||||
|
FieldAdoptAvatar = "adopt_avatar"
|
||||||
|
// FieldDecidedAt holds the string denoting the decided_at field in the database.
|
||||||
|
FieldDecidedAt = "decided_at"
|
||||||
|
// EdgePendingAuthSession holds the string denoting the pending_auth_session edge name in mutations.
|
||||||
|
EdgePendingAuthSession = "pending_auth_session"
|
||||||
|
// EdgeIdentity holds the string denoting the identity edge name in mutations.
|
||||||
|
EdgeIdentity = "identity"
|
||||||
|
// Table holds the table name of the identityadoptiondecision in the database.
|
||||||
|
Table = "identity_adoption_decisions"
|
||||||
|
// PendingAuthSessionTable is the table that holds the pending_auth_session relation/edge.
|
||||||
|
PendingAuthSessionTable = "identity_adoption_decisions"
|
||||||
|
// PendingAuthSessionInverseTable is the table name for the PendingAuthSession entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "pendingauthsession" package.
|
||||||
|
PendingAuthSessionInverseTable = "pending_auth_sessions"
|
||||||
|
// PendingAuthSessionColumn is the table column denoting the pending_auth_session relation/edge.
|
||||||
|
PendingAuthSessionColumn = "pending_auth_session_id"
|
||||||
|
// IdentityTable is the table that holds the identity relation/edge.
|
||||||
|
IdentityTable = "identity_adoption_decisions"
|
||||||
|
// IdentityInverseTable is the table name for the AuthIdentity entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "authidentity" package.
|
||||||
|
IdentityInverseTable = "auth_identities"
|
||||||
|
// IdentityColumn is the table column denoting the identity relation/edge.
|
||||||
|
IdentityColumn = "identity_id"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Columns holds all SQL columns for identityadoptiondecision fields.
|
||||||
|
var Columns = []string{
|
||||||
|
FieldID,
|
||||||
|
FieldCreatedAt,
|
||||||
|
FieldUpdatedAt,
|
||||||
|
FieldPendingAuthSessionID,
|
||||||
|
FieldIdentityID,
|
||||||
|
FieldAdoptDisplayName,
|
||||||
|
FieldAdoptAvatar,
|
||||||
|
FieldDecidedAt,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||||
|
func ValidColumn(column string) bool {
|
||||||
|
for i := range Columns {
|
||||||
|
if column == Columns[i] {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||||
|
DefaultCreatedAt func() time.Time
|
||||||
|
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||||
|
DefaultUpdatedAt func() time.Time
|
||||||
|
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||||
|
UpdateDefaultUpdatedAt func() time.Time
|
||||||
|
// DefaultAdoptDisplayName holds the default value on creation for the "adopt_display_name" field.
|
||||||
|
DefaultAdoptDisplayName bool
|
||||||
|
// DefaultAdoptAvatar holds the default value on creation for the "adopt_avatar" field.
|
||||||
|
DefaultAdoptAvatar bool
|
||||||
|
// DefaultDecidedAt holds the default value on creation for the "decided_at" field.
|
||||||
|
DefaultDecidedAt func() time.Time
|
||||||
|
)
|
||||||
|
|
||||||
|
// OrderOption defines the ordering options for the IdentityAdoptionDecision queries.
|
||||||
|
type OrderOption func(*sql.Selector)
|
||||||
|
|
||||||
|
// ByID orders the results by the id field.
|
||||||
|
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByCreatedAt orders the results by the created_at field.
|
||||||
|
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByUpdatedAt orders the results by the updated_at field.
|
||||||
|
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByPendingAuthSessionID orders the results by the pending_auth_session_id field.
|
||||||
|
func ByPendingAuthSessionID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldPendingAuthSessionID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByIdentityID orders the results by the identity_id field.
|
||||||
|
func ByIdentityID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldIdentityID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByAdoptDisplayName orders the results by the adopt_display_name field.
|
||||||
|
func ByAdoptDisplayName(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldAdoptDisplayName, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByAdoptAvatar orders the results by the adopt_avatar field.
|
||||||
|
func ByAdoptAvatar(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldAdoptAvatar, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByDecidedAt orders the results by the decided_at field.
|
||||||
|
func ByDecidedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldDecidedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByPendingAuthSessionField orders the results by pending_auth_session field.
|
||||||
|
func ByPendingAuthSessionField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborTerms(s, newPendingAuthSessionStep(), sql.OrderByField(field, opts...))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByIdentityField orders the results by identity field.
|
||||||
|
func ByIdentityField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborTerms(s, newIdentityStep(), sql.OrderByField(field, opts...))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func newPendingAuthSessionStep() *sqlgraph.Step {
|
||||||
|
return sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(PendingAuthSessionInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2O, true, PendingAuthSessionTable, PendingAuthSessionColumn),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
func newIdentityStep() *sqlgraph.Step {
|
||||||
|
return sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(IdentityInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, IdentityTable, IdentityColumn),
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,342 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package identityadoptiondecision
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/predicate"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ID filters vertices based on their ID field.
|
||||||
|
func ID(id int64) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDEQ applies the EQ predicate on the ID field.
|
||||||
|
func IDEQ(id int64) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNEQ applies the NEQ predicate on the ID field.
|
||||||
|
func IDNEQ(id int64) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldNEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDIn applies the In predicate on the ID field.
|
||||||
|
func IDIn(ids ...int64) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNotIn applies the NotIn predicate on the ID field.
|
||||||
|
func IDNotIn(ids ...int64) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldNotIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGT applies the GT predicate on the ID field.
|
||||||
|
func IDGT(id int64) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldGT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGTE applies the GTE predicate on the ID field.
|
||||||
|
func IDGTE(id int64) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldGTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLT applies the LT predicate on the ID field.
|
||||||
|
func IDLT(id int64) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldLT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLTE applies the LTE predicate on the ID field.
|
||||||
|
func IDLTE(id int64) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldLTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||||
|
func CreatedAt(v time.Time) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(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.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PendingAuthSessionID applies equality check predicate on the "pending_auth_session_id" field. It's identical to PendingAuthSessionIDEQ.
|
||||||
|
func PendingAuthSessionID(v int64) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldEQ(FieldPendingAuthSessionID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IdentityID applies equality check predicate on the "identity_id" field. It's identical to IdentityIDEQ.
|
||||||
|
func IdentityID(v int64) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldEQ(FieldIdentityID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdoptDisplayName applies equality check predicate on the "adopt_display_name" field. It's identical to AdoptDisplayNameEQ.
|
||||||
|
func AdoptDisplayName(v bool) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldEQ(FieldAdoptDisplayName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdoptAvatar applies equality check predicate on the "adopt_avatar" field. It's identical to AdoptAvatarEQ.
|
||||||
|
func AdoptAvatar(v bool) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldEQ(FieldAdoptAvatar, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DecidedAt applies equality check predicate on the "decided_at" field. It's identical to DecidedAtEQ.
|
||||||
|
func DecidedAt(v time.Time) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldEQ(FieldDecidedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtEQ(v time.Time) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtNEQ(v time.Time) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldNEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||||
|
func CreatedAtIn(vs ...time.Time) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||||
|
func CreatedAtNotIn(vs ...time.Time) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||||
|
func CreatedAtGT(v time.Time) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldGT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtGTE(v time.Time) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldGTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||||
|
func CreatedAtLT(v time.Time) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldLT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtLTE(v time.Time) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldLTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtEQ(v time.Time) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNEQ(v time.Time) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldNEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtIn(vs ...time.Time) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNotIn(vs ...time.Time) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldNotIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGT(v time.Time) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldGT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGTE(v time.Time) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldGTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLT(v time.Time) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldLT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLTE(v time.Time) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldLTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PendingAuthSessionIDEQ applies the EQ predicate on the "pending_auth_session_id" field.
|
||||||
|
func PendingAuthSessionIDEQ(v int64) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldEQ(FieldPendingAuthSessionID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PendingAuthSessionIDNEQ applies the NEQ predicate on the "pending_auth_session_id" field.
|
||||||
|
func PendingAuthSessionIDNEQ(v int64) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldNEQ(FieldPendingAuthSessionID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PendingAuthSessionIDIn applies the In predicate on the "pending_auth_session_id" field.
|
||||||
|
func PendingAuthSessionIDIn(vs ...int64) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldIn(FieldPendingAuthSessionID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PendingAuthSessionIDNotIn applies the NotIn predicate on the "pending_auth_session_id" field.
|
||||||
|
func PendingAuthSessionIDNotIn(vs ...int64) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldNotIn(FieldPendingAuthSessionID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IdentityIDEQ applies the EQ predicate on the "identity_id" field.
|
||||||
|
func IdentityIDEQ(v int64) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldEQ(FieldIdentityID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IdentityIDNEQ applies the NEQ predicate on the "identity_id" field.
|
||||||
|
func IdentityIDNEQ(v int64) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldNEQ(FieldIdentityID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IdentityIDIn applies the In predicate on the "identity_id" field.
|
||||||
|
func IdentityIDIn(vs ...int64) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldIn(FieldIdentityID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IdentityIDNotIn applies the NotIn predicate on the "identity_id" field.
|
||||||
|
func IdentityIDNotIn(vs ...int64) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldNotIn(FieldIdentityID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IdentityIDIsNil applies the IsNil predicate on the "identity_id" field.
|
||||||
|
func IdentityIDIsNil() predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldIsNull(FieldIdentityID))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IdentityIDNotNil applies the NotNil predicate on the "identity_id" field.
|
||||||
|
func IdentityIDNotNil() predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldNotNull(FieldIdentityID))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdoptDisplayNameEQ applies the EQ predicate on the "adopt_display_name" field.
|
||||||
|
func AdoptDisplayNameEQ(v bool) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldEQ(FieldAdoptDisplayName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdoptDisplayNameNEQ applies the NEQ predicate on the "adopt_display_name" field.
|
||||||
|
func AdoptDisplayNameNEQ(v bool) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldNEQ(FieldAdoptDisplayName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdoptAvatarEQ applies the EQ predicate on the "adopt_avatar" field.
|
||||||
|
func AdoptAvatarEQ(v bool) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldEQ(FieldAdoptAvatar, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdoptAvatarNEQ applies the NEQ predicate on the "adopt_avatar" field.
|
||||||
|
func AdoptAvatarNEQ(v bool) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldNEQ(FieldAdoptAvatar, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DecidedAtEQ applies the EQ predicate on the "decided_at" field.
|
||||||
|
func DecidedAtEQ(v time.Time) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldEQ(FieldDecidedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DecidedAtNEQ applies the NEQ predicate on the "decided_at" field.
|
||||||
|
func DecidedAtNEQ(v time.Time) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldNEQ(FieldDecidedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DecidedAtIn applies the In predicate on the "decided_at" field.
|
||||||
|
func DecidedAtIn(vs ...time.Time) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldIn(FieldDecidedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DecidedAtNotIn applies the NotIn predicate on the "decided_at" field.
|
||||||
|
func DecidedAtNotIn(vs ...time.Time) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldNotIn(FieldDecidedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DecidedAtGT applies the GT predicate on the "decided_at" field.
|
||||||
|
func DecidedAtGT(v time.Time) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldGT(FieldDecidedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DecidedAtGTE applies the GTE predicate on the "decided_at" field.
|
||||||
|
func DecidedAtGTE(v time.Time) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldGTE(FieldDecidedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DecidedAtLT applies the LT predicate on the "decided_at" field.
|
||||||
|
func DecidedAtLT(v time.Time) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldLT(FieldDecidedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DecidedAtLTE applies the LTE predicate on the "decided_at" field.
|
||||||
|
func DecidedAtLTE(v time.Time) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.FieldLTE(FieldDecidedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasPendingAuthSession applies the HasEdge predicate on the "pending_auth_session" edge.
|
||||||
|
func HasPendingAuthSession() predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2O, true, PendingAuthSessionTable, PendingAuthSessionColumn),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasPendingAuthSessionWith applies the HasEdge predicate on the "pending_auth_session" edge with a given conditions (other predicates).
|
||||||
|
func HasPendingAuthSessionWith(preds ...predicate.PendingAuthSession) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(func(s *sql.Selector) {
|
||||||
|
step := newPendingAuthSessionStep()
|
||||||
|
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasIdentity applies the HasEdge predicate on the "identity" edge.
|
||||||
|
func HasIdentity() predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, IdentityTable, IdentityColumn),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasIdentityWith applies the HasEdge predicate on the "identity" edge with a given conditions (other predicates).
|
||||||
|
func HasIdentityWith(preds ...predicate.AuthIdentity) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(func(s *sql.Selector) {
|
||||||
|
step := newIdentityStep()
|
||||||
|
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// And groups predicates with the AND operator between them.
|
||||||
|
func And(predicates ...predicate.IdentityAdoptionDecision) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.AndPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or groups predicates with the OR operator between them.
|
||||||
|
func Or(predicates ...predicate.IdentityAdoptionDecision) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.OrPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not applies the not operator on the given predicate.
|
||||||
|
func Not(p predicate.IdentityAdoptionDecision) predicate.IdentityAdoptionDecision {
|
||||||
|
return predicate.IdentityAdoptionDecision(sql.NotPredicates(p))
|
||||||
|
}
|
||||||
@@ -0,0 +1,843 @@
|
|||||||
|
// 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/authidentity"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/identityadoptiondecision"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/pendingauthsession"
|
||||||
|
)
|
||||||
|
|
||||||
|
// IdentityAdoptionDecisionCreate is the builder for creating a IdentityAdoptionDecision entity.
|
||||||
|
type IdentityAdoptionDecisionCreate struct {
|
||||||
|
config
|
||||||
|
mutation *IdentityAdoptionDecisionMutation
|
||||||
|
hooks []Hook
|
||||||
|
conflict []sql.ConflictOption
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreatedAt sets the "created_at" field.
|
||||||
|
func (_c *IdentityAdoptionDecisionCreate) SetCreatedAt(v time.Time) *IdentityAdoptionDecisionCreate {
|
||||||
|
_c.mutation.SetCreatedAt(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||||
|
func (_c *IdentityAdoptionDecisionCreate) SetNillableCreatedAt(v *time.Time) *IdentityAdoptionDecisionCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetCreatedAt(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (_c *IdentityAdoptionDecisionCreate) SetUpdatedAt(v time.Time) *IdentityAdoptionDecisionCreate {
|
||||||
|
_c.mutation.SetUpdatedAt(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||||
|
func (_c *IdentityAdoptionDecisionCreate) SetNillableUpdatedAt(v *time.Time) *IdentityAdoptionDecisionCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetUpdatedAt(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPendingAuthSessionID sets the "pending_auth_session_id" field.
|
||||||
|
func (_c *IdentityAdoptionDecisionCreate) SetPendingAuthSessionID(v int64) *IdentityAdoptionDecisionCreate {
|
||||||
|
_c.mutation.SetPendingAuthSessionID(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIdentityID sets the "identity_id" field.
|
||||||
|
func (_c *IdentityAdoptionDecisionCreate) SetIdentityID(v int64) *IdentityAdoptionDecisionCreate {
|
||||||
|
_c.mutation.SetIdentityID(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableIdentityID sets the "identity_id" field if the given value is not nil.
|
||||||
|
func (_c *IdentityAdoptionDecisionCreate) SetNillableIdentityID(v *int64) *IdentityAdoptionDecisionCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetIdentityID(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAdoptDisplayName sets the "adopt_display_name" field.
|
||||||
|
func (_c *IdentityAdoptionDecisionCreate) SetAdoptDisplayName(v bool) *IdentityAdoptionDecisionCreate {
|
||||||
|
_c.mutation.SetAdoptDisplayName(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableAdoptDisplayName sets the "adopt_display_name" field if the given value is not nil.
|
||||||
|
func (_c *IdentityAdoptionDecisionCreate) SetNillableAdoptDisplayName(v *bool) *IdentityAdoptionDecisionCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetAdoptDisplayName(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAdoptAvatar sets the "adopt_avatar" field.
|
||||||
|
func (_c *IdentityAdoptionDecisionCreate) SetAdoptAvatar(v bool) *IdentityAdoptionDecisionCreate {
|
||||||
|
_c.mutation.SetAdoptAvatar(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableAdoptAvatar sets the "adopt_avatar" field if the given value is not nil.
|
||||||
|
func (_c *IdentityAdoptionDecisionCreate) SetNillableAdoptAvatar(v *bool) *IdentityAdoptionDecisionCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetAdoptAvatar(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDecidedAt sets the "decided_at" field.
|
||||||
|
func (_c *IdentityAdoptionDecisionCreate) SetDecidedAt(v time.Time) *IdentityAdoptionDecisionCreate {
|
||||||
|
_c.mutation.SetDecidedAt(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDecidedAt sets the "decided_at" field if the given value is not nil.
|
||||||
|
func (_c *IdentityAdoptionDecisionCreate) SetNillableDecidedAt(v *time.Time) *IdentityAdoptionDecisionCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetDecidedAt(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPendingAuthSession sets the "pending_auth_session" edge to the PendingAuthSession entity.
|
||||||
|
func (_c *IdentityAdoptionDecisionCreate) SetPendingAuthSession(v *PendingAuthSession) *IdentityAdoptionDecisionCreate {
|
||||||
|
return _c.SetPendingAuthSessionID(v.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIdentity sets the "identity" edge to the AuthIdentity entity.
|
||||||
|
func (_c *IdentityAdoptionDecisionCreate) SetIdentity(v *AuthIdentity) *IdentityAdoptionDecisionCreate {
|
||||||
|
return _c.SetIdentityID(v.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the IdentityAdoptionDecisionMutation object of the builder.
|
||||||
|
func (_c *IdentityAdoptionDecisionCreate) Mutation() *IdentityAdoptionDecisionMutation {
|
||||||
|
return _c.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the IdentityAdoptionDecision in the database.
|
||||||
|
func (_c *IdentityAdoptionDecisionCreate) Save(ctx context.Context) (*IdentityAdoptionDecision, error) {
|
||||||
|
_c.defaults()
|
||||||
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX calls Save and panics if Save returns an error.
|
||||||
|
func (_c *IdentityAdoptionDecisionCreate) SaveX(ctx context.Context) *IdentityAdoptionDecision {
|
||||||
|
v, err := _c.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (_c *IdentityAdoptionDecisionCreate) Exec(ctx context.Context) error {
|
||||||
|
_, err := _c.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_c *IdentityAdoptionDecisionCreate) 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 *IdentityAdoptionDecisionCreate) defaults() {
|
||||||
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||||
|
v := identityadoptiondecision.DefaultCreatedAt()
|
||||||
|
_c.mutation.SetCreatedAt(v)
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||||||
|
v := identityadoptiondecision.DefaultUpdatedAt()
|
||||||
|
_c.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.AdoptDisplayName(); !ok {
|
||||||
|
v := identityadoptiondecision.DefaultAdoptDisplayName
|
||||||
|
_c.mutation.SetAdoptDisplayName(v)
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.AdoptAvatar(); !ok {
|
||||||
|
v := identityadoptiondecision.DefaultAdoptAvatar
|
||||||
|
_c.mutation.SetAdoptAvatar(v)
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.DecidedAt(); !ok {
|
||||||
|
v := identityadoptiondecision.DefaultDecidedAt()
|
||||||
|
_c.mutation.SetDecidedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (_c *IdentityAdoptionDecisionCreate) check() error {
|
||||||
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||||
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "IdentityAdoptionDecision.created_at"`)}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||||||
|
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "IdentityAdoptionDecision.updated_at"`)}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.PendingAuthSessionID(); !ok {
|
||||||
|
return &ValidationError{Name: "pending_auth_session_id", err: errors.New(`ent: missing required field "IdentityAdoptionDecision.pending_auth_session_id"`)}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.AdoptDisplayName(); !ok {
|
||||||
|
return &ValidationError{Name: "adopt_display_name", err: errors.New(`ent: missing required field "IdentityAdoptionDecision.adopt_display_name"`)}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.AdoptAvatar(); !ok {
|
||||||
|
return &ValidationError{Name: "adopt_avatar", err: errors.New(`ent: missing required field "IdentityAdoptionDecision.adopt_avatar"`)}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.DecidedAt(); !ok {
|
||||||
|
return &ValidationError{Name: "decided_at", err: errors.New(`ent: missing required field "IdentityAdoptionDecision.decided_at"`)}
|
||||||
|
}
|
||||||
|
if len(_c.mutation.PendingAuthSessionIDs()) == 0 {
|
||||||
|
return &ValidationError{Name: "pending_auth_session", err: errors.New(`ent: missing required edge "IdentityAdoptionDecision.pending_auth_session"`)}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_c *IdentityAdoptionDecisionCreate) sqlSave(ctx context.Context) (*IdentityAdoptionDecision, 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 *IdentityAdoptionDecisionCreate) createSpec() (*IdentityAdoptionDecision, *sqlgraph.CreateSpec) {
|
||||||
|
var (
|
||||||
|
_node = &IdentityAdoptionDecision{config: _c.config}
|
||||||
|
_spec = sqlgraph.NewCreateSpec(identityadoptiondecision.Table, sqlgraph.NewFieldSpec(identityadoptiondecision.FieldID, field.TypeInt64))
|
||||||
|
)
|
||||||
|
_spec.OnConflict = _c.conflict
|
||||||
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
||||||
|
_spec.SetField(identityadoptiondecision.FieldCreatedAt, field.TypeTime, value)
|
||||||
|
_node.CreatedAt = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(identityadoptiondecision.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
_node.UpdatedAt = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.AdoptDisplayName(); ok {
|
||||||
|
_spec.SetField(identityadoptiondecision.FieldAdoptDisplayName, field.TypeBool, value)
|
||||||
|
_node.AdoptDisplayName = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.AdoptAvatar(); ok {
|
||||||
|
_spec.SetField(identityadoptiondecision.FieldAdoptAvatar, field.TypeBool, value)
|
||||||
|
_node.AdoptAvatar = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.DecidedAt(); ok {
|
||||||
|
_spec.SetField(identityadoptiondecision.FieldDecidedAt, field.TypeTime, value)
|
||||||
|
_node.DecidedAt = value
|
||||||
|
}
|
||||||
|
if nodes := _c.mutation.PendingAuthSessionIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: identityadoptiondecision.PendingAuthSessionTable,
|
||||||
|
Columns: []string{identityadoptiondecision.PendingAuthSessionColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(pendingauthsession.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_node.PendingAuthSessionID = nodes[0]
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
|
if nodes := _c.mutation.IdentityIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: identityadoptiondecision.IdentityTable,
|
||||||
|
Columns: []string{identityadoptiondecision.IdentityColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_node.IdentityID = &nodes[0]
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
|
return _node, _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||||||
|
// of the `INSERT` statement. For example:
|
||||||
|
//
|
||||||
|
// client.IdentityAdoptionDecision.Create().
|
||||||
|
// SetCreatedAt(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.IdentityAdoptionDecisionUpsert) {
|
||||||
|
// SetCreatedAt(v+v).
|
||||||
|
// }).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (_c *IdentityAdoptionDecisionCreate) OnConflict(opts ...sql.ConflictOption) *IdentityAdoptionDecisionUpsertOne {
|
||||||
|
_c.conflict = opts
|
||||||
|
return &IdentityAdoptionDecisionUpsertOne{
|
||||||
|
create: _c,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
||||||
|
// as conflict target. Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.IdentityAdoptionDecision.Create().
|
||||||
|
// OnConflict(sql.ConflictColumns(columns...)).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (_c *IdentityAdoptionDecisionCreate) OnConflictColumns(columns ...string) *IdentityAdoptionDecisionUpsertOne {
|
||||||
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
||||||
|
return &IdentityAdoptionDecisionUpsertOne{
|
||||||
|
create: _c,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// IdentityAdoptionDecisionUpsertOne is the builder for "upsert"-ing
|
||||||
|
// one IdentityAdoptionDecision node.
|
||||||
|
IdentityAdoptionDecisionUpsertOne struct {
|
||||||
|
create *IdentityAdoptionDecisionCreate
|
||||||
|
}
|
||||||
|
|
||||||
|
// IdentityAdoptionDecisionUpsert is the "OnConflict" setter.
|
||||||
|
IdentityAdoptionDecisionUpsert struct {
|
||||||
|
*sql.UpdateSet
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsert) SetUpdatedAt(v time.Time) *IdentityAdoptionDecisionUpsert {
|
||||||
|
u.Set(identityadoptiondecision.FieldUpdatedAt, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsert) UpdateUpdatedAt() *IdentityAdoptionDecisionUpsert {
|
||||||
|
u.SetExcluded(identityadoptiondecision.FieldUpdatedAt)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPendingAuthSessionID sets the "pending_auth_session_id" field.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsert) SetPendingAuthSessionID(v int64) *IdentityAdoptionDecisionUpsert {
|
||||||
|
u.Set(identityadoptiondecision.FieldPendingAuthSessionID, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatePendingAuthSessionID sets the "pending_auth_session_id" field to the value that was provided on create.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsert) UpdatePendingAuthSessionID() *IdentityAdoptionDecisionUpsert {
|
||||||
|
u.SetExcluded(identityadoptiondecision.FieldPendingAuthSessionID)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIdentityID sets the "identity_id" field.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsert) SetIdentityID(v int64) *IdentityAdoptionDecisionUpsert {
|
||||||
|
u.Set(identityadoptiondecision.FieldIdentityID, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateIdentityID sets the "identity_id" field to the value that was provided on create.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsert) UpdateIdentityID() *IdentityAdoptionDecisionUpsert {
|
||||||
|
u.SetExcluded(identityadoptiondecision.FieldIdentityID)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearIdentityID clears the value of the "identity_id" field.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsert) ClearIdentityID() *IdentityAdoptionDecisionUpsert {
|
||||||
|
u.SetNull(identityadoptiondecision.FieldIdentityID)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAdoptDisplayName sets the "adopt_display_name" field.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsert) SetAdoptDisplayName(v bool) *IdentityAdoptionDecisionUpsert {
|
||||||
|
u.Set(identityadoptiondecision.FieldAdoptDisplayName, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateAdoptDisplayName sets the "adopt_display_name" field to the value that was provided on create.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsert) UpdateAdoptDisplayName() *IdentityAdoptionDecisionUpsert {
|
||||||
|
u.SetExcluded(identityadoptiondecision.FieldAdoptDisplayName)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAdoptAvatar sets the "adopt_avatar" field.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsert) SetAdoptAvatar(v bool) *IdentityAdoptionDecisionUpsert {
|
||||||
|
u.Set(identityadoptiondecision.FieldAdoptAvatar, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateAdoptAvatar sets the "adopt_avatar" field to the value that was provided on create.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsert) UpdateAdoptAvatar() *IdentityAdoptionDecisionUpsert {
|
||||||
|
u.SetExcluded(identityadoptiondecision.FieldAdoptAvatar)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
||||||
|
// Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.IdentityAdoptionDecision.Create().
|
||||||
|
// OnConflict(
|
||||||
|
// sql.ResolveWithNewValues(),
|
||||||
|
// ).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertOne) UpdateNewValues() *IdentityAdoptionDecisionUpsertOne {
|
||||||
|
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(identityadoptiondecision.FieldCreatedAt)
|
||||||
|
}
|
||||||
|
if _, exists := u.create.mutation.DecidedAt(); exists {
|
||||||
|
s.SetIgnore(identityadoptiondecision.FieldDecidedAt)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ignore sets each column to itself in case of conflict.
|
||||||
|
// Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.IdentityAdoptionDecision.Create().
|
||||||
|
// OnConflict(sql.ResolveWithIgnore()).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertOne) Ignore() *IdentityAdoptionDecisionUpsertOne {
|
||||||
|
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 *IdentityAdoptionDecisionUpsertOne) DoNothing() *IdentityAdoptionDecisionUpsertOne {
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update allows overriding fields `UPDATE` values. See the IdentityAdoptionDecisionCreate.OnConflict
|
||||||
|
// documentation for more info.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertOne) Update(set func(*IdentityAdoptionDecisionUpsert)) *IdentityAdoptionDecisionUpsertOne {
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||||||
|
set(&IdentityAdoptionDecisionUpsert{UpdateSet: update})
|
||||||
|
}))
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertOne) SetUpdatedAt(v time.Time) *IdentityAdoptionDecisionUpsertOne {
|
||||||
|
return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
|
||||||
|
s.SetUpdatedAt(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertOne) UpdateUpdatedAt() *IdentityAdoptionDecisionUpsertOne {
|
||||||
|
return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
|
||||||
|
s.UpdateUpdatedAt()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPendingAuthSessionID sets the "pending_auth_session_id" field.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertOne) SetPendingAuthSessionID(v int64) *IdentityAdoptionDecisionUpsertOne {
|
||||||
|
return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
|
||||||
|
s.SetPendingAuthSessionID(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatePendingAuthSessionID sets the "pending_auth_session_id" field to the value that was provided on create.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertOne) UpdatePendingAuthSessionID() *IdentityAdoptionDecisionUpsertOne {
|
||||||
|
return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
|
||||||
|
s.UpdatePendingAuthSessionID()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIdentityID sets the "identity_id" field.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertOne) SetIdentityID(v int64) *IdentityAdoptionDecisionUpsertOne {
|
||||||
|
return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
|
||||||
|
s.SetIdentityID(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateIdentityID sets the "identity_id" field to the value that was provided on create.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertOne) UpdateIdentityID() *IdentityAdoptionDecisionUpsertOne {
|
||||||
|
return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
|
||||||
|
s.UpdateIdentityID()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearIdentityID clears the value of the "identity_id" field.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertOne) ClearIdentityID() *IdentityAdoptionDecisionUpsertOne {
|
||||||
|
return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
|
||||||
|
s.ClearIdentityID()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAdoptDisplayName sets the "adopt_display_name" field.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertOne) SetAdoptDisplayName(v bool) *IdentityAdoptionDecisionUpsertOne {
|
||||||
|
return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
|
||||||
|
s.SetAdoptDisplayName(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateAdoptDisplayName sets the "adopt_display_name" field to the value that was provided on create.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertOne) UpdateAdoptDisplayName() *IdentityAdoptionDecisionUpsertOne {
|
||||||
|
return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
|
||||||
|
s.UpdateAdoptDisplayName()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAdoptAvatar sets the "adopt_avatar" field.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertOne) SetAdoptAvatar(v bool) *IdentityAdoptionDecisionUpsertOne {
|
||||||
|
return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
|
||||||
|
s.SetAdoptAvatar(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateAdoptAvatar sets the "adopt_avatar" field to the value that was provided on create.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertOne) UpdateAdoptAvatar() *IdentityAdoptionDecisionUpsertOne {
|
||||||
|
return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
|
||||||
|
s.UpdateAdoptAvatar()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertOne) Exec(ctx context.Context) error {
|
||||||
|
if len(u.create.conflict) == 0 {
|
||||||
|
return errors.New("ent: missing options for IdentityAdoptionDecisionCreate.OnConflict")
|
||||||
|
}
|
||||||
|
return u.create.Exec(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertOne) 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 *IdentityAdoptionDecisionUpsertOne) 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 *IdentityAdoptionDecisionUpsertOne) IDX(ctx context.Context) int64 {
|
||||||
|
id, err := u.ID(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// IdentityAdoptionDecisionCreateBulk is the builder for creating many IdentityAdoptionDecision entities in bulk.
|
||||||
|
type IdentityAdoptionDecisionCreateBulk struct {
|
||||||
|
config
|
||||||
|
err error
|
||||||
|
builders []*IdentityAdoptionDecisionCreate
|
||||||
|
conflict []sql.ConflictOption
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the IdentityAdoptionDecision entities in the database.
|
||||||
|
func (_c *IdentityAdoptionDecisionCreateBulk) Save(ctx context.Context) ([]*IdentityAdoptionDecision, error) {
|
||||||
|
if _c.err != nil {
|
||||||
|
return nil, _c.err
|
||||||
|
}
|
||||||
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||||
|
nodes := make([]*IdentityAdoptionDecision, 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.(*IdentityAdoptionDecisionMutation)
|
||||||
|
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 *IdentityAdoptionDecisionCreateBulk) SaveX(ctx context.Context) []*IdentityAdoptionDecision {
|
||||||
|
v, err := _c.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (_c *IdentityAdoptionDecisionCreateBulk) Exec(ctx context.Context) error {
|
||||||
|
_, err := _c.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_c *IdentityAdoptionDecisionCreateBulk) 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.IdentityAdoptionDecision.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.IdentityAdoptionDecisionUpsert) {
|
||||||
|
// SetCreatedAt(v+v).
|
||||||
|
// }).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (_c *IdentityAdoptionDecisionCreateBulk) OnConflict(opts ...sql.ConflictOption) *IdentityAdoptionDecisionUpsertBulk {
|
||||||
|
_c.conflict = opts
|
||||||
|
return &IdentityAdoptionDecisionUpsertBulk{
|
||||||
|
create: _c,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
||||||
|
// as conflict target. Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.IdentityAdoptionDecision.Create().
|
||||||
|
// OnConflict(sql.ConflictColumns(columns...)).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (_c *IdentityAdoptionDecisionCreateBulk) OnConflictColumns(columns ...string) *IdentityAdoptionDecisionUpsertBulk {
|
||||||
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
||||||
|
return &IdentityAdoptionDecisionUpsertBulk{
|
||||||
|
create: _c,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// IdentityAdoptionDecisionUpsertBulk is the builder for "upsert"-ing
|
||||||
|
// a bulk of IdentityAdoptionDecision nodes.
|
||||||
|
type IdentityAdoptionDecisionUpsertBulk struct {
|
||||||
|
create *IdentityAdoptionDecisionCreateBulk
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateNewValues updates the mutable fields using the new values that
|
||||||
|
// were set on create. Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.IdentityAdoptionDecision.Create().
|
||||||
|
// OnConflict(
|
||||||
|
// sql.ResolveWithNewValues(),
|
||||||
|
// ).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertBulk) UpdateNewValues() *IdentityAdoptionDecisionUpsertBulk {
|
||||||
|
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(identityadoptiondecision.FieldCreatedAt)
|
||||||
|
}
|
||||||
|
if _, exists := b.mutation.DecidedAt(); exists {
|
||||||
|
s.SetIgnore(identityadoptiondecision.FieldDecidedAt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ignore sets each column to itself in case of conflict.
|
||||||
|
// Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.IdentityAdoptionDecision.Create().
|
||||||
|
// OnConflict(sql.ResolveWithIgnore()).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertBulk) Ignore() *IdentityAdoptionDecisionUpsertBulk {
|
||||||
|
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 *IdentityAdoptionDecisionUpsertBulk) DoNothing() *IdentityAdoptionDecisionUpsertBulk {
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update allows overriding fields `UPDATE` values. See the IdentityAdoptionDecisionCreateBulk.OnConflict
|
||||||
|
// documentation for more info.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertBulk) Update(set func(*IdentityAdoptionDecisionUpsert)) *IdentityAdoptionDecisionUpsertBulk {
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||||||
|
set(&IdentityAdoptionDecisionUpsert{UpdateSet: update})
|
||||||
|
}))
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertBulk) SetUpdatedAt(v time.Time) *IdentityAdoptionDecisionUpsertBulk {
|
||||||
|
return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
|
||||||
|
s.SetUpdatedAt(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertBulk) UpdateUpdatedAt() *IdentityAdoptionDecisionUpsertBulk {
|
||||||
|
return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
|
||||||
|
s.UpdateUpdatedAt()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPendingAuthSessionID sets the "pending_auth_session_id" field.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertBulk) SetPendingAuthSessionID(v int64) *IdentityAdoptionDecisionUpsertBulk {
|
||||||
|
return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
|
||||||
|
s.SetPendingAuthSessionID(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatePendingAuthSessionID sets the "pending_auth_session_id" field to the value that was provided on create.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertBulk) UpdatePendingAuthSessionID() *IdentityAdoptionDecisionUpsertBulk {
|
||||||
|
return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
|
||||||
|
s.UpdatePendingAuthSessionID()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIdentityID sets the "identity_id" field.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertBulk) SetIdentityID(v int64) *IdentityAdoptionDecisionUpsertBulk {
|
||||||
|
return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
|
||||||
|
s.SetIdentityID(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateIdentityID sets the "identity_id" field to the value that was provided on create.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertBulk) UpdateIdentityID() *IdentityAdoptionDecisionUpsertBulk {
|
||||||
|
return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
|
||||||
|
s.UpdateIdentityID()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearIdentityID clears the value of the "identity_id" field.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertBulk) ClearIdentityID() *IdentityAdoptionDecisionUpsertBulk {
|
||||||
|
return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
|
||||||
|
s.ClearIdentityID()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAdoptDisplayName sets the "adopt_display_name" field.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertBulk) SetAdoptDisplayName(v bool) *IdentityAdoptionDecisionUpsertBulk {
|
||||||
|
return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
|
||||||
|
s.SetAdoptDisplayName(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateAdoptDisplayName sets the "adopt_display_name" field to the value that was provided on create.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertBulk) UpdateAdoptDisplayName() *IdentityAdoptionDecisionUpsertBulk {
|
||||||
|
return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
|
||||||
|
s.UpdateAdoptDisplayName()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAdoptAvatar sets the "adopt_avatar" field.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertBulk) SetAdoptAvatar(v bool) *IdentityAdoptionDecisionUpsertBulk {
|
||||||
|
return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
|
||||||
|
s.SetAdoptAvatar(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateAdoptAvatar sets the "adopt_avatar" field to the value that was provided on create.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertBulk) UpdateAdoptAvatar() *IdentityAdoptionDecisionUpsertBulk {
|
||||||
|
return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
|
||||||
|
s.UpdateAdoptAvatar()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertBulk) 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 IdentityAdoptionDecisionCreateBulk instead", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(u.create.conflict) == 0 {
|
||||||
|
return errors.New("ent: missing options for IdentityAdoptionDecisionCreateBulk.OnConflict")
|
||||||
|
}
|
||||||
|
return u.create.Exec(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (u *IdentityAdoptionDecisionUpsertBulk) ExecX(ctx context.Context) {
|
||||||
|
if err := u.create.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
// 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/identityadoptiondecision"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/predicate"
|
||||||
|
)
|
||||||
|
|
||||||
|
// IdentityAdoptionDecisionDelete is the builder for deleting a IdentityAdoptionDecision entity.
|
||||||
|
type IdentityAdoptionDecisionDelete struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *IdentityAdoptionDecisionMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the IdentityAdoptionDecisionDelete builder.
|
||||||
|
func (_d *IdentityAdoptionDecisionDelete) Where(ps ...predicate.IdentityAdoptionDecision) *IdentityAdoptionDecisionDelete {
|
||||||
|
_d.mutation.Where(ps...)
|
||||||
|
return _d
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||||
|
func (_d *IdentityAdoptionDecisionDelete) 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 *IdentityAdoptionDecisionDelete) ExecX(ctx context.Context) int {
|
||||||
|
n, err := _d.Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_d *IdentityAdoptionDecisionDelete) sqlExec(ctx context.Context) (int, error) {
|
||||||
|
_spec := sqlgraph.NewDeleteSpec(identityadoptiondecision.Table, sqlgraph.NewFieldSpec(identityadoptiondecision.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
|
||||||
|
}
|
||||||
|
|
||||||
|
// IdentityAdoptionDecisionDeleteOne is the builder for deleting a single IdentityAdoptionDecision entity.
|
||||||
|
type IdentityAdoptionDecisionDeleteOne struct {
|
||||||
|
_d *IdentityAdoptionDecisionDelete
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the IdentityAdoptionDecisionDelete builder.
|
||||||
|
func (_d *IdentityAdoptionDecisionDeleteOne) Where(ps ...predicate.IdentityAdoptionDecision) *IdentityAdoptionDecisionDeleteOne {
|
||||||
|
_d._d.mutation.Where(ps...)
|
||||||
|
return _d
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query.
|
||||||
|
func (_d *IdentityAdoptionDecisionDeleteOne) Exec(ctx context.Context) error {
|
||||||
|
n, err := _d._d.Exec(ctx)
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
|
case n == 0:
|
||||||
|
return &NotFoundError{identityadoptiondecision.Label}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_d *IdentityAdoptionDecisionDeleteOne) ExecX(ctx context.Context) {
|
||||||
|
if err := _d.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,721 @@
|
|||||||
|
// 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/authidentity"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/identityadoptiondecision"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/pendingauthsession"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/predicate"
|
||||||
|
)
|
||||||
|
|
||||||
|
// IdentityAdoptionDecisionQuery is the builder for querying IdentityAdoptionDecision entities.
|
||||||
|
type IdentityAdoptionDecisionQuery struct {
|
||||||
|
config
|
||||||
|
ctx *QueryContext
|
||||||
|
order []identityadoptiondecision.OrderOption
|
||||||
|
inters []Interceptor
|
||||||
|
predicates []predicate.IdentityAdoptionDecision
|
||||||
|
withPendingAuthSession *PendingAuthSessionQuery
|
||||||
|
withIdentity *AuthIdentityQuery
|
||||||
|
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 IdentityAdoptionDecisionQuery builder.
|
||||||
|
func (_q *IdentityAdoptionDecisionQuery) Where(ps ...predicate.IdentityAdoptionDecision) *IdentityAdoptionDecisionQuery {
|
||||||
|
_q.predicates = append(_q.predicates, ps...)
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit the number of records to be returned by this query.
|
||||||
|
func (_q *IdentityAdoptionDecisionQuery) Limit(limit int) *IdentityAdoptionDecisionQuery {
|
||||||
|
_q.ctx.Limit = &limit
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Offset to start from.
|
||||||
|
func (_q *IdentityAdoptionDecisionQuery) Offset(offset int) *IdentityAdoptionDecisionQuery {
|
||||||
|
_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 *IdentityAdoptionDecisionQuery) Unique(unique bool) *IdentityAdoptionDecisionQuery {
|
||||||
|
_q.ctx.Unique = &unique
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Order specifies how the records should be ordered.
|
||||||
|
func (_q *IdentityAdoptionDecisionQuery) Order(o ...identityadoptiondecision.OrderOption) *IdentityAdoptionDecisionQuery {
|
||||||
|
_q.order = append(_q.order, o...)
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryPendingAuthSession chains the current query on the "pending_auth_session" edge.
|
||||||
|
func (_q *IdentityAdoptionDecisionQuery) QueryPendingAuthSession() *PendingAuthSessionQuery {
|
||||||
|
query := (&PendingAuthSessionClient{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(identityadoptiondecision.Table, identityadoptiondecision.FieldID, selector),
|
||||||
|
sqlgraph.To(pendingauthsession.Table, pendingauthsession.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2O, true, identityadoptiondecision.PendingAuthSessionTable, identityadoptiondecision.PendingAuthSessionColumn),
|
||||||
|
)
|
||||||
|
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||||
|
return fromU, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryIdentity chains the current query on the "identity" edge.
|
||||||
|
func (_q *IdentityAdoptionDecisionQuery) QueryIdentity() *AuthIdentityQuery {
|
||||||
|
query := (&AuthIdentityClient{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(identityadoptiondecision.Table, identityadoptiondecision.FieldID, selector),
|
||||||
|
sqlgraph.To(authidentity.Table, authidentity.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, identityadoptiondecision.IdentityTable, identityadoptiondecision.IdentityColumn),
|
||||||
|
)
|
||||||
|
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||||
|
return fromU, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// First returns the first IdentityAdoptionDecision entity from the query.
|
||||||
|
// Returns a *NotFoundError when no IdentityAdoptionDecision was found.
|
||||||
|
func (_q *IdentityAdoptionDecisionQuery) First(ctx context.Context) (*IdentityAdoptionDecision, 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{identityadoptiondecision.Label}
|
||||||
|
}
|
||||||
|
return nodes[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstX is like First, but panics if an error occurs.
|
||||||
|
func (_q *IdentityAdoptionDecisionQuery) FirstX(ctx context.Context) *IdentityAdoptionDecision {
|
||||||
|
node, err := _q.First(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstID returns the first IdentityAdoptionDecision ID from the query.
|
||||||
|
// Returns a *NotFoundError when no IdentityAdoptionDecision ID was found.
|
||||||
|
func (_q *IdentityAdoptionDecisionQuery) 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{identityadoptiondecision.Label}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return ids[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||||
|
func (_q *IdentityAdoptionDecisionQuery) FirstIDX(ctx context.Context) int64 {
|
||||||
|
id, err := _q.FirstID(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only returns a single IdentityAdoptionDecision entity found by the query, ensuring it only returns one.
|
||||||
|
// Returns a *NotSingularError when more than one IdentityAdoptionDecision entity is found.
|
||||||
|
// Returns a *NotFoundError when no IdentityAdoptionDecision entities are found.
|
||||||
|
func (_q *IdentityAdoptionDecisionQuery) Only(ctx context.Context) (*IdentityAdoptionDecision, 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{identityadoptiondecision.Label}
|
||||||
|
default:
|
||||||
|
return nil, &NotSingularError{identityadoptiondecision.Label}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyX is like Only, but panics if an error occurs.
|
||||||
|
func (_q *IdentityAdoptionDecisionQuery) OnlyX(ctx context.Context) *IdentityAdoptionDecision {
|
||||||
|
node, err := _q.Only(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyID is like Only, but returns the only IdentityAdoptionDecision ID in the query.
|
||||||
|
// Returns a *NotSingularError when more than one IdentityAdoptionDecision ID is found.
|
||||||
|
// Returns a *NotFoundError when no entities are found.
|
||||||
|
func (_q *IdentityAdoptionDecisionQuery) 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{identityadoptiondecision.Label}
|
||||||
|
default:
|
||||||
|
err = &NotSingularError{identityadoptiondecision.Label}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||||
|
func (_q *IdentityAdoptionDecisionQuery) 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 IdentityAdoptionDecisions.
|
||||||
|
func (_q *IdentityAdoptionDecisionQuery) All(ctx context.Context) ([]*IdentityAdoptionDecision, error) {
|
||||||
|
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||||
|
if err := _q.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
qr := querierAll[[]*IdentityAdoptionDecision, *IdentityAdoptionDecisionQuery]()
|
||||||
|
return withInterceptors[[]*IdentityAdoptionDecision](ctx, _q, qr, _q.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllX is like All, but panics if an error occurs.
|
||||||
|
func (_q *IdentityAdoptionDecisionQuery) AllX(ctx context.Context) []*IdentityAdoptionDecision {
|
||||||
|
nodes, err := _q.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return nodes
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDs executes the query and returns a list of IdentityAdoptionDecision IDs.
|
||||||
|
func (_q *IdentityAdoptionDecisionQuery) 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(identityadoptiondecision.FieldID).Scan(ctx, &ids); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ids, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDsX is like IDs, but panics if an error occurs.
|
||||||
|
func (_q *IdentityAdoptionDecisionQuery) 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 *IdentityAdoptionDecisionQuery) 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[*IdentityAdoptionDecisionQuery](), _q.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountX is like Count, but panics if an error occurs.
|
||||||
|
func (_q *IdentityAdoptionDecisionQuery) 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 *IdentityAdoptionDecisionQuery) 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 *IdentityAdoptionDecisionQuery) ExistX(ctx context.Context) bool {
|
||||||
|
exist, err := _q.Exist(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return exist
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone returns a duplicate of the IdentityAdoptionDecisionQuery 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 *IdentityAdoptionDecisionQuery) Clone() *IdentityAdoptionDecisionQuery {
|
||||||
|
if _q == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &IdentityAdoptionDecisionQuery{
|
||||||
|
config: _q.config,
|
||||||
|
ctx: _q.ctx.Clone(),
|
||||||
|
order: append([]identityadoptiondecision.OrderOption{}, _q.order...),
|
||||||
|
inters: append([]Interceptor{}, _q.inters...),
|
||||||
|
predicates: append([]predicate.IdentityAdoptionDecision{}, _q.predicates...),
|
||||||
|
withPendingAuthSession: _q.withPendingAuthSession.Clone(),
|
||||||
|
withIdentity: _q.withIdentity.Clone(),
|
||||||
|
// clone intermediate query.
|
||||||
|
sql: _q.sql.Clone(),
|
||||||
|
path: _q.path,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithPendingAuthSession tells the query-builder to eager-load the nodes that are connected to
|
||||||
|
// the "pending_auth_session" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (_q *IdentityAdoptionDecisionQuery) WithPendingAuthSession(opts ...func(*PendingAuthSessionQuery)) *IdentityAdoptionDecisionQuery {
|
||||||
|
query := (&PendingAuthSessionClient{config: _q.config}).Query()
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
_q.withPendingAuthSession = query
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithIdentity tells the query-builder to eager-load the nodes that are connected to
|
||||||
|
// the "identity" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (_q *IdentityAdoptionDecisionQuery) WithIdentity(opts ...func(*AuthIdentityQuery)) *IdentityAdoptionDecisionQuery {
|
||||||
|
query := (&AuthIdentityClient{config: _q.config}).Query()
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
_q.withIdentity = query
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// Count int `json:"count,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.IdentityAdoptionDecision.Query().
|
||||||
|
// GroupBy(identityadoptiondecision.FieldCreatedAt).
|
||||||
|
// Aggregate(ent.Count()).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (_q *IdentityAdoptionDecisionQuery) GroupBy(field string, fields ...string) *IdentityAdoptionDecisionGroupBy {
|
||||||
|
_q.ctx.Fields = append([]string{field}, fields...)
|
||||||
|
grbuild := &IdentityAdoptionDecisionGroupBy{build: _q}
|
||||||
|
grbuild.flds = &_q.ctx.Fields
|
||||||
|
grbuild.label = identityadoptiondecision.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 {
|
||||||
|
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.IdentityAdoptionDecision.Query().
|
||||||
|
// Select(identityadoptiondecision.FieldCreatedAt).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (_q *IdentityAdoptionDecisionQuery) Select(fields ...string) *IdentityAdoptionDecisionSelect {
|
||||||
|
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||||
|
sbuild := &IdentityAdoptionDecisionSelect{IdentityAdoptionDecisionQuery: _q}
|
||||||
|
sbuild.label = identityadoptiondecision.Label
|
||||||
|
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||||
|
return sbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate returns a IdentityAdoptionDecisionSelect configured with the given aggregations.
|
||||||
|
func (_q *IdentityAdoptionDecisionQuery) Aggregate(fns ...AggregateFunc) *IdentityAdoptionDecisionSelect {
|
||||||
|
return _q.Select().Aggregate(fns...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *IdentityAdoptionDecisionQuery) 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 !identityadoptiondecision.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 *IdentityAdoptionDecisionQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*IdentityAdoptionDecision, error) {
|
||||||
|
var (
|
||||||
|
nodes = []*IdentityAdoptionDecision{}
|
||||||
|
_spec = _q.querySpec()
|
||||||
|
loadedTypes = [2]bool{
|
||||||
|
_q.withPendingAuthSession != nil,
|
||||||
|
_q.withIdentity != nil,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||||
|
return (*IdentityAdoptionDecision).scanValues(nil, columns)
|
||||||
|
}
|
||||||
|
_spec.Assign = func(columns []string, values []any) error {
|
||||||
|
node := &IdentityAdoptionDecision{config: _q.config}
|
||||||
|
nodes = append(nodes, node)
|
||||||
|
node.Edges.loadedTypes = loadedTypes
|
||||||
|
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
|
||||||
|
}
|
||||||
|
if query := _q.withPendingAuthSession; query != nil {
|
||||||
|
if err := _q.loadPendingAuthSession(ctx, query, nodes, nil,
|
||||||
|
func(n *IdentityAdoptionDecision, e *PendingAuthSession) { n.Edges.PendingAuthSession = e }); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if query := _q.withIdentity; query != nil {
|
||||||
|
if err := _q.loadIdentity(ctx, query, nodes, nil,
|
||||||
|
func(n *IdentityAdoptionDecision, e *AuthIdentity) { n.Edges.Identity = e }); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *IdentityAdoptionDecisionQuery) loadPendingAuthSession(ctx context.Context, query *PendingAuthSessionQuery, nodes []*IdentityAdoptionDecision, init func(*IdentityAdoptionDecision), assign func(*IdentityAdoptionDecision, *PendingAuthSession)) error {
|
||||||
|
ids := make([]int64, 0, len(nodes))
|
||||||
|
nodeids := make(map[int64][]*IdentityAdoptionDecision)
|
||||||
|
for i := range nodes {
|
||||||
|
fk := nodes[i].PendingAuthSessionID
|
||||||
|
if _, ok := nodeids[fk]; !ok {
|
||||||
|
ids = append(ids, fk)
|
||||||
|
}
|
||||||
|
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
query.Where(pendingauthsession.IDIn(ids...))
|
||||||
|
neighbors, err := query.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, n := range neighbors {
|
||||||
|
nodes, ok := nodeids[n.ID]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(`unexpected foreign-key "pending_auth_session_id" returned %v`, n.ID)
|
||||||
|
}
|
||||||
|
for i := range nodes {
|
||||||
|
assign(nodes[i], n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (_q *IdentityAdoptionDecisionQuery) loadIdentity(ctx context.Context, query *AuthIdentityQuery, nodes []*IdentityAdoptionDecision, init func(*IdentityAdoptionDecision), assign func(*IdentityAdoptionDecision, *AuthIdentity)) error {
|
||||||
|
ids := make([]int64, 0, len(nodes))
|
||||||
|
nodeids := make(map[int64][]*IdentityAdoptionDecision)
|
||||||
|
for i := range nodes {
|
||||||
|
if nodes[i].IdentityID == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fk := *nodes[i].IdentityID
|
||||||
|
if _, ok := nodeids[fk]; !ok {
|
||||||
|
ids = append(ids, fk)
|
||||||
|
}
|
||||||
|
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
query.Where(authidentity.IDIn(ids...))
|
||||||
|
neighbors, err := query.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, n := range neighbors {
|
||||||
|
nodes, ok := nodeids[n.ID]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(`unexpected foreign-key "identity_id" returned %v`, n.ID)
|
||||||
|
}
|
||||||
|
for i := range nodes {
|
||||||
|
assign(nodes[i], n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *IdentityAdoptionDecisionQuery) 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 *IdentityAdoptionDecisionQuery) querySpec() *sqlgraph.QuerySpec {
|
||||||
|
_spec := sqlgraph.NewQuerySpec(identityadoptiondecision.Table, identityadoptiondecision.Columns, sqlgraph.NewFieldSpec(identityadoptiondecision.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, identityadoptiondecision.FieldID)
|
||||||
|
for i := range fields {
|
||||||
|
if fields[i] != identityadoptiondecision.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _q.withPendingAuthSession != nil {
|
||||||
|
_spec.Node.AddColumnOnce(identityadoptiondecision.FieldPendingAuthSessionID)
|
||||||
|
}
|
||||||
|
if _q.withIdentity != nil {
|
||||||
|
_spec.Node.AddColumnOnce(identityadoptiondecision.FieldIdentityID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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 *IdentityAdoptionDecisionQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||||
|
builder := sql.Dialect(_q.driver.Dialect())
|
||||||
|
t1 := builder.Table(identityadoptiondecision.Table)
|
||||||
|
columns := _q.ctx.Fields
|
||||||
|
if len(columns) == 0 {
|
||||||
|
columns = identityadoptiondecision.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 *IdentityAdoptionDecisionQuery) ForUpdate(opts ...sql.LockOption) *IdentityAdoptionDecisionQuery {
|
||||||
|
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 *IdentityAdoptionDecisionQuery) ForShare(opts ...sql.LockOption) *IdentityAdoptionDecisionQuery {
|
||||||
|
if _q.driver.Dialect() == dialect.Postgres {
|
||||||
|
_q.Unique(false)
|
||||||
|
}
|
||||||
|
_q.modifiers = append(_q.modifiers, func(s *sql.Selector) {
|
||||||
|
s.ForShare(opts...)
|
||||||
|
})
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// IdentityAdoptionDecisionGroupBy is the group-by builder for IdentityAdoptionDecision entities.
|
||||||
|
type IdentityAdoptionDecisionGroupBy struct {
|
||||||
|
selector
|
||||||
|
build *IdentityAdoptionDecisionQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the group-by query.
|
||||||
|
func (_g *IdentityAdoptionDecisionGroupBy) Aggregate(fns ...AggregateFunc) *IdentityAdoptionDecisionGroupBy {
|
||||||
|
_g.fns = append(_g.fns, fns...)
|
||||||
|
return _g
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (_g *IdentityAdoptionDecisionGroupBy) 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[*IdentityAdoptionDecisionQuery, *IdentityAdoptionDecisionGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_g *IdentityAdoptionDecisionGroupBy) sqlScan(ctx context.Context, root *IdentityAdoptionDecisionQuery, 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IdentityAdoptionDecisionSelect is the builder for selecting fields of IdentityAdoptionDecision entities.
|
||||||
|
type IdentityAdoptionDecisionSelect struct {
|
||||||
|
*IdentityAdoptionDecisionQuery
|
||||||
|
selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the selector query.
|
||||||
|
func (_s *IdentityAdoptionDecisionSelect) Aggregate(fns ...AggregateFunc) *IdentityAdoptionDecisionSelect {
|
||||||
|
_s.fns = append(_s.fns, fns...)
|
||||||
|
return _s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (_s *IdentityAdoptionDecisionSelect) 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[*IdentityAdoptionDecisionQuery, *IdentityAdoptionDecisionSelect](ctx, _s.IdentityAdoptionDecisionQuery, _s, _s.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_s *IdentityAdoptionDecisionSelect) sqlScan(ctx context.Context, root *IdentityAdoptionDecisionQuery, 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)
|
||||||
|
}
|
||||||
@@ -0,0 +1,532 @@
|
|||||||
|
// 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/authidentity"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/identityadoptiondecision"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/pendingauthsession"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/predicate"
|
||||||
|
)
|
||||||
|
|
||||||
|
// IdentityAdoptionDecisionUpdate is the builder for updating IdentityAdoptionDecision entities.
|
||||||
|
type IdentityAdoptionDecisionUpdate struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *IdentityAdoptionDecisionMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the IdentityAdoptionDecisionUpdate builder.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdate) Where(ps ...predicate.IdentityAdoptionDecision) *IdentityAdoptionDecisionUpdate {
|
||||||
|
_u.mutation.Where(ps...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdate) SetUpdatedAt(v time.Time) *IdentityAdoptionDecisionUpdate {
|
||||||
|
_u.mutation.SetUpdatedAt(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPendingAuthSessionID sets the "pending_auth_session_id" field.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdate) SetPendingAuthSessionID(v int64) *IdentityAdoptionDecisionUpdate {
|
||||||
|
_u.mutation.SetPendingAuthSessionID(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillablePendingAuthSessionID sets the "pending_auth_session_id" field if the given value is not nil.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdate) SetNillablePendingAuthSessionID(v *int64) *IdentityAdoptionDecisionUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetPendingAuthSessionID(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIdentityID sets the "identity_id" field.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdate) SetIdentityID(v int64) *IdentityAdoptionDecisionUpdate {
|
||||||
|
_u.mutation.SetIdentityID(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableIdentityID sets the "identity_id" field if the given value is not nil.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdate) SetNillableIdentityID(v *int64) *IdentityAdoptionDecisionUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetIdentityID(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearIdentityID clears the value of the "identity_id" field.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdate) ClearIdentityID() *IdentityAdoptionDecisionUpdate {
|
||||||
|
_u.mutation.ClearIdentityID()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAdoptDisplayName sets the "adopt_display_name" field.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdate) SetAdoptDisplayName(v bool) *IdentityAdoptionDecisionUpdate {
|
||||||
|
_u.mutation.SetAdoptDisplayName(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableAdoptDisplayName sets the "adopt_display_name" field if the given value is not nil.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdate) SetNillableAdoptDisplayName(v *bool) *IdentityAdoptionDecisionUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetAdoptDisplayName(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAdoptAvatar sets the "adopt_avatar" field.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdate) SetAdoptAvatar(v bool) *IdentityAdoptionDecisionUpdate {
|
||||||
|
_u.mutation.SetAdoptAvatar(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableAdoptAvatar sets the "adopt_avatar" field if the given value is not nil.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdate) SetNillableAdoptAvatar(v *bool) *IdentityAdoptionDecisionUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetAdoptAvatar(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPendingAuthSession sets the "pending_auth_session" edge to the PendingAuthSession entity.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdate) SetPendingAuthSession(v *PendingAuthSession) *IdentityAdoptionDecisionUpdate {
|
||||||
|
return _u.SetPendingAuthSessionID(v.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIdentity sets the "identity" edge to the AuthIdentity entity.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdate) SetIdentity(v *AuthIdentity) *IdentityAdoptionDecisionUpdate {
|
||||||
|
return _u.SetIdentityID(v.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the IdentityAdoptionDecisionMutation object of the builder.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdate) Mutation() *IdentityAdoptionDecisionMutation {
|
||||||
|
return _u.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearPendingAuthSession clears the "pending_auth_session" edge to the PendingAuthSession entity.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdate) ClearPendingAuthSession() *IdentityAdoptionDecisionUpdate {
|
||||||
|
_u.mutation.ClearPendingAuthSession()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearIdentity clears the "identity" edge to the AuthIdentity entity.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdate) ClearIdentity() *IdentityAdoptionDecisionUpdate {
|
||||||
|
_u.mutation.ClearIdentity()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdate) 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 *IdentityAdoptionDecisionUpdate) SaveX(ctx context.Context) int {
|
||||||
|
affected, err := _u.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return affected
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdate) Exec(ctx context.Context) error {
|
||||||
|
_, err := _u.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdate) 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 *IdentityAdoptionDecisionUpdate) defaults() {
|
||||||
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
||||||
|
v := identityadoptiondecision.UpdateDefaultUpdatedAt()
|
||||||
|
_u.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdate) check() error {
|
||||||
|
if _u.mutation.PendingAuthSessionCleared() && len(_u.mutation.PendingAuthSessionIDs()) > 0 {
|
||||||
|
return errors.New(`ent: clearing a required unique edge "IdentityAdoptionDecision.pending_auth_session"`)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||||
|
if err := _u.check(); err != nil {
|
||||||
|
return _node, err
|
||||||
|
}
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(identityadoptiondecision.Table, identityadoptiondecision.Columns, sqlgraph.NewFieldSpec(identityadoptiondecision.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.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(identityadoptiondecision.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AdoptDisplayName(); ok {
|
||||||
|
_spec.SetField(identityadoptiondecision.FieldAdoptDisplayName, field.TypeBool, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AdoptAvatar(); ok {
|
||||||
|
_spec.SetField(identityadoptiondecision.FieldAdoptAvatar, field.TypeBool, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.PendingAuthSessionCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: identityadoptiondecision.PendingAuthSessionTable,
|
||||||
|
Columns: []string{identityadoptiondecision.PendingAuthSessionColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(pendingauthsession.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := _u.mutation.PendingAuthSessionIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: identityadoptiondecision.PendingAuthSessionTable,
|
||||||
|
Columns: []string{identityadoptiondecision.PendingAuthSessionColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(pendingauthsession.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if _u.mutation.IdentityCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: identityadoptiondecision.IdentityTable,
|
||||||
|
Columns: []string{identityadoptiondecision.IdentityColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := _u.mutation.IdentityIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: identityadoptiondecision.IdentityTable,
|
||||||
|
Columns: []string{identityadoptiondecision.IdentityColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(authidentity.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{identityadoptiondecision.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
_u.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IdentityAdoptionDecisionUpdateOne is the builder for updating a single IdentityAdoptionDecision entity.
|
||||||
|
type IdentityAdoptionDecisionUpdateOne struct {
|
||||||
|
config
|
||||||
|
fields []string
|
||||||
|
hooks []Hook
|
||||||
|
mutation *IdentityAdoptionDecisionMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdateOne) SetUpdatedAt(v time.Time) *IdentityAdoptionDecisionUpdateOne {
|
||||||
|
_u.mutation.SetUpdatedAt(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPendingAuthSessionID sets the "pending_auth_session_id" field.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdateOne) SetPendingAuthSessionID(v int64) *IdentityAdoptionDecisionUpdateOne {
|
||||||
|
_u.mutation.SetPendingAuthSessionID(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillablePendingAuthSessionID sets the "pending_auth_session_id" field if the given value is not nil.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdateOne) SetNillablePendingAuthSessionID(v *int64) *IdentityAdoptionDecisionUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetPendingAuthSessionID(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIdentityID sets the "identity_id" field.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdateOne) SetIdentityID(v int64) *IdentityAdoptionDecisionUpdateOne {
|
||||||
|
_u.mutation.SetIdentityID(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableIdentityID sets the "identity_id" field if the given value is not nil.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdateOne) SetNillableIdentityID(v *int64) *IdentityAdoptionDecisionUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetIdentityID(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearIdentityID clears the value of the "identity_id" field.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdateOne) ClearIdentityID() *IdentityAdoptionDecisionUpdateOne {
|
||||||
|
_u.mutation.ClearIdentityID()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAdoptDisplayName sets the "adopt_display_name" field.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdateOne) SetAdoptDisplayName(v bool) *IdentityAdoptionDecisionUpdateOne {
|
||||||
|
_u.mutation.SetAdoptDisplayName(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableAdoptDisplayName sets the "adopt_display_name" field if the given value is not nil.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdateOne) SetNillableAdoptDisplayName(v *bool) *IdentityAdoptionDecisionUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetAdoptDisplayName(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAdoptAvatar sets the "adopt_avatar" field.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdateOne) SetAdoptAvatar(v bool) *IdentityAdoptionDecisionUpdateOne {
|
||||||
|
_u.mutation.SetAdoptAvatar(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableAdoptAvatar sets the "adopt_avatar" field if the given value is not nil.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdateOne) SetNillableAdoptAvatar(v *bool) *IdentityAdoptionDecisionUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetAdoptAvatar(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPendingAuthSession sets the "pending_auth_session" edge to the PendingAuthSession entity.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdateOne) SetPendingAuthSession(v *PendingAuthSession) *IdentityAdoptionDecisionUpdateOne {
|
||||||
|
return _u.SetPendingAuthSessionID(v.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIdentity sets the "identity" edge to the AuthIdentity entity.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdateOne) SetIdentity(v *AuthIdentity) *IdentityAdoptionDecisionUpdateOne {
|
||||||
|
return _u.SetIdentityID(v.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the IdentityAdoptionDecisionMutation object of the builder.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdateOne) Mutation() *IdentityAdoptionDecisionMutation {
|
||||||
|
return _u.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearPendingAuthSession clears the "pending_auth_session" edge to the PendingAuthSession entity.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdateOne) ClearPendingAuthSession() *IdentityAdoptionDecisionUpdateOne {
|
||||||
|
_u.mutation.ClearPendingAuthSession()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearIdentity clears the "identity" edge to the AuthIdentity entity.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdateOne) ClearIdentity() *IdentityAdoptionDecisionUpdateOne {
|
||||||
|
_u.mutation.ClearIdentity()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the IdentityAdoptionDecisionUpdate builder.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdateOne) Where(ps ...predicate.IdentityAdoptionDecision) *IdentityAdoptionDecisionUpdateOne {
|
||||||
|
_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 *IdentityAdoptionDecisionUpdateOne) Select(field string, fields ...string) *IdentityAdoptionDecisionUpdateOne {
|
||||||
|
_u.fields = append([]string{field}, fields...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the updated IdentityAdoptionDecision entity.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdateOne) Save(ctx context.Context) (*IdentityAdoptionDecision, error) {
|
||||||
|
_u.defaults()
|
||||||
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdateOne) SaveX(ctx context.Context) *IdentityAdoptionDecision {
|
||||||
|
node, err := _u.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query on the entity.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdateOne) Exec(ctx context.Context) error {
|
||||||
|
_, err := _u.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdateOne) 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 *IdentityAdoptionDecisionUpdateOne) defaults() {
|
||||||
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
||||||
|
v := identityadoptiondecision.UpdateDefaultUpdatedAt()
|
||||||
|
_u.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdateOne) check() error {
|
||||||
|
if _u.mutation.PendingAuthSessionCleared() && len(_u.mutation.PendingAuthSessionIDs()) > 0 {
|
||||||
|
return errors.New(`ent: clearing a required unique edge "IdentityAdoptionDecision.pending_auth_session"`)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_u *IdentityAdoptionDecisionUpdateOne) sqlSave(ctx context.Context) (_node *IdentityAdoptionDecision, err error) {
|
||||||
|
if err := _u.check(); err != nil {
|
||||||
|
return _node, err
|
||||||
|
}
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(identityadoptiondecision.Table, identityadoptiondecision.Columns, sqlgraph.NewFieldSpec(identityadoptiondecision.FieldID, field.TypeInt64))
|
||||||
|
id, ok := _u.mutation.ID()
|
||||||
|
if !ok {
|
||||||
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "IdentityAdoptionDecision.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, identityadoptiondecision.FieldID)
|
||||||
|
for _, f := range fields {
|
||||||
|
if !identityadoptiondecision.ValidColumn(f) {
|
||||||
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
if f != identityadoptiondecision.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.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(identityadoptiondecision.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AdoptDisplayName(); ok {
|
||||||
|
_spec.SetField(identityadoptiondecision.FieldAdoptDisplayName, field.TypeBool, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AdoptAvatar(); ok {
|
||||||
|
_spec.SetField(identityadoptiondecision.FieldAdoptAvatar, field.TypeBool, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.PendingAuthSessionCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: identityadoptiondecision.PendingAuthSessionTable,
|
||||||
|
Columns: []string{identityadoptiondecision.PendingAuthSessionColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(pendingauthsession.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := _u.mutation.PendingAuthSessionIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: identityadoptiondecision.PendingAuthSessionTable,
|
||||||
|
Columns: []string{identityadoptiondecision.PendingAuthSessionColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(pendingauthsession.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if _u.mutation.IdentityCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: identityadoptiondecision.IdentityTable,
|
||||||
|
Columns: []string{identityadoptiondecision.IdentityColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := _u.mutation.IdentityIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: identityadoptiondecision.IdentityTable,
|
||||||
|
Columns: []string{identityadoptiondecision.IdentityColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
_node = &IdentityAdoptionDecision{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{identityadoptiondecision.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_u.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
@@ -13,12 +13,16 @@ import (
|
|||||||
"github.com/Wei-Shaw/sub2api/ent/announcement"
|
"github.com/Wei-Shaw/sub2api/ent/announcement"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/announcementread"
|
"github.com/Wei-Shaw/sub2api/ent/announcementread"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/apikey"
|
"github.com/Wei-Shaw/sub2api/ent/apikey"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/authidentity"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/authidentitychannel"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/errorpassthroughrule"
|
"github.com/Wei-Shaw/sub2api/ent/errorpassthroughrule"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/group"
|
"github.com/Wei-Shaw/sub2api/ent/group"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/idempotencyrecord"
|
"github.com/Wei-Shaw/sub2api/ent/idempotencyrecord"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/identityadoptiondecision"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/paymentauditlog"
|
"github.com/Wei-Shaw/sub2api/ent/paymentauditlog"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/paymentorder"
|
"github.com/Wei-Shaw/sub2api/ent/paymentorder"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/paymentproviderinstance"
|
"github.com/Wei-Shaw/sub2api/ent/paymentproviderinstance"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/pendingauthsession"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/predicate"
|
"github.com/Wei-Shaw/sub2api/ent/predicate"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/promocode"
|
"github.com/Wei-Shaw/sub2api/ent/promocode"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
|
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
|
||||||
@@ -228,6 +232,60 @@ func (f TraverseAnnouncementRead) Traverse(ctx context.Context, q ent.Query) err
|
|||||||
return fmt.Errorf("unexpected query type %T. expect *ent.AnnouncementReadQuery", q)
|
return fmt.Errorf("unexpected query type %T. expect *ent.AnnouncementReadQuery", q)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The AuthIdentityFunc type is an adapter to allow the use of ordinary function as a Querier.
|
||||||
|
type AuthIdentityFunc func(context.Context, *ent.AuthIdentityQuery) (ent.Value, error)
|
||||||
|
|
||||||
|
// Query calls f(ctx, q).
|
||||||
|
func (f AuthIdentityFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
|
||||||
|
if q, ok := q.(*ent.AuthIdentityQuery); ok {
|
||||||
|
return f(ctx, q)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unexpected query type %T. expect *ent.AuthIdentityQuery", q)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The TraverseAuthIdentity type is an adapter to allow the use of ordinary function as Traverser.
|
||||||
|
type TraverseAuthIdentity func(context.Context, *ent.AuthIdentityQuery) error
|
||||||
|
|
||||||
|
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
|
||||||
|
func (f TraverseAuthIdentity) Intercept(next ent.Querier) ent.Querier {
|
||||||
|
return next
|
||||||
|
}
|
||||||
|
|
||||||
|
// Traverse calls f(ctx, q).
|
||||||
|
func (f TraverseAuthIdentity) Traverse(ctx context.Context, q ent.Query) error {
|
||||||
|
if q, ok := q.(*ent.AuthIdentityQuery); ok {
|
||||||
|
return f(ctx, q)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("unexpected query type %T. expect *ent.AuthIdentityQuery", q)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The AuthIdentityChannelFunc type is an adapter to allow the use of ordinary function as a Querier.
|
||||||
|
type AuthIdentityChannelFunc func(context.Context, *ent.AuthIdentityChannelQuery) (ent.Value, error)
|
||||||
|
|
||||||
|
// Query calls f(ctx, q).
|
||||||
|
func (f AuthIdentityChannelFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
|
||||||
|
if q, ok := q.(*ent.AuthIdentityChannelQuery); ok {
|
||||||
|
return f(ctx, q)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unexpected query type %T. expect *ent.AuthIdentityChannelQuery", q)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The TraverseAuthIdentityChannel type is an adapter to allow the use of ordinary function as Traverser.
|
||||||
|
type TraverseAuthIdentityChannel func(context.Context, *ent.AuthIdentityChannelQuery) error
|
||||||
|
|
||||||
|
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
|
||||||
|
func (f TraverseAuthIdentityChannel) Intercept(next ent.Querier) ent.Querier {
|
||||||
|
return next
|
||||||
|
}
|
||||||
|
|
||||||
|
// Traverse calls f(ctx, q).
|
||||||
|
func (f TraverseAuthIdentityChannel) Traverse(ctx context.Context, q ent.Query) error {
|
||||||
|
if q, ok := q.(*ent.AuthIdentityChannelQuery); ok {
|
||||||
|
return f(ctx, q)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("unexpected query type %T. expect *ent.AuthIdentityChannelQuery", q)
|
||||||
|
}
|
||||||
|
|
||||||
// The ErrorPassthroughRuleFunc type is an adapter to allow the use of ordinary function as a Querier.
|
// The ErrorPassthroughRuleFunc type is an adapter to allow the use of ordinary function as a Querier.
|
||||||
type ErrorPassthroughRuleFunc func(context.Context, *ent.ErrorPassthroughRuleQuery) (ent.Value, error)
|
type ErrorPassthroughRuleFunc func(context.Context, *ent.ErrorPassthroughRuleQuery) (ent.Value, error)
|
||||||
|
|
||||||
@@ -309,6 +367,33 @@ func (f TraverseIdempotencyRecord) Traverse(ctx context.Context, q ent.Query) er
|
|||||||
return fmt.Errorf("unexpected query type %T. expect *ent.IdempotencyRecordQuery", q)
|
return fmt.Errorf("unexpected query type %T. expect *ent.IdempotencyRecordQuery", q)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The IdentityAdoptionDecisionFunc type is an adapter to allow the use of ordinary function as a Querier.
|
||||||
|
type IdentityAdoptionDecisionFunc func(context.Context, *ent.IdentityAdoptionDecisionQuery) (ent.Value, error)
|
||||||
|
|
||||||
|
// Query calls f(ctx, q).
|
||||||
|
func (f IdentityAdoptionDecisionFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
|
||||||
|
if q, ok := q.(*ent.IdentityAdoptionDecisionQuery); ok {
|
||||||
|
return f(ctx, q)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unexpected query type %T. expect *ent.IdentityAdoptionDecisionQuery", q)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The TraverseIdentityAdoptionDecision type is an adapter to allow the use of ordinary function as Traverser.
|
||||||
|
type TraverseIdentityAdoptionDecision func(context.Context, *ent.IdentityAdoptionDecisionQuery) error
|
||||||
|
|
||||||
|
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
|
||||||
|
func (f TraverseIdentityAdoptionDecision) Intercept(next ent.Querier) ent.Querier {
|
||||||
|
return next
|
||||||
|
}
|
||||||
|
|
||||||
|
// Traverse calls f(ctx, q).
|
||||||
|
func (f TraverseIdentityAdoptionDecision) Traverse(ctx context.Context, q ent.Query) error {
|
||||||
|
if q, ok := q.(*ent.IdentityAdoptionDecisionQuery); ok {
|
||||||
|
return f(ctx, q)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("unexpected query type %T. expect *ent.IdentityAdoptionDecisionQuery", q)
|
||||||
|
}
|
||||||
|
|
||||||
// The PaymentAuditLogFunc type is an adapter to allow the use of ordinary function as a Querier.
|
// The PaymentAuditLogFunc type is an adapter to allow the use of ordinary function as a Querier.
|
||||||
type PaymentAuditLogFunc func(context.Context, *ent.PaymentAuditLogQuery) (ent.Value, error)
|
type PaymentAuditLogFunc func(context.Context, *ent.PaymentAuditLogQuery) (ent.Value, error)
|
||||||
|
|
||||||
@@ -390,6 +475,33 @@ func (f TraversePaymentProviderInstance) Traverse(ctx context.Context, q ent.Que
|
|||||||
return fmt.Errorf("unexpected query type %T. expect *ent.PaymentProviderInstanceQuery", q)
|
return fmt.Errorf("unexpected query type %T. expect *ent.PaymentProviderInstanceQuery", q)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The PendingAuthSessionFunc type is an adapter to allow the use of ordinary function as a Querier.
|
||||||
|
type PendingAuthSessionFunc func(context.Context, *ent.PendingAuthSessionQuery) (ent.Value, error)
|
||||||
|
|
||||||
|
// Query calls f(ctx, q).
|
||||||
|
func (f PendingAuthSessionFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
|
||||||
|
if q, ok := q.(*ent.PendingAuthSessionQuery); ok {
|
||||||
|
return f(ctx, q)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unexpected query type %T. expect *ent.PendingAuthSessionQuery", q)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The TraversePendingAuthSession type is an adapter to allow the use of ordinary function as Traverser.
|
||||||
|
type TraversePendingAuthSession func(context.Context, *ent.PendingAuthSessionQuery) error
|
||||||
|
|
||||||
|
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
|
||||||
|
func (f TraversePendingAuthSession) Intercept(next ent.Querier) ent.Querier {
|
||||||
|
return next
|
||||||
|
}
|
||||||
|
|
||||||
|
// Traverse calls f(ctx, q).
|
||||||
|
func (f TraversePendingAuthSession) Traverse(ctx context.Context, q ent.Query) error {
|
||||||
|
if q, ok := q.(*ent.PendingAuthSessionQuery); ok {
|
||||||
|
return f(ctx, q)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("unexpected query type %T. expect *ent.PendingAuthSessionQuery", q)
|
||||||
|
}
|
||||||
|
|
||||||
// The PromoCodeFunc type is an adapter to allow the use of ordinary function as a Querier.
|
// The PromoCodeFunc type is an adapter to allow the use of ordinary function as a Querier.
|
||||||
type PromoCodeFunc func(context.Context, *ent.PromoCodeQuery) (ent.Value, error)
|
type PromoCodeFunc func(context.Context, *ent.PromoCodeQuery) (ent.Value, error)
|
||||||
|
|
||||||
@@ -808,18 +920,26 @@ func NewQuery(q ent.Query) (Query, error) {
|
|||||||
return &query[*ent.AnnouncementQuery, predicate.Announcement, announcement.OrderOption]{typ: ent.TypeAnnouncement, tq: q}, nil
|
return &query[*ent.AnnouncementQuery, predicate.Announcement, announcement.OrderOption]{typ: ent.TypeAnnouncement, tq: q}, nil
|
||||||
case *ent.AnnouncementReadQuery:
|
case *ent.AnnouncementReadQuery:
|
||||||
return &query[*ent.AnnouncementReadQuery, predicate.AnnouncementRead, announcementread.OrderOption]{typ: ent.TypeAnnouncementRead, tq: q}, nil
|
return &query[*ent.AnnouncementReadQuery, predicate.AnnouncementRead, announcementread.OrderOption]{typ: ent.TypeAnnouncementRead, tq: q}, nil
|
||||||
|
case *ent.AuthIdentityQuery:
|
||||||
|
return &query[*ent.AuthIdentityQuery, predicate.AuthIdentity, authidentity.OrderOption]{typ: ent.TypeAuthIdentity, tq: q}, nil
|
||||||
|
case *ent.AuthIdentityChannelQuery:
|
||||||
|
return &query[*ent.AuthIdentityChannelQuery, predicate.AuthIdentityChannel, authidentitychannel.OrderOption]{typ: ent.TypeAuthIdentityChannel, tq: q}, nil
|
||||||
case *ent.ErrorPassthroughRuleQuery:
|
case *ent.ErrorPassthroughRuleQuery:
|
||||||
return &query[*ent.ErrorPassthroughRuleQuery, predicate.ErrorPassthroughRule, errorpassthroughrule.OrderOption]{typ: ent.TypeErrorPassthroughRule, tq: q}, nil
|
return &query[*ent.ErrorPassthroughRuleQuery, predicate.ErrorPassthroughRule, errorpassthroughrule.OrderOption]{typ: ent.TypeErrorPassthroughRule, tq: q}, nil
|
||||||
case *ent.GroupQuery:
|
case *ent.GroupQuery:
|
||||||
return &query[*ent.GroupQuery, predicate.Group, group.OrderOption]{typ: ent.TypeGroup, tq: q}, nil
|
return &query[*ent.GroupQuery, predicate.Group, group.OrderOption]{typ: ent.TypeGroup, tq: q}, nil
|
||||||
case *ent.IdempotencyRecordQuery:
|
case *ent.IdempotencyRecordQuery:
|
||||||
return &query[*ent.IdempotencyRecordQuery, predicate.IdempotencyRecord, idempotencyrecord.OrderOption]{typ: ent.TypeIdempotencyRecord, tq: q}, nil
|
return &query[*ent.IdempotencyRecordQuery, predicate.IdempotencyRecord, idempotencyrecord.OrderOption]{typ: ent.TypeIdempotencyRecord, tq: q}, nil
|
||||||
|
case *ent.IdentityAdoptionDecisionQuery:
|
||||||
|
return &query[*ent.IdentityAdoptionDecisionQuery, predicate.IdentityAdoptionDecision, identityadoptiondecision.OrderOption]{typ: ent.TypeIdentityAdoptionDecision, tq: q}, nil
|
||||||
case *ent.PaymentAuditLogQuery:
|
case *ent.PaymentAuditLogQuery:
|
||||||
return &query[*ent.PaymentAuditLogQuery, predicate.PaymentAuditLog, paymentauditlog.OrderOption]{typ: ent.TypePaymentAuditLog, tq: q}, nil
|
return &query[*ent.PaymentAuditLogQuery, predicate.PaymentAuditLog, paymentauditlog.OrderOption]{typ: ent.TypePaymentAuditLog, tq: q}, nil
|
||||||
case *ent.PaymentOrderQuery:
|
case *ent.PaymentOrderQuery:
|
||||||
return &query[*ent.PaymentOrderQuery, predicate.PaymentOrder, paymentorder.OrderOption]{typ: ent.TypePaymentOrder, tq: q}, nil
|
return &query[*ent.PaymentOrderQuery, predicate.PaymentOrder, paymentorder.OrderOption]{typ: ent.TypePaymentOrder, tq: q}, nil
|
||||||
case *ent.PaymentProviderInstanceQuery:
|
case *ent.PaymentProviderInstanceQuery:
|
||||||
return &query[*ent.PaymentProviderInstanceQuery, predicate.PaymentProviderInstance, paymentproviderinstance.OrderOption]{typ: ent.TypePaymentProviderInstance, tq: q}, nil
|
return &query[*ent.PaymentProviderInstanceQuery, predicate.PaymentProviderInstance, paymentproviderinstance.OrderOption]{typ: ent.TypePaymentProviderInstance, tq: q}, nil
|
||||||
|
case *ent.PendingAuthSessionQuery:
|
||||||
|
return &query[*ent.PendingAuthSessionQuery, predicate.PendingAuthSession, pendingauthsession.OrderOption]{typ: ent.TypePendingAuthSession, tq: q}, nil
|
||||||
case *ent.PromoCodeQuery:
|
case *ent.PromoCodeQuery:
|
||||||
return &query[*ent.PromoCodeQuery, predicate.PromoCode, promocode.OrderOption]{typ: ent.TypePromoCode, tq: q}, nil
|
return &query[*ent.PromoCodeQuery, predicate.PromoCode, promocode.OrderOption]{typ: ent.TypePromoCode, tq: q}, nil
|
||||||
case *ent.PromoCodeUsageQuery:
|
case *ent.PromoCodeUsageQuery:
|
||||||
|
|||||||
@@ -338,6 +338,89 @@ var (
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
// AuthIdentitiesColumns holds the columns for the "auth_identities" table.
|
||||||
|
AuthIdentitiesColumns = []*schema.Column{
|
||||||
|
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||||
|
{Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
|
||||||
|
{Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
|
||||||
|
{Name: "provider_type", Type: field.TypeString, Size: 20},
|
||||||
|
{Name: "provider_key", Type: field.TypeString, SchemaType: map[string]string{"postgres": "text"}},
|
||||||
|
{Name: "provider_subject", Type: field.TypeString, SchemaType: map[string]string{"postgres": "text"}},
|
||||||
|
{Name: "verified_at", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}},
|
||||||
|
{Name: "issuer", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "text"}},
|
||||||
|
{Name: "metadata", Type: field.TypeJSON, SchemaType: map[string]string{"postgres": "jsonb"}},
|
||||||
|
{Name: "user_id", Type: field.TypeInt64},
|
||||||
|
}
|
||||||
|
// AuthIdentitiesTable holds the schema information for the "auth_identities" table.
|
||||||
|
AuthIdentitiesTable = &schema.Table{
|
||||||
|
Name: "auth_identities",
|
||||||
|
Columns: AuthIdentitiesColumns,
|
||||||
|
PrimaryKey: []*schema.Column{AuthIdentitiesColumns[0]},
|
||||||
|
ForeignKeys: []*schema.ForeignKey{
|
||||||
|
{
|
||||||
|
Symbol: "auth_identities_users_auth_identities",
|
||||||
|
Columns: []*schema.Column{AuthIdentitiesColumns[9]},
|
||||||
|
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||||
|
OnDelete: schema.NoAction,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Indexes: []*schema.Index{
|
||||||
|
{
|
||||||
|
Name: "authidentity_provider_type_provider_key_provider_subject",
|
||||||
|
Unique: true,
|
||||||
|
Columns: []*schema.Column{AuthIdentitiesColumns[3], AuthIdentitiesColumns[4], AuthIdentitiesColumns[5]},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "authidentity_user_id",
|
||||||
|
Unique: false,
|
||||||
|
Columns: []*schema.Column{AuthIdentitiesColumns[9]},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "authidentity_user_id_provider_type",
|
||||||
|
Unique: false,
|
||||||
|
Columns: []*schema.Column{AuthIdentitiesColumns[9], AuthIdentitiesColumns[3]},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
// AuthIdentityChannelsColumns holds the columns for the "auth_identity_channels" table.
|
||||||
|
AuthIdentityChannelsColumns = []*schema.Column{
|
||||||
|
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||||
|
{Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
|
||||||
|
{Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
|
||||||
|
{Name: "provider_type", Type: field.TypeString, Size: 20},
|
||||||
|
{Name: "provider_key", Type: field.TypeString, SchemaType: map[string]string{"postgres": "text"}},
|
||||||
|
{Name: "channel", Type: field.TypeString, Size: 20},
|
||||||
|
{Name: "channel_app_id", Type: field.TypeString, SchemaType: map[string]string{"postgres": "text"}},
|
||||||
|
{Name: "channel_subject", Type: field.TypeString, SchemaType: map[string]string{"postgres": "text"}},
|
||||||
|
{Name: "metadata", Type: field.TypeJSON, SchemaType: map[string]string{"postgres": "jsonb"}},
|
||||||
|
{Name: "identity_id", Type: field.TypeInt64},
|
||||||
|
}
|
||||||
|
// AuthIdentityChannelsTable holds the schema information for the "auth_identity_channels" table.
|
||||||
|
AuthIdentityChannelsTable = &schema.Table{
|
||||||
|
Name: "auth_identity_channels",
|
||||||
|
Columns: AuthIdentityChannelsColumns,
|
||||||
|
PrimaryKey: []*schema.Column{AuthIdentityChannelsColumns[0]},
|
||||||
|
ForeignKeys: []*schema.ForeignKey{
|
||||||
|
{
|
||||||
|
Symbol: "auth_identity_channels_auth_identities_channels",
|
||||||
|
Columns: []*schema.Column{AuthIdentityChannelsColumns[9]},
|
||||||
|
RefColumns: []*schema.Column{AuthIdentitiesColumns[0]},
|
||||||
|
OnDelete: schema.NoAction,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Indexes: []*schema.Index{
|
||||||
|
{
|
||||||
|
Name: "authidentitychannel_provider_type_provider_key_channel_channel_app_id_channel_subject",
|
||||||
|
Unique: true,
|
||||||
|
Columns: []*schema.Column{AuthIdentityChannelsColumns[3], AuthIdentityChannelsColumns[4], AuthIdentityChannelsColumns[5], AuthIdentityChannelsColumns[6], AuthIdentityChannelsColumns[7]},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "authidentitychannel_identity_id",
|
||||||
|
Unique: false,
|
||||||
|
Columns: []*schema.Column{AuthIdentityChannelsColumns[9]},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
// ErrorPassthroughRulesColumns holds the columns for the "error_passthrough_rules" table.
|
// ErrorPassthroughRulesColumns holds the columns for the "error_passthrough_rules" table.
|
||||||
ErrorPassthroughRulesColumns = []*schema.Column{
|
ErrorPassthroughRulesColumns = []*schema.Column{
|
||||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||||
@@ -485,6 +568,49 @@ var (
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
// IdentityAdoptionDecisionsColumns holds the columns for the "identity_adoption_decisions" table.
|
||||||
|
IdentityAdoptionDecisionsColumns = []*schema.Column{
|
||||||
|
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||||
|
{Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
|
||||||
|
{Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
|
||||||
|
{Name: "adopt_display_name", Type: field.TypeBool, Default: false},
|
||||||
|
{Name: "adopt_avatar", Type: field.TypeBool, Default: false},
|
||||||
|
{Name: "decided_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
|
||||||
|
{Name: "identity_id", Type: field.TypeInt64, Nullable: true},
|
||||||
|
{Name: "pending_auth_session_id", Type: field.TypeInt64, Unique: true},
|
||||||
|
}
|
||||||
|
// IdentityAdoptionDecisionsTable holds the schema information for the "identity_adoption_decisions" table.
|
||||||
|
IdentityAdoptionDecisionsTable = &schema.Table{
|
||||||
|
Name: "identity_adoption_decisions",
|
||||||
|
Columns: IdentityAdoptionDecisionsColumns,
|
||||||
|
PrimaryKey: []*schema.Column{IdentityAdoptionDecisionsColumns[0]},
|
||||||
|
ForeignKeys: []*schema.ForeignKey{
|
||||||
|
{
|
||||||
|
Symbol: "identity_adoption_decisions_auth_identities_adoption_decisions",
|
||||||
|
Columns: []*schema.Column{IdentityAdoptionDecisionsColumns[6]},
|
||||||
|
RefColumns: []*schema.Column{AuthIdentitiesColumns[0]},
|
||||||
|
OnDelete: schema.SetNull,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Symbol: "identity_adoption_decisions_pending_auth_sessions_adoption_decision",
|
||||||
|
Columns: []*schema.Column{IdentityAdoptionDecisionsColumns[7]},
|
||||||
|
RefColumns: []*schema.Column{PendingAuthSessionsColumns[0]},
|
||||||
|
OnDelete: schema.NoAction,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Indexes: []*schema.Index{
|
||||||
|
{
|
||||||
|
Name: "identityadoptiondecision_pending_auth_session_id",
|
||||||
|
Unique: true,
|
||||||
|
Columns: []*schema.Column{IdentityAdoptionDecisionsColumns[7]},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "identityadoptiondecision_identity_id",
|
||||||
|
Unique: false,
|
||||||
|
Columns: []*schema.Column{IdentityAdoptionDecisionsColumns[6]},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
// PaymentAuditLogsColumns holds the columns for the "payment_audit_logs" table.
|
// PaymentAuditLogsColumns holds the columns for the "payment_audit_logs" table.
|
||||||
PaymentAuditLogsColumns = []*schema.Column{
|
PaymentAuditLogsColumns = []*schema.Column{
|
||||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||||
@@ -528,6 +654,8 @@ var (
|
|||||||
{Name: "subscription_group_id", Type: field.TypeInt64, Nullable: true},
|
{Name: "subscription_group_id", Type: field.TypeInt64, Nullable: true},
|
||||||
{Name: "subscription_days", Type: field.TypeInt, Nullable: true},
|
{Name: "subscription_days", Type: field.TypeInt, Nullable: true},
|
||||||
{Name: "provider_instance_id", Type: field.TypeString, Nullable: true, Size: 64},
|
{Name: "provider_instance_id", Type: field.TypeString, Nullable: true, Size: 64},
|
||||||
|
{Name: "provider_key", Type: field.TypeString, Nullable: true, Size: 30},
|
||||||
|
{Name: "provider_snapshot", Type: field.TypeJSON, Nullable: true, SchemaType: map[string]string{"postgres": "jsonb"}},
|
||||||
{Name: "status", Type: field.TypeString, Size: 30, Default: "PENDING"},
|
{Name: "status", Type: field.TypeString, Size: 30, Default: "PENDING"},
|
||||||
{Name: "refund_amount", Type: field.TypeFloat64, Default: 0, SchemaType: map[string]string{"postgres": "decimal(20,2)"}},
|
{Name: "refund_amount", Type: field.TypeFloat64, Default: 0, SchemaType: map[string]string{"postgres": "decimal(20,2)"}},
|
||||||
{Name: "refund_reason", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "text"}},
|
{Name: "refund_reason", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "text"}},
|
||||||
@@ -556,7 +684,7 @@ var (
|
|||||||
ForeignKeys: []*schema.ForeignKey{
|
ForeignKeys: []*schema.ForeignKey{
|
||||||
{
|
{
|
||||||
Symbol: "payment_orders_users_payment_orders",
|
Symbol: "payment_orders_users_payment_orders",
|
||||||
Columns: []*schema.Column{PaymentOrdersColumns[37]},
|
Columns: []*schema.Column{PaymentOrdersColumns[39]},
|
||||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||||
OnDelete: schema.NoAction,
|
OnDelete: schema.NoAction,
|
||||||
},
|
},
|
||||||
@@ -570,32 +698,32 @@ var (
|
|||||||
{
|
{
|
||||||
Name: "paymentorder_user_id",
|
Name: "paymentorder_user_id",
|
||||||
Unique: false,
|
Unique: false,
|
||||||
Columns: []*schema.Column{PaymentOrdersColumns[37]},
|
Columns: []*schema.Column{PaymentOrdersColumns[39]},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "paymentorder_status",
|
Name: "paymentorder_status",
|
||||||
Unique: false,
|
Unique: false,
|
||||||
Columns: []*schema.Column{PaymentOrdersColumns[19]},
|
Columns: []*schema.Column{PaymentOrdersColumns[21]},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "paymentorder_expires_at",
|
Name: "paymentorder_expires_at",
|
||||||
Unique: false,
|
Unique: false,
|
||||||
Columns: []*schema.Column{PaymentOrdersColumns[27]},
|
Columns: []*schema.Column{PaymentOrdersColumns[29]},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "paymentorder_created_at",
|
Name: "paymentorder_created_at",
|
||||||
Unique: false,
|
Unique: false,
|
||||||
Columns: []*schema.Column{PaymentOrdersColumns[35]},
|
Columns: []*schema.Column{PaymentOrdersColumns[37]},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "paymentorder_paid_at",
|
Name: "paymentorder_paid_at",
|
||||||
Unique: false,
|
Unique: false,
|
||||||
Columns: []*schema.Column{PaymentOrdersColumns[28]},
|
Columns: []*schema.Column{PaymentOrdersColumns[30]},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "paymentorder_payment_type_paid_at",
|
Name: "paymentorder_payment_type_paid_at",
|
||||||
Unique: false,
|
Unique: false,
|
||||||
Columns: []*schema.Column{PaymentOrdersColumns[9], PaymentOrdersColumns[28]},
|
Columns: []*schema.Column{PaymentOrdersColumns[9], PaymentOrdersColumns[30]},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "paymentorder_order_type",
|
Name: "paymentorder_order_type",
|
||||||
@@ -638,6 +766,72 @@ var (
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
// PendingAuthSessionsColumns holds the columns for the "pending_auth_sessions" table.
|
||||||
|
PendingAuthSessionsColumns = []*schema.Column{
|
||||||
|
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||||
|
{Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
|
||||||
|
{Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
|
||||||
|
{Name: "session_token", Type: field.TypeString, Size: 255},
|
||||||
|
{Name: "intent", Type: field.TypeString, Size: 40},
|
||||||
|
{Name: "provider_type", Type: field.TypeString, Size: 20},
|
||||||
|
{Name: "provider_key", Type: field.TypeString, SchemaType: map[string]string{"postgres": "text"}},
|
||||||
|
{Name: "provider_subject", Type: field.TypeString, SchemaType: map[string]string{"postgres": "text"}},
|
||||||
|
{Name: "redirect_to", Type: field.TypeString, Default: "", SchemaType: map[string]string{"postgres": "text"}},
|
||||||
|
{Name: "resolved_email", Type: field.TypeString, Default: "", SchemaType: map[string]string{"postgres": "text"}},
|
||||||
|
{Name: "registration_password_hash", Type: field.TypeString, Default: "", SchemaType: map[string]string{"postgres": "text"}},
|
||||||
|
{Name: "upstream_identity_claims", Type: field.TypeJSON, SchemaType: map[string]string{"postgres": "jsonb"}},
|
||||||
|
{Name: "local_flow_state", Type: field.TypeJSON, SchemaType: map[string]string{"postgres": "jsonb"}},
|
||||||
|
{Name: "browser_session_key", Type: field.TypeString, Default: "", SchemaType: map[string]string{"postgres": "text"}},
|
||||||
|
{Name: "completion_code_hash", Type: field.TypeString, Default: "", SchemaType: map[string]string{"postgres": "text"}},
|
||||||
|
{Name: "completion_code_expires_at", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}},
|
||||||
|
{Name: "email_verified_at", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}},
|
||||||
|
{Name: "password_verified_at", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}},
|
||||||
|
{Name: "totp_verified_at", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}},
|
||||||
|
{Name: "expires_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
|
||||||
|
{Name: "consumed_at", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}},
|
||||||
|
{Name: "target_user_id", Type: field.TypeInt64, Nullable: true},
|
||||||
|
}
|
||||||
|
// PendingAuthSessionsTable holds the schema information for the "pending_auth_sessions" table.
|
||||||
|
PendingAuthSessionsTable = &schema.Table{
|
||||||
|
Name: "pending_auth_sessions",
|
||||||
|
Columns: PendingAuthSessionsColumns,
|
||||||
|
PrimaryKey: []*schema.Column{PendingAuthSessionsColumns[0]},
|
||||||
|
ForeignKeys: []*schema.ForeignKey{
|
||||||
|
{
|
||||||
|
Symbol: "pending_auth_sessions_users_pending_auth_sessions",
|
||||||
|
Columns: []*schema.Column{PendingAuthSessionsColumns[21]},
|
||||||
|
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||||
|
OnDelete: schema.SetNull,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Indexes: []*schema.Index{
|
||||||
|
{
|
||||||
|
Name: "pendingauthsession_session_token",
|
||||||
|
Unique: true,
|
||||||
|
Columns: []*schema.Column{PendingAuthSessionsColumns[3]},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "pendingauthsession_target_user_id",
|
||||||
|
Unique: false,
|
||||||
|
Columns: []*schema.Column{PendingAuthSessionsColumns[21]},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "pendingauthsession_expires_at",
|
||||||
|
Unique: false,
|
||||||
|
Columns: []*schema.Column{PendingAuthSessionsColumns[19]},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "pendingauthsession_provider_type_provider_key_provider_subject",
|
||||||
|
Unique: false,
|
||||||
|
Columns: []*schema.Column{PendingAuthSessionsColumns[5], PendingAuthSessionsColumns[6], PendingAuthSessionsColumns[7]},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "pendingauthsession_completion_code_hash",
|
||||||
|
Unique: false,
|
||||||
|
Columns: []*schema.Column{PendingAuthSessionsColumns[14]},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
// PromoCodesColumns holds the columns for the "promo_codes" table.
|
// PromoCodesColumns holds the columns for the "promo_codes" table.
|
||||||
PromoCodesColumns = []*schema.Column{
|
PromoCodesColumns = []*schema.Column{
|
||||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||||
@@ -1079,6 +1273,9 @@ var (
|
|||||||
{Name: "totp_secret_encrypted", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "text"}},
|
{Name: "totp_secret_encrypted", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "text"}},
|
||||||
{Name: "totp_enabled", Type: field.TypeBool, Default: false},
|
{Name: "totp_enabled", Type: field.TypeBool, Default: false},
|
||||||
{Name: "totp_enabled_at", Type: field.TypeTime, Nullable: true},
|
{Name: "totp_enabled_at", Type: field.TypeTime, Nullable: true},
|
||||||
|
{Name: "signup_source", Type: field.TypeString, Size: 20, Default: "email"},
|
||||||
|
{Name: "last_login_at", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}},
|
||||||
|
{Name: "last_active_at", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}},
|
||||||
{Name: "balance_notify_enabled", Type: field.TypeBool, Default: true},
|
{Name: "balance_notify_enabled", Type: field.TypeBool, Default: true},
|
||||||
{Name: "balance_notify_threshold_type", Type: field.TypeString, Default: "fixed"},
|
{Name: "balance_notify_threshold_type", Type: field.TypeString, Default: "fixed"},
|
||||||
{Name: "balance_notify_threshold", Type: field.TypeFloat64, Nullable: true, SchemaType: map[string]string{"postgres": "decimal(20,8)"}},
|
{Name: "balance_notify_threshold", Type: field.TypeFloat64, Nullable: true, SchemaType: map[string]string{"postgres": "decimal(20,8)"}},
|
||||||
@@ -1318,12 +1515,16 @@ var (
|
|||||||
AccountGroupsTable,
|
AccountGroupsTable,
|
||||||
AnnouncementsTable,
|
AnnouncementsTable,
|
||||||
AnnouncementReadsTable,
|
AnnouncementReadsTable,
|
||||||
|
AuthIdentitiesTable,
|
||||||
|
AuthIdentityChannelsTable,
|
||||||
ErrorPassthroughRulesTable,
|
ErrorPassthroughRulesTable,
|
||||||
GroupsTable,
|
GroupsTable,
|
||||||
IdempotencyRecordsTable,
|
IdempotencyRecordsTable,
|
||||||
|
IdentityAdoptionDecisionsTable,
|
||||||
PaymentAuditLogsTable,
|
PaymentAuditLogsTable,
|
||||||
PaymentOrdersTable,
|
PaymentOrdersTable,
|
||||||
PaymentProviderInstancesTable,
|
PaymentProviderInstancesTable,
|
||||||
|
PendingAuthSessionsTable,
|
||||||
PromoCodesTable,
|
PromoCodesTable,
|
||||||
PromoCodeUsagesTable,
|
PromoCodeUsagesTable,
|
||||||
ProxiesTable,
|
ProxiesTable,
|
||||||
@@ -1365,6 +1566,14 @@ func init() {
|
|||||||
AnnouncementReadsTable.Annotation = &entsql.Annotation{
|
AnnouncementReadsTable.Annotation = &entsql.Annotation{
|
||||||
Table: "announcement_reads",
|
Table: "announcement_reads",
|
||||||
}
|
}
|
||||||
|
AuthIdentitiesTable.ForeignKeys[0].RefTable = UsersTable
|
||||||
|
AuthIdentitiesTable.Annotation = &entsql.Annotation{
|
||||||
|
Table: "auth_identities",
|
||||||
|
}
|
||||||
|
AuthIdentityChannelsTable.ForeignKeys[0].RefTable = AuthIdentitiesTable
|
||||||
|
AuthIdentityChannelsTable.Annotation = &entsql.Annotation{
|
||||||
|
Table: "auth_identity_channels",
|
||||||
|
}
|
||||||
ErrorPassthroughRulesTable.Annotation = &entsql.Annotation{
|
ErrorPassthroughRulesTable.Annotation = &entsql.Annotation{
|
||||||
Table: "error_passthrough_rules",
|
Table: "error_passthrough_rules",
|
||||||
}
|
}
|
||||||
@@ -1374,6 +1583,11 @@ func init() {
|
|||||||
IdempotencyRecordsTable.Annotation = &entsql.Annotation{
|
IdempotencyRecordsTable.Annotation = &entsql.Annotation{
|
||||||
Table: "idempotency_records",
|
Table: "idempotency_records",
|
||||||
}
|
}
|
||||||
|
IdentityAdoptionDecisionsTable.ForeignKeys[0].RefTable = AuthIdentitiesTable
|
||||||
|
IdentityAdoptionDecisionsTable.ForeignKeys[1].RefTable = PendingAuthSessionsTable
|
||||||
|
IdentityAdoptionDecisionsTable.Annotation = &entsql.Annotation{
|
||||||
|
Table: "identity_adoption_decisions",
|
||||||
|
}
|
||||||
PaymentAuditLogsTable.Annotation = &entsql.Annotation{
|
PaymentAuditLogsTable.Annotation = &entsql.Annotation{
|
||||||
Table: "payment_audit_logs",
|
Table: "payment_audit_logs",
|
||||||
}
|
}
|
||||||
@@ -1384,6 +1598,10 @@ func init() {
|
|||||||
PaymentProviderInstancesTable.Annotation = &entsql.Annotation{
|
PaymentProviderInstancesTable.Annotation = &entsql.Annotation{
|
||||||
Table: "payment_provider_instances",
|
Table: "payment_provider_instances",
|
||||||
}
|
}
|
||||||
|
PendingAuthSessionsTable.ForeignKeys[0].RefTable = UsersTable
|
||||||
|
PendingAuthSessionsTable.Annotation = &entsql.Annotation{
|
||||||
|
Table: "pending_auth_sessions",
|
||||||
|
}
|
||||||
PromoCodesTable.Annotation = &entsql.Annotation{
|
PromoCodesTable.Annotation = &entsql.Annotation{
|
||||||
Table: "promo_codes",
|
Table: "promo_codes",
|
||||||
}
|
}
|
||||||
|
|||||||
+4778
-5
File diff suppressed because it is too large
Load Diff
@@ -3,6 +3,7 @@
|
|||||||
package ent
|
package ent
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -56,6 +57,10 @@ type PaymentOrder struct {
|
|||||||
SubscriptionDays *int `json:"subscription_days,omitempty"`
|
SubscriptionDays *int `json:"subscription_days,omitempty"`
|
||||||
// ProviderInstanceID holds the value of the "provider_instance_id" field.
|
// ProviderInstanceID holds the value of the "provider_instance_id" field.
|
||||||
ProviderInstanceID *string `json:"provider_instance_id,omitempty"`
|
ProviderInstanceID *string `json:"provider_instance_id,omitempty"`
|
||||||
|
// ProviderKey holds the value of the "provider_key" field.
|
||||||
|
ProviderKey *string `json:"provider_key,omitempty"`
|
||||||
|
// ProviderSnapshot holds the value of the "provider_snapshot" field.
|
||||||
|
ProviderSnapshot map[string]interface{} `json:"provider_snapshot,omitempty"`
|
||||||
// Status holds the value of the "status" field.
|
// Status holds the value of the "status" field.
|
||||||
Status string `json:"status,omitempty"`
|
Status string `json:"status,omitempty"`
|
||||||
// RefundAmount holds the value of the "refund_amount" field.
|
// RefundAmount holds the value of the "refund_amount" field.
|
||||||
@@ -123,13 +128,15 @@ func (*PaymentOrder) scanValues(columns []string) ([]any, error) {
|
|||||||
values := make([]any, len(columns))
|
values := make([]any, len(columns))
|
||||||
for i := range columns {
|
for i := range columns {
|
||||||
switch columns[i] {
|
switch columns[i] {
|
||||||
|
case paymentorder.FieldProviderSnapshot:
|
||||||
|
values[i] = new([]byte)
|
||||||
case paymentorder.FieldForceRefund:
|
case paymentorder.FieldForceRefund:
|
||||||
values[i] = new(sql.NullBool)
|
values[i] = new(sql.NullBool)
|
||||||
case paymentorder.FieldAmount, paymentorder.FieldPayAmount, paymentorder.FieldFeeRate, paymentorder.FieldRefundAmount:
|
case paymentorder.FieldAmount, paymentorder.FieldPayAmount, paymentorder.FieldFeeRate, paymentorder.FieldRefundAmount:
|
||||||
values[i] = new(sql.NullFloat64)
|
values[i] = new(sql.NullFloat64)
|
||||||
case paymentorder.FieldID, paymentorder.FieldUserID, paymentorder.FieldPlanID, paymentorder.FieldSubscriptionGroupID, paymentorder.FieldSubscriptionDays:
|
case paymentorder.FieldID, paymentorder.FieldUserID, paymentorder.FieldPlanID, paymentorder.FieldSubscriptionGroupID, paymentorder.FieldSubscriptionDays:
|
||||||
values[i] = new(sql.NullInt64)
|
values[i] = new(sql.NullInt64)
|
||||||
case paymentorder.FieldUserEmail, paymentorder.FieldUserName, paymentorder.FieldUserNotes, paymentorder.FieldRechargeCode, paymentorder.FieldOutTradeNo, paymentorder.FieldPaymentType, paymentorder.FieldPaymentTradeNo, paymentorder.FieldPayURL, paymentorder.FieldQrCode, paymentorder.FieldQrCodeImg, paymentorder.FieldOrderType, paymentorder.FieldProviderInstanceID, paymentorder.FieldStatus, paymentorder.FieldRefundReason, paymentorder.FieldRefundRequestReason, paymentorder.FieldRefundRequestedBy, paymentorder.FieldFailedReason, paymentorder.FieldClientIP, paymentorder.FieldSrcHost, paymentorder.FieldSrcURL:
|
case paymentorder.FieldUserEmail, paymentorder.FieldUserName, paymentorder.FieldUserNotes, paymentorder.FieldRechargeCode, paymentorder.FieldOutTradeNo, paymentorder.FieldPaymentType, paymentorder.FieldPaymentTradeNo, paymentorder.FieldPayURL, paymentorder.FieldQrCode, paymentorder.FieldQrCodeImg, paymentorder.FieldOrderType, paymentorder.FieldProviderInstanceID, paymentorder.FieldProviderKey, paymentorder.FieldStatus, paymentorder.FieldRefundReason, paymentorder.FieldRefundRequestReason, paymentorder.FieldRefundRequestedBy, paymentorder.FieldFailedReason, paymentorder.FieldClientIP, paymentorder.FieldSrcHost, paymentorder.FieldSrcURL:
|
||||||
values[i] = new(sql.NullString)
|
values[i] = new(sql.NullString)
|
||||||
case paymentorder.FieldRefundAt, paymentorder.FieldRefundRequestedAt, paymentorder.FieldExpiresAt, paymentorder.FieldPaidAt, paymentorder.FieldCompletedAt, paymentorder.FieldFailedAt, paymentorder.FieldCreatedAt, paymentorder.FieldUpdatedAt:
|
case paymentorder.FieldRefundAt, paymentorder.FieldRefundRequestedAt, paymentorder.FieldExpiresAt, paymentorder.FieldPaidAt, paymentorder.FieldCompletedAt, paymentorder.FieldFailedAt, paymentorder.FieldCreatedAt, paymentorder.FieldUpdatedAt:
|
||||||
values[i] = new(sql.NullTime)
|
values[i] = new(sql.NullTime)
|
||||||
@@ -276,6 +283,21 @@ func (_m *PaymentOrder) assignValues(columns []string, values []any) error {
|
|||||||
_m.ProviderInstanceID = new(string)
|
_m.ProviderInstanceID = new(string)
|
||||||
*_m.ProviderInstanceID = value.String
|
*_m.ProviderInstanceID = value.String
|
||||||
}
|
}
|
||||||
|
case paymentorder.FieldProviderKey:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field provider_key", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.ProviderKey = new(string)
|
||||||
|
*_m.ProviderKey = value.String
|
||||||
|
}
|
||||||
|
case paymentorder.FieldProviderSnapshot:
|
||||||
|
if value, ok := values[i].(*[]byte); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field provider_snapshot", values[i])
|
||||||
|
} else if value != nil && len(*value) > 0 {
|
||||||
|
if err := json.Unmarshal(*value, &_m.ProviderSnapshot); err != nil {
|
||||||
|
return fmt.Errorf("unmarshal field provider_snapshot: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
case paymentorder.FieldStatus:
|
case paymentorder.FieldStatus:
|
||||||
if value, ok := values[i].(*sql.NullString); !ok {
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
return fmt.Errorf("unexpected type %T for field status", values[i])
|
return fmt.Errorf("unexpected type %T for field status", values[i])
|
||||||
@@ -508,6 +530,14 @@ func (_m *PaymentOrder) String() string {
|
|||||||
builder.WriteString(*v)
|
builder.WriteString(*v)
|
||||||
}
|
}
|
||||||
builder.WriteString(", ")
|
builder.WriteString(", ")
|
||||||
|
if v := _m.ProviderKey; v != nil {
|
||||||
|
builder.WriteString("provider_key=")
|
||||||
|
builder.WriteString(*v)
|
||||||
|
}
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("provider_snapshot=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.ProviderSnapshot))
|
||||||
|
builder.WriteString(", ")
|
||||||
builder.WriteString("status=")
|
builder.WriteString("status=")
|
||||||
builder.WriteString(_m.Status)
|
builder.WriteString(_m.Status)
|
||||||
builder.WriteString(", ")
|
builder.WriteString(", ")
|
||||||
|
|||||||
@@ -52,6 +52,10 @@ const (
|
|||||||
FieldSubscriptionDays = "subscription_days"
|
FieldSubscriptionDays = "subscription_days"
|
||||||
// FieldProviderInstanceID holds the string denoting the provider_instance_id field in the database.
|
// FieldProviderInstanceID holds the string denoting the provider_instance_id field in the database.
|
||||||
FieldProviderInstanceID = "provider_instance_id"
|
FieldProviderInstanceID = "provider_instance_id"
|
||||||
|
// FieldProviderKey holds the string denoting the provider_key field in the database.
|
||||||
|
FieldProviderKey = "provider_key"
|
||||||
|
// FieldProviderSnapshot holds the string denoting the provider_snapshot field in the database.
|
||||||
|
FieldProviderSnapshot = "provider_snapshot"
|
||||||
// FieldStatus holds the string denoting the status field in the database.
|
// FieldStatus holds the string denoting the status field in the database.
|
||||||
FieldStatus = "status"
|
FieldStatus = "status"
|
||||||
// FieldRefundAmount holds the string denoting the refund_amount field in the database.
|
// FieldRefundAmount holds the string denoting the refund_amount field in the database.
|
||||||
@@ -123,6 +127,8 @@ var Columns = []string{
|
|||||||
FieldSubscriptionGroupID,
|
FieldSubscriptionGroupID,
|
||||||
FieldSubscriptionDays,
|
FieldSubscriptionDays,
|
||||||
FieldProviderInstanceID,
|
FieldProviderInstanceID,
|
||||||
|
FieldProviderKey,
|
||||||
|
FieldProviderSnapshot,
|
||||||
FieldStatus,
|
FieldStatus,
|
||||||
FieldRefundAmount,
|
FieldRefundAmount,
|
||||||
FieldRefundReason,
|
FieldRefundReason,
|
||||||
@@ -176,6 +182,8 @@ var (
|
|||||||
OrderTypeValidator func(string) error
|
OrderTypeValidator func(string) error
|
||||||
// ProviderInstanceIDValidator is a validator for the "provider_instance_id" field. It is called by the builders before save.
|
// ProviderInstanceIDValidator is a validator for the "provider_instance_id" field. It is called by the builders before save.
|
||||||
ProviderInstanceIDValidator func(string) error
|
ProviderInstanceIDValidator func(string) error
|
||||||
|
// ProviderKeyValidator is a validator for the "provider_key" field. It is called by the builders before save.
|
||||||
|
ProviderKeyValidator func(string) error
|
||||||
// DefaultStatus holds the default value on creation for the "status" field.
|
// DefaultStatus holds the default value on creation for the "status" field.
|
||||||
DefaultStatus string
|
DefaultStatus string
|
||||||
// StatusValidator is a validator for the "status" field. It is called by the builders before save.
|
// StatusValidator is a validator for the "status" field. It is called by the builders before save.
|
||||||
@@ -301,6 +309,11 @@ func ByProviderInstanceID(opts ...sql.OrderTermOption) OrderOption {
|
|||||||
return sql.OrderByField(FieldProviderInstanceID, opts...).ToFunc()
|
return sql.OrderByField(FieldProviderInstanceID, opts...).ToFunc()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ByProviderKey orders the results by the provider_key field.
|
||||||
|
func ByProviderKey(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldProviderKey, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
// ByStatus orders the results by the status field.
|
// ByStatus orders the results by the status field.
|
||||||
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
|
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
|
||||||
return sql.OrderByField(FieldStatus, opts...).ToFunc()
|
return sql.OrderByField(FieldStatus, opts...).ToFunc()
|
||||||
|
|||||||
@@ -150,6 +150,11 @@ func ProviderInstanceID(v string) predicate.PaymentOrder {
|
|||||||
return predicate.PaymentOrder(sql.FieldEQ(FieldProviderInstanceID, v))
|
return predicate.PaymentOrder(sql.FieldEQ(FieldProviderInstanceID, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ProviderKey applies equality check predicate on the "provider_key" field. It's identical to ProviderKeyEQ.
|
||||||
|
func ProviderKey(v string) predicate.PaymentOrder {
|
||||||
|
return predicate.PaymentOrder(sql.FieldEQ(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
// Status applies equality check predicate on the "status" field. It's identical to StatusEQ.
|
// Status applies equality check predicate on the "status" field. It's identical to StatusEQ.
|
||||||
func Status(v string) predicate.PaymentOrder {
|
func Status(v string) predicate.PaymentOrder {
|
||||||
return predicate.PaymentOrder(sql.FieldEQ(FieldStatus, v))
|
return predicate.PaymentOrder(sql.FieldEQ(FieldStatus, v))
|
||||||
@@ -1360,6 +1365,91 @@ func ProviderInstanceIDContainsFold(v string) predicate.PaymentOrder {
|
|||||||
return predicate.PaymentOrder(sql.FieldContainsFold(FieldProviderInstanceID, v))
|
return predicate.PaymentOrder(sql.FieldContainsFold(FieldProviderInstanceID, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ProviderKeyEQ applies the EQ predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyEQ(v string) predicate.PaymentOrder {
|
||||||
|
return predicate.PaymentOrder(sql.FieldEQ(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyNEQ applies the NEQ predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyNEQ(v string) predicate.PaymentOrder {
|
||||||
|
return predicate.PaymentOrder(sql.FieldNEQ(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyIn applies the In predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyIn(vs ...string) predicate.PaymentOrder {
|
||||||
|
return predicate.PaymentOrder(sql.FieldIn(FieldProviderKey, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyNotIn applies the NotIn predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyNotIn(vs ...string) predicate.PaymentOrder {
|
||||||
|
return predicate.PaymentOrder(sql.FieldNotIn(FieldProviderKey, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyGT applies the GT predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyGT(v string) predicate.PaymentOrder {
|
||||||
|
return predicate.PaymentOrder(sql.FieldGT(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyGTE applies the GTE predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyGTE(v string) predicate.PaymentOrder {
|
||||||
|
return predicate.PaymentOrder(sql.FieldGTE(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyLT applies the LT predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyLT(v string) predicate.PaymentOrder {
|
||||||
|
return predicate.PaymentOrder(sql.FieldLT(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyLTE applies the LTE predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyLTE(v string) predicate.PaymentOrder {
|
||||||
|
return predicate.PaymentOrder(sql.FieldLTE(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyContains applies the Contains predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyContains(v string) predicate.PaymentOrder {
|
||||||
|
return predicate.PaymentOrder(sql.FieldContains(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyHasPrefix applies the HasPrefix predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyHasPrefix(v string) predicate.PaymentOrder {
|
||||||
|
return predicate.PaymentOrder(sql.FieldHasPrefix(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyHasSuffix applies the HasSuffix predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyHasSuffix(v string) predicate.PaymentOrder {
|
||||||
|
return predicate.PaymentOrder(sql.FieldHasSuffix(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyIsNil applies the IsNil predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyIsNil() predicate.PaymentOrder {
|
||||||
|
return predicate.PaymentOrder(sql.FieldIsNull(FieldProviderKey))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyNotNil applies the NotNil predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyNotNil() predicate.PaymentOrder {
|
||||||
|
return predicate.PaymentOrder(sql.FieldNotNull(FieldProviderKey))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyEqualFold applies the EqualFold predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyEqualFold(v string) predicate.PaymentOrder {
|
||||||
|
return predicate.PaymentOrder(sql.FieldEqualFold(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderKeyContainsFold applies the ContainsFold predicate on the "provider_key" field.
|
||||||
|
func ProviderKeyContainsFold(v string) predicate.PaymentOrder {
|
||||||
|
return predicate.PaymentOrder(sql.FieldContainsFold(FieldProviderKey, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderSnapshotIsNil applies the IsNil predicate on the "provider_snapshot" field.
|
||||||
|
func ProviderSnapshotIsNil() predicate.PaymentOrder {
|
||||||
|
return predicate.PaymentOrder(sql.FieldIsNull(FieldProviderSnapshot))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProviderSnapshotNotNil applies the NotNil predicate on the "provider_snapshot" field.
|
||||||
|
func ProviderSnapshotNotNil() predicate.PaymentOrder {
|
||||||
|
return predicate.PaymentOrder(sql.FieldNotNull(FieldProviderSnapshot))
|
||||||
|
}
|
||||||
|
|
||||||
// StatusEQ applies the EQ predicate on the "status" field.
|
// StatusEQ applies the EQ predicate on the "status" field.
|
||||||
func StatusEQ(v string) predicate.PaymentOrder {
|
func StatusEQ(v string) predicate.PaymentOrder {
|
||||||
return predicate.PaymentOrder(sql.FieldEQ(FieldStatus, v))
|
return predicate.PaymentOrder(sql.FieldEQ(FieldStatus, v))
|
||||||
|
|||||||
@@ -225,6 +225,26 @@ func (_c *PaymentOrderCreate) SetNillableProviderInstanceID(v *string) *PaymentO
|
|||||||
return _c
|
return _c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetProviderKey sets the "provider_key" field.
|
||||||
|
func (_c *PaymentOrderCreate) SetProviderKey(v string) *PaymentOrderCreate {
|
||||||
|
_c.mutation.SetProviderKey(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableProviderKey sets the "provider_key" field if the given value is not nil.
|
||||||
|
func (_c *PaymentOrderCreate) SetNillableProviderKey(v *string) *PaymentOrderCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetProviderKey(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProviderSnapshot sets the "provider_snapshot" field.
|
||||||
|
func (_c *PaymentOrderCreate) SetProviderSnapshot(v map[string]interface{}) *PaymentOrderCreate {
|
||||||
|
_c.mutation.SetProviderSnapshot(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
// SetStatus sets the "status" field.
|
// SetStatus sets the "status" field.
|
||||||
func (_c *PaymentOrderCreate) SetStatus(v string) *PaymentOrderCreate {
|
func (_c *PaymentOrderCreate) SetStatus(v string) *PaymentOrderCreate {
|
||||||
_c.mutation.SetStatus(v)
|
_c.mutation.SetStatus(v)
|
||||||
@@ -602,6 +622,11 @@ func (_c *PaymentOrderCreate) check() error {
|
|||||||
return &ValidationError{Name: "provider_instance_id", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.provider_instance_id": %w`, err)}
|
return &ValidationError{Name: "provider_instance_id", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.provider_instance_id": %w`, err)}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if v, ok := _c.mutation.ProviderKey(); ok {
|
||||||
|
if err := paymentorder.ProviderKeyValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "provider_key", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.provider_key": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
if _, ok := _c.mutation.Status(); !ok {
|
if _, ok := _c.mutation.Status(); !ok {
|
||||||
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "PaymentOrder.status"`)}
|
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "PaymentOrder.status"`)}
|
||||||
}
|
}
|
||||||
@@ -748,6 +773,14 @@ func (_c *PaymentOrderCreate) createSpec() (*PaymentOrder, *sqlgraph.CreateSpec)
|
|||||||
_spec.SetField(paymentorder.FieldProviderInstanceID, field.TypeString, value)
|
_spec.SetField(paymentorder.FieldProviderInstanceID, field.TypeString, value)
|
||||||
_node.ProviderInstanceID = &value
|
_node.ProviderInstanceID = &value
|
||||||
}
|
}
|
||||||
|
if value, ok := _c.mutation.ProviderKey(); ok {
|
||||||
|
_spec.SetField(paymentorder.FieldProviderKey, field.TypeString, value)
|
||||||
|
_node.ProviderKey = &value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.ProviderSnapshot(); ok {
|
||||||
|
_spec.SetField(paymentorder.FieldProviderSnapshot, field.TypeJSON, value)
|
||||||
|
_node.ProviderSnapshot = value
|
||||||
|
}
|
||||||
if value, ok := _c.mutation.Status(); ok {
|
if value, ok := _c.mutation.Status(); ok {
|
||||||
_spec.SetField(paymentorder.FieldStatus, field.TypeString, value)
|
_spec.SetField(paymentorder.FieldStatus, field.TypeString, value)
|
||||||
_node.Status = value
|
_node.Status = value
|
||||||
@@ -1201,6 +1234,42 @@ func (u *PaymentOrderUpsert) ClearProviderInstanceID() *PaymentOrderUpsert {
|
|||||||
return u
|
return u
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetProviderKey sets the "provider_key" field.
|
||||||
|
func (u *PaymentOrderUpsert) SetProviderKey(v string) *PaymentOrderUpsert {
|
||||||
|
u.Set(paymentorder.FieldProviderKey, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateProviderKey sets the "provider_key" field to the value that was provided on create.
|
||||||
|
func (u *PaymentOrderUpsert) UpdateProviderKey() *PaymentOrderUpsert {
|
||||||
|
u.SetExcluded(paymentorder.FieldProviderKey)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearProviderKey clears the value of the "provider_key" field.
|
||||||
|
func (u *PaymentOrderUpsert) ClearProviderKey() *PaymentOrderUpsert {
|
||||||
|
u.SetNull(paymentorder.FieldProviderKey)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProviderSnapshot sets the "provider_snapshot" field.
|
||||||
|
func (u *PaymentOrderUpsert) SetProviderSnapshot(v map[string]interface{}) *PaymentOrderUpsert {
|
||||||
|
u.Set(paymentorder.FieldProviderSnapshot, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateProviderSnapshot sets the "provider_snapshot" field to the value that was provided on create.
|
||||||
|
func (u *PaymentOrderUpsert) UpdateProviderSnapshot() *PaymentOrderUpsert {
|
||||||
|
u.SetExcluded(paymentorder.FieldProviderSnapshot)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearProviderSnapshot clears the value of the "provider_snapshot" field.
|
||||||
|
func (u *PaymentOrderUpsert) ClearProviderSnapshot() *PaymentOrderUpsert {
|
||||||
|
u.SetNull(paymentorder.FieldProviderSnapshot)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
// SetStatus sets the "status" field.
|
// SetStatus sets the "status" field.
|
||||||
func (u *PaymentOrderUpsert) SetStatus(v string) *PaymentOrderUpsert {
|
func (u *PaymentOrderUpsert) SetStatus(v string) *PaymentOrderUpsert {
|
||||||
u.Set(paymentorder.FieldStatus, v)
|
u.Set(paymentorder.FieldStatus, v)
|
||||||
@@ -1880,6 +1949,48 @@ func (u *PaymentOrderUpsertOne) ClearProviderInstanceID() *PaymentOrderUpsertOne
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetProviderKey sets the "provider_key" field.
|
||||||
|
func (u *PaymentOrderUpsertOne) SetProviderKey(v string) *PaymentOrderUpsertOne {
|
||||||
|
return u.Update(func(s *PaymentOrderUpsert) {
|
||||||
|
s.SetProviderKey(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateProviderKey sets the "provider_key" field to the value that was provided on create.
|
||||||
|
func (u *PaymentOrderUpsertOne) UpdateProviderKey() *PaymentOrderUpsertOne {
|
||||||
|
return u.Update(func(s *PaymentOrderUpsert) {
|
||||||
|
s.UpdateProviderKey()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearProviderKey clears the value of the "provider_key" field.
|
||||||
|
func (u *PaymentOrderUpsertOne) ClearProviderKey() *PaymentOrderUpsertOne {
|
||||||
|
return u.Update(func(s *PaymentOrderUpsert) {
|
||||||
|
s.ClearProviderKey()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProviderSnapshot sets the "provider_snapshot" field.
|
||||||
|
func (u *PaymentOrderUpsertOne) SetProviderSnapshot(v map[string]interface{}) *PaymentOrderUpsertOne {
|
||||||
|
return u.Update(func(s *PaymentOrderUpsert) {
|
||||||
|
s.SetProviderSnapshot(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateProviderSnapshot sets the "provider_snapshot" field to the value that was provided on create.
|
||||||
|
func (u *PaymentOrderUpsertOne) UpdateProviderSnapshot() *PaymentOrderUpsertOne {
|
||||||
|
return u.Update(func(s *PaymentOrderUpsert) {
|
||||||
|
s.UpdateProviderSnapshot()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearProviderSnapshot clears the value of the "provider_snapshot" field.
|
||||||
|
func (u *PaymentOrderUpsertOne) ClearProviderSnapshot() *PaymentOrderUpsertOne {
|
||||||
|
return u.Update(func(s *PaymentOrderUpsert) {
|
||||||
|
s.ClearProviderSnapshot()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// SetStatus sets the "status" field.
|
// SetStatus sets the "status" field.
|
||||||
func (u *PaymentOrderUpsertOne) SetStatus(v string) *PaymentOrderUpsertOne {
|
func (u *PaymentOrderUpsertOne) SetStatus(v string) *PaymentOrderUpsertOne {
|
||||||
return u.Update(func(s *PaymentOrderUpsert) {
|
return u.Update(func(s *PaymentOrderUpsert) {
|
||||||
@@ -2770,6 +2881,48 @@ func (u *PaymentOrderUpsertBulk) ClearProviderInstanceID() *PaymentOrderUpsertBu
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetProviderKey sets the "provider_key" field.
|
||||||
|
func (u *PaymentOrderUpsertBulk) SetProviderKey(v string) *PaymentOrderUpsertBulk {
|
||||||
|
return u.Update(func(s *PaymentOrderUpsert) {
|
||||||
|
s.SetProviderKey(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateProviderKey sets the "provider_key" field to the value that was provided on create.
|
||||||
|
func (u *PaymentOrderUpsertBulk) UpdateProviderKey() *PaymentOrderUpsertBulk {
|
||||||
|
return u.Update(func(s *PaymentOrderUpsert) {
|
||||||
|
s.UpdateProviderKey()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearProviderKey clears the value of the "provider_key" field.
|
||||||
|
func (u *PaymentOrderUpsertBulk) ClearProviderKey() *PaymentOrderUpsertBulk {
|
||||||
|
return u.Update(func(s *PaymentOrderUpsert) {
|
||||||
|
s.ClearProviderKey()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProviderSnapshot sets the "provider_snapshot" field.
|
||||||
|
func (u *PaymentOrderUpsertBulk) SetProviderSnapshot(v map[string]interface{}) *PaymentOrderUpsertBulk {
|
||||||
|
return u.Update(func(s *PaymentOrderUpsert) {
|
||||||
|
s.SetProviderSnapshot(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateProviderSnapshot sets the "provider_snapshot" field to the value that was provided on create.
|
||||||
|
func (u *PaymentOrderUpsertBulk) UpdateProviderSnapshot() *PaymentOrderUpsertBulk {
|
||||||
|
return u.Update(func(s *PaymentOrderUpsert) {
|
||||||
|
s.UpdateProviderSnapshot()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearProviderSnapshot clears the value of the "provider_snapshot" field.
|
||||||
|
func (u *PaymentOrderUpsertBulk) ClearProviderSnapshot() *PaymentOrderUpsertBulk {
|
||||||
|
return u.Update(func(s *PaymentOrderUpsert) {
|
||||||
|
s.ClearProviderSnapshot()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// SetStatus sets the "status" field.
|
// SetStatus sets the "status" field.
|
||||||
func (u *PaymentOrderUpsertBulk) SetStatus(v string) *PaymentOrderUpsertBulk {
|
func (u *PaymentOrderUpsertBulk) SetStatus(v string) *PaymentOrderUpsertBulk {
|
||||||
return u.Update(func(s *PaymentOrderUpsert) {
|
return u.Update(func(s *PaymentOrderUpsert) {
|
||||||
|
|||||||
@@ -385,6 +385,38 @@ func (_u *PaymentOrderUpdate) ClearProviderInstanceID() *PaymentOrderUpdate {
|
|||||||
return _u
|
return _u
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetProviderKey sets the "provider_key" field.
|
||||||
|
func (_u *PaymentOrderUpdate) SetProviderKey(v string) *PaymentOrderUpdate {
|
||||||
|
_u.mutation.SetProviderKey(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableProviderKey sets the "provider_key" field if the given value is not nil.
|
||||||
|
func (_u *PaymentOrderUpdate) SetNillableProviderKey(v *string) *PaymentOrderUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetProviderKey(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearProviderKey clears the value of the "provider_key" field.
|
||||||
|
func (_u *PaymentOrderUpdate) ClearProviderKey() *PaymentOrderUpdate {
|
||||||
|
_u.mutation.ClearProviderKey()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProviderSnapshot sets the "provider_snapshot" field.
|
||||||
|
func (_u *PaymentOrderUpdate) SetProviderSnapshot(v map[string]interface{}) *PaymentOrderUpdate {
|
||||||
|
_u.mutation.SetProviderSnapshot(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearProviderSnapshot clears the value of the "provider_snapshot" field.
|
||||||
|
func (_u *PaymentOrderUpdate) ClearProviderSnapshot() *PaymentOrderUpdate {
|
||||||
|
_u.mutation.ClearProviderSnapshot()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
// SetStatus sets the "status" field.
|
// SetStatus sets the "status" field.
|
||||||
func (_u *PaymentOrderUpdate) SetStatus(v string) *PaymentOrderUpdate {
|
func (_u *PaymentOrderUpdate) SetStatus(v string) *PaymentOrderUpdate {
|
||||||
_u.mutation.SetStatus(v)
|
_u.mutation.SetStatus(v)
|
||||||
@@ -776,6 +808,11 @@ func (_u *PaymentOrderUpdate) check() error {
|
|||||||
return &ValidationError{Name: "provider_instance_id", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.provider_instance_id": %w`, err)}
|
return &ValidationError{Name: "provider_instance_id", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.provider_instance_id": %w`, err)}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if v, ok := _u.mutation.ProviderKey(); ok {
|
||||||
|
if err := paymentorder.ProviderKeyValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "provider_key", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.provider_key": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
if v, ok := _u.mutation.Status(); ok {
|
if v, ok := _u.mutation.Status(); ok {
|
||||||
if err := paymentorder.StatusValidator(v); err != nil {
|
if err := paymentorder.StatusValidator(v); err != nil {
|
||||||
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.status": %w`, err)}
|
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.status": %w`, err)}
|
||||||
@@ -910,6 +947,18 @@ func (_u *PaymentOrderUpdate) sqlSave(ctx context.Context) (_node int, err error
|
|||||||
if _u.mutation.ProviderInstanceIDCleared() {
|
if _u.mutation.ProviderInstanceIDCleared() {
|
||||||
_spec.ClearField(paymentorder.FieldProviderInstanceID, field.TypeString)
|
_spec.ClearField(paymentorder.FieldProviderInstanceID, field.TypeString)
|
||||||
}
|
}
|
||||||
|
if value, ok := _u.mutation.ProviderKey(); ok {
|
||||||
|
_spec.SetField(paymentorder.FieldProviderKey, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.ProviderKeyCleared() {
|
||||||
|
_spec.ClearField(paymentorder.FieldProviderKey, field.TypeString)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.ProviderSnapshot(); ok {
|
||||||
|
_spec.SetField(paymentorder.FieldProviderSnapshot, field.TypeJSON, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.ProviderSnapshotCleared() {
|
||||||
|
_spec.ClearField(paymentorder.FieldProviderSnapshot, field.TypeJSON)
|
||||||
|
}
|
||||||
if value, ok := _u.mutation.Status(); ok {
|
if value, ok := _u.mutation.Status(); ok {
|
||||||
_spec.SetField(paymentorder.FieldStatus, field.TypeString, value)
|
_spec.SetField(paymentorder.FieldStatus, field.TypeString, value)
|
||||||
}
|
}
|
||||||
@@ -1399,6 +1448,38 @@ func (_u *PaymentOrderUpdateOne) ClearProviderInstanceID() *PaymentOrderUpdateOn
|
|||||||
return _u
|
return _u
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetProviderKey sets the "provider_key" field.
|
||||||
|
func (_u *PaymentOrderUpdateOne) SetProviderKey(v string) *PaymentOrderUpdateOne {
|
||||||
|
_u.mutation.SetProviderKey(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableProviderKey sets the "provider_key" field if the given value is not nil.
|
||||||
|
func (_u *PaymentOrderUpdateOne) SetNillableProviderKey(v *string) *PaymentOrderUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetProviderKey(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearProviderKey clears the value of the "provider_key" field.
|
||||||
|
func (_u *PaymentOrderUpdateOne) ClearProviderKey() *PaymentOrderUpdateOne {
|
||||||
|
_u.mutation.ClearProviderKey()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProviderSnapshot sets the "provider_snapshot" field.
|
||||||
|
func (_u *PaymentOrderUpdateOne) SetProviderSnapshot(v map[string]interface{}) *PaymentOrderUpdateOne {
|
||||||
|
_u.mutation.SetProviderSnapshot(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearProviderSnapshot clears the value of the "provider_snapshot" field.
|
||||||
|
func (_u *PaymentOrderUpdateOne) ClearProviderSnapshot() *PaymentOrderUpdateOne {
|
||||||
|
_u.mutation.ClearProviderSnapshot()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
// SetStatus sets the "status" field.
|
// SetStatus sets the "status" field.
|
||||||
func (_u *PaymentOrderUpdateOne) SetStatus(v string) *PaymentOrderUpdateOne {
|
func (_u *PaymentOrderUpdateOne) SetStatus(v string) *PaymentOrderUpdateOne {
|
||||||
_u.mutation.SetStatus(v)
|
_u.mutation.SetStatus(v)
|
||||||
@@ -1803,6 +1884,11 @@ func (_u *PaymentOrderUpdateOne) check() error {
|
|||||||
return &ValidationError{Name: "provider_instance_id", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.provider_instance_id": %w`, err)}
|
return &ValidationError{Name: "provider_instance_id", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.provider_instance_id": %w`, err)}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if v, ok := _u.mutation.ProviderKey(); ok {
|
||||||
|
if err := paymentorder.ProviderKeyValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "provider_key", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.provider_key": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
if v, ok := _u.mutation.Status(); ok {
|
if v, ok := _u.mutation.Status(); ok {
|
||||||
if err := paymentorder.StatusValidator(v); err != nil {
|
if err := paymentorder.StatusValidator(v); err != nil {
|
||||||
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.status": %w`, err)}
|
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.status": %w`, err)}
|
||||||
@@ -1954,6 +2040,18 @@ func (_u *PaymentOrderUpdateOne) sqlSave(ctx context.Context) (_node *PaymentOrd
|
|||||||
if _u.mutation.ProviderInstanceIDCleared() {
|
if _u.mutation.ProviderInstanceIDCleared() {
|
||||||
_spec.ClearField(paymentorder.FieldProviderInstanceID, field.TypeString)
|
_spec.ClearField(paymentorder.FieldProviderInstanceID, field.TypeString)
|
||||||
}
|
}
|
||||||
|
if value, ok := _u.mutation.ProviderKey(); ok {
|
||||||
|
_spec.SetField(paymentorder.FieldProviderKey, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.ProviderKeyCleared() {
|
||||||
|
_spec.ClearField(paymentorder.FieldProviderKey, field.TypeString)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.ProviderSnapshot(); ok {
|
||||||
|
_spec.SetField(paymentorder.FieldProviderSnapshot, field.TypeJSON, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.ProviderSnapshotCleared() {
|
||||||
|
_spec.ClearField(paymentorder.FieldProviderSnapshot, field.TypeJSON)
|
||||||
|
}
|
||||||
if value, ok := _u.mutation.Status(); ok {
|
if value, ok := _u.mutation.Status(); ok {
|
||||||
_spec.SetField(paymentorder.FieldStatus, field.TypeString, value)
|
_spec.SetField(paymentorder.FieldStatus, field.TypeString, value)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,399 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/identityadoptiondecision"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/pendingauthsession"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/user"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PendingAuthSession is the model entity for the PendingAuthSession schema.
|
||||||
|
type PendingAuthSession 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"`
|
||||||
|
// SessionToken holds the value of the "session_token" field.
|
||||||
|
SessionToken string `json:"session_token,omitempty"`
|
||||||
|
// Intent holds the value of the "intent" field.
|
||||||
|
Intent string `json:"intent,omitempty"`
|
||||||
|
// ProviderType holds the value of the "provider_type" field.
|
||||||
|
ProviderType string `json:"provider_type,omitempty"`
|
||||||
|
// ProviderKey holds the value of the "provider_key" field.
|
||||||
|
ProviderKey string `json:"provider_key,omitempty"`
|
||||||
|
// ProviderSubject holds the value of the "provider_subject" field.
|
||||||
|
ProviderSubject string `json:"provider_subject,omitempty"`
|
||||||
|
// TargetUserID holds the value of the "target_user_id" field.
|
||||||
|
TargetUserID *int64 `json:"target_user_id,omitempty"`
|
||||||
|
// RedirectTo holds the value of the "redirect_to" field.
|
||||||
|
RedirectTo string `json:"redirect_to,omitempty"`
|
||||||
|
// ResolvedEmail holds the value of the "resolved_email" field.
|
||||||
|
ResolvedEmail string `json:"resolved_email,omitempty"`
|
||||||
|
// RegistrationPasswordHash holds the value of the "registration_password_hash" field.
|
||||||
|
RegistrationPasswordHash string `json:"registration_password_hash,omitempty"`
|
||||||
|
// UpstreamIdentityClaims holds the value of the "upstream_identity_claims" field.
|
||||||
|
UpstreamIdentityClaims map[string]interface{} `json:"upstream_identity_claims,omitempty"`
|
||||||
|
// LocalFlowState holds the value of the "local_flow_state" field.
|
||||||
|
LocalFlowState map[string]interface{} `json:"local_flow_state,omitempty"`
|
||||||
|
// BrowserSessionKey holds the value of the "browser_session_key" field.
|
||||||
|
BrowserSessionKey string `json:"browser_session_key,omitempty"`
|
||||||
|
// CompletionCodeHash holds the value of the "completion_code_hash" field.
|
||||||
|
CompletionCodeHash string `json:"completion_code_hash,omitempty"`
|
||||||
|
// CompletionCodeExpiresAt holds the value of the "completion_code_expires_at" field.
|
||||||
|
CompletionCodeExpiresAt *time.Time `json:"completion_code_expires_at,omitempty"`
|
||||||
|
// EmailVerifiedAt holds the value of the "email_verified_at" field.
|
||||||
|
EmailVerifiedAt *time.Time `json:"email_verified_at,omitempty"`
|
||||||
|
// PasswordVerifiedAt holds the value of the "password_verified_at" field.
|
||||||
|
PasswordVerifiedAt *time.Time `json:"password_verified_at,omitempty"`
|
||||||
|
// TotpVerifiedAt holds the value of the "totp_verified_at" field.
|
||||||
|
TotpVerifiedAt *time.Time `json:"totp_verified_at,omitempty"`
|
||||||
|
// ExpiresAt holds the value of the "expires_at" field.
|
||||||
|
ExpiresAt time.Time `json:"expires_at,omitempty"`
|
||||||
|
// ConsumedAt holds the value of the "consumed_at" field.
|
||||||
|
ConsumedAt *time.Time `json:"consumed_at,omitempty"`
|
||||||
|
// Edges holds the relations/edges for other nodes in the graph.
|
||||||
|
// The values are being populated by the PendingAuthSessionQuery when eager-loading is set.
|
||||||
|
Edges PendingAuthSessionEdges `json:"edges"`
|
||||||
|
selectValues sql.SelectValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// PendingAuthSessionEdges holds the relations/edges for other nodes in the graph.
|
||||||
|
type PendingAuthSessionEdges struct {
|
||||||
|
// TargetUser holds the value of the target_user edge.
|
||||||
|
TargetUser *User `json:"target_user,omitempty"`
|
||||||
|
// AdoptionDecision holds the value of the adoption_decision edge.
|
||||||
|
AdoptionDecision *IdentityAdoptionDecision `json:"adoption_decision,omitempty"`
|
||||||
|
// loadedTypes holds the information for reporting if a
|
||||||
|
// type was loaded (or requested) in eager-loading or not.
|
||||||
|
loadedTypes [2]bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// TargetUserOrErr returns the TargetUser value or an error if the edge
|
||||||
|
// was not loaded in eager-loading, or loaded but was not found.
|
||||||
|
func (e PendingAuthSessionEdges) TargetUserOrErr() (*User, error) {
|
||||||
|
if e.TargetUser != nil {
|
||||||
|
return e.TargetUser, nil
|
||||||
|
} else if e.loadedTypes[0] {
|
||||||
|
return nil, &NotFoundError{label: user.Label}
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "target_user"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdoptionDecisionOrErr returns the AdoptionDecision value or an error if the edge
|
||||||
|
// was not loaded in eager-loading, or loaded but was not found.
|
||||||
|
func (e PendingAuthSessionEdges) AdoptionDecisionOrErr() (*IdentityAdoptionDecision, error) {
|
||||||
|
if e.AdoptionDecision != nil {
|
||||||
|
return e.AdoptionDecision, nil
|
||||||
|
} else if e.loadedTypes[1] {
|
||||||
|
return nil, &NotFoundError{label: identityadoptiondecision.Label}
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "adoption_decision"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// scanValues returns the types for scanning values from sql.Rows.
|
||||||
|
func (*PendingAuthSession) scanValues(columns []string) ([]any, error) {
|
||||||
|
values := make([]any, len(columns))
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case pendingauthsession.FieldUpstreamIdentityClaims, pendingauthsession.FieldLocalFlowState:
|
||||||
|
values[i] = new([]byte)
|
||||||
|
case pendingauthsession.FieldID, pendingauthsession.FieldTargetUserID:
|
||||||
|
values[i] = new(sql.NullInt64)
|
||||||
|
case pendingauthsession.FieldSessionToken, pendingauthsession.FieldIntent, pendingauthsession.FieldProviderType, pendingauthsession.FieldProviderKey, pendingauthsession.FieldProviderSubject, pendingauthsession.FieldRedirectTo, pendingauthsession.FieldResolvedEmail, pendingauthsession.FieldRegistrationPasswordHash, pendingauthsession.FieldBrowserSessionKey, pendingauthsession.FieldCompletionCodeHash:
|
||||||
|
values[i] = new(sql.NullString)
|
||||||
|
case pendingauthsession.FieldCreatedAt, pendingauthsession.FieldUpdatedAt, pendingauthsession.FieldCompletionCodeExpiresAt, pendingauthsession.FieldEmailVerifiedAt, pendingauthsession.FieldPasswordVerifiedAt, pendingauthsession.FieldTotpVerifiedAt, pendingauthsession.FieldExpiresAt, pendingauthsession.FieldConsumedAt:
|
||||||
|
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 PendingAuthSession fields.
|
||||||
|
func (_m *PendingAuthSession) 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 pendingauthsession.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 pendingauthsession.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 pendingauthsession.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 pendingauthsession.FieldSessionToken:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field session_token", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.SessionToken = value.String
|
||||||
|
}
|
||||||
|
case pendingauthsession.FieldIntent:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field intent", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.Intent = value.String
|
||||||
|
}
|
||||||
|
case pendingauthsession.FieldProviderType:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field provider_type", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.ProviderType = value.String
|
||||||
|
}
|
||||||
|
case pendingauthsession.FieldProviderKey:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field provider_key", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.ProviderKey = value.String
|
||||||
|
}
|
||||||
|
case pendingauthsession.FieldProviderSubject:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field provider_subject", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.ProviderSubject = value.String
|
||||||
|
}
|
||||||
|
case pendingauthsession.FieldTargetUserID:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field target_user_id", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.TargetUserID = new(int64)
|
||||||
|
*_m.TargetUserID = value.Int64
|
||||||
|
}
|
||||||
|
case pendingauthsession.FieldRedirectTo:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field redirect_to", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.RedirectTo = value.String
|
||||||
|
}
|
||||||
|
case pendingauthsession.FieldResolvedEmail:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field resolved_email", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.ResolvedEmail = value.String
|
||||||
|
}
|
||||||
|
case pendingauthsession.FieldRegistrationPasswordHash:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field registration_password_hash", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.RegistrationPasswordHash = value.String
|
||||||
|
}
|
||||||
|
case pendingauthsession.FieldUpstreamIdentityClaims:
|
||||||
|
if value, ok := values[i].(*[]byte); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field upstream_identity_claims", values[i])
|
||||||
|
} else if value != nil && len(*value) > 0 {
|
||||||
|
if err := json.Unmarshal(*value, &_m.UpstreamIdentityClaims); err != nil {
|
||||||
|
return fmt.Errorf("unmarshal field upstream_identity_claims: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case pendingauthsession.FieldLocalFlowState:
|
||||||
|
if value, ok := values[i].(*[]byte); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field local_flow_state", values[i])
|
||||||
|
} else if value != nil && len(*value) > 0 {
|
||||||
|
if err := json.Unmarshal(*value, &_m.LocalFlowState); err != nil {
|
||||||
|
return fmt.Errorf("unmarshal field local_flow_state: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case pendingauthsession.FieldBrowserSessionKey:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field browser_session_key", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.BrowserSessionKey = value.String
|
||||||
|
}
|
||||||
|
case pendingauthsession.FieldCompletionCodeHash:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field completion_code_hash", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.CompletionCodeHash = value.String
|
||||||
|
}
|
||||||
|
case pendingauthsession.FieldCompletionCodeExpiresAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field completion_code_expires_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.CompletionCodeExpiresAt = new(time.Time)
|
||||||
|
*_m.CompletionCodeExpiresAt = value.Time
|
||||||
|
}
|
||||||
|
case pendingauthsession.FieldEmailVerifiedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field email_verified_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.EmailVerifiedAt = new(time.Time)
|
||||||
|
*_m.EmailVerifiedAt = value.Time
|
||||||
|
}
|
||||||
|
case pendingauthsession.FieldPasswordVerifiedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field password_verified_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.PasswordVerifiedAt = new(time.Time)
|
||||||
|
*_m.PasswordVerifiedAt = value.Time
|
||||||
|
}
|
||||||
|
case pendingauthsession.FieldTotpVerifiedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field totp_verified_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.TotpVerifiedAt = new(time.Time)
|
||||||
|
*_m.TotpVerifiedAt = value.Time
|
||||||
|
}
|
||||||
|
case pendingauthsession.FieldExpiresAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field expires_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.ExpiresAt = value.Time
|
||||||
|
}
|
||||||
|
case pendingauthsession.FieldConsumedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field consumed_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.ConsumedAt = new(time.Time)
|
||||||
|
*_m.ConsumedAt = value.Time
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
_m.selectValues.Set(columns[i], values[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value returns the ent.Value that was dynamically selected and assigned to the PendingAuthSession.
|
||||||
|
// This includes values selected through modifiers, order, etc.
|
||||||
|
func (_m *PendingAuthSession) Value(name string) (ent.Value, error) {
|
||||||
|
return _m.selectValues.Get(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryTargetUser queries the "target_user" edge of the PendingAuthSession entity.
|
||||||
|
func (_m *PendingAuthSession) QueryTargetUser() *UserQuery {
|
||||||
|
return NewPendingAuthSessionClient(_m.config).QueryTargetUser(_m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryAdoptionDecision queries the "adoption_decision" edge of the PendingAuthSession entity.
|
||||||
|
func (_m *PendingAuthSession) QueryAdoptionDecision() *IdentityAdoptionDecisionQuery {
|
||||||
|
return NewPendingAuthSessionClient(_m.config).QueryAdoptionDecision(_m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns a builder for updating this PendingAuthSession.
|
||||||
|
// Note that you need to call PendingAuthSession.Unwrap() before calling this method if this PendingAuthSession
|
||||||
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||||
|
func (_m *PendingAuthSession) Update() *PendingAuthSessionUpdateOne {
|
||||||
|
return NewPendingAuthSessionClient(_m.config).UpdateOne(_m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap unwraps the PendingAuthSession 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 *PendingAuthSession) Unwrap() *PendingAuthSession {
|
||||||
|
_tx, ok := _m.config.driver.(*txDriver)
|
||||||
|
if !ok {
|
||||||
|
panic("ent: PendingAuthSession is not a transactional entity")
|
||||||
|
}
|
||||||
|
_m.config.driver = _tx.drv
|
||||||
|
return _m
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements the fmt.Stringer.
|
||||||
|
func (_m *PendingAuthSession) String() string {
|
||||||
|
var builder strings.Builder
|
||||||
|
builder.WriteString("PendingAuthSession(")
|
||||||
|
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(", ")
|
||||||
|
builder.WriteString("session_token=")
|
||||||
|
builder.WriteString(_m.SessionToken)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("intent=")
|
||||||
|
builder.WriteString(_m.Intent)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("provider_type=")
|
||||||
|
builder.WriteString(_m.ProviderType)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("provider_key=")
|
||||||
|
builder.WriteString(_m.ProviderKey)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("provider_subject=")
|
||||||
|
builder.WriteString(_m.ProviderSubject)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
if v := _m.TargetUserID; v != nil {
|
||||||
|
builder.WriteString("target_user_id=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", *v))
|
||||||
|
}
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("redirect_to=")
|
||||||
|
builder.WriteString(_m.RedirectTo)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("resolved_email=")
|
||||||
|
builder.WriteString(_m.ResolvedEmail)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("registration_password_hash=")
|
||||||
|
builder.WriteString(_m.RegistrationPasswordHash)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("upstream_identity_claims=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.UpstreamIdentityClaims))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("local_flow_state=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.LocalFlowState))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("browser_session_key=")
|
||||||
|
builder.WriteString(_m.BrowserSessionKey)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("completion_code_hash=")
|
||||||
|
builder.WriteString(_m.CompletionCodeHash)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
if v := _m.CompletionCodeExpiresAt; v != nil {
|
||||||
|
builder.WriteString("completion_code_expires_at=")
|
||||||
|
builder.WriteString(v.Format(time.ANSIC))
|
||||||
|
}
|
||||||
|
builder.WriteString(", ")
|
||||||
|
if v := _m.EmailVerifiedAt; v != nil {
|
||||||
|
builder.WriteString("email_verified_at=")
|
||||||
|
builder.WriteString(v.Format(time.ANSIC))
|
||||||
|
}
|
||||||
|
builder.WriteString(", ")
|
||||||
|
if v := _m.PasswordVerifiedAt; v != nil {
|
||||||
|
builder.WriteString("password_verified_at=")
|
||||||
|
builder.WriteString(v.Format(time.ANSIC))
|
||||||
|
}
|
||||||
|
builder.WriteString(", ")
|
||||||
|
if v := _m.TotpVerifiedAt; v != nil {
|
||||||
|
builder.WriteString("totp_verified_at=")
|
||||||
|
builder.WriteString(v.Format(time.ANSIC))
|
||||||
|
}
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("expires_at=")
|
||||||
|
builder.WriteString(_m.ExpiresAt.Format(time.ANSIC))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
if v := _m.ConsumedAt; v != nil {
|
||||||
|
builder.WriteString("consumed_at=")
|
||||||
|
builder.WriteString(v.Format(time.ANSIC))
|
||||||
|
}
|
||||||
|
builder.WriteByte(')')
|
||||||
|
return builder.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// PendingAuthSessions is a parsable slice of PendingAuthSession.
|
||||||
|
type PendingAuthSessions []*PendingAuthSession
|
||||||
@@ -0,0 +1,279 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package pendingauthsession
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Label holds the string label denoting the pendingauthsession type in the database.
|
||||||
|
Label = "pending_auth_session"
|
||||||
|
// FieldID holds the string denoting the id field in the database.
|
||||||
|
FieldID = "id"
|
||||||
|
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||||
|
FieldCreatedAt = "created_at"
|
||||||
|
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||||
|
FieldUpdatedAt = "updated_at"
|
||||||
|
// FieldSessionToken holds the string denoting the session_token field in the database.
|
||||||
|
FieldSessionToken = "session_token"
|
||||||
|
// FieldIntent holds the string denoting the intent field in the database.
|
||||||
|
FieldIntent = "intent"
|
||||||
|
// FieldProviderType holds the string denoting the provider_type field in the database.
|
||||||
|
FieldProviderType = "provider_type"
|
||||||
|
// FieldProviderKey holds the string denoting the provider_key field in the database.
|
||||||
|
FieldProviderKey = "provider_key"
|
||||||
|
// FieldProviderSubject holds the string denoting the provider_subject field in the database.
|
||||||
|
FieldProviderSubject = "provider_subject"
|
||||||
|
// FieldTargetUserID holds the string denoting the target_user_id field in the database.
|
||||||
|
FieldTargetUserID = "target_user_id"
|
||||||
|
// FieldRedirectTo holds the string denoting the redirect_to field in the database.
|
||||||
|
FieldRedirectTo = "redirect_to"
|
||||||
|
// FieldResolvedEmail holds the string denoting the resolved_email field in the database.
|
||||||
|
FieldResolvedEmail = "resolved_email"
|
||||||
|
// FieldRegistrationPasswordHash holds the string denoting the registration_password_hash field in the database.
|
||||||
|
FieldRegistrationPasswordHash = "registration_password_hash"
|
||||||
|
// FieldUpstreamIdentityClaims holds the string denoting the upstream_identity_claims field in the database.
|
||||||
|
FieldUpstreamIdentityClaims = "upstream_identity_claims"
|
||||||
|
// FieldLocalFlowState holds the string denoting the local_flow_state field in the database.
|
||||||
|
FieldLocalFlowState = "local_flow_state"
|
||||||
|
// FieldBrowserSessionKey holds the string denoting the browser_session_key field in the database.
|
||||||
|
FieldBrowserSessionKey = "browser_session_key"
|
||||||
|
// FieldCompletionCodeHash holds the string denoting the completion_code_hash field in the database.
|
||||||
|
FieldCompletionCodeHash = "completion_code_hash"
|
||||||
|
// FieldCompletionCodeExpiresAt holds the string denoting the completion_code_expires_at field in the database.
|
||||||
|
FieldCompletionCodeExpiresAt = "completion_code_expires_at"
|
||||||
|
// FieldEmailVerifiedAt holds the string denoting the email_verified_at field in the database.
|
||||||
|
FieldEmailVerifiedAt = "email_verified_at"
|
||||||
|
// FieldPasswordVerifiedAt holds the string denoting the password_verified_at field in the database.
|
||||||
|
FieldPasswordVerifiedAt = "password_verified_at"
|
||||||
|
// FieldTotpVerifiedAt holds the string denoting the totp_verified_at field in the database.
|
||||||
|
FieldTotpVerifiedAt = "totp_verified_at"
|
||||||
|
// FieldExpiresAt holds the string denoting the expires_at field in the database.
|
||||||
|
FieldExpiresAt = "expires_at"
|
||||||
|
// FieldConsumedAt holds the string denoting the consumed_at field in the database.
|
||||||
|
FieldConsumedAt = "consumed_at"
|
||||||
|
// EdgeTargetUser holds the string denoting the target_user edge name in mutations.
|
||||||
|
EdgeTargetUser = "target_user"
|
||||||
|
// EdgeAdoptionDecision holds the string denoting the adoption_decision edge name in mutations.
|
||||||
|
EdgeAdoptionDecision = "adoption_decision"
|
||||||
|
// Table holds the table name of the pendingauthsession in the database.
|
||||||
|
Table = "pending_auth_sessions"
|
||||||
|
// TargetUserTable is the table that holds the target_user relation/edge.
|
||||||
|
TargetUserTable = "pending_auth_sessions"
|
||||||
|
// TargetUserInverseTable is the table name for the User entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "user" package.
|
||||||
|
TargetUserInverseTable = "users"
|
||||||
|
// TargetUserColumn is the table column denoting the target_user relation/edge.
|
||||||
|
TargetUserColumn = "target_user_id"
|
||||||
|
// AdoptionDecisionTable is the table that holds the adoption_decision relation/edge.
|
||||||
|
AdoptionDecisionTable = "identity_adoption_decisions"
|
||||||
|
// AdoptionDecisionInverseTable is the table name for the IdentityAdoptionDecision entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "identityadoptiondecision" package.
|
||||||
|
AdoptionDecisionInverseTable = "identity_adoption_decisions"
|
||||||
|
// AdoptionDecisionColumn is the table column denoting the adoption_decision relation/edge.
|
||||||
|
AdoptionDecisionColumn = "pending_auth_session_id"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Columns holds all SQL columns for pendingauthsession fields.
|
||||||
|
var Columns = []string{
|
||||||
|
FieldID,
|
||||||
|
FieldCreatedAt,
|
||||||
|
FieldUpdatedAt,
|
||||||
|
FieldSessionToken,
|
||||||
|
FieldIntent,
|
||||||
|
FieldProviderType,
|
||||||
|
FieldProviderKey,
|
||||||
|
FieldProviderSubject,
|
||||||
|
FieldTargetUserID,
|
||||||
|
FieldRedirectTo,
|
||||||
|
FieldResolvedEmail,
|
||||||
|
FieldRegistrationPasswordHash,
|
||||||
|
FieldUpstreamIdentityClaims,
|
||||||
|
FieldLocalFlowState,
|
||||||
|
FieldBrowserSessionKey,
|
||||||
|
FieldCompletionCodeHash,
|
||||||
|
FieldCompletionCodeExpiresAt,
|
||||||
|
FieldEmailVerifiedAt,
|
||||||
|
FieldPasswordVerifiedAt,
|
||||||
|
FieldTotpVerifiedAt,
|
||||||
|
FieldExpiresAt,
|
||||||
|
FieldConsumedAt,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||||
|
func ValidColumn(column string) bool {
|
||||||
|
for i := range Columns {
|
||||||
|
if column == Columns[i] {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||||
|
DefaultCreatedAt func() time.Time
|
||||||
|
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||||
|
DefaultUpdatedAt func() time.Time
|
||||||
|
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||||
|
UpdateDefaultUpdatedAt func() time.Time
|
||||||
|
// SessionTokenValidator is a validator for the "session_token" field. It is called by the builders before save.
|
||||||
|
SessionTokenValidator func(string) error
|
||||||
|
// IntentValidator is a validator for the "intent" field. It is called by the builders before save.
|
||||||
|
IntentValidator func(string) error
|
||||||
|
// ProviderTypeValidator is a validator for the "provider_type" field. It is called by the builders before save.
|
||||||
|
ProviderTypeValidator func(string) error
|
||||||
|
// ProviderKeyValidator is a validator for the "provider_key" field. It is called by the builders before save.
|
||||||
|
ProviderKeyValidator func(string) error
|
||||||
|
// ProviderSubjectValidator is a validator for the "provider_subject" field. It is called by the builders before save.
|
||||||
|
ProviderSubjectValidator func(string) error
|
||||||
|
// DefaultRedirectTo holds the default value on creation for the "redirect_to" field.
|
||||||
|
DefaultRedirectTo string
|
||||||
|
// DefaultResolvedEmail holds the default value on creation for the "resolved_email" field.
|
||||||
|
DefaultResolvedEmail string
|
||||||
|
// DefaultRegistrationPasswordHash holds the default value on creation for the "registration_password_hash" field.
|
||||||
|
DefaultRegistrationPasswordHash string
|
||||||
|
// DefaultUpstreamIdentityClaims holds the default value on creation for the "upstream_identity_claims" field.
|
||||||
|
DefaultUpstreamIdentityClaims func() map[string]interface{}
|
||||||
|
// DefaultLocalFlowState holds the default value on creation for the "local_flow_state" field.
|
||||||
|
DefaultLocalFlowState func() map[string]interface{}
|
||||||
|
// DefaultBrowserSessionKey holds the default value on creation for the "browser_session_key" field.
|
||||||
|
DefaultBrowserSessionKey string
|
||||||
|
// DefaultCompletionCodeHash holds the default value on creation for the "completion_code_hash" field.
|
||||||
|
DefaultCompletionCodeHash string
|
||||||
|
)
|
||||||
|
|
||||||
|
// OrderOption defines the ordering options for the PendingAuthSession queries.
|
||||||
|
type OrderOption func(*sql.Selector)
|
||||||
|
|
||||||
|
// ByID orders the results by the id field.
|
||||||
|
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByCreatedAt orders the results by the created_at field.
|
||||||
|
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByUpdatedAt orders the results by the updated_at field.
|
||||||
|
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// BySessionToken orders the results by the session_token field.
|
||||||
|
func BySessionToken(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldSessionToken, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByIntent orders the results by the intent field.
|
||||||
|
func ByIntent(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldIntent, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByProviderType orders the results by the provider_type field.
|
||||||
|
func ByProviderType(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldProviderType, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByProviderKey orders the results by the provider_key field.
|
||||||
|
func ByProviderKey(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldProviderKey, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByProviderSubject orders the results by the provider_subject field.
|
||||||
|
func ByProviderSubject(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldProviderSubject, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByTargetUserID orders the results by the target_user_id field.
|
||||||
|
func ByTargetUserID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldTargetUserID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByRedirectTo orders the results by the redirect_to field.
|
||||||
|
func ByRedirectTo(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldRedirectTo, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByResolvedEmail orders the results by the resolved_email field.
|
||||||
|
func ByResolvedEmail(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldResolvedEmail, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByRegistrationPasswordHash orders the results by the registration_password_hash field.
|
||||||
|
func ByRegistrationPasswordHash(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldRegistrationPasswordHash, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByBrowserSessionKey orders the results by the browser_session_key field.
|
||||||
|
func ByBrowserSessionKey(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldBrowserSessionKey, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByCompletionCodeHash orders the results by the completion_code_hash field.
|
||||||
|
func ByCompletionCodeHash(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldCompletionCodeHash, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByCompletionCodeExpiresAt orders the results by the completion_code_expires_at field.
|
||||||
|
func ByCompletionCodeExpiresAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldCompletionCodeExpiresAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByEmailVerifiedAt orders the results by the email_verified_at field.
|
||||||
|
func ByEmailVerifiedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldEmailVerifiedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByPasswordVerifiedAt orders the results by the password_verified_at field.
|
||||||
|
func ByPasswordVerifiedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldPasswordVerifiedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByTotpVerifiedAt orders the results by the totp_verified_at field.
|
||||||
|
func ByTotpVerifiedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldTotpVerifiedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByExpiresAt orders the results by the expires_at field.
|
||||||
|
func ByExpiresAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldExpiresAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByConsumedAt orders the results by the consumed_at field.
|
||||||
|
func ByConsumedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldConsumedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByTargetUserField orders the results by target_user field.
|
||||||
|
func ByTargetUserField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborTerms(s, newTargetUserStep(), sql.OrderByField(field, opts...))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByAdoptionDecisionField orders the results by adoption_decision field.
|
||||||
|
func ByAdoptionDecisionField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborTerms(s, newAdoptionDecisionStep(), sql.OrderByField(field, opts...))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func newTargetUserStep() *sqlgraph.Step {
|
||||||
|
return sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(TargetUserInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, TargetUserTable, TargetUserColumn),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
func newAdoptionDecisionStep() *sqlgraph.Step {
|
||||||
|
return sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(AdoptionDecisionInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2O, false, AdoptionDecisionTable, AdoptionDecisionColumn),
|
||||||
|
)
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,88 @@
|
|||||||
|
// 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/pendingauthsession"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/predicate"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PendingAuthSessionDelete is the builder for deleting a PendingAuthSession entity.
|
||||||
|
type PendingAuthSessionDelete struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *PendingAuthSessionMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the PendingAuthSessionDelete builder.
|
||||||
|
func (_d *PendingAuthSessionDelete) Where(ps ...predicate.PendingAuthSession) *PendingAuthSessionDelete {
|
||||||
|
_d.mutation.Where(ps...)
|
||||||
|
return _d
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||||
|
func (_d *PendingAuthSessionDelete) 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 *PendingAuthSessionDelete) ExecX(ctx context.Context) int {
|
||||||
|
n, err := _d.Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_d *PendingAuthSessionDelete) sqlExec(ctx context.Context) (int, error) {
|
||||||
|
_spec := sqlgraph.NewDeleteSpec(pendingauthsession.Table, sqlgraph.NewFieldSpec(pendingauthsession.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
|
||||||
|
}
|
||||||
|
|
||||||
|
// PendingAuthSessionDeleteOne is the builder for deleting a single PendingAuthSession entity.
|
||||||
|
type PendingAuthSessionDeleteOne struct {
|
||||||
|
_d *PendingAuthSessionDelete
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the PendingAuthSessionDelete builder.
|
||||||
|
func (_d *PendingAuthSessionDeleteOne) Where(ps ...predicate.PendingAuthSession) *PendingAuthSessionDeleteOne {
|
||||||
|
_d._d.mutation.Where(ps...)
|
||||||
|
return _d
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query.
|
||||||
|
func (_d *PendingAuthSessionDeleteOne) Exec(ctx context.Context) error {
|
||||||
|
n, err := _d._d.Exec(ctx)
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
|
case n == 0:
|
||||||
|
return &NotFoundError{pendingauthsession.Label}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_d *PendingAuthSessionDeleteOne) ExecX(ctx context.Context) {
|
||||||
|
if err := _d.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,717 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql/driver"
|
||||||
|
"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/identityadoptiondecision"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/pendingauthsession"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/predicate"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/user"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PendingAuthSessionQuery is the builder for querying PendingAuthSession entities.
|
||||||
|
type PendingAuthSessionQuery struct {
|
||||||
|
config
|
||||||
|
ctx *QueryContext
|
||||||
|
order []pendingauthsession.OrderOption
|
||||||
|
inters []Interceptor
|
||||||
|
predicates []predicate.PendingAuthSession
|
||||||
|
withTargetUser *UserQuery
|
||||||
|
withAdoptionDecision *IdentityAdoptionDecisionQuery
|
||||||
|
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 PendingAuthSessionQuery builder.
|
||||||
|
func (_q *PendingAuthSessionQuery) Where(ps ...predicate.PendingAuthSession) *PendingAuthSessionQuery {
|
||||||
|
_q.predicates = append(_q.predicates, ps...)
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit the number of records to be returned by this query.
|
||||||
|
func (_q *PendingAuthSessionQuery) Limit(limit int) *PendingAuthSessionQuery {
|
||||||
|
_q.ctx.Limit = &limit
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Offset to start from.
|
||||||
|
func (_q *PendingAuthSessionQuery) Offset(offset int) *PendingAuthSessionQuery {
|
||||||
|
_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 *PendingAuthSessionQuery) Unique(unique bool) *PendingAuthSessionQuery {
|
||||||
|
_q.ctx.Unique = &unique
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Order specifies how the records should be ordered.
|
||||||
|
func (_q *PendingAuthSessionQuery) Order(o ...pendingauthsession.OrderOption) *PendingAuthSessionQuery {
|
||||||
|
_q.order = append(_q.order, o...)
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryTargetUser chains the current query on the "target_user" edge.
|
||||||
|
func (_q *PendingAuthSessionQuery) QueryTargetUser() *UserQuery {
|
||||||
|
query := (&UserClient{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(pendingauthsession.Table, pendingauthsession.FieldID, selector),
|
||||||
|
sqlgraph.To(user.Table, user.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, pendingauthsession.TargetUserTable, pendingauthsession.TargetUserColumn),
|
||||||
|
)
|
||||||
|
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||||
|
return fromU, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryAdoptionDecision chains the current query on the "adoption_decision" edge.
|
||||||
|
func (_q *PendingAuthSessionQuery) QueryAdoptionDecision() *IdentityAdoptionDecisionQuery {
|
||||||
|
query := (&IdentityAdoptionDecisionClient{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(pendingauthsession.Table, pendingauthsession.FieldID, selector),
|
||||||
|
sqlgraph.To(identityadoptiondecision.Table, identityadoptiondecision.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2O, false, pendingauthsession.AdoptionDecisionTable, pendingauthsession.AdoptionDecisionColumn),
|
||||||
|
)
|
||||||
|
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||||
|
return fromU, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// First returns the first PendingAuthSession entity from the query.
|
||||||
|
// Returns a *NotFoundError when no PendingAuthSession was found.
|
||||||
|
func (_q *PendingAuthSessionQuery) First(ctx context.Context) (*PendingAuthSession, 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{pendingauthsession.Label}
|
||||||
|
}
|
||||||
|
return nodes[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstX is like First, but panics if an error occurs.
|
||||||
|
func (_q *PendingAuthSessionQuery) FirstX(ctx context.Context) *PendingAuthSession {
|
||||||
|
node, err := _q.First(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstID returns the first PendingAuthSession ID from the query.
|
||||||
|
// Returns a *NotFoundError when no PendingAuthSession ID was found.
|
||||||
|
func (_q *PendingAuthSessionQuery) 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{pendingauthsession.Label}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return ids[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||||
|
func (_q *PendingAuthSessionQuery) FirstIDX(ctx context.Context) int64 {
|
||||||
|
id, err := _q.FirstID(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only returns a single PendingAuthSession entity found by the query, ensuring it only returns one.
|
||||||
|
// Returns a *NotSingularError when more than one PendingAuthSession entity is found.
|
||||||
|
// Returns a *NotFoundError when no PendingAuthSession entities are found.
|
||||||
|
func (_q *PendingAuthSessionQuery) Only(ctx context.Context) (*PendingAuthSession, 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{pendingauthsession.Label}
|
||||||
|
default:
|
||||||
|
return nil, &NotSingularError{pendingauthsession.Label}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyX is like Only, but panics if an error occurs.
|
||||||
|
func (_q *PendingAuthSessionQuery) OnlyX(ctx context.Context) *PendingAuthSession {
|
||||||
|
node, err := _q.Only(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyID is like Only, but returns the only PendingAuthSession ID in the query.
|
||||||
|
// Returns a *NotSingularError when more than one PendingAuthSession ID is found.
|
||||||
|
// Returns a *NotFoundError when no entities are found.
|
||||||
|
func (_q *PendingAuthSessionQuery) 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{pendingauthsession.Label}
|
||||||
|
default:
|
||||||
|
err = &NotSingularError{pendingauthsession.Label}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||||
|
func (_q *PendingAuthSessionQuery) 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 PendingAuthSessions.
|
||||||
|
func (_q *PendingAuthSessionQuery) All(ctx context.Context) ([]*PendingAuthSession, error) {
|
||||||
|
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||||
|
if err := _q.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
qr := querierAll[[]*PendingAuthSession, *PendingAuthSessionQuery]()
|
||||||
|
return withInterceptors[[]*PendingAuthSession](ctx, _q, qr, _q.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllX is like All, but panics if an error occurs.
|
||||||
|
func (_q *PendingAuthSessionQuery) AllX(ctx context.Context) []*PendingAuthSession {
|
||||||
|
nodes, err := _q.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return nodes
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDs executes the query and returns a list of PendingAuthSession IDs.
|
||||||
|
func (_q *PendingAuthSessionQuery) 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(pendingauthsession.FieldID).Scan(ctx, &ids); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ids, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDsX is like IDs, but panics if an error occurs.
|
||||||
|
func (_q *PendingAuthSessionQuery) 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 *PendingAuthSessionQuery) 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[*PendingAuthSessionQuery](), _q.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountX is like Count, but panics if an error occurs.
|
||||||
|
func (_q *PendingAuthSessionQuery) 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 *PendingAuthSessionQuery) 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 *PendingAuthSessionQuery) ExistX(ctx context.Context) bool {
|
||||||
|
exist, err := _q.Exist(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return exist
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone returns a duplicate of the PendingAuthSessionQuery 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 *PendingAuthSessionQuery) Clone() *PendingAuthSessionQuery {
|
||||||
|
if _q == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &PendingAuthSessionQuery{
|
||||||
|
config: _q.config,
|
||||||
|
ctx: _q.ctx.Clone(),
|
||||||
|
order: append([]pendingauthsession.OrderOption{}, _q.order...),
|
||||||
|
inters: append([]Interceptor{}, _q.inters...),
|
||||||
|
predicates: append([]predicate.PendingAuthSession{}, _q.predicates...),
|
||||||
|
withTargetUser: _q.withTargetUser.Clone(),
|
||||||
|
withAdoptionDecision: _q.withAdoptionDecision.Clone(),
|
||||||
|
// clone intermediate query.
|
||||||
|
sql: _q.sql.Clone(),
|
||||||
|
path: _q.path,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithTargetUser tells the query-builder to eager-load the nodes that are connected to
|
||||||
|
// the "target_user" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (_q *PendingAuthSessionQuery) WithTargetUser(opts ...func(*UserQuery)) *PendingAuthSessionQuery {
|
||||||
|
query := (&UserClient{config: _q.config}).Query()
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
_q.withTargetUser = query
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithAdoptionDecision tells the query-builder to eager-load the nodes that are connected to
|
||||||
|
// the "adoption_decision" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (_q *PendingAuthSessionQuery) WithAdoptionDecision(opts ...func(*IdentityAdoptionDecisionQuery)) *PendingAuthSessionQuery {
|
||||||
|
query := (&IdentityAdoptionDecisionClient{config: _q.config}).Query()
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
_q.withAdoptionDecision = query
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// Count int `json:"count,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.PendingAuthSession.Query().
|
||||||
|
// GroupBy(pendingauthsession.FieldCreatedAt).
|
||||||
|
// Aggregate(ent.Count()).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (_q *PendingAuthSessionQuery) GroupBy(field string, fields ...string) *PendingAuthSessionGroupBy {
|
||||||
|
_q.ctx.Fields = append([]string{field}, fields...)
|
||||||
|
grbuild := &PendingAuthSessionGroupBy{build: _q}
|
||||||
|
grbuild.flds = &_q.ctx.Fields
|
||||||
|
grbuild.label = pendingauthsession.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 {
|
||||||
|
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.PendingAuthSession.Query().
|
||||||
|
// Select(pendingauthsession.FieldCreatedAt).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (_q *PendingAuthSessionQuery) Select(fields ...string) *PendingAuthSessionSelect {
|
||||||
|
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||||
|
sbuild := &PendingAuthSessionSelect{PendingAuthSessionQuery: _q}
|
||||||
|
sbuild.label = pendingauthsession.Label
|
||||||
|
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||||
|
return sbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate returns a PendingAuthSessionSelect configured with the given aggregations.
|
||||||
|
func (_q *PendingAuthSessionQuery) Aggregate(fns ...AggregateFunc) *PendingAuthSessionSelect {
|
||||||
|
return _q.Select().Aggregate(fns...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *PendingAuthSessionQuery) 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 !pendingauthsession.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 *PendingAuthSessionQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*PendingAuthSession, error) {
|
||||||
|
var (
|
||||||
|
nodes = []*PendingAuthSession{}
|
||||||
|
_spec = _q.querySpec()
|
||||||
|
loadedTypes = [2]bool{
|
||||||
|
_q.withTargetUser != nil,
|
||||||
|
_q.withAdoptionDecision != nil,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||||
|
return (*PendingAuthSession).scanValues(nil, columns)
|
||||||
|
}
|
||||||
|
_spec.Assign = func(columns []string, values []any) error {
|
||||||
|
node := &PendingAuthSession{config: _q.config}
|
||||||
|
nodes = append(nodes, node)
|
||||||
|
node.Edges.loadedTypes = loadedTypes
|
||||||
|
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
|
||||||
|
}
|
||||||
|
if query := _q.withTargetUser; query != nil {
|
||||||
|
if err := _q.loadTargetUser(ctx, query, nodes, nil,
|
||||||
|
func(n *PendingAuthSession, e *User) { n.Edges.TargetUser = e }); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if query := _q.withAdoptionDecision; query != nil {
|
||||||
|
if err := _q.loadAdoptionDecision(ctx, query, nodes, nil,
|
||||||
|
func(n *PendingAuthSession, e *IdentityAdoptionDecision) { n.Edges.AdoptionDecision = e }); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *PendingAuthSessionQuery) loadTargetUser(ctx context.Context, query *UserQuery, nodes []*PendingAuthSession, init func(*PendingAuthSession), assign func(*PendingAuthSession, *User)) error {
|
||||||
|
ids := make([]int64, 0, len(nodes))
|
||||||
|
nodeids := make(map[int64][]*PendingAuthSession)
|
||||||
|
for i := range nodes {
|
||||||
|
if nodes[i].TargetUserID == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fk := *nodes[i].TargetUserID
|
||||||
|
if _, ok := nodeids[fk]; !ok {
|
||||||
|
ids = append(ids, fk)
|
||||||
|
}
|
||||||
|
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
query.Where(user.IDIn(ids...))
|
||||||
|
neighbors, err := query.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, n := range neighbors {
|
||||||
|
nodes, ok := nodeids[n.ID]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(`unexpected foreign-key "target_user_id" returned %v`, n.ID)
|
||||||
|
}
|
||||||
|
for i := range nodes {
|
||||||
|
assign(nodes[i], n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (_q *PendingAuthSessionQuery) loadAdoptionDecision(ctx context.Context, query *IdentityAdoptionDecisionQuery, nodes []*PendingAuthSession, init func(*PendingAuthSession), assign func(*PendingAuthSession, *IdentityAdoptionDecision)) error {
|
||||||
|
fks := make([]driver.Value, 0, len(nodes))
|
||||||
|
nodeids := make(map[int64]*PendingAuthSession)
|
||||||
|
for i := range nodes {
|
||||||
|
fks = append(fks, nodes[i].ID)
|
||||||
|
nodeids[nodes[i].ID] = nodes[i]
|
||||||
|
}
|
||||||
|
if len(query.ctx.Fields) > 0 {
|
||||||
|
query.ctx.AppendFieldOnce(identityadoptiondecision.FieldPendingAuthSessionID)
|
||||||
|
}
|
||||||
|
query.Where(predicate.IdentityAdoptionDecision(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.InValues(s.C(pendingauthsession.AdoptionDecisionColumn), fks...))
|
||||||
|
}))
|
||||||
|
neighbors, err := query.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, n := range neighbors {
|
||||||
|
fk := n.PendingAuthSessionID
|
||||||
|
node, ok := nodeids[fk]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(`unexpected referenced foreign-key "pending_auth_session_id" returned %v for node %v`, fk, n.ID)
|
||||||
|
}
|
||||||
|
assign(node, n)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *PendingAuthSessionQuery) 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 *PendingAuthSessionQuery) querySpec() *sqlgraph.QuerySpec {
|
||||||
|
_spec := sqlgraph.NewQuerySpec(pendingauthsession.Table, pendingauthsession.Columns, sqlgraph.NewFieldSpec(pendingauthsession.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, pendingauthsession.FieldID)
|
||||||
|
for i := range fields {
|
||||||
|
if fields[i] != pendingauthsession.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _q.withTargetUser != nil {
|
||||||
|
_spec.Node.AddColumnOnce(pendingauthsession.FieldTargetUserID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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 *PendingAuthSessionQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||||
|
builder := sql.Dialect(_q.driver.Dialect())
|
||||||
|
t1 := builder.Table(pendingauthsession.Table)
|
||||||
|
columns := _q.ctx.Fields
|
||||||
|
if len(columns) == 0 {
|
||||||
|
columns = pendingauthsession.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 *PendingAuthSessionQuery) ForUpdate(opts ...sql.LockOption) *PendingAuthSessionQuery {
|
||||||
|
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 *PendingAuthSessionQuery) ForShare(opts ...sql.LockOption) *PendingAuthSessionQuery {
|
||||||
|
if _q.driver.Dialect() == dialect.Postgres {
|
||||||
|
_q.Unique(false)
|
||||||
|
}
|
||||||
|
_q.modifiers = append(_q.modifiers, func(s *sql.Selector) {
|
||||||
|
s.ForShare(opts...)
|
||||||
|
})
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// PendingAuthSessionGroupBy is the group-by builder for PendingAuthSession entities.
|
||||||
|
type PendingAuthSessionGroupBy struct {
|
||||||
|
selector
|
||||||
|
build *PendingAuthSessionQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the group-by query.
|
||||||
|
func (_g *PendingAuthSessionGroupBy) Aggregate(fns ...AggregateFunc) *PendingAuthSessionGroupBy {
|
||||||
|
_g.fns = append(_g.fns, fns...)
|
||||||
|
return _g
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (_g *PendingAuthSessionGroupBy) 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[*PendingAuthSessionQuery, *PendingAuthSessionGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_g *PendingAuthSessionGroupBy) sqlScan(ctx context.Context, root *PendingAuthSessionQuery, 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PendingAuthSessionSelect is the builder for selecting fields of PendingAuthSession entities.
|
||||||
|
type PendingAuthSessionSelect struct {
|
||||||
|
*PendingAuthSessionQuery
|
||||||
|
selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the selector query.
|
||||||
|
func (_s *PendingAuthSessionSelect) Aggregate(fns ...AggregateFunc) *PendingAuthSessionSelect {
|
||||||
|
_s.fns = append(_s.fns, fns...)
|
||||||
|
return _s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (_s *PendingAuthSessionSelect) 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[*PendingAuthSessionQuery, *PendingAuthSessionSelect](ctx, _s.PendingAuthSessionQuery, _s, _s.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_s *PendingAuthSessionSelect) sqlScan(ctx context.Context, root *PendingAuthSessionQuery, 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)
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -21,6 +21,12 @@ type Announcement func(*sql.Selector)
|
|||||||
// AnnouncementRead is the predicate function for announcementread builders.
|
// AnnouncementRead is the predicate function for announcementread builders.
|
||||||
type AnnouncementRead func(*sql.Selector)
|
type AnnouncementRead func(*sql.Selector)
|
||||||
|
|
||||||
|
// AuthIdentity is the predicate function for authidentity builders.
|
||||||
|
type AuthIdentity func(*sql.Selector)
|
||||||
|
|
||||||
|
// AuthIdentityChannel is the predicate function for authidentitychannel builders.
|
||||||
|
type AuthIdentityChannel func(*sql.Selector)
|
||||||
|
|
||||||
// ErrorPassthroughRule is the predicate function for errorpassthroughrule builders.
|
// ErrorPassthroughRule is the predicate function for errorpassthroughrule builders.
|
||||||
type ErrorPassthroughRule func(*sql.Selector)
|
type ErrorPassthroughRule func(*sql.Selector)
|
||||||
|
|
||||||
@@ -30,6 +36,9 @@ type Group func(*sql.Selector)
|
|||||||
// IdempotencyRecord is the predicate function for idempotencyrecord builders.
|
// IdempotencyRecord is the predicate function for idempotencyrecord builders.
|
||||||
type IdempotencyRecord func(*sql.Selector)
|
type IdempotencyRecord func(*sql.Selector)
|
||||||
|
|
||||||
|
// IdentityAdoptionDecision is the predicate function for identityadoptiondecision builders.
|
||||||
|
type IdentityAdoptionDecision func(*sql.Selector)
|
||||||
|
|
||||||
// PaymentAuditLog is the predicate function for paymentauditlog builders.
|
// PaymentAuditLog is the predicate function for paymentauditlog builders.
|
||||||
type PaymentAuditLog func(*sql.Selector)
|
type PaymentAuditLog func(*sql.Selector)
|
||||||
|
|
||||||
@@ -39,6 +48,9 @@ type PaymentOrder func(*sql.Selector)
|
|||||||
// PaymentProviderInstance is the predicate function for paymentproviderinstance builders.
|
// PaymentProviderInstance is the predicate function for paymentproviderinstance builders.
|
||||||
type PaymentProviderInstance func(*sql.Selector)
|
type PaymentProviderInstance func(*sql.Selector)
|
||||||
|
|
||||||
|
// PendingAuthSession is the predicate function for pendingauthsession builders.
|
||||||
|
type PendingAuthSession func(*sql.Selector)
|
||||||
|
|
||||||
// PromoCode is the predicate function for promocode builders.
|
// PromoCode is the predicate function for promocode builders.
|
||||||
type PromoCode func(*sql.Selector)
|
type PromoCode func(*sql.Selector)
|
||||||
|
|
||||||
|
|||||||
+274
-12
@@ -10,12 +10,16 @@ import (
|
|||||||
"github.com/Wei-Shaw/sub2api/ent/announcement"
|
"github.com/Wei-Shaw/sub2api/ent/announcement"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/announcementread"
|
"github.com/Wei-Shaw/sub2api/ent/announcementread"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/apikey"
|
"github.com/Wei-Shaw/sub2api/ent/apikey"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/authidentity"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/authidentitychannel"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/errorpassthroughrule"
|
"github.com/Wei-Shaw/sub2api/ent/errorpassthroughrule"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/group"
|
"github.com/Wei-Shaw/sub2api/ent/group"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/idempotencyrecord"
|
"github.com/Wei-Shaw/sub2api/ent/idempotencyrecord"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/identityadoptiondecision"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/paymentauditlog"
|
"github.com/Wei-Shaw/sub2api/ent/paymentauditlog"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/paymentorder"
|
"github.com/Wei-Shaw/sub2api/ent/paymentorder"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/paymentproviderinstance"
|
"github.com/Wei-Shaw/sub2api/ent/paymentproviderinstance"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/pendingauthsession"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/promocode"
|
"github.com/Wei-Shaw/sub2api/ent/promocode"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
|
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/proxy"
|
"github.com/Wei-Shaw/sub2api/ent/proxy"
|
||||||
@@ -309,6 +313,120 @@ func init() {
|
|||||||
announcementreadDescCreatedAt := announcementreadFields[3].Descriptor()
|
announcementreadDescCreatedAt := announcementreadFields[3].Descriptor()
|
||||||
// announcementread.DefaultCreatedAt holds the default value on creation for the created_at field.
|
// announcementread.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||||
announcementread.DefaultCreatedAt = announcementreadDescCreatedAt.Default.(func() time.Time)
|
announcementread.DefaultCreatedAt = announcementreadDescCreatedAt.Default.(func() time.Time)
|
||||||
|
authidentityMixin := schema.AuthIdentity{}.Mixin()
|
||||||
|
authidentityMixinFields0 := authidentityMixin[0].Fields()
|
||||||
|
_ = authidentityMixinFields0
|
||||||
|
authidentityFields := schema.AuthIdentity{}.Fields()
|
||||||
|
_ = authidentityFields
|
||||||
|
// authidentityDescCreatedAt is the schema descriptor for created_at field.
|
||||||
|
authidentityDescCreatedAt := authidentityMixinFields0[0].Descriptor()
|
||||||
|
// authidentity.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||||
|
authidentity.DefaultCreatedAt = authidentityDescCreatedAt.Default.(func() time.Time)
|
||||||
|
// authidentityDescUpdatedAt is the schema descriptor for updated_at field.
|
||||||
|
authidentityDescUpdatedAt := authidentityMixinFields0[1].Descriptor()
|
||||||
|
// authidentity.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||||
|
authidentity.DefaultUpdatedAt = authidentityDescUpdatedAt.Default.(func() time.Time)
|
||||||
|
// authidentity.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||||
|
authidentity.UpdateDefaultUpdatedAt = authidentityDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||||
|
// authidentityDescProviderType is the schema descriptor for provider_type field.
|
||||||
|
authidentityDescProviderType := authidentityFields[1].Descriptor()
|
||||||
|
// authidentity.ProviderTypeValidator is a validator for the "provider_type" field. It is called by the builders before save.
|
||||||
|
authidentity.ProviderTypeValidator = func() func(string) error {
|
||||||
|
validators := authidentityDescProviderType.Validators
|
||||||
|
fns := [...]func(string) error{
|
||||||
|
validators[0].(func(string) error),
|
||||||
|
validators[1].(func(string) error),
|
||||||
|
validators[2].(func(string) error),
|
||||||
|
}
|
||||||
|
return func(provider_type string) error {
|
||||||
|
for _, fn := range fns {
|
||||||
|
if err := fn(provider_type); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
// authidentityDescProviderKey is the schema descriptor for provider_key field.
|
||||||
|
authidentityDescProviderKey := authidentityFields[2].Descriptor()
|
||||||
|
// authidentity.ProviderKeyValidator is a validator for the "provider_key" field. It is called by the builders before save.
|
||||||
|
authidentity.ProviderKeyValidator = authidentityDescProviderKey.Validators[0].(func(string) error)
|
||||||
|
// authidentityDescProviderSubject is the schema descriptor for provider_subject field.
|
||||||
|
authidentityDescProviderSubject := authidentityFields[3].Descriptor()
|
||||||
|
// authidentity.ProviderSubjectValidator is a validator for the "provider_subject" field. It is called by the builders before save.
|
||||||
|
authidentity.ProviderSubjectValidator = authidentityDescProviderSubject.Validators[0].(func(string) error)
|
||||||
|
// authidentityDescMetadata is the schema descriptor for metadata field.
|
||||||
|
authidentityDescMetadata := authidentityFields[6].Descriptor()
|
||||||
|
// authidentity.DefaultMetadata holds the default value on creation for the metadata field.
|
||||||
|
authidentity.DefaultMetadata = authidentityDescMetadata.Default.(func() map[string]interface{})
|
||||||
|
authidentitychannelMixin := schema.AuthIdentityChannel{}.Mixin()
|
||||||
|
authidentitychannelMixinFields0 := authidentitychannelMixin[0].Fields()
|
||||||
|
_ = authidentitychannelMixinFields0
|
||||||
|
authidentitychannelFields := schema.AuthIdentityChannel{}.Fields()
|
||||||
|
_ = authidentitychannelFields
|
||||||
|
// authidentitychannelDescCreatedAt is the schema descriptor for created_at field.
|
||||||
|
authidentitychannelDescCreatedAt := authidentitychannelMixinFields0[0].Descriptor()
|
||||||
|
// authidentitychannel.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||||
|
authidentitychannel.DefaultCreatedAt = authidentitychannelDescCreatedAt.Default.(func() time.Time)
|
||||||
|
// authidentitychannelDescUpdatedAt is the schema descriptor for updated_at field.
|
||||||
|
authidentitychannelDescUpdatedAt := authidentitychannelMixinFields0[1].Descriptor()
|
||||||
|
// authidentitychannel.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||||
|
authidentitychannel.DefaultUpdatedAt = authidentitychannelDescUpdatedAt.Default.(func() time.Time)
|
||||||
|
// authidentitychannel.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||||
|
authidentitychannel.UpdateDefaultUpdatedAt = authidentitychannelDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||||
|
// authidentitychannelDescProviderType is the schema descriptor for provider_type field.
|
||||||
|
authidentitychannelDescProviderType := authidentitychannelFields[1].Descriptor()
|
||||||
|
// authidentitychannel.ProviderTypeValidator is a validator for the "provider_type" field. It is called by the builders before save.
|
||||||
|
authidentitychannel.ProviderTypeValidator = func() func(string) error {
|
||||||
|
validators := authidentitychannelDescProviderType.Validators
|
||||||
|
fns := [...]func(string) error{
|
||||||
|
validators[0].(func(string) error),
|
||||||
|
validators[1].(func(string) error),
|
||||||
|
validators[2].(func(string) error),
|
||||||
|
}
|
||||||
|
return func(provider_type string) error {
|
||||||
|
for _, fn := range fns {
|
||||||
|
if err := fn(provider_type); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
// authidentitychannelDescProviderKey is the schema descriptor for provider_key field.
|
||||||
|
authidentitychannelDescProviderKey := authidentitychannelFields[2].Descriptor()
|
||||||
|
// authidentitychannel.ProviderKeyValidator is a validator for the "provider_key" field. It is called by the builders before save.
|
||||||
|
authidentitychannel.ProviderKeyValidator = authidentitychannelDescProviderKey.Validators[0].(func(string) error)
|
||||||
|
// authidentitychannelDescChannel is the schema descriptor for channel field.
|
||||||
|
authidentitychannelDescChannel := authidentitychannelFields[3].Descriptor()
|
||||||
|
// authidentitychannel.ChannelValidator is a validator for the "channel" field. It is called by the builders before save.
|
||||||
|
authidentitychannel.ChannelValidator = func() func(string) error {
|
||||||
|
validators := authidentitychannelDescChannel.Validators
|
||||||
|
fns := [...]func(string) error{
|
||||||
|
validators[0].(func(string) error),
|
||||||
|
validators[1].(func(string) error),
|
||||||
|
}
|
||||||
|
return func(channel string) error {
|
||||||
|
for _, fn := range fns {
|
||||||
|
if err := fn(channel); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
// authidentitychannelDescChannelAppID is the schema descriptor for channel_app_id field.
|
||||||
|
authidentitychannelDescChannelAppID := authidentitychannelFields[4].Descriptor()
|
||||||
|
// authidentitychannel.ChannelAppIDValidator is a validator for the "channel_app_id" field. It is called by the builders before save.
|
||||||
|
authidentitychannel.ChannelAppIDValidator = authidentitychannelDescChannelAppID.Validators[0].(func(string) error)
|
||||||
|
// authidentitychannelDescChannelSubject is the schema descriptor for channel_subject field.
|
||||||
|
authidentitychannelDescChannelSubject := authidentitychannelFields[5].Descriptor()
|
||||||
|
// authidentitychannel.ChannelSubjectValidator is a validator for the "channel_subject" field. It is called by the builders before save.
|
||||||
|
authidentitychannel.ChannelSubjectValidator = authidentitychannelDescChannelSubject.Validators[0].(func(string) error)
|
||||||
|
// authidentitychannelDescMetadata is the schema descriptor for metadata field.
|
||||||
|
authidentitychannelDescMetadata := authidentitychannelFields[6].Descriptor()
|
||||||
|
// authidentitychannel.DefaultMetadata holds the default value on creation for the metadata field.
|
||||||
|
authidentitychannel.DefaultMetadata = authidentitychannelDescMetadata.Default.(func() map[string]interface{})
|
||||||
errorpassthroughruleMixin := schema.ErrorPassthroughRule{}.Mixin()
|
errorpassthroughruleMixin := schema.ErrorPassthroughRule{}.Mixin()
|
||||||
errorpassthroughruleMixinFields0 := errorpassthroughruleMixin[0].Fields()
|
errorpassthroughruleMixinFields0 := errorpassthroughruleMixin[0].Fields()
|
||||||
_ = errorpassthroughruleMixinFields0
|
_ = errorpassthroughruleMixinFields0
|
||||||
@@ -512,6 +630,33 @@ func init() {
|
|||||||
idempotencyrecordDescErrorReason := idempotencyrecordFields[6].Descriptor()
|
idempotencyrecordDescErrorReason := idempotencyrecordFields[6].Descriptor()
|
||||||
// idempotencyrecord.ErrorReasonValidator is a validator for the "error_reason" field. It is called by the builders before save.
|
// idempotencyrecord.ErrorReasonValidator is a validator for the "error_reason" field. It is called by the builders before save.
|
||||||
idempotencyrecord.ErrorReasonValidator = idempotencyrecordDescErrorReason.Validators[0].(func(string) error)
|
idempotencyrecord.ErrorReasonValidator = idempotencyrecordDescErrorReason.Validators[0].(func(string) error)
|
||||||
|
identityadoptiondecisionMixin := schema.IdentityAdoptionDecision{}.Mixin()
|
||||||
|
identityadoptiondecisionMixinFields0 := identityadoptiondecisionMixin[0].Fields()
|
||||||
|
_ = identityadoptiondecisionMixinFields0
|
||||||
|
identityadoptiondecisionFields := schema.IdentityAdoptionDecision{}.Fields()
|
||||||
|
_ = identityadoptiondecisionFields
|
||||||
|
// identityadoptiondecisionDescCreatedAt is the schema descriptor for created_at field.
|
||||||
|
identityadoptiondecisionDescCreatedAt := identityadoptiondecisionMixinFields0[0].Descriptor()
|
||||||
|
// identityadoptiondecision.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||||
|
identityadoptiondecision.DefaultCreatedAt = identityadoptiondecisionDescCreatedAt.Default.(func() time.Time)
|
||||||
|
// identityadoptiondecisionDescUpdatedAt is the schema descriptor for updated_at field.
|
||||||
|
identityadoptiondecisionDescUpdatedAt := identityadoptiondecisionMixinFields0[1].Descriptor()
|
||||||
|
// identityadoptiondecision.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||||
|
identityadoptiondecision.DefaultUpdatedAt = identityadoptiondecisionDescUpdatedAt.Default.(func() time.Time)
|
||||||
|
// identityadoptiondecision.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||||
|
identityadoptiondecision.UpdateDefaultUpdatedAt = identityadoptiondecisionDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||||
|
// identityadoptiondecisionDescAdoptDisplayName is the schema descriptor for adopt_display_name field.
|
||||||
|
identityadoptiondecisionDescAdoptDisplayName := identityadoptiondecisionFields[2].Descriptor()
|
||||||
|
// identityadoptiondecision.DefaultAdoptDisplayName holds the default value on creation for the adopt_display_name field.
|
||||||
|
identityadoptiondecision.DefaultAdoptDisplayName = identityadoptiondecisionDescAdoptDisplayName.Default.(bool)
|
||||||
|
// identityadoptiondecisionDescAdoptAvatar is the schema descriptor for adopt_avatar field.
|
||||||
|
identityadoptiondecisionDescAdoptAvatar := identityadoptiondecisionFields[3].Descriptor()
|
||||||
|
// identityadoptiondecision.DefaultAdoptAvatar holds the default value on creation for the adopt_avatar field.
|
||||||
|
identityadoptiondecision.DefaultAdoptAvatar = identityadoptiondecisionDescAdoptAvatar.Default.(bool)
|
||||||
|
// identityadoptiondecisionDescDecidedAt is the schema descriptor for decided_at field.
|
||||||
|
identityadoptiondecisionDescDecidedAt := identityadoptiondecisionFields[4].Descriptor()
|
||||||
|
// identityadoptiondecision.DefaultDecidedAt holds the default value on creation for the decided_at field.
|
||||||
|
identityadoptiondecision.DefaultDecidedAt = identityadoptiondecisionDescDecidedAt.Default.(func() time.Time)
|
||||||
paymentauditlogFields := schema.PaymentAuditLog{}.Fields()
|
paymentauditlogFields := schema.PaymentAuditLog{}.Fields()
|
||||||
_ = paymentauditlogFields
|
_ = paymentauditlogFields
|
||||||
// paymentauditlogDescOrderID is the schema descriptor for order_id field.
|
// paymentauditlogDescOrderID is the schema descriptor for order_id field.
|
||||||
@@ -578,38 +723,42 @@ func init() {
|
|||||||
paymentorderDescProviderInstanceID := paymentorderFields[18].Descriptor()
|
paymentorderDescProviderInstanceID := paymentorderFields[18].Descriptor()
|
||||||
// paymentorder.ProviderInstanceIDValidator is a validator for the "provider_instance_id" field. It is called by the builders before save.
|
// paymentorder.ProviderInstanceIDValidator is a validator for the "provider_instance_id" field. It is called by the builders before save.
|
||||||
paymentorder.ProviderInstanceIDValidator = paymentorderDescProviderInstanceID.Validators[0].(func(string) error)
|
paymentorder.ProviderInstanceIDValidator = paymentorderDescProviderInstanceID.Validators[0].(func(string) error)
|
||||||
|
// paymentorderDescProviderKey is the schema descriptor for provider_key field.
|
||||||
|
paymentorderDescProviderKey := paymentorderFields[19].Descriptor()
|
||||||
|
// paymentorder.ProviderKeyValidator is a validator for the "provider_key" field. It is called by the builders before save.
|
||||||
|
paymentorder.ProviderKeyValidator = paymentorderDescProviderKey.Validators[0].(func(string) error)
|
||||||
// paymentorderDescStatus is the schema descriptor for status field.
|
// paymentorderDescStatus is the schema descriptor for status field.
|
||||||
paymentorderDescStatus := paymentorderFields[19].Descriptor()
|
paymentorderDescStatus := paymentorderFields[21].Descriptor()
|
||||||
// paymentorder.DefaultStatus holds the default value on creation for the status field.
|
// paymentorder.DefaultStatus holds the default value on creation for the status field.
|
||||||
paymentorder.DefaultStatus = paymentorderDescStatus.Default.(string)
|
paymentorder.DefaultStatus = paymentorderDescStatus.Default.(string)
|
||||||
// paymentorder.StatusValidator is a validator for the "status" field. It is called by the builders before save.
|
// paymentorder.StatusValidator is a validator for the "status" field. It is called by the builders before save.
|
||||||
paymentorder.StatusValidator = paymentorderDescStatus.Validators[0].(func(string) error)
|
paymentorder.StatusValidator = paymentorderDescStatus.Validators[0].(func(string) error)
|
||||||
// paymentorderDescRefundAmount is the schema descriptor for refund_amount field.
|
// paymentorderDescRefundAmount is the schema descriptor for refund_amount field.
|
||||||
paymentorderDescRefundAmount := paymentorderFields[20].Descriptor()
|
paymentorderDescRefundAmount := paymentorderFields[22].Descriptor()
|
||||||
// paymentorder.DefaultRefundAmount holds the default value on creation for the refund_amount field.
|
// paymentorder.DefaultRefundAmount holds the default value on creation for the refund_amount field.
|
||||||
paymentorder.DefaultRefundAmount = paymentorderDescRefundAmount.Default.(float64)
|
paymentorder.DefaultRefundAmount = paymentorderDescRefundAmount.Default.(float64)
|
||||||
// paymentorderDescForceRefund is the schema descriptor for force_refund field.
|
// paymentorderDescForceRefund is the schema descriptor for force_refund field.
|
||||||
paymentorderDescForceRefund := paymentorderFields[23].Descriptor()
|
paymentorderDescForceRefund := paymentorderFields[25].Descriptor()
|
||||||
// paymentorder.DefaultForceRefund holds the default value on creation for the force_refund field.
|
// paymentorder.DefaultForceRefund holds the default value on creation for the force_refund field.
|
||||||
paymentorder.DefaultForceRefund = paymentorderDescForceRefund.Default.(bool)
|
paymentorder.DefaultForceRefund = paymentorderDescForceRefund.Default.(bool)
|
||||||
// paymentorderDescRefundRequestedBy is the schema descriptor for refund_requested_by field.
|
// paymentorderDescRefundRequestedBy is the schema descriptor for refund_requested_by field.
|
||||||
paymentorderDescRefundRequestedBy := paymentorderFields[26].Descriptor()
|
paymentorderDescRefundRequestedBy := paymentorderFields[28].Descriptor()
|
||||||
// paymentorder.RefundRequestedByValidator is a validator for the "refund_requested_by" field. It is called by the builders before save.
|
// paymentorder.RefundRequestedByValidator is a validator for the "refund_requested_by" field. It is called by the builders before save.
|
||||||
paymentorder.RefundRequestedByValidator = paymentorderDescRefundRequestedBy.Validators[0].(func(string) error)
|
paymentorder.RefundRequestedByValidator = paymentorderDescRefundRequestedBy.Validators[0].(func(string) error)
|
||||||
// paymentorderDescClientIP is the schema descriptor for client_ip field.
|
// paymentorderDescClientIP is the schema descriptor for client_ip field.
|
||||||
paymentorderDescClientIP := paymentorderFields[32].Descriptor()
|
paymentorderDescClientIP := paymentorderFields[34].Descriptor()
|
||||||
// paymentorder.ClientIPValidator is a validator for the "client_ip" field. It is called by the builders before save.
|
// paymentorder.ClientIPValidator is a validator for the "client_ip" field. It is called by the builders before save.
|
||||||
paymentorder.ClientIPValidator = paymentorderDescClientIP.Validators[0].(func(string) error)
|
paymentorder.ClientIPValidator = paymentorderDescClientIP.Validators[0].(func(string) error)
|
||||||
// paymentorderDescSrcHost is the schema descriptor for src_host field.
|
// paymentorderDescSrcHost is the schema descriptor for src_host field.
|
||||||
paymentorderDescSrcHost := paymentorderFields[33].Descriptor()
|
paymentorderDescSrcHost := paymentorderFields[35].Descriptor()
|
||||||
// paymentorder.SrcHostValidator is a validator for the "src_host" field. It is called by the builders before save.
|
// paymentorder.SrcHostValidator is a validator for the "src_host" field. It is called by the builders before save.
|
||||||
paymentorder.SrcHostValidator = paymentorderDescSrcHost.Validators[0].(func(string) error)
|
paymentorder.SrcHostValidator = paymentorderDescSrcHost.Validators[0].(func(string) error)
|
||||||
// paymentorderDescCreatedAt is the schema descriptor for created_at field.
|
// paymentorderDescCreatedAt is the schema descriptor for created_at field.
|
||||||
paymentorderDescCreatedAt := paymentorderFields[35].Descriptor()
|
paymentorderDescCreatedAt := paymentorderFields[37].Descriptor()
|
||||||
// paymentorder.DefaultCreatedAt holds the default value on creation for the created_at field.
|
// paymentorder.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||||
paymentorder.DefaultCreatedAt = paymentorderDescCreatedAt.Default.(func() time.Time)
|
paymentorder.DefaultCreatedAt = paymentorderDescCreatedAt.Default.(func() time.Time)
|
||||||
// paymentorderDescUpdatedAt is the schema descriptor for updated_at field.
|
// paymentorderDescUpdatedAt is the schema descriptor for updated_at field.
|
||||||
paymentorderDescUpdatedAt := paymentorderFields[36].Descriptor()
|
paymentorderDescUpdatedAt := paymentorderFields[38].Descriptor()
|
||||||
// paymentorder.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
// paymentorder.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||||
paymentorder.DefaultUpdatedAt = paymentorderDescUpdatedAt.Default.(func() time.Time)
|
paymentorder.DefaultUpdatedAt = paymentorderDescUpdatedAt.Default.(func() time.Time)
|
||||||
// paymentorder.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
// paymentorder.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||||
@@ -682,6 +831,113 @@ func init() {
|
|||||||
paymentproviderinstance.DefaultUpdatedAt = paymentproviderinstanceDescUpdatedAt.Default.(func() time.Time)
|
paymentproviderinstance.DefaultUpdatedAt = paymentproviderinstanceDescUpdatedAt.Default.(func() time.Time)
|
||||||
// paymentproviderinstance.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
// paymentproviderinstance.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||||
paymentproviderinstance.UpdateDefaultUpdatedAt = paymentproviderinstanceDescUpdatedAt.UpdateDefault.(func() time.Time)
|
paymentproviderinstance.UpdateDefaultUpdatedAt = paymentproviderinstanceDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||||
|
pendingauthsessionMixin := schema.PendingAuthSession{}.Mixin()
|
||||||
|
pendingauthsessionMixinFields0 := pendingauthsessionMixin[0].Fields()
|
||||||
|
_ = pendingauthsessionMixinFields0
|
||||||
|
pendingauthsessionFields := schema.PendingAuthSession{}.Fields()
|
||||||
|
_ = pendingauthsessionFields
|
||||||
|
// pendingauthsessionDescCreatedAt is the schema descriptor for created_at field.
|
||||||
|
pendingauthsessionDescCreatedAt := pendingauthsessionMixinFields0[0].Descriptor()
|
||||||
|
// pendingauthsession.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||||
|
pendingauthsession.DefaultCreatedAt = pendingauthsessionDescCreatedAt.Default.(func() time.Time)
|
||||||
|
// pendingauthsessionDescUpdatedAt is the schema descriptor for updated_at field.
|
||||||
|
pendingauthsessionDescUpdatedAt := pendingauthsessionMixinFields0[1].Descriptor()
|
||||||
|
// pendingauthsession.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||||
|
pendingauthsession.DefaultUpdatedAt = pendingauthsessionDescUpdatedAt.Default.(func() time.Time)
|
||||||
|
// pendingauthsession.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||||
|
pendingauthsession.UpdateDefaultUpdatedAt = pendingauthsessionDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||||
|
// pendingauthsessionDescSessionToken is the schema descriptor for session_token field.
|
||||||
|
pendingauthsessionDescSessionToken := pendingauthsessionFields[0].Descriptor()
|
||||||
|
// pendingauthsession.SessionTokenValidator is a validator for the "session_token" field. It is called by the builders before save.
|
||||||
|
pendingauthsession.SessionTokenValidator = func() func(string) error {
|
||||||
|
validators := pendingauthsessionDescSessionToken.Validators
|
||||||
|
fns := [...]func(string) error{
|
||||||
|
validators[0].(func(string) error),
|
||||||
|
validators[1].(func(string) error),
|
||||||
|
}
|
||||||
|
return func(session_token string) error {
|
||||||
|
for _, fn := range fns {
|
||||||
|
if err := fn(session_token); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
// pendingauthsessionDescIntent is the schema descriptor for intent field.
|
||||||
|
pendingauthsessionDescIntent := pendingauthsessionFields[1].Descriptor()
|
||||||
|
// pendingauthsession.IntentValidator is a validator for the "intent" field. It is called by the builders before save.
|
||||||
|
pendingauthsession.IntentValidator = func() func(string) error {
|
||||||
|
validators := pendingauthsessionDescIntent.Validators
|
||||||
|
fns := [...]func(string) error{
|
||||||
|
validators[0].(func(string) error),
|
||||||
|
validators[1].(func(string) error),
|
||||||
|
validators[2].(func(string) error),
|
||||||
|
}
|
||||||
|
return func(intent string) error {
|
||||||
|
for _, fn := range fns {
|
||||||
|
if err := fn(intent); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
// pendingauthsessionDescProviderType is the schema descriptor for provider_type field.
|
||||||
|
pendingauthsessionDescProviderType := pendingauthsessionFields[2].Descriptor()
|
||||||
|
// pendingauthsession.ProviderTypeValidator is a validator for the "provider_type" field. It is called by the builders before save.
|
||||||
|
pendingauthsession.ProviderTypeValidator = func() func(string) error {
|
||||||
|
validators := pendingauthsessionDescProviderType.Validators
|
||||||
|
fns := [...]func(string) error{
|
||||||
|
validators[0].(func(string) error),
|
||||||
|
validators[1].(func(string) error),
|
||||||
|
validators[2].(func(string) error),
|
||||||
|
}
|
||||||
|
return func(provider_type string) error {
|
||||||
|
for _, fn := range fns {
|
||||||
|
if err := fn(provider_type); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
// pendingauthsessionDescProviderKey is the schema descriptor for provider_key field.
|
||||||
|
pendingauthsessionDescProviderKey := pendingauthsessionFields[3].Descriptor()
|
||||||
|
// pendingauthsession.ProviderKeyValidator is a validator for the "provider_key" field. It is called by the builders before save.
|
||||||
|
pendingauthsession.ProviderKeyValidator = pendingauthsessionDescProviderKey.Validators[0].(func(string) error)
|
||||||
|
// pendingauthsessionDescProviderSubject is the schema descriptor for provider_subject field.
|
||||||
|
pendingauthsessionDescProviderSubject := pendingauthsessionFields[4].Descriptor()
|
||||||
|
// pendingauthsession.ProviderSubjectValidator is a validator for the "provider_subject" field. It is called by the builders before save.
|
||||||
|
pendingauthsession.ProviderSubjectValidator = pendingauthsessionDescProviderSubject.Validators[0].(func(string) error)
|
||||||
|
// pendingauthsessionDescRedirectTo is the schema descriptor for redirect_to field.
|
||||||
|
pendingauthsessionDescRedirectTo := pendingauthsessionFields[6].Descriptor()
|
||||||
|
// pendingauthsession.DefaultRedirectTo holds the default value on creation for the redirect_to field.
|
||||||
|
pendingauthsession.DefaultRedirectTo = pendingauthsessionDescRedirectTo.Default.(string)
|
||||||
|
// pendingauthsessionDescResolvedEmail is the schema descriptor for resolved_email field.
|
||||||
|
pendingauthsessionDescResolvedEmail := pendingauthsessionFields[7].Descriptor()
|
||||||
|
// pendingauthsession.DefaultResolvedEmail holds the default value on creation for the resolved_email field.
|
||||||
|
pendingauthsession.DefaultResolvedEmail = pendingauthsessionDescResolvedEmail.Default.(string)
|
||||||
|
// pendingauthsessionDescRegistrationPasswordHash is the schema descriptor for registration_password_hash field.
|
||||||
|
pendingauthsessionDescRegistrationPasswordHash := pendingauthsessionFields[8].Descriptor()
|
||||||
|
// pendingauthsession.DefaultRegistrationPasswordHash holds the default value on creation for the registration_password_hash field.
|
||||||
|
pendingauthsession.DefaultRegistrationPasswordHash = pendingauthsessionDescRegistrationPasswordHash.Default.(string)
|
||||||
|
// pendingauthsessionDescUpstreamIdentityClaims is the schema descriptor for upstream_identity_claims field.
|
||||||
|
pendingauthsessionDescUpstreamIdentityClaims := pendingauthsessionFields[9].Descriptor()
|
||||||
|
// pendingauthsession.DefaultUpstreamIdentityClaims holds the default value on creation for the upstream_identity_claims field.
|
||||||
|
pendingauthsession.DefaultUpstreamIdentityClaims = pendingauthsessionDescUpstreamIdentityClaims.Default.(func() map[string]interface{})
|
||||||
|
// pendingauthsessionDescLocalFlowState is the schema descriptor for local_flow_state field.
|
||||||
|
pendingauthsessionDescLocalFlowState := pendingauthsessionFields[10].Descriptor()
|
||||||
|
// pendingauthsession.DefaultLocalFlowState holds the default value on creation for the local_flow_state field.
|
||||||
|
pendingauthsession.DefaultLocalFlowState = pendingauthsessionDescLocalFlowState.Default.(func() map[string]interface{})
|
||||||
|
// pendingauthsessionDescBrowserSessionKey is the schema descriptor for browser_session_key field.
|
||||||
|
pendingauthsessionDescBrowserSessionKey := pendingauthsessionFields[11].Descriptor()
|
||||||
|
// pendingauthsession.DefaultBrowserSessionKey holds the default value on creation for the browser_session_key field.
|
||||||
|
pendingauthsession.DefaultBrowserSessionKey = pendingauthsessionDescBrowserSessionKey.Default.(string)
|
||||||
|
// pendingauthsessionDescCompletionCodeHash is the schema descriptor for completion_code_hash field.
|
||||||
|
pendingauthsessionDescCompletionCodeHash := pendingauthsessionFields[12].Descriptor()
|
||||||
|
// pendingauthsession.DefaultCompletionCodeHash holds the default value on creation for the completion_code_hash field.
|
||||||
|
pendingauthsession.DefaultCompletionCodeHash = pendingauthsessionDescCompletionCodeHash.Default.(string)
|
||||||
promocodeFields := schema.PromoCode{}.Fields()
|
promocodeFields := schema.PromoCode{}.Fields()
|
||||||
_ = promocodeFields
|
_ = promocodeFields
|
||||||
// promocodeDescCode is the schema descriptor for code field.
|
// promocodeDescCode is the schema descriptor for code field.
|
||||||
@@ -1297,20 +1553,26 @@ func init() {
|
|||||||
userDescTotpEnabled := userFields[9].Descriptor()
|
userDescTotpEnabled := userFields[9].Descriptor()
|
||||||
// user.DefaultTotpEnabled holds the default value on creation for the totp_enabled field.
|
// user.DefaultTotpEnabled holds the default value on creation for the totp_enabled field.
|
||||||
user.DefaultTotpEnabled = userDescTotpEnabled.Default.(bool)
|
user.DefaultTotpEnabled = userDescTotpEnabled.Default.(bool)
|
||||||
|
// userDescSignupSource is the schema descriptor for signup_source field.
|
||||||
|
userDescSignupSource := userFields[11].Descriptor()
|
||||||
|
// user.DefaultSignupSource holds the default value on creation for the signup_source field.
|
||||||
|
user.DefaultSignupSource = userDescSignupSource.Default.(string)
|
||||||
|
// user.SignupSourceValidator is a validator for the "signup_source" field. It is called by the builders before save.
|
||||||
|
user.SignupSourceValidator = userDescSignupSource.Validators[0].(func(string) error)
|
||||||
// userDescBalanceNotifyEnabled is the schema descriptor for balance_notify_enabled field.
|
// userDescBalanceNotifyEnabled is the schema descriptor for balance_notify_enabled field.
|
||||||
userDescBalanceNotifyEnabled := userFields[11].Descriptor()
|
userDescBalanceNotifyEnabled := userFields[14].Descriptor()
|
||||||
// user.DefaultBalanceNotifyEnabled holds the default value on creation for the balance_notify_enabled field.
|
// user.DefaultBalanceNotifyEnabled holds the default value on creation for the balance_notify_enabled field.
|
||||||
user.DefaultBalanceNotifyEnabled = userDescBalanceNotifyEnabled.Default.(bool)
|
user.DefaultBalanceNotifyEnabled = userDescBalanceNotifyEnabled.Default.(bool)
|
||||||
// userDescBalanceNotifyThresholdType is the schema descriptor for balance_notify_threshold_type field.
|
// userDescBalanceNotifyThresholdType is the schema descriptor for balance_notify_threshold_type field.
|
||||||
userDescBalanceNotifyThresholdType := userFields[12].Descriptor()
|
userDescBalanceNotifyThresholdType := userFields[15].Descriptor()
|
||||||
// user.DefaultBalanceNotifyThresholdType holds the default value on creation for the balance_notify_threshold_type field.
|
// user.DefaultBalanceNotifyThresholdType holds the default value on creation for the balance_notify_threshold_type field.
|
||||||
user.DefaultBalanceNotifyThresholdType = userDescBalanceNotifyThresholdType.Default.(string)
|
user.DefaultBalanceNotifyThresholdType = userDescBalanceNotifyThresholdType.Default.(string)
|
||||||
// userDescBalanceNotifyExtraEmails is the schema descriptor for balance_notify_extra_emails field.
|
// userDescBalanceNotifyExtraEmails is the schema descriptor for balance_notify_extra_emails field.
|
||||||
userDescBalanceNotifyExtraEmails := userFields[14].Descriptor()
|
userDescBalanceNotifyExtraEmails := userFields[17].Descriptor()
|
||||||
// user.DefaultBalanceNotifyExtraEmails holds the default value on creation for the balance_notify_extra_emails field.
|
// user.DefaultBalanceNotifyExtraEmails holds the default value on creation for the balance_notify_extra_emails field.
|
||||||
user.DefaultBalanceNotifyExtraEmails = userDescBalanceNotifyExtraEmails.Default.(string)
|
user.DefaultBalanceNotifyExtraEmails = userDescBalanceNotifyExtraEmails.Default.(string)
|
||||||
// userDescTotalRecharged is the schema descriptor for total_recharged field.
|
// userDescTotalRecharged is the schema descriptor for total_recharged field.
|
||||||
userDescTotalRecharged := userFields[15].Descriptor()
|
userDescTotalRecharged := userFields[18].Descriptor()
|
||||||
// user.DefaultTotalRecharged holds the default value on creation for the total_recharged field.
|
// user.DefaultTotalRecharged holds the default value on creation for the total_recharged field.
|
||||||
user.DefaultTotalRecharged = userDescTotalRecharged.Default.(float64)
|
user.DefaultTotalRecharged = userDescTotalRecharged.Default.(float64)
|
||||||
userallowedgroupFields := schema.UserAllowedGroup{}.Fields()
|
userallowedgroupFields := schema.UserAllowedGroup{}.Fields()
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
package schema
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/schema/mixins"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
"entgo.io/ent/dialect/entsql"
|
||||||
|
"entgo.io/ent/schema"
|
||||||
|
"entgo.io/ent/schema/edge"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"entgo.io/ent/schema/index"
|
||||||
|
)
|
||||||
|
|
||||||
|
var authProviderTypes = map[string]struct{}{
|
||||||
|
"email": {},
|
||||||
|
"linuxdo": {},
|
||||||
|
"oidc": {},
|
||||||
|
"wechat": {},
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateAuthProviderType(value string) error {
|
||||||
|
if _, ok := authProviderTypes[value]; ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("invalid auth provider type %q", value)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthIdentity stores the canonical login identity for an account.
|
||||||
|
type AuthIdentity struct {
|
||||||
|
ent.Schema
|
||||||
|
}
|
||||||
|
|
||||||
|
func (AuthIdentity) Annotations() []schema.Annotation {
|
||||||
|
return []schema.Annotation{
|
||||||
|
entsql.Annotation{Table: "auth_identities"},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (AuthIdentity) Mixin() []ent.Mixin {
|
||||||
|
return []ent.Mixin{
|
||||||
|
mixins.TimeMixin{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (AuthIdentity) Fields() []ent.Field {
|
||||||
|
return []ent.Field{
|
||||||
|
field.Int64("user_id"),
|
||||||
|
field.String("provider_type").
|
||||||
|
MaxLen(20).
|
||||||
|
NotEmpty().
|
||||||
|
Validate(validateAuthProviderType),
|
||||||
|
field.String("provider_key").
|
||||||
|
NotEmpty().
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "text"}),
|
||||||
|
field.String("provider_subject").
|
||||||
|
NotEmpty().
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "text"}),
|
||||||
|
field.Time("verified_at").
|
||||||
|
Optional().
|
||||||
|
Nillable().
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "timestamptz"}),
|
||||||
|
field.String("issuer").
|
||||||
|
Optional().
|
||||||
|
Nillable().
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "text"}),
|
||||||
|
field.JSON("metadata", map[string]any{}).
|
||||||
|
Default(func() map[string]any { return map[string]any{} }).
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "jsonb"}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (AuthIdentity) Edges() []ent.Edge {
|
||||||
|
return []ent.Edge{
|
||||||
|
edge.From("user", User.Type).
|
||||||
|
Ref("auth_identities").
|
||||||
|
Field("user_id").
|
||||||
|
Required().
|
||||||
|
Unique(),
|
||||||
|
edge.To("channels", AuthIdentityChannel.Type),
|
||||||
|
edge.To("adoption_decisions", IdentityAdoptionDecision.Type),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (AuthIdentity) Indexes() []ent.Index {
|
||||||
|
return []ent.Index{
|
||||||
|
index.Fields("provider_type", "provider_key", "provider_subject").Unique(),
|
||||||
|
index.Fields("user_id"),
|
||||||
|
index.Fields("user_id", "provider_type"),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package schema
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/schema/mixins"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
"entgo.io/ent/dialect/entsql"
|
||||||
|
"entgo.io/ent/schema"
|
||||||
|
"entgo.io/ent/schema/edge"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"entgo.io/ent/schema/index"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AuthIdentityChannel stores channel-scoped identifiers for a canonical identity.
|
||||||
|
type AuthIdentityChannel struct {
|
||||||
|
ent.Schema
|
||||||
|
}
|
||||||
|
|
||||||
|
func (AuthIdentityChannel) Annotations() []schema.Annotation {
|
||||||
|
return []schema.Annotation{
|
||||||
|
entsql.Annotation{Table: "auth_identity_channels"},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (AuthIdentityChannel) Mixin() []ent.Mixin {
|
||||||
|
return []ent.Mixin{
|
||||||
|
mixins.TimeMixin{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (AuthIdentityChannel) Fields() []ent.Field {
|
||||||
|
return []ent.Field{
|
||||||
|
field.Int64("identity_id"),
|
||||||
|
field.String("provider_type").
|
||||||
|
MaxLen(20).
|
||||||
|
NotEmpty().
|
||||||
|
Validate(validateAuthProviderType),
|
||||||
|
field.String("provider_key").
|
||||||
|
NotEmpty().
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "text"}),
|
||||||
|
field.String("channel").
|
||||||
|
MaxLen(20).
|
||||||
|
NotEmpty(),
|
||||||
|
field.String("channel_app_id").
|
||||||
|
NotEmpty().
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "text"}),
|
||||||
|
field.String("channel_subject").
|
||||||
|
NotEmpty().
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "text"}),
|
||||||
|
field.JSON("metadata", map[string]any{}).
|
||||||
|
Default(func() map[string]any { return map[string]any{} }).
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "jsonb"}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (AuthIdentityChannel) Edges() []ent.Edge {
|
||||||
|
return []ent.Edge{
|
||||||
|
edge.From("identity", AuthIdentity.Type).
|
||||||
|
Ref("channels").
|
||||||
|
Field("identity_id").
|
||||||
|
Required().
|
||||||
|
Unique(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (AuthIdentityChannel) Indexes() []ent.Index {
|
||||||
|
return []ent.Index{
|
||||||
|
index.Fields("provider_type", "provider_key", "channel", "channel_app_id", "channel_subject").Unique(),
|
||||||
|
index.Fields("identity_id"),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
package schema
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"entgo.io/ent/entc/load"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAuthIdentityFoundationSchemas(t *testing.T) {
|
||||||
|
spec, err := (&load.Config{Path: "."}).Load()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
schemas := map[string]*load.Schema{}
|
||||||
|
for _, schema := range spec.Schemas {
|
||||||
|
schemas[schema.Name] = schema
|
||||||
|
}
|
||||||
|
|
||||||
|
authIdentity := requireSchema(t, schemas, "AuthIdentity")
|
||||||
|
requireSchemaFields(t, authIdentity,
|
||||||
|
"user_id",
|
||||||
|
"provider_type",
|
||||||
|
"provider_key",
|
||||||
|
"provider_subject",
|
||||||
|
"verified_at",
|
||||||
|
"issuer",
|
||||||
|
"metadata",
|
||||||
|
)
|
||||||
|
requireHasUniqueIndex(t, authIdentity, "provider_type", "provider_key", "provider_subject")
|
||||||
|
|
||||||
|
authIdentityChannel := requireSchema(t, schemas, "AuthIdentityChannel")
|
||||||
|
requireSchemaFields(t, authIdentityChannel,
|
||||||
|
"identity_id",
|
||||||
|
"provider_type",
|
||||||
|
"provider_key",
|
||||||
|
"channel",
|
||||||
|
"channel_app_id",
|
||||||
|
"channel_subject",
|
||||||
|
"metadata",
|
||||||
|
)
|
||||||
|
requireHasUniqueIndex(t, authIdentityChannel, "provider_type", "provider_key", "channel", "channel_app_id", "channel_subject")
|
||||||
|
|
||||||
|
pendingAuthSession := requireSchema(t, schemas, "PendingAuthSession")
|
||||||
|
requireSchemaFields(t, pendingAuthSession,
|
||||||
|
"intent",
|
||||||
|
"provider_type",
|
||||||
|
"provider_key",
|
||||||
|
"provider_subject",
|
||||||
|
"target_user_id",
|
||||||
|
"redirect_to",
|
||||||
|
"resolved_email",
|
||||||
|
"registration_password_hash",
|
||||||
|
"upstream_identity_claims",
|
||||||
|
"local_flow_state",
|
||||||
|
"browser_session_key",
|
||||||
|
"completion_code_hash",
|
||||||
|
"completion_code_expires_at",
|
||||||
|
"email_verified_at",
|
||||||
|
"password_verified_at",
|
||||||
|
"totp_verified_at",
|
||||||
|
"expires_at",
|
||||||
|
"consumed_at",
|
||||||
|
)
|
||||||
|
|
||||||
|
adoptionDecision := requireSchema(t, schemas, "IdentityAdoptionDecision")
|
||||||
|
requireSchemaFields(t, adoptionDecision,
|
||||||
|
"pending_auth_session_id",
|
||||||
|
"identity_id",
|
||||||
|
"adopt_display_name",
|
||||||
|
"adopt_avatar",
|
||||||
|
"decided_at",
|
||||||
|
)
|
||||||
|
requireHasUniqueIndex(t, adoptionDecision, "pending_auth_session_id")
|
||||||
|
|
||||||
|
userSchema := requireSchema(t, schemas, "User")
|
||||||
|
requireSchemaFields(t, userSchema, "signup_source", "last_login_at", "last_active_at")
|
||||||
|
}
|
||||||
|
|
||||||
|
func requireSchema(t *testing.T, schemas map[string]*load.Schema, name string) *load.Schema {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
schema, ok := schemas[name]
|
||||||
|
require.True(t, ok, "schema %s should exist", name)
|
||||||
|
return schema
|
||||||
|
}
|
||||||
|
|
||||||
|
func requireSchemaFields(t *testing.T, schema *load.Schema, names ...string) {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
fields := map[string]struct{}{}
|
||||||
|
for _, field := range schema.Fields {
|
||||||
|
fields[field.Name] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, name := range names {
|
||||||
|
_, ok := fields[name]
|
||||||
|
require.True(t, ok, "schema %s should include field %s", schema.Name, name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func requireHasUniqueIndex(t *testing.T, schema *load.Schema, fields ...string) {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
for _, index := range schema.Indexes {
|
||||||
|
if !index.Unique {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if len(index.Fields) != len(fields) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
match := true
|
||||||
|
for i := range fields {
|
||||||
|
if index.Fields[i] != fields[i] {
|
||||||
|
match = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if match {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
require.Failf(t, "missing unique index", "schema %s should include unique index on %v", schema.Name, fields)
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package schema
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/schema/mixins"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
"entgo.io/ent/dialect/entsql"
|
||||||
|
"entgo.io/ent/schema"
|
||||||
|
"entgo.io/ent/schema/edge"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"entgo.io/ent/schema/index"
|
||||||
|
)
|
||||||
|
|
||||||
|
// IdentityAdoptionDecision stores the one-time profile adoption choice captured during a pending auth flow.
|
||||||
|
type IdentityAdoptionDecision struct {
|
||||||
|
ent.Schema
|
||||||
|
}
|
||||||
|
|
||||||
|
func (IdentityAdoptionDecision) Annotations() []schema.Annotation {
|
||||||
|
return []schema.Annotation{
|
||||||
|
entsql.Annotation{Table: "identity_adoption_decisions"},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (IdentityAdoptionDecision) Mixin() []ent.Mixin {
|
||||||
|
return []ent.Mixin{
|
||||||
|
mixins.TimeMixin{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (IdentityAdoptionDecision) Fields() []ent.Field {
|
||||||
|
return []ent.Field{
|
||||||
|
field.Int64("pending_auth_session_id"),
|
||||||
|
field.Int64("identity_id").
|
||||||
|
Optional().
|
||||||
|
Nillable(),
|
||||||
|
field.Bool("adopt_display_name").
|
||||||
|
Default(false),
|
||||||
|
field.Bool("adopt_avatar").
|
||||||
|
Default(false),
|
||||||
|
field.Time("decided_at").
|
||||||
|
Immutable().
|
||||||
|
Default(time.Now).
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "timestamptz"}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (IdentityAdoptionDecision) Edges() []ent.Edge {
|
||||||
|
return []ent.Edge{
|
||||||
|
edge.From("pending_auth_session", PendingAuthSession.Type).
|
||||||
|
Ref("adoption_decision").
|
||||||
|
Field("pending_auth_session_id").
|
||||||
|
Required().
|
||||||
|
Unique(),
|
||||||
|
edge.From("identity", AuthIdentity.Type).
|
||||||
|
Ref("adoption_decisions").
|
||||||
|
Field("identity_id").
|
||||||
|
Unique(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (IdentityAdoptionDecision) Indexes() []ent.Index {
|
||||||
|
return []ent.Index{
|
||||||
|
index.Fields("pending_auth_session_id").Unique(),
|
||||||
|
index.Fields("identity_id"),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -91,6 +91,13 @@ func (PaymentOrder) Fields() []ent.Field {
|
|||||||
Optional().
|
Optional().
|
||||||
Nillable().
|
Nillable().
|
||||||
MaxLen(64),
|
MaxLen(64),
|
||||||
|
field.String("provider_key").
|
||||||
|
Optional().
|
||||||
|
Nillable().
|
||||||
|
MaxLen(30),
|
||||||
|
field.JSON("provider_snapshot", map[string]any{}).
|
||||||
|
Optional().
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "jsonb"}),
|
||||||
|
|
||||||
// 状态
|
// 状态
|
||||||
field.String("status").
|
field.String("status").
|
||||||
|
|||||||
@@ -0,0 +1,134 @@
|
|||||||
|
package schema
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/schema/mixins"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
"entgo.io/ent/dialect/entsql"
|
||||||
|
"entgo.io/ent/schema"
|
||||||
|
"entgo.io/ent/schema/edge"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"entgo.io/ent/schema/index"
|
||||||
|
)
|
||||||
|
|
||||||
|
var pendingAuthIntents = map[string]struct{}{
|
||||||
|
"login": {},
|
||||||
|
"bind_current_user": {},
|
||||||
|
"adopt_existing_user_by_email": {},
|
||||||
|
}
|
||||||
|
|
||||||
|
func validatePendingAuthIntent(value string) error {
|
||||||
|
if _, ok := pendingAuthIntents[value]; ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("invalid pending auth intent %q", value)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PendingAuthSession stores a short-lived post-auth decision session.
|
||||||
|
type PendingAuthSession struct {
|
||||||
|
ent.Schema
|
||||||
|
}
|
||||||
|
|
||||||
|
func (PendingAuthSession) Annotations() []schema.Annotation {
|
||||||
|
return []schema.Annotation{
|
||||||
|
entsql.Annotation{Table: "pending_auth_sessions"},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (PendingAuthSession) Mixin() []ent.Mixin {
|
||||||
|
return []ent.Mixin{
|
||||||
|
mixins.TimeMixin{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (PendingAuthSession) Fields() []ent.Field {
|
||||||
|
return []ent.Field{
|
||||||
|
field.String("session_token").
|
||||||
|
MaxLen(255).
|
||||||
|
NotEmpty(),
|
||||||
|
field.String("intent").
|
||||||
|
MaxLen(40).
|
||||||
|
NotEmpty().
|
||||||
|
Validate(validatePendingAuthIntent),
|
||||||
|
field.String("provider_type").
|
||||||
|
MaxLen(20).
|
||||||
|
NotEmpty().
|
||||||
|
Validate(validateAuthProviderType),
|
||||||
|
field.String("provider_key").
|
||||||
|
NotEmpty().
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "text"}),
|
||||||
|
field.String("provider_subject").
|
||||||
|
NotEmpty().
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "text"}),
|
||||||
|
field.Int64("target_user_id").
|
||||||
|
Optional().
|
||||||
|
Nillable(),
|
||||||
|
field.String("redirect_to").
|
||||||
|
Default("").
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "text"}),
|
||||||
|
field.String("resolved_email").
|
||||||
|
Default("").
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "text"}),
|
||||||
|
field.String("registration_password_hash").
|
||||||
|
Default("").
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "text"}),
|
||||||
|
field.JSON("upstream_identity_claims", map[string]any{}).
|
||||||
|
Default(func() map[string]any { return map[string]any{} }).
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "jsonb"}),
|
||||||
|
field.JSON("local_flow_state", map[string]any{}).
|
||||||
|
Default(func() map[string]any { return map[string]any{} }).
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "jsonb"}),
|
||||||
|
field.String("browser_session_key").
|
||||||
|
Default("").
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "text"}),
|
||||||
|
field.String("completion_code_hash").
|
||||||
|
Default("").
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "text"}),
|
||||||
|
field.Time("completion_code_expires_at").
|
||||||
|
Optional().
|
||||||
|
Nillable().
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "timestamptz"}),
|
||||||
|
field.Time("email_verified_at").
|
||||||
|
Optional().
|
||||||
|
Nillable().
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "timestamptz"}),
|
||||||
|
field.Time("password_verified_at").
|
||||||
|
Optional().
|
||||||
|
Nillable().
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "timestamptz"}),
|
||||||
|
field.Time("totp_verified_at").
|
||||||
|
Optional().
|
||||||
|
Nillable().
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "timestamptz"}),
|
||||||
|
field.Time("expires_at").
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "timestamptz"}),
|
||||||
|
field.Time("consumed_at").
|
||||||
|
Optional().
|
||||||
|
Nillable().
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "timestamptz"}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (PendingAuthSession) Edges() []ent.Edge {
|
||||||
|
return []ent.Edge{
|
||||||
|
edge.From("target_user", User.Type).
|
||||||
|
Ref("pending_auth_sessions").
|
||||||
|
Field("target_user_id").
|
||||||
|
Unique(),
|
||||||
|
edge.To("adoption_decision", IdentityAdoptionDecision.Type).
|
||||||
|
Unique(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (PendingAuthSession) Indexes() []ent.Index {
|
||||||
|
return []ent.Index{
|
||||||
|
index.Fields("session_token").Unique(),
|
||||||
|
index.Fields("target_user_id"),
|
||||||
|
index.Fields("expires_at"),
|
||||||
|
index.Fields("provider_type", "provider_key", "provider_subject"),
|
||||||
|
index.Fields("completion_code_hash"),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -72,6 +72,17 @@ func (User) Fields() []ent.Field {
|
|||||||
field.Time("totp_enabled_at").
|
field.Time("totp_enabled_at").
|
||||||
Optional().
|
Optional().
|
||||||
Nillable(),
|
Nillable(),
|
||||||
|
field.String("signup_source").
|
||||||
|
MaxLen(20).
|
||||||
|
Default("email"),
|
||||||
|
field.Time("last_login_at").
|
||||||
|
Optional().
|
||||||
|
Nillable().
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "timestamptz"}),
|
||||||
|
field.Time("last_active_at").
|
||||||
|
Optional().
|
||||||
|
Nillable().
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "timestamptz"}),
|
||||||
|
|
||||||
// 余额不足通知
|
// 余额不足通知
|
||||||
field.Bool("balance_notify_enabled").
|
field.Bool("balance_notify_enabled").
|
||||||
@@ -104,6 +115,8 @@ func (User) Edges() []ent.Edge {
|
|||||||
edge.To("attribute_values", UserAttributeValue.Type),
|
edge.To("attribute_values", UserAttributeValue.Type),
|
||||||
edge.To("promo_code_usages", PromoCodeUsage.Type),
|
edge.To("promo_code_usages", PromoCodeUsage.Type),
|
||||||
edge.To("payment_orders", PaymentOrder.Type),
|
edge.To("payment_orders", PaymentOrder.Type),
|
||||||
|
edge.To("auth_identities", AuthIdentity.Type),
|
||||||
|
edge.To("pending_auth_sessions", PendingAuthSession.Type),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,18 +24,26 @@ type Tx struct {
|
|||||||
Announcement *AnnouncementClient
|
Announcement *AnnouncementClient
|
||||||
// AnnouncementRead is the client for interacting with the AnnouncementRead builders.
|
// AnnouncementRead is the client for interacting with the AnnouncementRead builders.
|
||||||
AnnouncementRead *AnnouncementReadClient
|
AnnouncementRead *AnnouncementReadClient
|
||||||
|
// AuthIdentity is the client for interacting with the AuthIdentity builders.
|
||||||
|
AuthIdentity *AuthIdentityClient
|
||||||
|
// AuthIdentityChannel is the client for interacting with the AuthIdentityChannel builders.
|
||||||
|
AuthIdentityChannel *AuthIdentityChannelClient
|
||||||
// ErrorPassthroughRule is the client for interacting with the ErrorPassthroughRule builders.
|
// ErrorPassthroughRule is the client for interacting with the ErrorPassthroughRule builders.
|
||||||
ErrorPassthroughRule *ErrorPassthroughRuleClient
|
ErrorPassthroughRule *ErrorPassthroughRuleClient
|
||||||
// Group is the client for interacting with the Group builders.
|
// Group is the client for interacting with the Group builders.
|
||||||
Group *GroupClient
|
Group *GroupClient
|
||||||
// IdempotencyRecord is the client for interacting with the IdempotencyRecord builders.
|
// IdempotencyRecord is the client for interacting with the IdempotencyRecord builders.
|
||||||
IdempotencyRecord *IdempotencyRecordClient
|
IdempotencyRecord *IdempotencyRecordClient
|
||||||
|
// IdentityAdoptionDecision is the client for interacting with the IdentityAdoptionDecision builders.
|
||||||
|
IdentityAdoptionDecision *IdentityAdoptionDecisionClient
|
||||||
// PaymentAuditLog is the client for interacting with the PaymentAuditLog builders.
|
// PaymentAuditLog is the client for interacting with the PaymentAuditLog builders.
|
||||||
PaymentAuditLog *PaymentAuditLogClient
|
PaymentAuditLog *PaymentAuditLogClient
|
||||||
// PaymentOrder is the client for interacting with the PaymentOrder builders.
|
// PaymentOrder is the client for interacting with the PaymentOrder builders.
|
||||||
PaymentOrder *PaymentOrderClient
|
PaymentOrder *PaymentOrderClient
|
||||||
// PaymentProviderInstance is the client for interacting with the PaymentProviderInstance builders.
|
// PaymentProviderInstance is the client for interacting with the PaymentProviderInstance builders.
|
||||||
PaymentProviderInstance *PaymentProviderInstanceClient
|
PaymentProviderInstance *PaymentProviderInstanceClient
|
||||||
|
// PendingAuthSession is the client for interacting with the PendingAuthSession builders.
|
||||||
|
PendingAuthSession *PendingAuthSessionClient
|
||||||
// PromoCode is the client for interacting with the PromoCode builders.
|
// PromoCode is the client for interacting with the PromoCode builders.
|
||||||
PromoCode *PromoCodeClient
|
PromoCode *PromoCodeClient
|
||||||
// PromoCodeUsage is the client for interacting with the PromoCodeUsage builders.
|
// PromoCodeUsage is the client for interacting with the PromoCodeUsage builders.
|
||||||
@@ -202,12 +210,16 @@ func (tx *Tx) init() {
|
|||||||
tx.AccountGroup = NewAccountGroupClient(tx.config)
|
tx.AccountGroup = NewAccountGroupClient(tx.config)
|
||||||
tx.Announcement = NewAnnouncementClient(tx.config)
|
tx.Announcement = NewAnnouncementClient(tx.config)
|
||||||
tx.AnnouncementRead = NewAnnouncementReadClient(tx.config)
|
tx.AnnouncementRead = NewAnnouncementReadClient(tx.config)
|
||||||
|
tx.AuthIdentity = NewAuthIdentityClient(tx.config)
|
||||||
|
tx.AuthIdentityChannel = NewAuthIdentityChannelClient(tx.config)
|
||||||
tx.ErrorPassthroughRule = NewErrorPassthroughRuleClient(tx.config)
|
tx.ErrorPassthroughRule = NewErrorPassthroughRuleClient(tx.config)
|
||||||
tx.Group = NewGroupClient(tx.config)
|
tx.Group = NewGroupClient(tx.config)
|
||||||
tx.IdempotencyRecord = NewIdempotencyRecordClient(tx.config)
|
tx.IdempotencyRecord = NewIdempotencyRecordClient(tx.config)
|
||||||
|
tx.IdentityAdoptionDecision = NewIdentityAdoptionDecisionClient(tx.config)
|
||||||
tx.PaymentAuditLog = NewPaymentAuditLogClient(tx.config)
|
tx.PaymentAuditLog = NewPaymentAuditLogClient(tx.config)
|
||||||
tx.PaymentOrder = NewPaymentOrderClient(tx.config)
|
tx.PaymentOrder = NewPaymentOrderClient(tx.config)
|
||||||
tx.PaymentProviderInstance = NewPaymentProviderInstanceClient(tx.config)
|
tx.PaymentProviderInstance = NewPaymentProviderInstanceClient(tx.config)
|
||||||
|
tx.PendingAuthSession = NewPendingAuthSessionClient(tx.config)
|
||||||
tx.PromoCode = NewPromoCodeClient(tx.config)
|
tx.PromoCode = NewPromoCodeClient(tx.config)
|
||||||
tx.PromoCodeUsage = NewPromoCodeUsageClient(tx.config)
|
tx.PromoCodeUsage = NewPromoCodeUsageClient(tx.config)
|
||||||
tx.Proxy = NewProxyClient(tx.config)
|
tx.Proxy = NewProxyClient(tx.config)
|
||||||
|
|||||||
+75
-4
@@ -45,6 +45,12 @@ type User struct {
|
|||||||
TotpEnabled bool `json:"totp_enabled,omitempty"`
|
TotpEnabled bool `json:"totp_enabled,omitempty"`
|
||||||
// TotpEnabledAt holds the value of the "totp_enabled_at" field.
|
// TotpEnabledAt holds the value of the "totp_enabled_at" field.
|
||||||
TotpEnabledAt *time.Time `json:"totp_enabled_at,omitempty"`
|
TotpEnabledAt *time.Time `json:"totp_enabled_at,omitempty"`
|
||||||
|
// SignupSource holds the value of the "signup_source" field.
|
||||||
|
SignupSource string `json:"signup_source,omitempty"`
|
||||||
|
// LastLoginAt holds the value of the "last_login_at" field.
|
||||||
|
LastLoginAt *time.Time `json:"last_login_at,omitempty"`
|
||||||
|
// LastActiveAt holds the value of the "last_active_at" field.
|
||||||
|
LastActiveAt *time.Time `json:"last_active_at,omitempty"`
|
||||||
// BalanceNotifyEnabled holds the value of the "balance_notify_enabled" field.
|
// BalanceNotifyEnabled holds the value of the "balance_notify_enabled" field.
|
||||||
BalanceNotifyEnabled bool `json:"balance_notify_enabled,omitempty"`
|
BalanceNotifyEnabled bool `json:"balance_notify_enabled,omitempty"`
|
||||||
// BalanceNotifyThresholdType holds the value of the "balance_notify_threshold_type" field.
|
// BalanceNotifyThresholdType holds the value of the "balance_notify_threshold_type" field.
|
||||||
@@ -83,11 +89,15 @@ type UserEdges struct {
|
|||||||
PromoCodeUsages []*PromoCodeUsage `json:"promo_code_usages,omitempty"`
|
PromoCodeUsages []*PromoCodeUsage `json:"promo_code_usages,omitempty"`
|
||||||
// PaymentOrders holds the value of the payment_orders edge.
|
// PaymentOrders holds the value of the payment_orders edge.
|
||||||
PaymentOrders []*PaymentOrder `json:"payment_orders,omitempty"`
|
PaymentOrders []*PaymentOrder `json:"payment_orders,omitempty"`
|
||||||
|
// AuthIdentities holds the value of the auth_identities edge.
|
||||||
|
AuthIdentities []*AuthIdentity `json:"auth_identities,omitempty"`
|
||||||
|
// PendingAuthSessions holds the value of the pending_auth_sessions edge.
|
||||||
|
PendingAuthSessions []*PendingAuthSession `json:"pending_auth_sessions,omitempty"`
|
||||||
// UserAllowedGroups holds the value of the user_allowed_groups edge.
|
// UserAllowedGroups holds the value of the user_allowed_groups edge.
|
||||||
UserAllowedGroups []*UserAllowedGroup `json:"user_allowed_groups,omitempty"`
|
UserAllowedGroups []*UserAllowedGroup `json:"user_allowed_groups,omitempty"`
|
||||||
// loadedTypes holds the information for reporting if a
|
// loadedTypes holds the information for reporting if a
|
||||||
// type was loaded (or requested) in eager-loading or not.
|
// type was loaded (or requested) in eager-loading or not.
|
||||||
loadedTypes [11]bool
|
loadedTypes [13]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// APIKeysOrErr returns the APIKeys value or an error if the edge
|
// APIKeysOrErr returns the APIKeys value or an error if the edge
|
||||||
@@ -180,10 +190,28 @@ func (e UserEdges) PaymentOrdersOrErr() ([]*PaymentOrder, error) {
|
|||||||
return nil, &NotLoadedError{edge: "payment_orders"}
|
return nil, &NotLoadedError{edge: "payment_orders"}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AuthIdentitiesOrErr returns the AuthIdentities value or an error if the edge
|
||||||
|
// was not loaded in eager-loading.
|
||||||
|
func (e UserEdges) AuthIdentitiesOrErr() ([]*AuthIdentity, error) {
|
||||||
|
if e.loadedTypes[10] {
|
||||||
|
return e.AuthIdentities, nil
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "auth_identities"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PendingAuthSessionsOrErr returns the PendingAuthSessions value or an error if the edge
|
||||||
|
// was not loaded in eager-loading.
|
||||||
|
func (e UserEdges) PendingAuthSessionsOrErr() ([]*PendingAuthSession, error) {
|
||||||
|
if e.loadedTypes[11] {
|
||||||
|
return e.PendingAuthSessions, nil
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "pending_auth_sessions"}
|
||||||
|
}
|
||||||
|
|
||||||
// UserAllowedGroupsOrErr returns the UserAllowedGroups value or an error if the edge
|
// UserAllowedGroupsOrErr returns the UserAllowedGroups value or an error if the edge
|
||||||
// was not loaded in eager-loading.
|
// was not loaded in eager-loading.
|
||||||
func (e UserEdges) UserAllowedGroupsOrErr() ([]*UserAllowedGroup, error) {
|
func (e UserEdges) UserAllowedGroupsOrErr() ([]*UserAllowedGroup, error) {
|
||||||
if e.loadedTypes[10] {
|
if e.loadedTypes[12] {
|
||||||
return e.UserAllowedGroups, nil
|
return e.UserAllowedGroups, nil
|
||||||
}
|
}
|
||||||
return nil, &NotLoadedError{edge: "user_allowed_groups"}
|
return nil, &NotLoadedError{edge: "user_allowed_groups"}
|
||||||
@@ -200,9 +228,9 @@ func (*User) scanValues(columns []string) ([]any, error) {
|
|||||||
values[i] = new(sql.NullFloat64)
|
values[i] = new(sql.NullFloat64)
|
||||||
case user.FieldID, user.FieldConcurrency:
|
case user.FieldID, user.FieldConcurrency:
|
||||||
values[i] = new(sql.NullInt64)
|
values[i] = new(sql.NullInt64)
|
||||||
case user.FieldEmail, user.FieldPasswordHash, user.FieldRole, user.FieldStatus, user.FieldUsername, user.FieldNotes, user.FieldTotpSecretEncrypted, user.FieldBalanceNotifyThresholdType, user.FieldBalanceNotifyExtraEmails:
|
case user.FieldEmail, user.FieldPasswordHash, user.FieldRole, user.FieldStatus, user.FieldUsername, user.FieldNotes, user.FieldTotpSecretEncrypted, user.FieldSignupSource, user.FieldBalanceNotifyThresholdType, user.FieldBalanceNotifyExtraEmails:
|
||||||
values[i] = new(sql.NullString)
|
values[i] = new(sql.NullString)
|
||||||
case user.FieldCreatedAt, user.FieldUpdatedAt, user.FieldDeletedAt, user.FieldTotpEnabledAt:
|
case user.FieldCreatedAt, user.FieldUpdatedAt, user.FieldDeletedAt, user.FieldTotpEnabledAt, user.FieldLastLoginAt, user.FieldLastActiveAt:
|
||||||
values[i] = new(sql.NullTime)
|
values[i] = new(sql.NullTime)
|
||||||
default:
|
default:
|
||||||
values[i] = new(sql.UnknownType)
|
values[i] = new(sql.UnknownType)
|
||||||
@@ -312,6 +340,26 @@ func (_m *User) assignValues(columns []string, values []any) error {
|
|||||||
_m.TotpEnabledAt = new(time.Time)
|
_m.TotpEnabledAt = new(time.Time)
|
||||||
*_m.TotpEnabledAt = value.Time
|
*_m.TotpEnabledAt = value.Time
|
||||||
}
|
}
|
||||||
|
case user.FieldSignupSource:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field signup_source", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.SignupSource = value.String
|
||||||
|
}
|
||||||
|
case user.FieldLastLoginAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field last_login_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.LastLoginAt = new(time.Time)
|
||||||
|
*_m.LastLoginAt = value.Time
|
||||||
|
}
|
||||||
|
case user.FieldLastActiveAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field last_active_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.LastActiveAt = new(time.Time)
|
||||||
|
*_m.LastActiveAt = value.Time
|
||||||
|
}
|
||||||
case user.FieldBalanceNotifyEnabled:
|
case user.FieldBalanceNotifyEnabled:
|
||||||
if value, ok := values[i].(*sql.NullBool); !ok {
|
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||||
return fmt.Errorf("unexpected type %T for field balance_notify_enabled", values[i])
|
return fmt.Errorf("unexpected type %T for field balance_notify_enabled", values[i])
|
||||||
@@ -406,6 +454,16 @@ func (_m *User) QueryPaymentOrders() *PaymentOrderQuery {
|
|||||||
return NewUserClient(_m.config).QueryPaymentOrders(_m)
|
return NewUserClient(_m.config).QueryPaymentOrders(_m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QueryAuthIdentities queries the "auth_identities" edge of the User entity.
|
||||||
|
func (_m *User) QueryAuthIdentities() *AuthIdentityQuery {
|
||||||
|
return NewUserClient(_m.config).QueryAuthIdentities(_m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryPendingAuthSessions queries the "pending_auth_sessions" edge of the User entity.
|
||||||
|
func (_m *User) QueryPendingAuthSessions() *PendingAuthSessionQuery {
|
||||||
|
return NewUserClient(_m.config).QueryPendingAuthSessions(_m)
|
||||||
|
}
|
||||||
|
|
||||||
// QueryUserAllowedGroups queries the "user_allowed_groups" edge of the User entity.
|
// QueryUserAllowedGroups queries the "user_allowed_groups" edge of the User entity.
|
||||||
func (_m *User) QueryUserAllowedGroups() *UserAllowedGroupQuery {
|
func (_m *User) QueryUserAllowedGroups() *UserAllowedGroupQuery {
|
||||||
return NewUserClient(_m.config).QueryUserAllowedGroups(_m)
|
return NewUserClient(_m.config).QueryUserAllowedGroups(_m)
|
||||||
@@ -482,6 +540,19 @@ func (_m *User) String() string {
|
|||||||
builder.WriteString(v.Format(time.ANSIC))
|
builder.WriteString(v.Format(time.ANSIC))
|
||||||
}
|
}
|
||||||
builder.WriteString(", ")
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("signup_source=")
|
||||||
|
builder.WriteString(_m.SignupSource)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
if v := _m.LastLoginAt; v != nil {
|
||||||
|
builder.WriteString("last_login_at=")
|
||||||
|
builder.WriteString(v.Format(time.ANSIC))
|
||||||
|
}
|
||||||
|
builder.WriteString(", ")
|
||||||
|
if v := _m.LastActiveAt; v != nil {
|
||||||
|
builder.WriteString("last_active_at=")
|
||||||
|
builder.WriteString(v.Format(time.ANSIC))
|
||||||
|
}
|
||||||
|
builder.WriteString(", ")
|
||||||
builder.WriteString("balance_notify_enabled=")
|
builder.WriteString("balance_notify_enabled=")
|
||||||
builder.WriteString(fmt.Sprintf("%v", _m.BalanceNotifyEnabled))
|
builder.WriteString(fmt.Sprintf("%v", _m.BalanceNotifyEnabled))
|
||||||
builder.WriteString(", ")
|
builder.WriteString(", ")
|
||||||
|
|||||||
@@ -43,6 +43,12 @@ const (
|
|||||||
FieldTotpEnabled = "totp_enabled"
|
FieldTotpEnabled = "totp_enabled"
|
||||||
// FieldTotpEnabledAt holds the string denoting the totp_enabled_at field in the database.
|
// FieldTotpEnabledAt holds the string denoting the totp_enabled_at field in the database.
|
||||||
FieldTotpEnabledAt = "totp_enabled_at"
|
FieldTotpEnabledAt = "totp_enabled_at"
|
||||||
|
// FieldSignupSource holds the string denoting the signup_source field in the database.
|
||||||
|
FieldSignupSource = "signup_source"
|
||||||
|
// FieldLastLoginAt holds the string denoting the last_login_at field in the database.
|
||||||
|
FieldLastLoginAt = "last_login_at"
|
||||||
|
// FieldLastActiveAt holds the string denoting the last_active_at field in the database.
|
||||||
|
FieldLastActiveAt = "last_active_at"
|
||||||
// FieldBalanceNotifyEnabled holds the string denoting the balance_notify_enabled field in the database.
|
// FieldBalanceNotifyEnabled holds the string denoting the balance_notify_enabled field in the database.
|
||||||
FieldBalanceNotifyEnabled = "balance_notify_enabled"
|
FieldBalanceNotifyEnabled = "balance_notify_enabled"
|
||||||
// FieldBalanceNotifyThresholdType holds the string denoting the balance_notify_threshold_type field in the database.
|
// FieldBalanceNotifyThresholdType holds the string denoting the balance_notify_threshold_type field in the database.
|
||||||
@@ -73,6 +79,10 @@ const (
|
|||||||
EdgePromoCodeUsages = "promo_code_usages"
|
EdgePromoCodeUsages = "promo_code_usages"
|
||||||
// EdgePaymentOrders holds the string denoting the payment_orders edge name in mutations.
|
// EdgePaymentOrders holds the string denoting the payment_orders edge name in mutations.
|
||||||
EdgePaymentOrders = "payment_orders"
|
EdgePaymentOrders = "payment_orders"
|
||||||
|
// EdgeAuthIdentities holds the string denoting the auth_identities edge name in mutations.
|
||||||
|
EdgeAuthIdentities = "auth_identities"
|
||||||
|
// EdgePendingAuthSessions holds the string denoting the pending_auth_sessions edge name in mutations.
|
||||||
|
EdgePendingAuthSessions = "pending_auth_sessions"
|
||||||
// EdgeUserAllowedGroups holds the string denoting the user_allowed_groups edge name in mutations.
|
// EdgeUserAllowedGroups holds the string denoting the user_allowed_groups edge name in mutations.
|
||||||
EdgeUserAllowedGroups = "user_allowed_groups"
|
EdgeUserAllowedGroups = "user_allowed_groups"
|
||||||
// Table holds the table name of the user in the database.
|
// Table holds the table name of the user in the database.
|
||||||
@@ -145,6 +155,20 @@ const (
|
|||||||
PaymentOrdersInverseTable = "payment_orders"
|
PaymentOrdersInverseTable = "payment_orders"
|
||||||
// PaymentOrdersColumn is the table column denoting the payment_orders relation/edge.
|
// PaymentOrdersColumn is the table column denoting the payment_orders relation/edge.
|
||||||
PaymentOrdersColumn = "user_id"
|
PaymentOrdersColumn = "user_id"
|
||||||
|
// AuthIdentitiesTable is the table that holds the auth_identities relation/edge.
|
||||||
|
AuthIdentitiesTable = "auth_identities"
|
||||||
|
// AuthIdentitiesInverseTable is the table name for the AuthIdentity entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "authidentity" package.
|
||||||
|
AuthIdentitiesInverseTable = "auth_identities"
|
||||||
|
// AuthIdentitiesColumn is the table column denoting the auth_identities relation/edge.
|
||||||
|
AuthIdentitiesColumn = "user_id"
|
||||||
|
// PendingAuthSessionsTable is the table that holds the pending_auth_sessions relation/edge.
|
||||||
|
PendingAuthSessionsTable = "pending_auth_sessions"
|
||||||
|
// PendingAuthSessionsInverseTable is the table name for the PendingAuthSession entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "pendingauthsession" package.
|
||||||
|
PendingAuthSessionsInverseTable = "pending_auth_sessions"
|
||||||
|
// PendingAuthSessionsColumn is the table column denoting the pending_auth_sessions relation/edge.
|
||||||
|
PendingAuthSessionsColumn = "target_user_id"
|
||||||
// UserAllowedGroupsTable is the table that holds the user_allowed_groups relation/edge.
|
// UserAllowedGroupsTable is the table that holds the user_allowed_groups relation/edge.
|
||||||
UserAllowedGroupsTable = "user_allowed_groups"
|
UserAllowedGroupsTable = "user_allowed_groups"
|
||||||
// UserAllowedGroupsInverseTable is the table name for the UserAllowedGroup entity.
|
// UserAllowedGroupsInverseTable is the table name for the UserAllowedGroup entity.
|
||||||
@@ -171,6 +195,9 @@ var Columns = []string{
|
|||||||
FieldTotpSecretEncrypted,
|
FieldTotpSecretEncrypted,
|
||||||
FieldTotpEnabled,
|
FieldTotpEnabled,
|
||||||
FieldTotpEnabledAt,
|
FieldTotpEnabledAt,
|
||||||
|
FieldSignupSource,
|
||||||
|
FieldLastLoginAt,
|
||||||
|
FieldLastActiveAt,
|
||||||
FieldBalanceNotifyEnabled,
|
FieldBalanceNotifyEnabled,
|
||||||
FieldBalanceNotifyThresholdType,
|
FieldBalanceNotifyThresholdType,
|
||||||
FieldBalanceNotifyThreshold,
|
FieldBalanceNotifyThreshold,
|
||||||
@@ -232,6 +259,10 @@ var (
|
|||||||
DefaultNotes string
|
DefaultNotes string
|
||||||
// DefaultTotpEnabled holds the default value on creation for the "totp_enabled" field.
|
// DefaultTotpEnabled holds the default value on creation for the "totp_enabled" field.
|
||||||
DefaultTotpEnabled bool
|
DefaultTotpEnabled bool
|
||||||
|
// DefaultSignupSource holds the default value on creation for the "signup_source" field.
|
||||||
|
DefaultSignupSource string
|
||||||
|
// SignupSourceValidator is a validator for the "signup_source" field. It is called by the builders before save.
|
||||||
|
SignupSourceValidator func(string) error
|
||||||
// DefaultBalanceNotifyEnabled holds the default value on creation for the "balance_notify_enabled" field.
|
// DefaultBalanceNotifyEnabled holds the default value on creation for the "balance_notify_enabled" field.
|
||||||
DefaultBalanceNotifyEnabled bool
|
DefaultBalanceNotifyEnabled bool
|
||||||
// DefaultBalanceNotifyThresholdType holds the default value on creation for the "balance_notify_threshold_type" field.
|
// DefaultBalanceNotifyThresholdType holds the default value on creation for the "balance_notify_threshold_type" field.
|
||||||
@@ -320,6 +351,21 @@ func ByTotpEnabledAt(opts ...sql.OrderTermOption) OrderOption {
|
|||||||
return sql.OrderByField(FieldTotpEnabledAt, opts...).ToFunc()
|
return sql.OrderByField(FieldTotpEnabledAt, opts...).ToFunc()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BySignupSource orders the results by the signup_source field.
|
||||||
|
func BySignupSource(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldSignupSource, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByLastLoginAt orders the results by the last_login_at field.
|
||||||
|
func ByLastLoginAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldLastLoginAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByLastActiveAt orders the results by the last_active_at field.
|
||||||
|
func ByLastActiveAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldLastActiveAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
// ByBalanceNotifyEnabled orders the results by the balance_notify_enabled field.
|
// ByBalanceNotifyEnabled orders the results by the balance_notify_enabled field.
|
||||||
func ByBalanceNotifyEnabled(opts ...sql.OrderTermOption) OrderOption {
|
func ByBalanceNotifyEnabled(opts ...sql.OrderTermOption) OrderOption {
|
||||||
return sql.OrderByField(FieldBalanceNotifyEnabled, opts...).ToFunc()
|
return sql.OrderByField(FieldBalanceNotifyEnabled, opts...).ToFunc()
|
||||||
@@ -485,6 +531,34 @@ func ByPaymentOrders(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ByAuthIdentitiesCount orders the results by auth_identities count.
|
||||||
|
func ByAuthIdentitiesCount(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborsCount(s, newAuthIdentitiesStep(), opts...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByAuthIdentities orders the results by auth_identities terms.
|
||||||
|
func ByAuthIdentities(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborTerms(s, newAuthIdentitiesStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByPendingAuthSessionsCount orders the results by pending_auth_sessions count.
|
||||||
|
func ByPendingAuthSessionsCount(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborsCount(s, newPendingAuthSessionsStep(), opts...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByPendingAuthSessions orders the results by pending_auth_sessions terms.
|
||||||
|
func ByPendingAuthSessions(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborTerms(s, newPendingAuthSessionsStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ByUserAllowedGroupsCount orders the results by user_allowed_groups count.
|
// ByUserAllowedGroupsCount orders the results by user_allowed_groups count.
|
||||||
func ByUserAllowedGroupsCount(opts ...sql.OrderTermOption) OrderOption {
|
func ByUserAllowedGroupsCount(opts ...sql.OrderTermOption) OrderOption {
|
||||||
return func(s *sql.Selector) {
|
return func(s *sql.Selector) {
|
||||||
@@ -568,6 +642,20 @@ func newPaymentOrdersStep() *sqlgraph.Step {
|
|||||||
sqlgraph.Edge(sqlgraph.O2M, false, PaymentOrdersTable, PaymentOrdersColumn),
|
sqlgraph.Edge(sqlgraph.O2M, false, PaymentOrdersTable, PaymentOrdersColumn),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
func newAuthIdentitiesStep() *sqlgraph.Step {
|
||||||
|
return sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(AuthIdentitiesInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, AuthIdentitiesTable, AuthIdentitiesColumn),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
func newPendingAuthSessionsStep() *sqlgraph.Step {
|
||||||
|
return sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(PendingAuthSessionsInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, PendingAuthSessionsTable, PendingAuthSessionsColumn),
|
||||||
|
)
|
||||||
|
}
|
||||||
func newUserAllowedGroupsStep() *sqlgraph.Step {
|
func newUserAllowedGroupsStep() *sqlgraph.Step {
|
||||||
return sqlgraph.NewStep(
|
return sqlgraph.NewStep(
|
||||||
sqlgraph.From(Table, FieldID),
|
sqlgraph.From(Table, FieldID),
|
||||||
|
|||||||
@@ -125,6 +125,21 @@ func TotpEnabledAt(v time.Time) predicate.User {
|
|||||||
return predicate.User(sql.FieldEQ(FieldTotpEnabledAt, v))
|
return predicate.User(sql.FieldEQ(FieldTotpEnabledAt, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SignupSource applies equality check predicate on the "signup_source" field. It's identical to SignupSourceEQ.
|
||||||
|
func SignupSource(v string) predicate.User {
|
||||||
|
return predicate.User(sql.FieldEQ(FieldSignupSource, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LastLoginAt applies equality check predicate on the "last_login_at" field. It's identical to LastLoginAtEQ.
|
||||||
|
func LastLoginAt(v time.Time) predicate.User {
|
||||||
|
return predicate.User(sql.FieldEQ(FieldLastLoginAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LastActiveAt applies equality check predicate on the "last_active_at" field. It's identical to LastActiveAtEQ.
|
||||||
|
func LastActiveAt(v time.Time) predicate.User {
|
||||||
|
return predicate.User(sql.FieldEQ(FieldLastActiveAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
// BalanceNotifyEnabled applies equality check predicate on the "balance_notify_enabled" field. It's identical to BalanceNotifyEnabledEQ.
|
// BalanceNotifyEnabled applies equality check predicate on the "balance_notify_enabled" field. It's identical to BalanceNotifyEnabledEQ.
|
||||||
func BalanceNotifyEnabled(v bool) predicate.User {
|
func BalanceNotifyEnabled(v bool) predicate.User {
|
||||||
return predicate.User(sql.FieldEQ(FieldBalanceNotifyEnabled, v))
|
return predicate.User(sql.FieldEQ(FieldBalanceNotifyEnabled, v))
|
||||||
@@ -885,6 +900,171 @@ func TotpEnabledAtNotNil() predicate.User {
|
|||||||
return predicate.User(sql.FieldNotNull(FieldTotpEnabledAt))
|
return predicate.User(sql.FieldNotNull(FieldTotpEnabledAt))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SignupSourceEQ applies the EQ predicate on the "signup_source" field.
|
||||||
|
func SignupSourceEQ(v string) predicate.User {
|
||||||
|
return predicate.User(sql.FieldEQ(FieldSignupSource, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SignupSourceNEQ applies the NEQ predicate on the "signup_source" field.
|
||||||
|
func SignupSourceNEQ(v string) predicate.User {
|
||||||
|
return predicate.User(sql.FieldNEQ(FieldSignupSource, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SignupSourceIn applies the In predicate on the "signup_source" field.
|
||||||
|
func SignupSourceIn(vs ...string) predicate.User {
|
||||||
|
return predicate.User(sql.FieldIn(FieldSignupSource, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SignupSourceNotIn applies the NotIn predicate on the "signup_source" field.
|
||||||
|
func SignupSourceNotIn(vs ...string) predicate.User {
|
||||||
|
return predicate.User(sql.FieldNotIn(FieldSignupSource, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SignupSourceGT applies the GT predicate on the "signup_source" field.
|
||||||
|
func SignupSourceGT(v string) predicate.User {
|
||||||
|
return predicate.User(sql.FieldGT(FieldSignupSource, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SignupSourceGTE applies the GTE predicate on the "signup_source" field.
|
||||||
|
func SignupSourceGTE(v string) predicate.User {
|
||||||
|
return predicate.User(sql.FieldGTE(FieldSignupSource, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SignupSourceLT applies the LT predicate on the "signup_source" field.
|
||||||
|
func SignupSourceLT(v string) predicate.User {
|
||||||
|
return predicate.User(sql.FieldLT(FieldSignupSource, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SignupSourceLTE applies the LTE predicate on the "signup_source" field.
|
||||||
|
func SignupSourceLTE(v string) predicate.User {
|
||||||
|
return predicate.User(sql.FieldLTE(FieldSignupSource, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SignupSourceContains applies the Contains predicate on the "signup_source" field.
|
||||||
|
func SignupSourceContains(v string) predicate.User {
|
||||||
|
return predicate.User(sql.FieldContains(FieldSignupSource, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SignupSourceHasPrefix applies the HasPrefix predicate on the "signup_source" field.
|
||||||
|
func SignupSourceHasPrefix(v string) predicate.User {
|
||||||
|
return predicate.User(sql.FieldHasPrefix(FieldSignupSource, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SignupSourceHasSuffix applies the HasSuffix predicate on the "signup_source" field.
|
||||||
|
func SignupSourceHasSuffix(v string) predicate.User {
|
||||||
|
return predicate.User(sql.FieldHasSuffix(FieldSignupSource, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SignupSourceEqualFold applies the EqualFold predicate on the "signup_source" field.
|
||||||
|
func SignupSourceEqualFold(v string) predicate.User {
|
||||||
|
return predicate.User(sql.FieldEqualFold(FieldSignupSource, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SignupSourceContainsFold applies the ContainsFold predicate on the "signup_source" field.
|
||||||
|
func SignupSourceContainsFold(v string) predicate.User {
|
||||||
|
return predicate.User(sql.FieldContainsFold(FieldSignupSource, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LastLoginAtEQ applies the EQ predicate on the "last_login_at" field.
|
||||||
|
func LastLoginAtEQ(v time.Time) predicate.User {
|
||||||
|
return predicate.User(sql.FieldEQ(FieldLastLoginAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LastLoginAtNEQ applies the NEQ predicate on the "last_login_at" field.
|
||||||
|
func LastLoginAtNEQ(v time.Time) predicate.User {
|
||||||
|
return predicate.User(sql.FieldNEQ(FieldLastLoginAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LastLoginAtIn applies the In predicate on the "last_login_at" field.
|
||||||
|
func LastLoginAtIn(vs ...time.Time) predicate.User {
|
||||||
|
return predicate.User(sql.FieldIn(FieldLastLoginAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LastLoginAtNotIn applies the NotIn predicate on the "last_login_at" field.
|
||||||
|
func LastLoginAtNotIn(vs ...time.Time) predicate.User {
|
||||||
|
return predicate.User(sql.FieldNotIn(FieldLastLoginAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LastLoginAtGT applies the GT predicate on the "last_login_at" field.
|
||||||
|
func LastLoginAtGT(v time.Time) predicate.User {
|
||||||
|
return predicate.User(sql.FieldGT(FieldLastLoginAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LastLoginAtGTE applies the GTE predicate on the "last_login_at" field.
|
||||||
|
func LastLoginAtGTE(v time.Time) predicate.User {
|
||||||
|
return predicate.User(sql.FieldGTE(FieldLastLoginAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LastLoginAtLT applies the LT predicate on the "last_login_at" field.
|
||||||
|
func LastLoginAtLT(v time.Time) predicate.User {
|
||||||
|
return predicate.User(sql.FieldLT(FieldLastLoginAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LastLoginAtLTE applies the LTE predicate on the "last_login_at" field.
|
||||||
|
func LastLoginAtLTE(v time.Time) predicate.User {
|
||||||
|
return predicate.User(sql.FieldLTE(FieldLastLoginAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LastLoginAtIsNil applies the IsNil predicate on the "last_login_at" field.
|
||||||
|
func LastLoginAtIsNil() predicate.User {
|
||||||
|
return predicate.User(sql.FieldIsNull(FieldLastLoginAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LastLoginAtNotNil applies the NotNil predicate on the "last_login_at" field.
|
||||||
|
func LastLoginAtNotNil() predicate.User {
|
||||||
|
return predicate.User(sql.FieldNotNull(FieldLastLoginAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LastActiveAtEQ applies the EQ predicate on the "last_active_at" field.
|
||||||
|
func LastActiveAtEQ(v time.Time) predicate.User {
|
||||||
|
return predicate.User(sql.FieldEQ(FieldLastActiveAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LastActiveAtNEQ applies the NEQ predicate on the "last_active_at" field.
|
||||||
|
func LastActiveAtNEQ(v time.Time) predicate.User {
|
||||||
|
return predicate.User(sql.FieldNEQ(FieldLastActiveAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LastActiveAtIn applies the In predicate on the "last_active_at" field.
|
||||||
|
func LastActiveAtIn(vs ...time.Time) predicate.User {
|
||||||
|
return predicate.User(sql.FieldIn(FieldLastActiveAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LastActiveAtNotIn applies the NotIn predicate on the "last_active_at" field.
|
||||||
|
func LastActiveAtNotIn(vs ...time.Time) predicate.User {
|
||||||
|
return predicate.User(sql.FieldNotIn(FieldLastActiveAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LastActiveAtGT applies the GT predicate on the "last_active_at" field.
|
||||||
|
func LastActiveAtGT(v time.Time) predicate.User {
|
||||||
|
return predicate.User(sql.FieldGT(FieldLastActiveAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LastActiveAtGTE applies the GTE predicate on the "last_active_at" field.
|
||||||
|
func LastActiveAtGTE(v time.Time) predicate.User {
|
||||||
|
return predicate.User(sql.FieldGTE(FieldLastActiveAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LastActiveAtLT applies the LT predicate on the "last_active_at" field.
|
||||||
|
func LastActiveAtLT(v time.Time) predicate.User {
|
||||||
|
return predicate.User(sql.FieldLT(FieldLastActiveAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LastActiveAtLTE applies the LTE predicate on the "last_active_at" field.
|
||||||
|
func LastActiveAtLTE(v time.Time) predicate.User {
|
||||||
|
return predicate.User(sql.FieldLTE(FieldLastActiveAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LastActiveAtIsNil applies the IsNil predicate on the "last_active_at" field.
|
||||||
|
func LastActiveAtIsNil() predicate.User {
|
||||||
|
return predicate.User(sql.FieldIsNull(FieldLastActiveAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LastActiveAtNotNil applies the NotNil predicate on the "last_active_at" field.
|
||||||
|
func LastActiveAtNotNil() predicate.User {
|
||||||
|
return predicate.User(sql.FieldNotNull(FieldLastActiveAt))
|
||||||
|
}
|
||||||
|
|
||||||
// BalanceNotifyEnabledEQ applies the EQ predicate on the "balance_notify_enabled" field.
|
// BalanceNotifyEnabledEQ applies the EQ predicate on the "balance_notify_enabled" field.
|
||||||
func BalanceNotifyEnabledEQ(v bool) predicate.User {
|
func BalanceNotifyEnabledEQ(v bool) predicate.User {
|
||||||
return predicate.User(sql.FieldEQ(FieldBalanceNotifyEnabled, v))
|
return predicate.User(sql.FieldEQ(FieldBalanceNotifyEnabled, v))
|
||||||
@@ -1345,6 +1525,52 @@ func HasPaymentOrdersWith(preds ...predicate.PaymentOrder) predicate.User {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasAuthIdentities applies the HasEdge predicate on the "auth_identities" edge.
|
||||||
|
func HasAuthIdentities() predicate.User {
|
||||||
|
return predicate.User(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, AuthIdentitiesTable, AuthIdentitiesColumn),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasAuthIdentitiesWith applies the HasEdge predicate on the "auth_identities" edge with a given conditions (other predicates).
|
||||||
|
func HasAuthIdentitiesWith(preds ...predicate.AuthIdentity) predicate.User {
|
||||||
|
return predicate.User(func(s *sql.Selector) {
|
||||||
|
step := newAuthIdentitiesStep()
|
||||||
|
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasPendingAuthSessions applies the HasEdge predicate on the "pending_auth_sessions" edge.
|
||||||
|
func HasPendingAuthSessions() predicate.User {
|
||||||
|
return predicate.User(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, PendingAuthSessionsTable, PendingAuthSessionsColumn),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasPendingAuthSessionsWith applies the HasEdge predicate on the "pending_auth_sessions" edge with a given conditions (other predicates).
|
||||||
|
func HasPendingAuthSessionsWith(preds ...predicate.PendingAuthSession) predicate.User {
|
||||||
|
return predicate.User(func(s *sql.Selector) {
|
||||||
|
step := newPendingAuthSessionsStep()
|
||||||
|
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.
|
// HasUserAllowedGroups applies the HasEdge predicate on the "user_allowed_groups" edge.
|
||||||
func HasUserAllowedGroups() predicate.User {
|
func HasUserAllowedGroups() predicate.User {
|
||||||
return predicate.User(func(s *sql.Selector) {
|
return predicate.User(func(s *sql.Selector) {
|
||||||
|
|||||||
@@ -13,8 +13,10 @@ import (
|
|||||||
"entgo.io/ent/schema/field"
|
"entgo.io/ent/schema/field"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/announcementread"
|
"github.com/Wei-Shaw/sub2api/ent/announcementread"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/apikey"
|
"github.com/Wei-Shaw/sub2api/ent/apikey"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/authidentity"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/group"
|
"github.com/Wei-Shaw/sub2api/ent/group"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/paymentorder"
|
"github.com/Wei-Shaw/sub2api/ent/paymentorder"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/pendingauthsession"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
|
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
|
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/usagelog"
|
"github.com/Wei-Shaw/sub2api/ent/usagelog"
|
||||||
@@ -211,6 +213,48 @@ func (_c *UserCreate) SetNillableTotpEnabledAt(v *time.Time) *UserCreate {
|
|||||||
return _c
|
return _c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetSignupSource sets the "signup_source" field.
|
||||||
|
func (_c *UserCreate) SetSignupSource(v string) *UserCreate {
|
||||||
|
_c.mutation.SetSignupSource(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableSignupSource sets the "signup_source" field if the given value is not nil.
|
||||||
|
func (_c *UserCreate) SetNillableSignupSource(v *string) *UserCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetSignupSource(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLastLoginAt sets the "last_login_at" field.
|
||||||
|
func (_c *UserCreate) SetLastLoginAt(v time.Time) *UserCreate {
|
||||||
|
_c.mutation.SetLastLoginAt(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableLastLoginAt sets the "last_login_at" field if the given value is not nil.
|
||||||
|
func (_c *UserCreate) SetNillableLastLoginAt(v *time.Time) *UserCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetLastLoginAt(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLastActiveAt sets the "last_active_at" field.
|
||||||
|
func (_c *UserCreate) SetLastActiveAt(v time.Time) *UserCreate {
|
||||||
|
_c.mutation.SetLastActiveAt(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableLastActiveAt sets the "last_active_at" field if the given value is not nil.
|
||||||
|
func (_c *UserCreate) SetNillableLastActiveAt(v *time.Time) *UserCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetLastActiveAt(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
// SetBalanceNotifyEnabled sets the "balance_notify_enabled" field.
|
// SetBalanceNotifyEnabled sets the "balance_notify_enabled" field.
|
||||||
func (_c *UserCreate) SetBalanceNotifyEnabled(v bool) *UserCreate {
|
func (_c *UserCreate) SetBalanceNotifyEnabled(v bool) *UserCreate {
|
||||||
_c.mutation.SetBalanceNotifyEnabled(v)
|
_c.mutation.SetBalanceNotifyEnabled(v)
|
||||||
@@ -431,6 +475,36 @@ func (_c *UserCreate) AddPaymentOrders(v ...*PaymentOrder) *UserCreate {
|
|||||||
return _c.AddPaymentOrderIDs(ids...)
|
return _c.AddPaymentOrderIDs(ids...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddAuthIdentityIDs adds the "auth_identities" edge to the AuthIdentity entity by IDs.
|
||||||
|
func (_c *UserCreate) AddAuthIdentityIDs(ids ...int64) *UserCreate {
|
||||||
|
_c.mutation.AddAuthIdentityIDs(ids...)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddAuthIdentities adds the "auth_identities" edges to the AuthIdentity entity.
|
||||||
|
func (_c *UserCreate) AddAuthIdentities(v ...*AuthIdentity) *UserCreate {
|
||||||
|
ids := make([]int64, len(v))
|
||||||
|
for i := range v {
|
||||||
|
ids[i] = v[i].ID
|
||||||
|
}
|
||||||
|
return _c.AddAuthIdentityIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPendingAuthSessionIDs adds the "pending_auth_sessions" edge to the PendingAuthSession entity by IDs.
|
||||||
|
func (_c *UserCreate) AddPendingAuthSessionIDs(ids ...int64) *UserCreate {
|
||||||
|
_c.mutation.AddPendingAuthSessionIDs(ids...)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPendingAuthSessions adds the "pending_auth_sessions" edges to the PendingAuthSession entity.
|
||||||
|
func (_c *UserCreate) AddPendingAuthSessions(v ...*PendingAuthSession) *UserCreate {
|
||||||
|
ids := make([]int64, len(v))
|
||||||
|
for i := range v {
|
||||||
|
ids[i] = v[i].ID
|
||||||
|
}
|
||||||
|
return _c.AddPendingAuthSessionIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
// Mutation returns the UserMutation object of the builder.
|
// Mutation returns the UserMutation object of the builder.
|
||||||
func (_c *UserCreate) Mutation() *UserMutation {
|
func (_c *UserCreate) Mutation() *UserMutation {
|
||||||
return _c.mutation
|
return _c.mutation
|
||||||
@@ -510,6 +584,10 @@ func (_c *UserCreate) defaults() error {
|
|||||||
v := user.DefaultTotpEnabled
|
v := user.DefaultTotpEnabled
|
||||||
_c.mutation.SetTotpEnabled(v)
|
_c.mutation.SetTotpEnabled(v)
|
||||||
}
|
}
|
||||||
|
if _, ok := _c.mutation.SignupSource(); !ok {
|
||||||
|
v := user.DefaultSignupSource
|
||||||
|
_c.mutation.SetSignupSource(v)
|
||||||
|
}
|
||||||
if _, ok := _c.mutation.BalanceNotifyEnabled(); !ok {
|
if _, ok := _c.mutation.BalanceNotifyEnabled(); !ok {
|
||||||
v := user.DefaultBalanceNotifyEnabled
|
v := user.DefaultBalanceNotifyEnabled
|
||||||
_c.mutation.SetBalanceNotifyEnabled(v)
|
_c.mutation.SetBalanceNotifyEnabled(v)
|
||||||
@@ -589,6 +667,14 @@ func (_c *UserCreate) check() error {
|
|||||||
if _, ok := _c.mutation.TotpEnabled(); !ok {
|
if _, ok := _c.mutation.TotpEnabled(); !ok {
|
||||||
return &ValidationError{Name: "totp_enabled", err: errors.New(`ent: missing required field "User.totp_enabled"`)}
|
return &ValidationError{Name: "totp_enabled", err: errors.New(`ent: missing required field "User.totp_enabled"`)}
|
||||||
}
|
}
|
||||||
|
if _, ok := _c.mutation.SignupSource(); !ok {
|
||||||
|
return &ValidationError{Name: "signup_source", err: errors.New(`ent: missing required field "User.signup_source"`)}
|
||||||
|
}
|
||||||
|
if v, ok := _c.mutation.SignupSource(); ok {
|
||||||
|
if err := user.SignupSourceValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "signup_source", err: fmt.Errorf(`ent: validator failed for field "User.signup_source": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
if _, ok := _c.mutation.BalanceNotifyEnabled(); !ok {
|
if _, ok := _c.mutation.BalanceNotifyEnabled(); !ok {
|
||||||
return &ValidationError{Name: "balance_notify_enabled", err: errors.New(`ent: missing required field "User.balance_notify_enabled"`)}
|
return &ValidationError{Name: "balance_notify_enabled", err: errors.New(`ent: missing required field "User.balance_notify_enabled"`)}
|
||||||
}
|
}
|
||||||
@@ -684,6 +770,18 @@ func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
|
|||||||
_spec.SetField(user.FieldTotpEnabledAt, field.TypeTime, value)
|
_spec.SetField(user.FieldTotpEnabledAt, field.TypeTime, value)
|
||||||
_node.TotpEnabledAt = &value
|
_node.TotpEnabledAt = &value
|
||||||
}
|
}
|
||||||
|
if value, ok := _c.mutation.SignupSource(); ok {
|
||||||
|
_spec.SetField(user.FieldSignupSource, field.TypeString, value)
|
||||||
|
_node.SignupSource = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.LastLoginAt(); ok {
|
||||||
|
_spec.SetField(user.FieldLastLoginAt, field.TypeTime, value)
|
||||||
|
_node.LastLoginAt = &value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.LastActiveAt(); ok {
|
||||||
|
_spec.SetField(user.FieldLastActiveAt, field.TypeTime, value)
|
||||||
|
_node.LastActiveAt = &value
|
||||||
|
}
|
||||||
if value, ok := _c.mutation.BalanceNotifyEnabled(); ok {
|
if value, ok := _c.mutation.BalanceNotifyEnabled(); ok {
|
||||||
_spec.SetField(user.FieldBalanceNotifyEnabled, field.TypeBool, value)
|
_spec.SetField(user.FieldBalanceNotifyEnabled, field.TypeBool, value)
|
||||||
_node.BalanceNotifyEnabled = value
|
_node.BalanceNotifyEnabled = value
|
||||||
@@ -868,6 +966,38 @@ func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
|
|||||||
}
|
}
|
||||||
_spec.Edges = append(_spec.Edges, edge)
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
}
|
}
|
||||||
|
if nodes := _c.mutation.AuthIdentitiesIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: user.AuthIdentitiesTable,
|
||||||
|
Columns: []string{user.AuthIdentitiesColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
|
if nodes := _c.mutation.PendingAuthSessionsIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: user.PendingAuthSessionsTable,
|
||||||
|
Columns: []string{user.PendingAuthSessionsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(pendingauthsession.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
return _node, _spec
|
return _node, _spec
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1106,6 +1236,54 @@ func (u *UserUpsert) ClearTotpEnabledAt() *UserUpsert {
|
|||||||
return u
|
return u
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetSignupSource sets the "signup_source" field.
|
||||||
|
func (u *UserUpsert) SetSignupSource(v string) *UserUpsert {
|
||||||
|
u.Set(user.FieldSignupSource, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateSignupSource sets the "signup_source" field to the value that was provided on create.
|
||||||
|
func (u *UserUpsert) UpdateSignupSource() *UserUpsert {
|
||||||
|
u.SetExcluded(user.FieldSignupSource)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLastLoginAt sets the "last_login_at" field.
|
||||||
|
func (u *UserUpsert) SetLastLoginAt(v time.Time) *UserUpsert {
|
||||||
|
u.Set(user.FieldLastLoginAt, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateLastLoginAt sets the "last_login_at" field to the value that was provided on create.
|
||||||
|
func (u *UserUpsert) UpdateLastLoginAt() *UserUpsert {
|
||||||
|
u.SetExcluded(user.FieldLastLoginAt)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearLastLoginAt clears the value of the "last_login_at" field.
|
||||||
|
func (u *UserUpsert) ClearLastLoginAt() *UserUpsert {
|
||||||
|
u.SetNull(user.FieldLastLoginAt)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLastActiveAt sets the "last_active_at" field.
|
||||||
|
func (u *UserUpsert) SetLastActiveAt(v time.Time) *UserUpsert {
|
||||||
|
u.Set(user.FieldLastActiveAt, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateLastActiveAt sets the "last_active_at" field to the value that was provided on create.
|
||||||
|
func (u *UserUpsert) UpdateLastActiveAt() *UserUpsert {
|
||||||
|
u.SetExcluded(user.FieldLastActiveAt)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearLastActiveAt clears the value of the "last_active_at" field.
|
||||||
|
func (u *UserUpsert) ClearLastActiveAt() *UserUpsert {
|
||||||
|
u.SetNull(user.FieldLastActiveAt)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
// SetBalanceNotifyEnabled sets the "balance_notify_enabled" field.
|
// SetBalanceNotifyEnabled sets the "balance_notify_enabled" field.
|
||||||
func (u *UserUpsert) SetBalanceNotifyEnabled(v bool) *UserUpsert {
|
func (u *UserUpsert) SetBalanceNotifyEnabled(v bool) *UserUpsert {
|
||||||
u.Set(user.FieldBalanceNotifyEnabled, v)
|
u.Set(user.FieldBalanceNotifyEnabled, v)
|
||||||
@@ -1446,6 +1624,62 @@ func (u *UserUpsertOne) ClearTotpEnabledAt() *UserUpsertOne {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetSignupSource sets the "signup_source" field.
|
||||||
|
func (u *UserUpsertOne) SetSignupSource(v string) *UserUpsertOne {
|
||||||
|
return u.Update(func(s *UserUpsert) {
|
||||||
|
s.SetSignupSource(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateSignupSource sets the "signup_source" field to the value that was provided on create.
|
||||||
|
func (u *UserUpsertOne) UpdateSignupSource() *UserUpsertOne {
|
||||||
|
return u.Update(func(s *UserUpsert) {
|
||||||
|
s.UpdateSignupSource()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLastLoginAt sets the "last_login_at" field.
|
||||||
|
func (u *UserUpsertOne) SetLastLoginAt(v time.Time) *UserUpsertOne {
|
||||||
|
return u.Update(func(s *UserUpsert) {
|
||||||
|
s.SetLastLoginAt(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateLastLoginAt sets the "last_login_at" field to the value that was provided on create.
|
||||||
|
func (u *UserUpsertOne) UpdateLastLoginAt() *UserUpsertOne {
|
||||||
|
return u.Update(func(s *UserUpsert) {
|
||||||
|
s.UpdateLastLoginAt()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearLastLoginAt clears the value of the "last_login_at" field.
|
||||||
|
func (u *UserUpsertOne) ClearLastLoginAt() *UserUpsertOne {
|
||||||
|
return u.Update(func(s *UserUpsert) {
|
||||||
|
s.ClearLastLoginAt()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLastActiveAt sets the "last_active_at" field.
|
||||||
|
func (u *UserUpsertOne) SetLastActiveAt(v time.Time) *UserUpsertOne {
|
||||||
|
return u.Update(func(s *UserUpsert) {
|
||||||
|
s.SetLastActiveAt(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateLastActiveAt sets the "last_active_at" field to the value that was provided on create.
|
||||||
|
func (u *UserUpsertOne) UpdateLastActiveAt() *UserUpsertOne {
|
||||||
|
return u.Update(func(s *UserUpsert) {
|
||||||
|
s.UpdateLastActiveAt()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearLastActiveAt clears the value of the "last_active_at" field.
|
||||||
|
func (u *UserUpsertOne) ClearLastActiveAt() *UserUpsertOne {
|
||||||
|
return u.Update(func(s *UserUpsert) {
|
||||||
|
s.ClearLastActiveAt()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// SetBalanceNotifyEnabled sets the "balance_notify_enabled" field.
|
// SetBalanceNotifyEnabled sets the "balance_notify_enabled" field.
|
||||||
func (u *UserUpsertOne) SetBalanceNotifyEnabled(v bool) *UserUpsertOne {
|
func (u *UserUpsertOne) SetBalanceNotifyEnabled(v bool) *UserUpsertOne {
|
||||||
return u.Update(func(s *UserUpsert) {
|
return u.Update(func(s *UserUpsert) {
|
||||||
@@ -1965,6 +2199,62 @@ func (u *UserUpsertBulk) ClearTotpEnabledAt() *UserUpsertBulk {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetSignupSource sets the "signup_source" field.
|
||||||
|
func (u *UserUpsertBulk) SetSignupSource(v string) *UserUpsertBulk {
|
||||||
|
return u.Update(func(s *UserUpsert) {
|
||||||
|
s.SetSignupSource(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateSignupSource sets the "signup_source" field to the value that was provided on create.
|
||||||
|
func (u *UserUpsertBulk) UpdateSignupSource() *UserUpsertBulk {
|
||||||
|
return u.Update(func(s *UserUpsert) {
|
||||||
|
s.UpdateSignupSource()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLastLoginAt sets the "last_login_at" field.
|
||||||
|
func (u *UserUpsertBulk) SetLastLoginAt(v time.Time) *UserUpsertBulk {
|
||||||
|
return u.Update(func(s *UserUpsert) {
|
||||||
|
s.SetLastLoginAt(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateLastLoginAt sets the "last_login_at" field to the value that was provided on create.
|
||||||
|
func (u *UserUpsertBulk) UpdateLastLoginAt() *UserUpsertBulk {
|
||||||
|
return u.Update(func(s *UserUpsert) {
|
||||||
|
s.UpdateLastLoginAt()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearLastLoginAt clears the value of the "last_login_at" field.
|
||||||
|
func (u *UserUpsertBulk) ClearLastLoginAt() *UserUpsertBulk {
|
||||||
|
return u.Update(func(s *UserUpsert) {
|
||||||
|
s.ClearLastLoginAt()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLastActiveAt sets the "last_active_at" field.
|
||||||
|
func (u *UserUpsertBulk) SetLastActiveAt(v time.Time) *UserUpsertBulk {
|
||||||
|
return u.Update(func(s *UserUpsert) {
|
||||||
|
s.SetLastActiveAt(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateLastActiveAt sets the "last_active_at" field to the value that was provided on create.
|
||||||
|
func (u *UserUpsertBulk) UpdateLastActiveAt() *UserUpsertBulk {
|
||||||
|
return u.Update(func(s *UserUpsert) {
|
||||||
|
s.UpdateLastActiveAt()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearLastActiveAt clears the value of the "last_active_at" field.
|
||||||
|
func (u *UserUpsertBulk) ClearLastActiveAt() *UserUpsertBulk {
|
||||||
|
return u.Update(func(s *UserUpsert) {
|
||||||
|
s.ClearLastActiveAt()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// SetBalanceNotifyEnabled sets the "balance_notify_enabled" field.
|
// SetBalanceNotifyEnabled sets the "balance_notify_enabled" field.
|
||||||
func (u *UserUpsertBulk) SetBalanceNotifyEnabled(v bool) *UserUpsertBulk {
|
func (u *UserUpsertBulk) SetBalanceNotifyEnabled(v bool) *UserUpsertBulk {
|
||||||
return u.Update(func(s *UserUpsert) {
|
return u.Update(func(s *UserUpsert) {
|
||||||
|
|||||||
+154
-1
@@ -15,8 +15,10 @@ import (
|
|||||||
"entgo.io/ent/schema/field"
|
"entgo.io/ent/schema/field"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/announcementread"
|
"github.com/Wei-Shaw/sub2api/ent/announcementread"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/apikey"
|
"github.com/Wei-Shaw/sub2api/ent/apikey"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/authidentity"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/group"
|
"github.com/Wei-Shaw/sub2api/ent/group"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/paymentorder"
|
"github.com/Wei-Shaw/sub2api/ent/paymentorder"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/pendingauthsession"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/predicate"
|
"github.com/Wei-Shaw/sub2api/ent/predicate"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
|
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
|
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
|
||||||
@@ -44,6 +46,8 @@ type UserQuery struct {
|
|||||||
withAttributeValues *UserAttributeValueQuery
|
withAttributeValues *UserAttributeValueQuery
|
||||||
withPromoCodeUsages *PromoCodeUsageQuery
|
withPromoCodeUsages *PromoCodeUsageQuery
|
||||||
withPaymentOrders *PaymentOrderQuery
|
withPaymentOrders *PaymentOrderQuery
|
||||||
|
withAuthIdentities *AuthIdentityQuery
|
||||||
|
withPendingAuthSessions *PendingAuthSessionQuery
|
||||||
withUserAllowedGroups *UserAllowedGroupQuery
|
withUserAllowedGroups *UserAllowedGroupQuery
|
||||||
modifiers []func(*sql.Selector)
|
modifiers []func(*sql.Selector)
|
||||||
// intermediate query (i.e. traversal path).
|
// intermediate query (i.e. traversal path).
|
||||||
@@ -302,6 +306,50 @@ func (_q *UserQuery) QueryPaymentOrders() *PaymentOrderQuery {
|
|||||||
return query
|
return query
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QueryAuthIdentities chains the current query on the "auth_identities" edge.
|
||||||
|
func (_q *UserQuery) QueryAuthIdentities() *AuthIdentityQuery {
|
||||||
|
query := (&AuthIdentityClient{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(authidentity.Table, authidentity.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, user.AuthIdentitiesTable, user.AuthIdentitiesColumn),
|
||||||
|
)
|
||||||
|
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||||
|
return fromU, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryPendingAuthSessions chains the current query on the "pending_auth_sessions" edge.
|
||||||
|
func (_q *UserQuery) QueryPendingAuthSessions() *PendingAuthSessionQuery {
|
||||||
|
query := (&PendingAuthSessionClient{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(pendingauthsession.Table, pendingauthsession.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, user.PendingAuthSessionsTable, user.PendingAuthSessionsColumn),
|
||||||
|
)
|
||||||
|
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||||
|
return fromU, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
// QueryUserAllowedGroups chains the current query on the "user_allowed_groups" edge.
|
// QueryUserAllowedGroups chains the current query on the "user_allowed_groups" edge.
|
||||||
func (_q *UserQuery) QueryUserAllowedGroups() *UserAllowedGroupQuery {
|
func (_q *UserQuery) QueryUserAllowedGroups() *UserAllowedGroupQuery {
|
||||||
query := (&UserAllowedGroupClient{config: _q.config}).Query()
|
query := (&UserAllowedGroupClient{config: _q.config}).Query()
|
||||||
@@ -526,6 +574,8 @@ func (_q *UserQuery) Clone() *UserQuery {
|
|||||||
withAttributeValues: _q.withAttributeValues.Clone(),
|
withAttributeValues: _q.withAttributeValues.Clone(),
|
||||||
withPromoCodeUsages: _q.withPromoCodeUsages.Clone(),
|
withPromoCodeUsages: _q.withPromoCodeUsages.Clone(),
|
||||||
withPaymentOrders: _q.withPaymentOrders.Clone(),
|
withPaymentOrders: _q.withPaymentOrders.Clone(),
|
||||||
|
withAuthIdentities: _q.withAuthIdentities.Clone(),
|
||||||
|
withPendingAuthSessions: _q.withPendingAuthSessions.Clone(),
|
||||||
withUserAllowedGroups: _q.withUserAllowedGroups.Clone(),
|
withUserAllowedGroups: _q.withUserAllowedGroups.Clone(),
|
||||||
// clone intermediate query.
|
// clone intermediate query.
|
||||||
sql: _q.sql.Clone(),
|
sql: _q.sql.Clone(),
|
||||||
@@ -643,6 +693,28 @@ func (_q *UserQuery) WithPaymentOrders(opts ...func(*PaymentOrderQuery)) *UserQu
|
|||||||
return _q
|
return _q
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithAuthIdentities tells the query-builder to eager-load the nodes that are connected to
|
||||||
|
// the "auth_identities" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (_q *UserQuery) WithAuthIdentities(opts ...func(*AuthIdentityQuery)) *UserQuery {
|
||||||
|
query := (&AuthIdentityClient{config: _q.config}).Query()
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
_q.withAuthIdentities = query
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithPendingAuthSessions tells the query-builder to eager-load the nodes that are connected to
|
||||||
|
// the "pending_auth_sessions" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (_q *UserQuery) WithPendingAuthSessions(opts ...func(*PendingAuthSessionQuery)) *UserQuery {
|
||||||
|
query := (&PendingAuthSessionClient{config: _q.config}).Query()
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
_q.withPendingAuthSessions = query
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
// WithUserAllowedGroups tells the query-builder to eager-load the nodes that are connected to
|
// 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.
|
// 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 {
|
func (_q *UserQuery) WithUserAllowedGroups(opts ...func(*UserAllowedGroupQuery)) *UserQuery {
|
||||||
@@ -732,7 +804,7 @@ func (_q *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e
|
|||||||
var (
|
var (
|
||||||
nodes = []*User{}
|
nodes = []*User{}
|
||||||
_spec = _q.querySpec()
|
_spec = _q.querySpec()
|
||||||
loadedTypes = [11]bool{
|
loadedTypes = [13]bool{
|
||||||
_q.withAPIKeys != nil,
|
_q.withAPIKeys != nil,
|
||||||
_q.withRedeemCodes != nil,
|
_q.withRedeemCodes != nil,
|
||||||
_q.withSubscriptions != nil,
|
_q.withSubscriptions != nil,
|
||||||
@@ -743,6 +815,8 @@ func (_q *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e
|
|||||||
_q.withAttributeValues != nil,
|
_q.withAttributeValues != nil,
|
||||||
_q.withPromoCodeUsages != nil,
|
_q.withPromoCodeUsages != nil,
|
||||||
_q.withPaymentOrders != nil,
|
_q.withPaymentOrders != nil,
|
||||||
|
_q.withAuthIdentities != nil,
|
||||||
|
_q.withPendingAuthSessions != nil,
|
||||||
_q.withUserAllowedGroups != nil,
|
_q.withUserAllowedGroups != nil,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -839,6 +913,22 @@ func (_q *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if query := _q.withAuthIdentities; query != nil {
|
||||||
|
if err := _q.loadAuthIdentities(ctx, query, nodes,
|
||||||
|
func(n *User) { n.Edges.AuthIdentities = []*AuthIdentity{} },
|
||||||
|
func(n *User, e *AuthIdentity) { n.Edges.AuthIdentities = append(n.Edges.AuthIdentities, e) }); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if query := _q.withPendingAuthSessions; query != nil {
|
||||||
|
if err := _q.loadPendingAuthSessions(ctx, query, nodes,
|
||||||
|
func(n *User) { n.Edges.PendingAuthSessions = []*PendingAuthSession{} },
|
||||||
|
func(n *User, e *PendingAuthSession) {
|
||||||
|
n.Edges.PendingAuthSessions = append(n.Edges.PendingAuthSessions, e)
|
||||||
|
}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
if query := _q.withUserAllowedGroups; query != nil {
|
if query := _q.withUserAllowedGroups; query != nil {
|
||||||
if err := _q.loadUserAllowedGroups(ctx, query, nodes,
|
if err := _q.loadUserAllowedGroups(ctx, query, nodes,
|
||||||
func(n *User) { n.Edges.UserAllowedGroups = []*UserAllowedGroup{} },
|
func(n *User) { n.Edges.UserAllowedGroups = []*UserAllowedGroup{} },
|
||||||
@@ -1186,6 +1276,69 @@ func (_q *UserQuery) loadPaymentOrders(ctx context.Context, query *PaymentOrderQ
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
func (_q *UserQuery) loadAuthIdentities(ctx context.Context, query *AuthIdentityQuery, nodes []*User, init func(*User), assign func(*User, *AuthIdentity)) 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(authidentity.FieldUserID)
|
||||||
|
}
|
||||||
|
query.Where(predicate.AuthIdentity(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.InValues(s.C(user.AuthIdentitiesColumn), 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) loadPendingAuthSessions(ctx context.Context, query *PendingAuthSessionQuery, nodes []*User, init func(*User), assign func(*User, *PendingAuthSession)) 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(pendingauthsession.FieldTargetUserID)
|
||||||
|
}
|
||||||
|
query.Where(predicate.PendingAuthSession(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.InValues(s.C(user.PendingAuthSessionsColumn), fks...))
|
||||||
|
}))
|
||||||
|
neighbors, err := query.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, n := range neighbors {
|
||||||
|
fk := n.TargetUserID
|
||||||
|
if fk == nil {
|
||||||
|
return fmt.Errorf(`foreign-key "target_user_id" is nil for node %v`, n.ID)
|
||||||
|
}
|
||||||
|
node, ok := nodeids[*fk]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(`unexpected referenced foreign-key "target_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 {
|
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))
|
fks := make([]driver.Value, 0, len(nodes))
|
||||||
nodeids := make(map[int64]*User)
|
nodeids := make(map[int64]*User)
|
||||||
|
|||||||
@@ -13,8 +13,10 @@ import (
|
|||||||
"entgo.io/ent/schema/field"
|
"entgo.io/ent/schema/field"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/announcementread"
|
"github.com/Wei-Shaw/sub2api/ent/announcementread"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/apikey"
|
"github.com/Wei-Shaw/sub2api/ent/apikey"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/authidentity"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/group"
|
"github.com/Wei-Shaw/sub2api/ent/group"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/paymentorder"
|
"github.com/Wei-Shaw/sub2api/ent/paymentorder"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/pendingauthsession"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/predicate"
|
"github.com/Wei-Shaw/sub2api/ent/predicate"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
|
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
|
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
|
||||||
@@ -243,6 +245,60 @@ func (_u *UserUpdate) ClearTotpEnabledAt() *UserUpdate {
|
|||||||
return _u
|
return _u
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetSignupSource sets the "signup_source" field.
|
||||||
|
func (_u *UserUpdate) SetSignupSource(v string) *UserUpdate {
|
||||||
|
_u.mutation.SetSignupSource(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableSignupSource sets the "signup_source" field if the given value is not nil.
|
||||||
|
func (_u *UserUpdate) SetNillableSignupSource(v *string) *UserUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetSignupSource(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLastLoginAt sets the "last_login_at" field.
|
||||||
|
func (_u *UserUpdate) SetLastLoginAt(v time.Time) *UserUpdate {
|
||||||
|
_u.mutation.SetLastLoginAt(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableLastLoginAt sets the "last_login_at" field if the given value is not nil.
|
||||||
|
func (_u *UserUpdate) SetNillableLastLoginAt(v *time.Time) *UserUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetLastLoginAt(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearLastLoginAt clears the value of the "last_login_at" field.
|
||||||
|
func (_u *UserUpdate) ClearLastLoginAt() *UserUpdate {
|
||||||
|
_u.mutation.ClearLastLoginAt()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLastActiveAt sets the "last_active_at" field.
|
||||||
|
func (_u *UserUpdate) SetLastActiveAt(v time.Time) *UserUpdate {
|
||||||
|
_u.mutation.SetLastActiveAt(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableLastActiveAt sets the "last_active_at" field if the given value is not nil.
|
||||||
|
func (_u *UserUpdate) SetNillableLastActiveAt(v *time.Time) *UserUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetLastActiveAt(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearLastActiveAt clears the value of the "last_active_at" field.
|
||||||
|
func (_u *UserUpdate) ClearLastActiveAt() *UserUpdate {
|
||||||
|
_u.mutation.ClearLastActiveAt()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
// SetBalanceNotifyEnabled sets the "balance_notify_enabled" field.
|
// SetBalanceNotifyEnabled sets the "balance_notify_enabled" field.
|
||||||
func (_u *UserUpdate) SetBalanceNotifyEnabled(v bool) *UserUpdate {
|
func (_u *UserUpdate) SetBalanceNotifyEnabled(v bool) *UserUpdate {
|
||||||
_u.mutation.SetBalanceNotifyEnabled(v)
|
_u.mutation.SetBalanceNotifyEnabled(v)
|
||||||
@@ -483,6 +539,36 @@ func (_u *UserUpdate) AddPaymentOrders(v ...*PaymentOrder) *UserUpdate {
|
|||||||
return _u.AddPaymentOrderIDs(ids...)
|
return _u.AddPaymentOrderIDs(ids...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddAuthIdentityIDs adds the "auth_identities" edge to the AuthIdentity entity by IDs.
|
||||||
|
func (_u *UserUpdate) AddAuthIdentityIDs(ids ...int64) *UserUpdate {
|
||||||
|
_u.mutation.AddAuthIdentityIDs(ids...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddAuthIdentities adds the "auth_identities" edges to the AuthIdentity entity.
|
||||||
|
func (_u *UserUpdate) AddAuthIdentities(v ...*AuthIdentity) *UserUpdate {
|
||||||
|
ids := make([]int64, len(v))
|
||||||
|
for i := range v {
|
||||||
|
ids[i] = v[i].ID
|
||||||
|
}
|
||||||
|
return _u.AddAuthIdentityIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPendingAuthSessionIDs adds the "pending_auth_sessions" edge to the PendingAuthSession entity by IDs.
|
||||||
|
func (_u *UserUpdate) AddPendingAuthSessionIDs(ids ...int64) *UserUpdate {
|
||||||
|
_u.mutation.AddPendingAuthSessionIDs(ids...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPendingAuthSessions adds the "pending_auth_sessions" edges to the PendingAuthSession entity.
|
||||||
|
func (_u *UserUpdate) AddPendingAuthSessions(v ...*PendingAuthSession) *UserUpdate {
|
||||||
|
ids := make([]int64, len(v))
|
||||||
|
for i := range v {
|
||||||
|
ids[i] = v[i].ID
|
||||||
|
}
|
||||||
|
return _u.AddPendingAuthSessionIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
// Mutation returns the UserMutation object of the builder.
|
// Mutation returns the UserMutation object of the builder.
|
||||||
func (_u *UserUpdate) Mutation() *UserMutation {
|
func (_u *UserUpdate) Mutation() *UserMutation {
|
||||||
return _u.mutation
|
return _u.mutation
|
||||||
@@ -698,6 +784,48 @@ func (_u *UserUpdate) RemovePaymentOrders(v ...*PaymentOrder) *UserUpdate {
|
|||||||
return _u.RemovePaymentOrderIDs(ids...)
|
return _u.RemovePaymentOrderIDs(ids...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClearAuthIdentities clears all "auth_identities" edges to the AuthIdentity entity.
|
||||||
|
func (_u *UserUpdate) ClearAuthIdentities() *UserUpdate {
|
||||||
|
_u.mutation.ClearAuthIdentities()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveAuthIdentityIDs removes the "auth_identities" edge to AuthIdentity entities by IDs.
|
||||||
|
func (_u *UserUpdate) RemoveAuthIdentityIDs(ids ...int64) *UserUpdate {
|
||||||
|
_u.mutation.RemoveAuthIdentityIDs(ids...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveAuthIdentities removes "auth_identities" edges to AuthIdentity entities.
|
||||||
|
func (_u *UserUpdate) RemoveAuthIdentities(v ...*AuthIdentity) *UserUpdate {
|
||||||
|
ids := make([]int64, len(v))
|
||||||
|
for i := range v {
|
||||||
|
ids[i] = v[i].ID
|
||||||
|
}
|
||||||
|
return _u.RemoveAuthIdentityIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearPendingAuthSessions clears all "pending_auth_sessions" edges to the PendingAuthSession entity.
|
||||||
|
func (_u *UserUpdate) ClearPendingAuthSessions() *UserUpdate {
|
||||||
|
_u.mutation.ClearPendingAuthSessions()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemovePendingAuthSessionIDs removes the "pending_auth_sessions" edge to PendingAuthSession entities by IDs.
|
||||||
|
func (_u *UserUpdate) RemovePendingAuthSessionIDs(ids ...int64) *UserUpdate {
|
||||||
|
_u.mutation.RemovePendingAuthSessionIDs(ids...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemovePendingAuthSessions removes "pending_auth_sessions" edges to PendingAuthSession entities.
|
||||||
|
func (_u *UserUpdate) RemovePendingAuthSessions(v ...*PendingAuthSession) *UserUpdate {
|
||||||
|
ids := make([]int64, len(v))
|
||||||
|
for i := range v {
|
||||||
|
ids[i] = v[i].ID
|
||||||
|
}
|
||||||
|
return _u.RemovePendingAuthSessionIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||||
func (_u *UserUpdate) Save(ctx context.Context) (int, error) {
|
func (_u *UserUpdate) Save(ctx context.Context) (int, error) {
|
||||||
if err := _u.defaults(); err != nil {
|
if err := _u.defaults(); err != nil {
|
||||||
@@ -767,6 +895,11 @@ func (_u *UserUpdate) check() error {
|
|||||||
return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "User.username": %w`, err)}
|
return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "User.username": %w`, err)}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if v, ok := _u.mutation.SignupSource(); ok {
|
||||||
|
if err := user.SignupSourceValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "signup_source", err: fmt.Errorf(`ent: validator failed for field "User.signup_source": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -836,6 +969,21 @@ func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|||||||
if _u.mutation.TotpEnabledAtCleared() {
|
if _u.mutation.TotpEnabledAtCleared() {
|
||||||
_spec.ClearField(user.FieldTotpEnabledAt, field.TypeTime)
|
_spec.ClearField(user.FieldTotpEnabledAt, field.TypeTime)
|
||||||
}
|
}
|
||||||
|
if value, ok := _u.mutation.SignupSource(); ok {
|
||||||
|
_spec.SetField(user.FieldSignupSource, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.LastLoginAt(); ok {
|
||||||
|
_spec.SetField(user.FieldLastLoginAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.LastLoginAtCleared() {
|
||||||
|
_spec.ClearField(user.FieldLastLoginAt, field.TypeTime)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.LastActiveAt(); ok {
|
||||||
|
_spec.SetField(user.FieldLastActiveAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.LastActiveAtCleared() {
|
||||||
|
_spec.ClearField(user.FieldLastActiveAt, field.TypeTime)
|
||||||
|
}
|
||||||
if value, ok := _u.mutation.BalanceNotifyEnabled(); ok {
|
if value, ok := _u.mutation.BalanceNotifyEnabled(); ok {
|
||||||
_spec.SetField(user.FieldBalanceNotifyEnabled, field.TypeBool, value)
|
_spec.SetField(user.FieldBalanceNotifyEnabled, field.TypeBool, value)
|
||||||
}
|
}
|
||||||
@@ -1322,6 +1470,96 @@ func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|||||||
}
|
}
|
||||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
}
|
}
|
||||||
|
if _u.mutation.AuthIdentitiesCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: user.AuthIdentitiesTable,
|
||||||
|
Columns: []string{user.AuthIdentitiesColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := _u.mutation.RemovedAuthIdentitiesIDs(); len(nodes) > 0 && !_u.mutation.AuthIdentitiesCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: user.AuthIdentitiesTable,
|
||||||
|
Columns: []string{user.AuthIdentitiesColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(authidentity.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.AuthIdentitiesIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: user.AuthIdentitiesTable,
|
||||||
|
Columns: []string{user.AuthIdentitiesColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if _u.mutation.PendingAuthSessionsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: user.PendingAuthSessionsTable,
|
||||||
|
Columns: []string{user.PendingAuthSessionsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(pendingauthsession.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := _u.mutation.RemovedPendingAuthSessionsIDs(); len(nodes) > 0 && !_u.mutation.PendingAuthSessionsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: user.PendingAuthSessionsTable,
|
||||||
|
Columns: []string{user.PendingAuthSessionsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(pendingauthsession.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.PendingAuthSessionsIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: user.PendingAuthSessionsTable,
|
||||||
|
Columns: []string{user.PendingAuthSessionsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(pendingauthsession.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 _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
err = &NotFoundError{user.Label}
|
err = &NotFoundError{user.Label}
|
||||||
@@ -1548,6 +1786,60 @@ func (_u *UserUpdateOne) ClearTotpEnabledAt() *UserUpdateOne {
|
|||||||
return _u
|
return _u
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetSignupSource sets the "signup_source" field.
|
||||||
|
func (_u *UserUpdateOne) SetSignupSource(v string) *UserUpdateOne {
|
||||||
|
_u.mutation.SetSignupSource(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableSignupSource sets the "signup_source" field if the given value is not nil.
|
||||||
|
func (_u *UserUpdateOne) SetNillableSignupSource(v *string) *UserUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetSignupSource(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLastLoginAt sets the "last_login_at" field.
|
||||||
|
func (_u *UserUpdateOne) SetLastLoginAt(v time.Time) *UserUpdateOne {
|
||||||
|
_u.mutation.SetLastLoginAt(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableLastLoginAt sets the "last_login_at" field if the given value is not nil.
|
||||||
|
func (_u *UserUpdateOne) SetNillableLastLoginAt(v *time.Time) *UserUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetLastLoginAt(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearLastLoginAt clears the value of the "last_login_at" field.
|
||||||
|
func (_u *UserUpdateOne) ClearLastLoginAt() *UserUpdateOne {
|
||||||
|
_u.mutation.ClearLastLoginAt()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLastActiveAt sets the "last_active_at" field.
|
||||||
|
func (_u *UserUpdateOne) SetLastActiveAt(v time.Time) *UserUpdateOne {
|
||||||
|
_u.mutation.SetLastActiveAt(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableLastActiveAt sets the "last_active_at" field if the given value is not nil.
|
||||||
|
func (_u *UserUpdateOne) SetNillableLastActiveAt(v *time.Time) *UserUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetLastActiveAt(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearLastActiveAt clears the value of the "last_active_at" field.
|
||||||
|
func (_u *UserUpdateOne) ClearLastActiveAt() *UserUpdateOne {
|
||||||
|
_u.mutation.ClearLastActiveAt()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
// SetBalanceNotifyEnabled sets the "balance_notify_enabled" field.
|
// SetBalanceNotifyEnabled sets the "balance_notify_enabled" field.
|
||||||
func (_u *UserUpdateOne) SetBalanceNotifyEnabled(v bool) *UserUpdateOne {
|
func (_u *UserUpdateOne) SetBalanceNotifyEnabled(v bool) *UserUpdateOne {
|
||||||
_u.mutation.SetBalanceNotifyEnabled(v)
|
_u.mutation.SetBalanceNotifyEnabled(v)
|
||||||
@@ -1788,6 +2080,36 @@ func (_u *UserUpdateOne) AddPaymentOrders(v ...*PaymentOrder) *UserUpdateOne {
|
|||||||
return _u.AddPaymentOrderIDs(ids...)
|
return _u.AddPaymentOrderIDs(ids...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddAuthIdentityIDs adds the "auth_identities" edge to the AuthIdentity entity by IDs.
|
||||||
|
func (_u *UserUpdateOne) AddAuthIdentityIDs(ids ...int64) *UserUpdateOne {
|
||||||
|
_u.mutation.AddAuthIdentityIDs(ids...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddAuthIdentities adds the "auth_identities" edges to the AuthIdentity entity.
|
||||||
|
func (_u *UserUpdateOne) AddAuthIdentities(v ...*AuthIdentity) *UserUpdateOne {
|
||||||
|
ids := make([]int64, len(v))
|
||||||
|
for i := range v {
|
||||||
|
ids[i] = v[i].ID
|
||||||
|
}
|
||||||
|
return _u.AddAuthIdentityIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPendingAuthSessionIDs adds the "pending_auth_sessions" edge to the PendingAuthSession entity by IDs.
|
||||||
|
func (_u *UserUpdateOne) AddPendingAuthSessionIDs(ids ...int64) *UserUpdateOne {
|
||||||
|
_u.mutation.AddPendingAuthSessionIDs(ids...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPendingAuthSessions adds the "pending_auth_sessions" edges to the PendingAuthSession entity.
|
||||||
|
func (_u *UserUpdateOne) AddPendingAuthSessions(v ...*PendingAuthSession) *UserUpdateOne {
|
||||||
|
ids := make([]int64, len(v))
|
||||||
|
for i := range v {
|
||||||
|
ids[i] = v[i].ID
|
||||||
|
}
|
||||||
|
return _u.AddPendingAuthSessionIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
// Mutation returns the UserMutation object of the builder.
|
// Mutation returns the UserMutation object of the builder.
|
||||||
func (_u *UserUpdateOne) Mutation() *UserMutation {
|
func (_u *UserUpdateOne) Mutation() *UserMutation {
|
||||||
return _u.mutation
|
return _u.mutation
|
||||||
@@ -2003,6 +2325,48 @@ func (_u *UserUpdateOne) RemovePaymentOrders(v ...*PaymentOrder) *UserUpdateOne
|
|||||||
return _u.RemovePaymentOrderIDs(ids...)
|
return _u.RemovePaymentOrderIDs(ids...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClearAuthIdentities clears all "auth_identities" edges to the AuthIdentity entity.
|
||||||
|
func (_u *UserUpdateOne) ClearAuthIdentities() *UserUpdateOne {
|
||||||
|
_u.mutation.ClearAuthIdentities()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveAuthIdentityIDs removes the "auth_identities" edge to AuthIdentity entities by IDs.
|
||||||
|
func (_u *UserUpdateOne) RemoveAuthIdentityIDs(ids ...int64) *UserUpdateOne {
|
||||||
|
_u.mutation.RemoveAuthIdentityIDs(ids...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveAuthIdentities removes "auth_identities" edges to AuthIdentity entities.
|
||||||
|
func (_u *UserUpdateOne) RemoveAuthIdentities(v ...*AuthIdentity) *UserUpdateOne {
|
||||||
|
ids := make([]int64, len(v))
|
||||||
|
for i := range v {
|
||||||
|
ids[i] = v[i].ID
|
||||||
|
}
|
||||||
|
return _u.RemoveAuthIdentityIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearPendingAuthSessions clears all "pending_auth_sessions" edges to the PendingAuthSession entity.
|
||||||
|
func (_u *UserUpdateOne) ClearPendingAuthSessions() *UserUpdateOne {
|
||||||
|
_u.mutation.ClearPendingAuthSessions()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemovePendingAuthSessionIDs removes the "pending_auth_sessions" edge to PendingAuthSession entities by IDs.
|
||||||
|
func (_u *UserUpdateOne) RemovePendingAuthSessionIDs(ids ...int64) *UserUpdateOne {
|
||||||
|
_u.mutation.RemovePendingAuthSessionIDs(ids...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemovePendingAuthSessions removes "pending_auth_sessions" edges to PendingAuthSession entities.
|
||||||
|
func (_u *UserUpdateOne) RemovePendingAuthSessions(v ...*PendingAuthSession) *UserUpdateOne {
|
||||||
|
ids := make([]int64, len(v))
|
||||||
|
for i := range v {
|
||||||
|
ids[i] = v[i].ID
|
||||||
|
}
|
||||||
|
return _u.RemovePendingAuthSessionIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
// Where appends a list predicates to the UserUpdate builder.
|
// Where appends a list predicates to the UserUpdate builder.
|
||||||
func (_u *UserUpdateOne) Where(ps ...predicate.User) *UserUpdateOne {
|
func (_u *UserUpdateOne) Where(ps ...predicate.User) *UserUpdateOne {
|
||||||
_u.mutation.Where(ps...)
|
_u.mutation.Where(ps...)
|
||||||
@@ -2085,6 +2449,11 @@ func (_u *UserUpdateOne) check() error {
|
|||||||
return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "User.username": %w`, err)}
|
return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "User.username": %w`, err)}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if v, ok := _u.mutation.SignupSource(); ok {
|
||||||
|
if err := user.SignupSourceValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "signup_source", err: fmt.Errorf(`ent: validator failed for field "User.signup_source": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2171,6 +2540,21 @@ func (_u *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
|
|||||||
if _u.mutation.TotpEnabledAtCleared() {
|
if _u.mutation.TotpEnabledAtCleared() {
|
||||||
_spec.ClearField(user.FieldTotpEnabledAt, field.TypeTime)
|
_spec.ClearField(user.FieldTotpEnabledAt, field.TypeTime)
|
||||||
}
|
}
|
||||||
|
if value, ok := _u.mutation.SignupSource(); ok {
|
||||||
|
_spec.SetField(user.FieldSignupSource, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.LastLoginAt(); ok {
|
||||||
|
_spec.SetField(user.FieldLastLoginAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.LastLoginAtCleared() {
|
||||||
|
_spec.ClearField(user.FieldLastLoginAt, field.TypeTime)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.LastActiveAt(); ok {
|
||||||
|
_spec.SetField(user.FieldLastActiveAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.LastActiveAtCleared() {
|
||||||
|
_spec.ClearField(user.FieldLastActiveAt, field.TypeTime)
|
||||||
|
}
|
||||||
if value, ok := _u.mutation.BalanceNotifyEnabled(); ok {
|
if value, ok := _u.mutation.BalanceNotifyEnabled(); ok {
|
||||||
_spec.SetField(user.FieldBalanceNotifyEnabled, field.TypeBool, value)
|
_spec.SetField(user.FieldBalanceNotifyEnabled, field.TypeBool, value)
|
||||||
}
|
}
|
||||||
@@ -2657,6 +3041,96 @@ func (_u *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
|
|||||||
}
|
}
|
||||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
}
|
}
|
||||||
|
if _u.mutation.AuthIdentitiesCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: user.AuthIdentitiesTable,
|
||||||
|
Columns: []string{user.AuthIdentitiesColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := _u.mutation.RemovedAuthIdentitiesIDs(); len(nodes) > 0 && !_u.mutation.AuthIdentitiesCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: user.AuthIdentitiesTable,
|
||||||
|
Columns: []string{user.AuthIdentitiesColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(authidentity.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.AuthIdentitiesIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: user.AuthIdentitiesTable,
|
||||||
|
Columns: []string{user.AuthIdentitiesColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if _u.mutation.PendingAuthSessionsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: user.PendingAuthSessionsTable,
|
||||||
|
Columns: []string{user.PendingAuthSessionsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(pendingauthsession.FieldID, field.TypeInt64),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := _u.mutation.RemovedPendingAuthSessionsIDs(); len(nodes) > 0 && !_u.mutation.PendingAuthSessionsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: user.PendingAuthSessionsTable,
|
||||||
|
Columns: []string{user.PendingAuthSessionsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(pendingauthsession.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.PendingAuthSessionsIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: user.PendingAuthSessionsTable,
|
||||||
|
Columns: []string{user.PendingAuthSessionsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(pendingauthsession.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}
|
_node = &User{config: _u.config}
|
||||||
_spec.Assign = _node.assignValues
|
_spec.Assign = _node.assignValues
|
||||||
_spec.ScanValues = _node.scanValues
|
_spec.ScanValues = _node.scanValues
|
||||||
|
|||||||
+9
-9
@@ -39,10 +39,11 @@ require (
|
|||||||
github.com/wechatpay-apiv3/wechatpay-go v0.2.21
|
github.com/wechatpay-apiv3/wechatpay-go v0.2.21
|
||||||
github.com/zeromicro/go-zero v1.9.4
|
github.com/zeromicro/go-zero v1.9.4
|
||||||
go.uber.org/zap v1.24.0
|
go.uber.org/zap v1.24.0
|
||||||
golang.org/x/crypto v0.48.0
|
golang.org/x/crypto v0.49.0
|
||||||
golang.org/x/net v0.49.0
|
golang.org/x/image v0.39.0
|
||||||
golang.org/x/sync v0.19.0
|
golang.org/x/net v0.52.0
|
||||||
golang.org/x/term v0.40.0
|
golang.org/x/sync v0.20.0
|
||||||
|
golang.org/x/term v0.41.0
|
||||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1
|
gopkg.in/natefinch/lumberjack.v2 v2.2.1
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
modernc.org/sqlite v1.44.3
|
modernc.org/sqlite v1.44.3
|
||||||
@@ -103,7 +104,6 @@ require (
|
|||||||
github.com/goccy/go-json v0.10.2 // indirect
|
github.com/goccy/go-json v0.10.2 // indirect
|
||||||
github.com/google/go-cmp v0.7.0 // indirect
|
github.com/google/go-cmp v0.7.0 // indirect
|
||||||
github.com/google/go-querystring v1.1.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/grpc-ecosystem/grpc-gateway/v2 v2.27.3 // indirect
|
||||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||||
github.com/hashicorp/hcl/v2 v2.18.1 // indirect
|
github.com/hashicorp/hcl/v2 v2.18.1 // indirect
|
||||||
@@ -172,10 +172,10 @@ require (
|
|||||||
go.uber.org/multierr v1.9.0 // indirect
|
go.uber.org/multierr v1.9.0 // indirect
|
||||||
golang.org/x/arch v0.3.0 // indirect
|
golang.org/x/arch v0.3.0 // indirect
|
||||||
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 // indirect
|
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 // indirect
|
||||||
golang.org/x/mod v0.32.0 // indirect
|
golang.org/x/mod v0.34.0 // indirect
|
||||||
golang.org/x/sys v0.41.0 // indirect
|
golang.org/x/sys v0.42.0 // indirect
|
||||||
golang.org/x/text v0.34.0 // indirect
|
golang.org/x/text v0.36.0 // indirect
|
||||||
golang.org/x/tools v0.41.0 // indirect
|
golang.org/x/tools v0.43.0 // indirect
|
||||||
google.golang.org/grpc v1.75.1 // indirect
|
google.golang.org/grpc v1.75.1 // indirect
|
||||||
google.golang.org/protobuf v1.36.10 // indirect
|
google.golang.org/protobuf v1.36.10 // indirect
|
||||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||||
|
|||||||
+18
-28
@@ -162,8 +162,6 @@ 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/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 h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs=
|
||||||
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
|
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 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
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=
|
github.com/google/wire v0.7.0 h1:JxUKI6+CVBgCO2WToKy/nQk0sS+amI9z9EjVmdaocj4=
|
||||||
@@ -183,8 +181,6 @@ github.com/icholy/digest v1.1.0 h1:HfGg9Irj7i+IX1o1QAmPfIBNu/Q5A5Tu3n/MED9k9H4=
|
|||||||
github.com/icholy/digest v1.1.0/go.mod h1:QNrsSGQ5v7v9cReDI0+eyjsXGUoRSUZQHeQ5C4XLa0Y=
|
github.com/icholy/digest v1.1.0/go.mod h1:QNrsSGQ5v7v9cReDI0+eyjsXGUoRSUZQHeQ5C4XLa0Y=
|
||||||
github.com/imroc/req/v3 v3.57.0 h1:LMTUjNRUybUkTPn8oJDq8Kg3JRBOBTcnDhKu7mzupKI=
|
github.com/imroc/req/v3 v3.57.0 h1:LMTUjNRUybUkTPn8oJDq8Kg3JRBOBTcnDhKu7mzupKI=
|
||||||
github.com/imroc/req/v3 v3.57.0/go.mod h1:JL62ey1nvSLq81HORNcosvlf7SxZStONNqOprg0Pz00=
|
github.com/imroc/req/v3 v3.57.0/go.mod h1:JL62ey1nvSLq81HORNcosvlf7SxZStONNqOprg0Pz00=
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
|
||||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
|
||||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
||||||
@@ -220,8 +216,6 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
|
|||||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
|
|
||||||
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
|
||||||
github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM=
|
github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM=
|
||||||
github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||||
github.com/mdelapenya/tlscert v0.2.0 h1:7H81W6Z/4weDvZBNOfQte5GpIMo0lGYEeWbkGp5LJHI=
|
github.com/mdelapenya/tlscert v0.2.0 h1:7H81W6Z/4weDvZBNOfQte5GpIMo0lGYEeWbkGp5LJHI=
|
||||||
@@ -255,8 +249,6 @@ github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
|
|||||||
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
|
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
|
||||||
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
|
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
|
||||||
github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
|
github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
|
||||||
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
|
||||||
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
|
||||||
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
|
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
|
||||||
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
|
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
|
||||||
github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=
|
github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=
|
||||||
@@ -286,8 +278,6 @@ github.com/refraction-networking/utls v1.8.2 h1:j4Q1gJj0xngdeH+Ox/qND11aEfhpgoEv
|
|||||||
github.com/refraction-networking/utls v1.8.2/go.mod h1:jkSOEkLqn+S/jtpEHPOsVv/4V4EVnelwbMQl4vCWXAM=
|
github.com/refraction-networking/utls v1.8.2/go.mod h1:jkSOEkLqn+S/jtpEHPOsVv/4V4EVnelwbMQl4vCWXAM=
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
|
||||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
|
||||||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
||||||
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
||||||
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
||||||
@@ -320,8 +310,6 @@ github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
|
|||||||
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
|
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
|
||||||
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
|
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
|
||||||
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
|
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
|
||||||
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
|
|
||||||
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
|
|
||||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ=
|
github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ=
|
||||||
@@ -413,16 +401,18 @@ go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
|
|||||||
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||||
golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k=
|
golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k=
|
||||||
golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||||
golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts=
|
golang.org/x/crypto v0.49.0 h1:+Ng2ULVvLHnJ/ZFEq4KdcDd/cfjrrjjNSXNzxg0Y4U4=
|
||||||
golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos=
|
golang.org/x/crypto v0.49.0/go.mod h1:ErX4dUh2UM+CFYiXZRTcMpEcN8b/1gxEuv3nODoYtCA=
|
||||||
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 h1:mgKeJMpvi0yx/sU5GsxQ7p6s2wtOnGAHZWCHUM4KGzY=
|
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 h1:mgKeJMpvi0yx/sU5GsxQ7p6s2wtOnGAHZWCHUM4KGzY=
|
||||||
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546/go.mod h1:j/pmGrbnkbPtQfxEe5D0VQhZC6qKbfKifgD0oM7sR70=
|
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546/go.mod h1:j/pmGrbnkbPtQfxEe5D0VQhZC6qKbfKifgD0oM7sR70=
|
||||||
golang.org/x/mod v0.32.0 h1:9F4d3PHLljb6x//jOyokMv3eX+YDeepZSEo3mFJy93c=
|
golang.org/x/image v0.39.0 h1:skVYidAEVKgn8lZ602XO75asgXBgLj9G/FE3RbuPFww=
|
||||||
golang.org/x/mod v0.32.0/go.mod h1:SgipZ/3h2Ci89DlEtEXWUk/HteuRin+HHhN+WbNhguU=
|
golang.org/x/image v0.39.0/go.mod h1:sIbmppfU+xFLPIG0FoVUTvyBMmgng1/XAMhQ2ft0hpA=
|
||||||
golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o=
|
golang.org/x/mod v0.34.0 h1:xIHgNUUnW6sYkcM5Jleh05DvLOtwc6RitGHbDk4akRI=
|
||||||
golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8=
|
golang.org/x/mod v0.34.0/go.mod h1:ykgH52iCZe79kzLLMhyCUzhMci+nQj+0XkbXpNYtVjY=
|
||||||
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
|
golang.org/x/net v0.52.0 h1:He/TN1l0e4mmR3QqHMT2Xab3Aj3L9qjbhRm78/6jrW0=
|
||||||
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
golang.org/x/net v0.52.0/go.mod h1:R1MAz7uMZxVMualyPXb+VaqGSa3LIaUqk0eEt3w36Sw=
|
||||||
|
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
|
||||||
|
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
@@ -432,16 +422,16 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
|
|||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
|
golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=
|
||||||
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||||
golang.org/x/term v0.40.0 h1:36e4zGLqU4yhjlmxEaagx2KuYbJq3EwY8K943ZsHcvg=
|
golang.org/x/term v0.41.0 h1:QCgPso/Q3RTJx2Th4bDLqML4W6iJiaXFq2/ftQF13YU=
|
||||||
golang.org/x/term v0.40.0/go.mod h1:w2P8uVp06p2iyKKuvXIm7N/y0UCRt3UfJTfZ7oOpglM=
|
golang.org/x/term v0.41.0/go.mod h1:3pfBgksrReYfZ5lvYM0kSO0LIkAl4Yl2bXOkKP7Ec2A=
|
||||||
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
|
golang.org/x/text v0.36.0 h1:JfKh3XmcRPqZPKevfXVpI1wXPTqbkE5f7JA92a55Yxg=
|
||||||
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
|
golang.org/x/text v0.36.0/go.mod h1:NIdBknypM8iqVmPiuco0Dh6P5Jcdk8lJL0CUebqK164=
|
||||||
golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
|
golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
|
||||||
golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
|
golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
|
||||||
golang.org/x/tools v0.41.0 h1:a9b8iMweWG+S0OBnlU36rzLp20z1Rp10w+IY2czHTQc=
|
golang.org/x/tools v0.43.0 h1:12BdW9CeB3Z+J/I/wj34VMl8X+fEXBxVR90JeMX5E7s=
|
||||||
golang.org/x/tools v0.41.0/go.mod h1:XSY6eDqxVNiYgezAVqqCeihT4j1U2CCsqvH3WhQpnlg=
|
golang.org/x/tools v0.43.0/go.mod h1:uHkMso649BX2cZK6+RpuIPXS3ho2hZo4FVwfoy1vIk0=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 h1:wpZ8pe2x1Q3f2KyT5f8oP/fa9rHAKgFPr/HZdNuS+PQ=
|
google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 h1:wpZ8pe2x1Q3f2KyT5f8oP/fa9rHAKgFPr/HZdNuS+PQ=
|
||||||
google.golang.org/genproto/googleapis/api v0.0.0-20250929231259-57b25ae835d4 h1:8XJ4pajGwOlasW+L13MnEGA8W4115jJySQtVfS2/IBU=
|
google.golang.org/genproto/googleapis/api v0.0.0-20250929231259-57b25ae835d4 h1:8XJ4pajGwOlasW+L13MnEGA8W4115jJySQtVfS2/IBU=
|
||||||
|
|||||||
@@ -1613,6 +1613,9 @@ func (c *Config) Validate() error {
|
|||||||
return fmt.Errorf("security.csp.policy is required when CSP is enabled")
|
return fmt.Errorf("security.csp.policy is required when CSP is enabled")
|
||||||
}
|
}
|
||||||
if c.LinuxDo.Enabled {
|
if c.LinuxDo.Enabled {
|
||||||
|
if !c.LinuxDo.UsePKCE {
|
||||||
|
return fmt.Errorf("linuxdo_connect.use_pkce must be true when linuxdo_connect.enabled=true")
|
||||||
|
}
|
||||||
if strings.TrimSpace(c.LinuxDo.ClientID) == "" {
|
if strings.TrimSpace(c.LinuxDo.ClientID) == "" {
|
||||||
return fmt.Errorf("linuxdo_connect.client_id is required when linuxdo_connect.enabled=true")
|
return fmt.Errorf("linuxdo_connect.client_id is required when linuxdo_connect.enabled=true")
|
||||||
}
|
}
|
||||||
@@ -1634,9 +1637,6 @@ func (c *Config) Validate() error {
|
|||||||
default:
|
default:
|
||||||
return fmt.Errorf("linuxdo_connect.token_auth_method must be one of: client_secret_post/client_secret_basic/none")
|
return fmt.Errorf("linuxdo_connect.token_auth_method must be one of: client_secret_post/client_secret_basic/none")
|
||||||
}
|
}
|
||||||
if method == "none" && !c.LinuxDo.UsePKCE {
|
|
||||||
return fmt.Errorf("linuxdo_connect.use_pkce must be true when linuxdo_connect.token_auth_method=none")
|
|
||||||
}
|
|
||||||
if (method == "" || method == "client_secret_post" || method == "client_secret_basic") &&
|
if (method == "" || method == "client_secret_post" || method == "client_secret_basic") &&
|
||||||
strings.TrimSpace(c.LinuxDo.ClientSecret) == "" {
|
strings.TrimSpace(c.LinuxDo.ClientSecret) == "" {
|
||||||
return fmt.Errorf("linuxdo_connect.client_secret is required when linuxdo_connect.enabled=true and token_auth_method is client_secret_post/client_secret_basic")
|
return fmt.Errorf("linuxdo_connect.client_secret is required when linuxdo_connect.enabled=true and token_auth_method is client_secret_post/client_secret_basic")
|
||||||
@@ -1668,6 +1668,12 @@ func (c *Config) Validate() error {
|
|||||||
warnIfInsecureURL("linuxdo_connect.frontend_redirect_url", c.LinuxDo.FrontendRedirectURL)
|
warnIfInsecureURL("linuxdo_connect.frontend_redirect_url", c.LinuxDo.FrontendRedirectURL)
|
||||||
}
|
}
|
||||||
if c.OIDC.Enabled {
|
if c.OIDC.Enabled {
|
||||||
|
if !c.OIDC.UsePKCE {
|
||||||
|
return fmt.Errorf("oidc_connect.use_pkce must be true when oidc_connect.enabled=true")
|
||||||
|
}
|
||||||
|
if !c.OIDC.ValidateIDToken {
|
||||||
|
return fmt.Errorf("oidc_connect.validate_id_token must be true when oidc_connect.enabled=true")
|
||||||
|
}
|
||||||
if strings.TrimSpace(c.OIDC.ClientID) == "" {
|
if strings.TrimSpace(c.OIDC.ClientID) == "" {
|
||||||
return fmt.Errorf("oidc_connect.client_id is required when oidc_connect.enabled=true")
|
return fmt.Errorf("oidc_connect.client_id is required when oidc_connect.enabled=true")
|
||||||
}
|
}
|
||||||
@@ -1690,9 +1696,6 @@ func (c *Config) Validate() error {
|
|||||||
default:
|
default:
|
||||||
return fmt.Errorf("oidc_connect.token_auth_method must be one of: client_secret_post/client_secret_basic/none")
|
return fmt.Errorf("oidc_connect.token_auth_method must be one of: client_secret_post/client_secret_basic/none")
|
||||||
}
|
}
|
||||||
if method == "none" && !c.OIDC.UsePKCE {
|
|
||||||
return fmt.Errorf("oidc_connect.use_pkce must be true when oidc_connect.token_auth_method=none")
|
|
||||||
}
|
|
||||||
if (method == "" || method == "client_secret_post" || method == "client_secret_basic") &&
|
if (method == "" || method == "client_secret_post" || method == "client_secret_basic") &&
|
||||||
strings.TrimSpace(c.OIDC.ClientSecret) == "" {
|
strings.TrimSpace(c.OIDC.ClientSecret) == "" {
|
||||||
return fmt.Errorf("oidc_connect.client_secret is required when oidc_connect.enabled=true and token_auth_method is client_secret_post/client_secret_basic")
|
return fmt.Errorf("oidc_connect.client_secret is required when oidc_connect.enabled=true and token_auth_method is client_secret_post/client_secret_basic")
|
||||||
|
|||||||
@@ -334,7 +334,7 @@ func TestValidateLinuxDoFrontendRedirectURL(t *testing.T) {
|
|||||||
cfg.LinuxDo.ClientSecret = "test-secret"
|
cfg.LinuxDo.ClientSecret = "test-secret"
|
||||||
cfg.LinuxDo.RedirectURL = "https://example.com/api/v1/auth/oauth/linuxdo/callback"
|
cfg.LinuxDo.RedirectURL = "https://example.com/api/v1/auth/oauth/linuxdo/callback"
|
||||||
cfg.LinuxDo.TokenAuthMethod = "client_secret_post"
|
cfg.LinuxDo.TokenAuthMethod = "client_secret_post"
|
||||||
cfg.LinuxDo.UsePKCE = false
|
cfg.LinuxDo.UsePKCE = true
|
||||||
|
|
||||||
cfg.LinuxDo.FrontendRedirectURL = "javascript:alert(1)"
|
cfg.LinuxDo.FrontendRedirectURL = "javascript:alert(1)"
|
||||||
err = cfg.Validate()
|
err = cfg.Validate()
|
||||||
@@ -389,6 +389,7 @@ func TestValidateOIDCScopesMustContainOpenID(t *testing.T) {
|
|||||||
cfg.OIDC.RedirectURL = "https://example.com/api/v1/auth/oauth/oidc/callback"
|
cfg.OIDC.RedirectURL = "https://example.com/api/v1/auth/oauth/oidc/callback"
|
||||||
cfg.OIDC.FrontendRedirectURL = "/auth/oidc/callback"
|
cfg.OIDC.FrontendRedirectURL = "/auth/oidc/callback"
|
||||||
cfg.OIDC.Scopes = "profile email"
|
cfg.OIDC.Scopes = "profile email"
|
||||||
|
cfg.OIDC.UsePKCE = true
|
||||||
|
|
||||||
err = cfg.Validate()
|
err = cfg.Validate()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -418,6 +419,7 @@ func TestValidateOIDCAllowsIssuerOnlyEndpointsWithDiscoveryFallback(t *testing.T
|
|||||||
cfg.OIDC.FrontendRedirectURL = "/auth/oidc/callback"
|
cfg.OIDC.FrontendRedirectURL = "/auth/oidc/callback"
|
||||||
cfg.OIDC.Scopes = "openid email profile"
|
cfg.OIDC.Scopes = "openid email profile"
|
||||||
cfg.OIDC.ValidateIDToken = true
|
cfg.OIDC.ValidateIDToken = true
|
||||||
|
cfg.OIDC.UsePKCE = true
|
||||||
|
|
||||||
err = cfg.Validate()
|
err = cfg.Validate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -840,6 +842,7 @@ func TestValidateConfigWithLinuxDoEnabled(t *testing.T) {
|
|||||||
cfg.LinuxDo.RedirectURL = "https://example.com/api/v1/auth/oauth/linuxdo/callback"
|
cfg.LinuxDo.RedirectURL = "https://example.com/api/v1/auth/oauth/linuxdo/callback"
|
||||||
cfg.LinuxDo.FrontendRedirectURL = "/auth/linuxdo/callback"
|
cfg.LinuxDo.FrontendRedirectURL = "/auth/linuxdo/callback"
|
||||||
cfg.LinuxDo.TokenAuthMethod = "client_secret_post"
|
cfg.LinuxDo.TokenAuthMethod = "client_secret_post"
|
||||||
|
cfg.LinuxDo.UsePKCE = true
|
||||||
|
|
||||||
if err := cfg.Validate(); err != nil {
|
if err := cfg.Validate(); err != nil {
|
||||||
t.Fatalf("Validate() unexpected error: %v", err)
|
t.Fatalf("Validate() unexpected error: %v", err)
|
||||||
@@ -990,6 +993,7 @@ func TestValidateConfigErrors(t *testing.T) {
|
|||||||
name: "linuxdo client id required",
|
name: "linuxdo client id required",
|
||||||
mutate: func(c *Config) {
|
mutate: func(c *Config) {
|
||||||
c.LinuxDo.Enabled = true
|
c.LinuxDo.Enabled = true
|
||||||
|
c.LinuxDo.UsePKCE = true
|
||||||
c.LinuxDo.ClientID = ""
|
c.LinuxDo.ClientID = ""
|
||||||
},
|
},
|
||||||
wantErr: "linuxdo_connect.client_id",
|
wantErr: "linuxdo_connect.client_id",
|
||||||
@@ -998,6 +1002,7 @@ func TestValidateConfigErrors(t *testing.T) {
|
|||||||
name: "linuxdo token auth method",
|
name: "linuxdo token auth method",
|
||||||
mutate: func(c *Config) {
|
mutate: func(c *Config) {
|
||||||
c.LinuxDo.Enabled = true
|
c.LinuxDo.Enabled = true
|
||||||
|
c.LinuxDo.UsePKCE = true
|
||||||
c.LinuxDo.ClientID = "client"
|
c.LinuxDo.ClientID = "client"
|
||||||
c.LinuxDo.ClientSecret = "secret"
|
c.LinuxDo.ClientSecret = "secret"
|
||||||
c.LinuxDo.AuthorizeURL = "https://example.com/authorize"
|
c.LinuxDo.AuthorizeURL = "https://example.com/authorize"
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ func setupAdminRouter() (*gin.Engine, *stubAdminService) {
|
|||||||
|
|
||||||
router.GET("/api/v1/admin/users", userHandler.List)
|
router.GET("/api/v1/admin/users", userHandler.List)
|
||||||
router.GET("/api/v1/admin/users/:id", userHandler.GetByID)
|
router.GET("/api/v1/admin/users/:id", userHandler.GetByID)
|
||||||
|
router.POST("/api/v1/admin/users/:id/auth-identities", userHandler.BindAuthIdentity)
|
||||||
router.POST("/api/v1/admin/users", userHandler.Create)
|
router.POST("/api/v1/admin/users", userHandler.Create)
|
||||||
router.PUT("/api/v1/admin/users/:id", userHandler.Update)
|
router.PUT("/api/v1/admin/users/:id", userHandler.Update)
|
||||||
router.DELETE("/api/v1/admin/users/:id", userHandler.Delete)
|
router.DELETE("/api/v1/admin/users/:id", userHandler.Delete)
|
||||||
@@ -75,8 +76,26 @@ func TestUserHandlerEndpoints(t *testing.T) {
|
|||||||
router.ServeHTTP(rec, req)
|
router.ServeHTTP(rec, req)
|
||||||
require.Equal(t, http.StatusOK, rec.Code)
|
require.Equal(t, http.StatusOK, rec.Code)
|
||||||
|
|
||||||
|
bindBody := map[string]any{
|
||||||
|
"provider_type": "wechat",
|
||||||
|
"provider_key": "wechat-main",
|
||||||
|
"provider_subject": "union-123",
|
||||||
|
"metadata": map[string]any{"source": "admin-repair"},
|
||||||
|
"channel": map[string]any{
|
||||||
|
"channel": "open",
|
||||||
|
"channel_app_id": "wx-open",
|
||||||
|
"channel_subject": "openid-123",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
body, _ := json.Marshal(bindBody)
|
||||||
|
rec = httptest.NewRecorder()
|
||||||
|
req = httptest.NewRequest(http.MethodPost, "/api/v1/admin/users/1/auth-identities", bytes.NewReader(body))
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
router.ServeHTTP(rec, req)
|
||||||
|
require.Equal(t, http.StatusOK, rec.Code)
|
||||||
|
|
||||||
createBody := map[string]any{"email": "new@example.com", "password": "pass123", "balance": 1, "concurrency": 2}
|
createBody := map[string]any{"email": "new@example.com", "password": "pass123", "balance": 1, "concurrency": 2}
|
||||||
body, _ := json.Marshal(createBody)
|
body, _ = json.Marshal(createBody)
|
||||||
rec = httptest.NewRecorder()
|
rec = httptest.NewRecorder()
|
||||||
req = httptest.NewRequest(http.MethodPost, "/api/v1/admin/users", bytes.NewReader(body))
|
req = httptest.NewRequest(http.MethodPost, "/api/v1/admin/users", bytes.NewReader(body))
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
@@ -113,6 +132,33 @@ func TestUserHandlerEndpoints(t *testing.T) {
|
|||||||
require.Equal(t, http.StatusOK, rec.Code)
|
require.Equal(t, http.StatusOK, rec.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUserHandlerBindAuthIdentityMapsRequest(t *testing.T) {
|
||||||
|
router, adminSvc := setupAdminRouter()
|
||||||
|
|
||||||
|
body, err := json.Marshal(map[string]any{
|
||||||
|
"provider_type": "oidc",
|
||||||
|
"provider_key": "https://issuer.example",
|
||||||
|
"provider_subject": "subject-123",
|
||||||
|
"issuer": "https://issuer.example",
|
||||||
|
"metadata": map[string]any{"report_id": 12},
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
rec := httptest.NewRecorder()
|
||||||
|
req := httptest.NewRequest(http.MethodPost, "/api/v1/admin/users/9/auth-identities", bytes.NewReader(body))
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
router.ServeHTTP(rec, req)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusOK, rec.Code)
|
||||||
|
require.Equal(t, int64(9), adminSvc.boundAuthIdentityFor)
|
||||||
|
require.NotNil(t, adminSvc.boundAuthIdentity)
|
||||||
|
require.Equal(t, "oidc", adminSvc.boundAuthIdentity.ProviderType)
|
||||||
|
require.Equal(t, "https://issuer.example", adminSvc.boundAuthIdentity.ProviderKey)
|
||||||
|
require.Equal(t, "subject-123", adminSvc.boundAuthIdentity.ProviderSubject)
|
||||||
|
require.Nil(t, adminSvc.boundAuthIdentity.Channel)
|
||||||
|
require.Equal(t, float64(12), adminSvc.boundAuthIdentity.Metadata["report_id"])
|
||||||
|
}
|
||||||
|
|
||||||
func TestGroupHandlerEndpoints(t *testing.T) {
|
func TestGroupHandlerEndpoints(t *testing.T) {
|
||||||
router, _ := setupAdminRouter()
|
router, _ := setupAdminRouter()
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ type stubAdminService struct {
|
|||||||
proxies []service.Proxy
|
proxies []service.Proxy
|
||||||
proxyCounts []service.ProxyWithAccountCount
|
proxyCounts []service.ProxyWithAccountCount
|
||||||
redeems []service.RedeemCode
|
redeems []service.RedeemCode
|
||||||
|
boundAuthIdentity *service.AdminBindAuthIdentityInput
|
||||||
|
boundAuthIdentityFor int64
|
||||||
createdAccounts []*service.CreateAccountInput
|
createdAccounts []*service.CreateAccountInput
|
||||||
createdProxies []*service.CreateProxyInput
|
createdProxies []*service.CreateProxyInput
|
||||||
updatedProxyIDs []int64
|
updatedProxyIDs []int64
|
||||||
@@ -42,6 +44,14 @@ type stubAdminService struct {
|
|||||||
sortOrder string
|
sortOrder string
|
||||||
calls int
|
calls int
|
||||||
}
|
}
|
||||||
|
lastListUsers struct {
|
||||||
|
page int
|
||||||
|
pageSize int
|
||||||
|
filters service.UserListFilters
|
||||||
|
sortBy string
|
||||||
|
sortOrder string
|
||||||
|
calls int
|
||||||
|
}
|
||||||
lastListProxies struct {
|
lastListProxies struct {
|
||||||
protocol string
|
protocol string
|
||||||
status string
|
status string
|
||||||
@@ -127,6 +137,12 @@ func newStubAdminService() *stubAdminService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *stubAdminService) ListUsers(ctx context.Context, page, pageSize int, filters service.UserListFilters, sortBy, sortOrder string) ([]service.User, int64, error) {
|
func (s *stubAdminService) ListUsers(ctx context.Context, page, pageSize int, filters service.UserListFilters, sortBy, sortOrder string) ([]service.User, int64, error) {
|
||||||
|
s.lastListUsers.page = page
|
||||||
|
s.lastListUsers.pageSize = pageSize
|
||||||
|
s.lastListUsers.filters = filters
|
||||||
|
s.lastListUsers.sortBy = sortBy
|
||||||
|
s.lastListUsers.sortOrder = sortOrder
|
||||||
|
s.lastListUsers.calls++
|
||||||
return s.users, int64(len(s.users)), nil
|
return s.users, int64(len(s.users)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,6 +183,52 @@ func (s *stubAdminService) GetUserUsageStats(ctx context.Context, userID int64,
|
|||||||
return map[string]any{"user_id": userID}, nil
|
return map[string]any{"user_id": userID}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *stubAdminService) BindUserAuthIdentity(ctx context.Context, userID int64, input service.AdminBindAuthIdentityInput) (*service.AdminBoundAuthIdentity, error) {
|
||||||
|
s.boundAuthIdentityFor = userID
|
||||||
|
copied := input
|
||||||
|
if input.Metadata != nil {
|
||||||
|
copied.Metadata = map[string]any{}
|
||||||
|
for key, value := range input.Metadata {
|
||||||
|
copied.Metadata[key] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if input.Channel != nil {
|
||||||
|
channel := *input.Channel
|
||||||
|
if input.Channel.Metadata != nil {
|
||||||
|
channel.Metadata = map[string]any{}
|
||||||
|
for key, value := range input.Channel.Metadata {
|
||||||
|
channel.Metadata[key] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
copied.Channel = &channel
|
||||||
|
}
|
||||||
|
s.boundAuthIdentity = &copied
|
||||||
|
|
||||||
|
now := time.Now().UTC()
|
||||||
|
result := &service.AdminBoundAuthIdentity{
|
||||||
|
UserID: userID,
|
||||||
|
ProviderType: input.ProviderType,
|
||||||
|
ProviderKey: input.ProviderKey,
|
||||||
|
ProviderSubject: input.ProviderSubject,
|
||||||
|
VerifiedAt: &now,
|
||||||
|
Issuer: input.Issuer,
|
||||||
|
Metadata: input.Metadata,
|
||||||
|
CreatedAt: now,
|
||||||
|
UpdatedAt: now,
|
||||||
|
}
|
||||||
|
if input.Channel != nil {
|
||||||
|
result.Channel = &service.AdminBoundAuthIdentityChannel{
|
||||||
|
Channel: input.Channel.Channel,
|
||||||
|
ChannelAppID: input.Channel.ChannelAppID,
|
||||||
|
ChannelSubject: input.Channel.ChannelSubject,
|
||||||
|
Metadata: input.Channel.Metadata,
|
||||||
|
CreatedAt: now,
|
||||||
|
UpdatedAt: now,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *stubAdminService) ListGroups(ctx context.Context, page, pageSize int, platform, status, search string, isExclusive *bool, sortBy, sortOrder string) ([]service.Group, int64, error) {
|
func (s *stubAdminService) ListGroups(ctx context.Context, page, pageSize int, platform, status, search string, isExclusive *bool, sortBy, sortOrder string) ([]service.Group, int64, error) {
|
||||||
return s.groups, int64(len(s.groups)), nil
|
return s.groups, int64(len(s.groups)), nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package admin
|
|||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
dbent "github.com/Wei-Shaw/sub2api/ent"
|
||||||
"github.com/Wei-Shaw/sub2api/internal/pkg/response"
|
"github.com/Wei-Shaw/sub2api/internal/pkg/response"
|
||||||
"github.com/Wei-Shaw/sub2api/internal/service"
|
"github.com/Wei-Shaw/sub2api/internal/service"
|
||||||
|
|
||||||
@@ -66,7 +67,7 @@ func (h *PaymentHandler) ListOrders(c *gin.Context) {
|
|||||||
response.ErrorFrom(c, err)
|
response.ErrorFrom(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
response.Paginated(c, orders, int64(total), page, pageSize)
|
response.Paginated(c, sanitizeAdminPaymentOrdersForResponse(orders), int64(total), page, pageSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOrderDetail returns detailed information about a single order.
|
// GetOrderDetail returns detailed information about a single order.
|
||||||
@@ -82,7 +83,7 @@ func (h *PaymentHandler) GetOrderDetail(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
auditLogs, _ := h.paymentService.GetOrderAuditLogs(c.Request.Context(), orderID)
|
auditLogs, _ := h.paymentService.GetOrderAuditLogs(c.Request.Context(), orderID)
|
||||||
response.Success(c, gin.H{"order": order, "auditLogs": auditLogs})
|
response.Success(c, gin.H{"order": sanitizeAdminPaymentOrderForResponse(order), "auditLogs": auditLogs})
|
||||||
}
|
}
|
||||||
|
|
||||||
// CancelOrder cancels a pending order (admin).
|
// CancelOrder cancels a pending order (admin).
|
||||||
@@ -114,6 +115,26 @@ func (h *PaymentHandler) RetryFulfillment(c *gin.Context) {
|
|||||||
response.Success(c, gin.H{"message": "fulfillment retried"})
|
response.Success(c, gin.H{"message": "fulfillment retried"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sanitizeAdminPaymentOrdersForResponse(orders []*dbent.PaymentOrder) []*dbent.PaymentOrder {
|
||||||
|
if len(orders) == 0 {
|
||||||
|
return orders
|
||||||
|
}
|
||||||
|
out := make([]*dbent.PaymentOrder, 0, len(orders))
|
||||||
|
for _, order := range orders {
|
||||||
|
out = append(out, sanitizeAdminPaymentOrderForResponse(order))
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func sanitizeAdminPaymentOrderForResponse(order *dbent.PaymentOrder) *dbent.PaymentOrder {
|
||||||
|
if order == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
cloned := *order
|
||||||
|
cloned.ProviderSnapshot = nil
|
||||||
|
return &cloned
|
||||||
|
}
|
||||||
|
|
||||||
// AdminProcessRefundRequest is the request body for admin refund processing.
|
// AdminProcessRefundRequest is the request body for admin refund processing.
|
||||||
type AdminProcessRefundRequest struct {
|
type AdminProcessRefundRequest struct {
|
||||||
Amount float64 `json:"amount"`
|
Amount float64 `json:"amount"`
|
||||||
|
|||||||
@@ -43,6 +43,15 @@ func scopesContainOpenID(scopes string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func firstNonEmpty(values ...string) string {
|
||||||
|
for _, value := range values {
|
||||||
|
if trimmed := strings.TrimSpace(value); trimmed != "" {
|
||||||
|
return trimmed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
// SettingHandler 系统设置处理器
|
// SettingHandler 系统设置处理器
|
||||||
type SettingHandler struct {
|
type SettingHandler struct {
|
||||||
settingService *service.SettingService
|
settingService *service.SettingService
|
||||||
@@ -73,6 +82,11 @@ func (h *SettingHandler) GetSettings(c *gin.Context) {
|
|||||||
response.ErrorFrom(c, err)
|
response.ErrorFrom(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
authSourceDefaults, err := h.settingService.GetAuthSourceDefaultSettings(c.Request.Context())
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Check if ops monitoring is enabled (respects config.ops.enabled)
|
// Check if ops monitoring is enabled (respects config.ops.enabled)
|
||||||
opsEnabled := h.opsService != nil && h.opsService.IsMonitoringEnabled(c.Request.Context())
|
opsEnabled := h.opsService != nil && h.opsService.IsMonitoringEnabled(c.Request.Context())
|
||||||
@@ -93,7 +107,7 @@ func (h *SettingHandler) GetSettings(c *gin.Context) {
|
|||||||
paymentCfg = &service.PaymentConfig{}
|
paymentCfg = &service.PaymentConfig{}
|
||||||
}
|
}
|
||||||
|
|
||||||
response.Success(c, dto.SystemSettings{
|
payload := dto.SystemSettings{
|
||||||
RegistrationEnabled: settings.RegistrationEnabled,
|
RegistrationEnabled: settings.RegistrationEnabled,
|
||||||
EmailVerifyEnabled: settings.EmailVerifyEnabled,
|
EmailVerifyEnabled: settings.EmailVerifyEnabled,
|
||||||
RegistrationEmailSuffixWhitelist: settings.RegistrationEmailSuffixWhitelist,
|
RegistrationEmailSuffixWhitelist: settings.RegistrationEmailSuffixWhitelist,
|
||||||
@@ -117,6 +131,22 @@ func (h *SettingHandler) GetSettings(c *gin.Context) {
|
|||||||
LinuxDoConnectClientID: settings.LinuxDoConnectClientID,
|
LinuxDoConnectClientID: settings.LinuxDoConnectClientID,
|
||||||
LinuxDoConnectClientSecretConfigured: settings.LinuxDoConnectClientSecretConfigured,
|
LinuxDoConnectClientSecretConfigured: settings.LinuxDoConnectClientSecretConfigured,
|
||||||
LinuxDoConnectRedirectURL: settings.LinuxDoConnectRedirectURL,
|
LinuxDoConnectRedirectURL: settings.LinuxDoConnectRedirectURL,
|
||||||
|
WeChatConnectEnabled: settings.WeChatConnectEnabled,
|
||||||
|
WeChatConnectAppID: settings.WeChatConnectAppID,
|
||||||
|
WeChatConnectAppSecretConfigured: settings.WeChatConnectAppSecretConfigured,
|
||||||
|
WeChatConnectOpenAppID: settings.WeChatConnectOpenAppID,
|
||||||
|
WeChatConnectOpenAppSecretConfigured: settings.WeChatConnectOpenAppSecretConfigured,
|
||||||
|
WeChatConnectMPAppID: settings.WeChatConnectMPAppID,
|
||||||
|
WeChatConnectMPAppSecretConfigured: settings.WeChatConnectMPAppSecretConfigured,
|
||||||
|
WeChatConnectMobileAppID: settings.WeChatConnectMobileAppID,
|
||||||
|
WeChatConnectMobileAppSecretConfigured: settings.WeChatConnectMobileAppSecretConfigured,
|
||||||
|
WeChatConnectOpenEnabled: settings.WeChatConnectOpenEnabled,
|
||||||
|
WeChatConnectMPEnabled: settings.WeChatConnectMPEnabled,
|
||||||
|
WeChatConnectMobileEnabled: settings.WeChatConnectMobileEnabled,
|
||||||
|
WeChatConnectMode: settings.WeChatConnectMode,
|
||||||
|
WeChatConnectScopes: settings.WeChatConnectScopes,
|
||||||
|
WeChatConnectRedirectURL: settings.WeChatConnectRedirectURL,
|
||||||
|
WeChatConnectFrontendRedirectURL: settings.WeChatConnectFrontendRedirectURL,
|
||||||
OIDCConnectEnabled: settings.OIDCConnectEnabled,
|
OIDCConnectEnabled: settings.OIDCConnectEnabled,
|
||||||
OIDCConnectProviderName: settings.OIDCConnectProviderName,
|
OIDCConnectProviderName: settings.OIDCConnectProviderName,
|
||||||
OIDCConnectClientID: settings.OIDCConnectClientID,
|
OIDCConnectClientID: settings.OIDCConnectClientID,
|
||||||
@@ -175,6 +205,11 @@ func (h *SettingHandler) GetSettings(c *gin.Context) {
|
|||||||
EnableMetadataPassthrough: settings.EnableMetadataPassthrough,
|
EnableMetadataPassthrough: settings.EnableMetadataPassthrough,
|
||||||
EnableCCHSigning: settings.EnableCCHSigning,
|
EnableCCHSigning: settings.EnableCCHSigning,
|
||||||
WebSearchEmulationEnabled: settings.WebSearchEmulationEnabled,
|
WebSearchEmulationEnabled: settings.WebSearchEmulationEnabled,
|
||||||
|
PaymentVisibleMethodAlipaySource: settings.PaymentVisibleMethodAlipaySource,
|
||||||
|
PaymentVisibleMethodWxpaySource: settings.PaymentVisibleMethodWxpaySource,
|
||||||
|
PaymentVisibleMethodAlipayEnabled: settings.PaymentVisibleMethodAlipayEnabled,
|
||||||
|
PaymentVisibleMethodWxpayEnabled: settings.PaymentVisibleMethodWxpayEnabled,
|
||||||
|
OpenAIAdvancedSchedulerEnabled: settings.OpenAIAdvancedSchedulerEnabled,
|
||||||
BalanceLowNotifyEnabled: settings.BalanceLowNotifyEnabled,
|
BalanceLowNotifyEnabled: settings.BalanceLowNotifyEnabled,
|
||||||
BalanceLowNotifyThreshold: settings.BalanceLowNotifyThreshold,
|
BalanceLowNotifyThreshold: settings.BalanceLowNotifyThreshold,
|
||||||
BalanceLowNotifyRechargeURL: settings.BalanceLowNotifyRechargeURL,
|
BalanceLowNotifyRechargeURL: settings.BalanceLowNotifyRechargeURL,
|
||||||
@@ -200,7 +235,8 @@ func (h *SettingHandler) GetSettings(c *gin.Context) {
|
|||||||
PaymentCancelRateLimitWindow: paymentCfg.CancelRateLimitWindow,
|
PaymentCancelRateLimitWindow: paymentCfg.CancelRateLimitWindow,
|
||||||
PaymentCancelRateLimitUnit: paymentCfg.CancelRateLimitUnit,
|
PaymentCancelRateLimitUnit: paymentCfg.CancelRateLimitUnit,
|
||||||
PaymentCancelRateLimitMode: paymentCfg.CancelRateLimitMode,
|
PaymentCancelRateLimitMode: paymentCfg.CancelRateLimitMode,
|
||||||
})
|
}
|
||||||
|
response.Success(c, systemSettingsResponseData(payload, authSourceDefaults))
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateSettingsRequest 更新设置请求
|
// UpdateSettingsRequest 更新设置请求
|
||||||
@@ -235,6 +271,24 @@ type UpdateSettingsRequest struct {
|
|||||||
LinuxDoConnectClientSecret string `json:"linuxdo_connect_client_secret"`
|
LinuxDoConnectClientSecret string `json:"linuxdo_connect_client_secret"`
|
||||||
LinuxDoConnectRedirectURL string `json:"linuxdo_connect_redirect_url"`
|
LinuxDoConnectRedirectURL string `json:"linuxdo_connect_redirect_url"`
|
||||||
|
|
||||||
|
// WeChat Connect OAuth 登录
|
||||||
|
WeChatConnectEnabled bool `json:"wechat_connect_enabled"`
|
||||||
|
WeChatConnectAppID string `json:"wechat_connect_app_id"`
|
||||||
|
WeChatConnectAppSecret string `json:"wechat_connect_app_secret"`
|
||||||
|
WeChatConnectOpenAppID string `json:"wechat_connect_open_app_id"`
|
||||||
|
WeChatConnectOpenAppSecret string `json:"wechat_connect_open_app_secret"`
|
||||||
|
WeChatConnectMPAppID string `json:"wechat_connect_mp_app_id"`
|
||||||
|
WeChatConnectMPAppSecret string `json:"wechat_connect_mp_app_secret"`
|
||||||
|
WeChatConnectMobileAppID string `json:"wechat_connect_mobile_app_id"`
|
||||||
|
WeChatConnectMobileAppSecret string `json:"wechat_connect_mobile_app_secret"`
|
||||||
|
WeChatConnectOpenEnabled bool `json:"wechat_connect_open_enabled"`
|
||||||
|
WeChatConnectMPEnabled bool `json:"wechat_connect_mp_enabled"`
|
||||||
|
WeChatConnectMobileEnabled bool `json:"wechat_connect_mobile_enabled"`
|
||||||
|
WeChatConnectMode string `json:"wechat_connect_mode"`
|
||||||
|
WeChatConnectScopes string `json:"wechat_connect_scopes"`
|
||||||
|
WeChatConnectRedirectURL string `json:"wechat_connect_redirect_url"`
|
||||||
|
WeChatConnectFrontendRedirectURL string `json:"wechat_connect_frontend_redirect_url"`
|
||||||
|
|
||||||
// Generic OIDC OAuth 登录
|
// Generic OIDC OAuth 登录
|
||||||
OIDCConnectEnabled bool `json:"oidc_connect_enabled"`
|
OIDCConnectEnabled bool `json:"oidc_connect_enabled"`
|
||||||
OIDCConnectProviderName string `json:"oidc_connect_provider_name"`
|
OIDCConnectProviderName string `json:"oidc_connect_provider_name"`
|
||||||
@@ -279,6 +333,27 @@ type UpdateSettingsRequest struct {
|
|||||||
DefaultConcurrency int `json:"default_concurrency"`
|
DefaultConcurrency int `json:"default_concurrency"`
|
||||||
DefaultBalance float64 `json:"default_balance"`
|
DefaultBalance float64 `json:"default_balance"`
|
||||||
DefaultSubscriptions []dto.DefaultSubscriptionSetting `json:"default_subscriptions"`
|
DefaultSubscriptions []dto.DefaultSubscriptionSetting `json:"default_subscriptions"`
|
||||||
|
AuthSourceDefaultEmailBalance *float64 `json:"auth_source_default_email_balance"`
|
||||||
|
AuthSourceDefaultEmailConcurrency *int `json:"auth_source_default_email_concurrency"`
|
||||||
|
AuthSourceDefaultEmailSubscriptions *[]dto.DefaultSubscriptionSetting `json:"auth_source_default_email_subscriptions"`
|
||||||
|
AuthSourceDefaultEmailGrantOnSignup *bool `json:"auth_source_default_email_grant_on_signup"`
|
||||||
|
AuthSourceDefaultEmailGrantOnFirstBind *bool `json:"auth_source_default_email_grant_on_first_bind"`
|
||||||
|
AuthSourceDefaultLinuxDoBalance *float64 `json:"auth_source_default_linuxdo_balance"`
|
||||||
|
AuthSourceDefaultLinuxDoConcurrency *int `json:"auth_source_default_linuxdo_concurrency"`
|
||||||
|
AuthSourceDefaultLinuxDoSubscriptions *[]dto.DefaultSubscriptionSetting `json:"auth_source_default_linuxdo_subscriptions"`
|
||||||
|
AuthSourceDefaultLinuxDoGrantOnSignup *bool `json:"auth_source_default_linuxdo_grant_on_signup"`
|
||||||
|
AuthSourceDefaultLinuxDoGrantOnFirstBind *bool `json:"auth_source_default_linuxdo_grant_on_first_bind"`
|
||||||
|
AuthSourceDefaultOIDCBalance *float64 `json:"auth_source_default_oidc_balance"`
|
||||||
|
AuthSourceDefaultOIDCConcurrency *int `json:"auth_source_default_oidc_concurrency"`
|
||||||
|
AuthSourceDefaultOIDCSubscriptions *[]dto.DefaultSubscriptionSetting `json:"auth_source_default_oidc_subscriptions"`
|
||||||
|
AuthSourceDefaultOIDCGrantOnSignup *bool `json:"auth_source_default_oidc_grant_on_signup"`
|
||||||
|
AuthSourceDefaultOIDCGrantOnFirstBind *bool `json:"auth_source_default_oidc_grant_on_first_bind"`
|
||||||
|
AuthSourceDefaultWeChatBalance *float64 `json:"auth_source_default_wechat_balance"`
|
||||||
|
AuthSourceDefaultWeChatConcurrency *int `json:"auth_source_default_wechat_concurrency"`
|
||||||
|
AuthSourceDefaultWeChatSubscriptions *[]dto.DefaultSubscriptionSetting `json:"auth_source_default_wechat_subscriptions"`
|
||||||
|
AuthSourceDefaultWeChatGrantOnSignup *bool `json:"auth_source_default_wechat_grant_on_signup"`
|
||||||
|
AuthSourceDefaultWeChatGrantOnFirstBind *bool `json:"auth_source_default_wechat_grant_on_first_bind"`
|
||||||
|
ForceEmailOnThirdPartySignup *bool `json:"force_email_on_third_party_signup"`
|
||||||
|
|
||||||
// Model fallback configuration
|
// Model fallback configuration
|
||||||
EnableModelFallback bool `json:"enable_model_fallback"`
|
EnableModelFallback bool `json:"enable_model_fallback"`
|
||||||
@@ -311,6 +386,15 @@ type UpdateSettingsRequest struct {
|
|||||||
EnableMetadataPassthrough *bool `json:"enable_metadata_passthrough"`
|
EnableMetadataPassthrough *bool `json:"enable_metadata_passthrough"`
|
||||||
EnableCCHSigning *bool `json:"enable_cch_signing"`
|
EnableCCHSigning *bool `json:"enable_cch_signing"`
|
||||||
|
|
||||||
|
// Payment visible method routing
|
||||||
|
PaymentVisibleMethodAlipaySource *string `json:"payment_visible_method_alipay_source"`
|
||||||
|
PaymentVisibleMethodWxpaySource *string `json:"payment_visible_method_wxpay_source"`
|
||||||
|
PaymentVisibleMethodAlipayEnabled *bool `json:"payment_visible_method_alipay_enabled"`
|
||||||
|
PaymentVisibleMethodWxpayEnabled *bool `json:"payment_visible_method_wxpay_enabled"`
|
||||||
|
|
||||||
|
// OpenAI account scheduling
|
||||||
|
OpenAIAdvancedSchedulerEnabled *bool `json:"openai_advanced_scheduler_enabled"`
|
||||||
|
|
||||||
// Balance low notification
|
// Balance low notification
|
||||||
BalanceLowNotifyEnabled *bool `json:"balance_low_notify_enabled"`
|
BalanceLowNotifyEnabled *bool `json:"balance_low_notify_enabled"`
|
||||||
BalanceLowNotifyThreshold *float64 `json:"balance_low_notify_threshold"`
|
BalanceLowNotifyThreshold *float64 `json:"balance_low_notify_threshold"`
|
||||||
@@ -357,6 +441,11 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
|
|||||||
response.ErrorFrom(c, err)
|
response.ErrorFrom(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
previousAuthSourceDefaults, err := h.settingService.GetAuthSourceDefaultSettings(c.Request.Context())
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 验证参数
|
// 验证参数
|
||||||
if req.DefaultConcurrency < 1 {
|
if req.DefaultConcurrency < 1 {
|
||||||
@@ -381,6 +470,10 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
|
|||||||
req.SMTPPort = 587
|
req.SMTPPort = 587
|
||||||
}
|
}
|
||||||
req.DefaultSubscriptions = normalizeDefaultSubscriptions(req.DefaultSubscriptions)
|
req.DefaultSubscriptions = normalizeDefaultSubscriptions(req.DefaultSubscriptions)
|
||||||
|
req.AuthSourceDefaultEmailSubscriptions = normalizeOptionalDefaultSubscriptions(req.AuthSourceDefaultEmailSubscriptions)
|
||||||
|
req.AuthSourceDefaultLinuxDoSubscriptions = normalizeOptionalDefaultSubscriptions(req.AuthSourceDefaultLinuxDoSubscriptions)
|
||||||
|
req.AuthSourceDefaultOIDCSubscriptions = normalizeOptionalDefaultSubscriptions(req.AuthSourceDefaultOIDCSubscriptions)
|
||||||
|
req.AuthSourceDefaultWeChatSubscriptions = normalizeOptionalDefaultSubscriptions(req.AuthSourceDefaultWeChatSubscriptions)
|
||||||
|
|
||||||
// SMTP 配置保护:如果请求中 smtp_host 为空但数据库中已有配置,则保留已有 SMTP 配置
|
// SMTP 配置保护:如果请求中 smtp_host 为空但数据库中已有配置,则保留已有 SMTP 配置
|
||||||
// 防止前端加载设置失败时空表单覆盖已保存的 SMTP 配置
|
// 防止前端加载设置失败时空表单覆盖已保存的 SMTP 配置
|
||||||
@@ -459,6 +552,124 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if req.WeChatConnectEnabled {
|
||||||
|
req.WeChatConnectAppID = strings.TrimSpace(req.WeChatConnectAppID)
|
||||||
|
req.WeChatConnectAppSecret = strings.TrimSpace(req.WeChatConnectAppSecret)
|
||||||
|
req.WeChatConnectOpenAppID = strings.TrimSpace(req.WeChatConnectOpenAppID)
|
||||||
|
req.WeChatConnectOpenAppSecret = strings.TrimSpace(req.WeChatConnectOpenAppSecret)
|
||||||
|
req.WeChatConnectMPAppID = strings.TrimSpace(req.WeChatConnectMPAppID)
|
||||||
|
req.WeChatConnectMPAppSecret = strings.TrimSpace(req.WeChatConnectMPAppSecret)
|
||||||
|
req.WeChatConnectMobileAppID = strings.TrimSpace(req.WeChatConnectMobileAppID)
|
||||||
|
req.WeChatConnectMobileAppSecret = strings.TrimSpace(req.WeChatConnectMobileAppSecret)
|
||||||
|
req.WeChatConnectMode = strings.ToLower(strings.TrimSpace(req.WeChatConnectMode))
|
||||||
|
req.WeChatConnectScopes = strings.TrimSpace(req.WeChatConnectScopes)
|
||||||
|
req.WeChatConnectRedirectURL = strings.TrimSpace(req.WeChatConnectRedirectURL)
|
||||||
|
req.WeChatConnectFrontendRedirectURL = strings.TrimSpace(req.WeChatConnectFrontendRedirectURL)
|
||||||
|
|
||||||
|
if req.WeChatConnectMPEnabled && req.WeChatConnectMobileEnabled {
|
||||||
|
response.BadRequest(c, "WeChat Official Account and Mobile App cannot be enabled at the same time")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if req.WeChatConnectMode != "" {
|
||||||
|
switch req.WeChatConnectMode {
|
||||||
|
case "open", "mp", "mobile":
|
||||||
|
default:
|
||||||
|
response.BadRequest(c, "WeChat mode must be open, mp, or mobile")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !req.WeChatConnectOpenEnabled && !req.WeChatConnectMPEnabled && !req.WeChatConnectMobileEnabled {
|
||||||
|
switch req.WeChatConnectMode {
|
||||||
|
case "mp":
|
||||||
|
req.WeChatConnectMPEnabled = true
|
||||||
|
case "mobile":
|
||||||
|
req.WeChatConnectMobileEnabled = true
|
||||||
|
default:
|
||||||
|
req.WeChatConnectOpenEnabled = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if req.WeChatConnectMode == "" {
|
||||||
|
if req.WeChatConnectMPEnabled {
|
||||||
|
req.WeChatConnectMode = "mp"
|
||||||
|
} else if req.WeChatConnectMobileEnabled {
|
||||||
|
req.WeChatConnectMode = "mobile"
|
||||||
|
} else {
|
||||||
|
req.WeChatConnectMode = "open"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
req.WeChatConnectOpenAppID = strings.TrimSpace(firstNonEmpty(req.WeChatConnectOpenAppID, req.WeChatConnectAppID))
|
||||||
|
req.WeChatConnectMPAppID = strings.TrimSpace(firstNonEmpty(req.WeChatConnectMPAppID, req.WeChatConnectAppID))
|
||||||
|
req.WeChatConnectMobileAppID = strings.TrimSpace(firstNonEmpty(req.WeChatConnectMobileAppID, req.WeChatConnectAppID))
|
||||||
|
|
||||||
|
if req.WeChatConnectOpenAppSecret == "" {
|
||||||
|
req.WeChatConnectOpenAppSecret = strings.TrimSpace(firstNonEmpty(previousSettings.WeChatConnectOpenAppSecret, previousSettings.WeChatConnectAppSecret, req.WeChatConnectAppSecret))
|
||||||
|
}
|
||||||
|
if req.WeChatConnectMPAppSecret == "" {
|
||||||
|
req.WeChatConnectMPAppSecret = strings.TrimSpace(firstNonEmpty(previousSettings.WeChatConnectMPAppSecret, previousSettings.WeChatConnectAppSecret, req.WeChatConnectAppSecret))
|
||||||
|
}
|
||||||
|
if req.WeChatConnectMobileAppSecret == "" {
|
||||||
|
req.WeChatConnectMobileAppSecret = strings.TrimSpace(firstNonEmpty(previousSettings.WeChatConnectMobileAppSecret, previousSettings.WeChatConnectAppSecret, req.WeChatConnectAppSecret))
|
||||||
|
}
|
||||||
|
if req.WeChatConnectAppSecret == "" {
|
||||||
|
req.WeChatConnectAppSecret = strings.TrimSpace(firstNonEmpty(req.WeChatConnectOpenAppSecret, req.WeChatConnectMPAppSecret, req.WeChatConnectMobileAppSecret, previousSettings.WeChatConnectAppSecret))
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.WeChatConnectOpenEnabled {
|
||||||
|
if req.WeChatConnectOpenAppID == "" {
|
||||||
|
response.BadRequest(c, "WeChat PC App ID is required when enabled")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if req.WeChatConnectOpenAppSecret == "" {
|
||||||
|
response.BadRequest(c, "WeChat PC App Secret is required when enabled")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if req.WeChatConnectMPEnabled {
|
||||||
|
if req.WeChatConnectMPAppID == "" {
|
||||||
|
response.BadRequest(c, "WeChat Official Account App ID is required when enabled")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if req.WeChatConnectMPAppSecret == "" {
|
||||||
|
response.BadRequest(c, "WeChat Official Account App Secret is required when enabled")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if req.WeChatConnectMobileEnabled {
|
||||||
|
if req.WeChatConnectMobileAppID == "" {
|
||||||
|
response.BadRequest(c, "WeChat Mobile App ID is required when enabled")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if req.WeChatConnectMobileAppSecret == "" {
|
||||||
|
response.BadRequest(c, "WeChat Mobile App Secret is required when enabled")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.WeChatConnectScopes == "" {
|
||||||
|
if req.WeChatConnectMPEnabled {
|
||||||
|
req.WeChatConnectScopes = service.DefaultWeChatConnectScopesForMode("mp")
|
||||||
|
} else {
|
||||||
|
req.WeChatConnectScopes = service.DefaultWeChatConnectScopesForMode(req.WeChatConnectMode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if req.WeChatConnectRedirectURL == "" {
|
||||||
|
response.BadRequest(c, "WeChat Redirect URL is required when enabled")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := config.ValidateAbsoluteHTTPURL(req.WeChatConnectRedirectURL); err != nil {
|
||||||
|
response.BadRequest(c, "WeChat Redirect URL must be an absolute http(s) URL")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if req.WeChatConnectFrontendRedirectURL == "" {
|
||||||
|
req.WeChatConnectFrontendRedirectURL = "/auth/wechat/callback"
|
||||||
|
}
|
||||||
|
if err := config.ValidateFrontendRedirectURL(req.WeChatConnectFrontendRedirectURL); err != nil {
|
||||||
|
response.BadRequest(c, "WeChat Frontend Redirect URL is invalid")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Generic OIDC 参数验证
|
// Generic OIDC 参数验证
|
||||||
if req.OIDCConnectEnabled {
|
if req.OIDCConnectEnabled {
|
||||||
req.OIDCConnectProviderName = strings.TrimSpace(req.OIDCConnectProviderName)
|
req.OIDCConnectProviderName = strings.TrimSpace(req.OIDCConnectProviderName)
|
||||||
@@ -538,26 +749,28 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
|
|||||||
response.BadRequest(c, "OIDC scopes must contain openid")
|
response.BadRequest(c, "OIDC scopes must contain openid")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if !req.OIDCConnectUsePKCE {
|
||||||
|
response.BadRequest(c, "OIDC PKCE must be enabled")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !req.OIDCConnectValidateIDToken {
|
||||||
|
response.BadRequest(c, "OIDC ID Token validation must be enabled")
|
||||||
|
return
|
||||||
|
}
|
||||||
switch req.OIDCConnectTokenAuthMethod {
|
switch req.OIDCConnectTokenAuthMethod {
|
||||||
case "", "client_secret_post", "client_secret_basic", "none":
|
case "", "client_secret_post", "client_secret_basic", "none":
|
||||||
default:
|
default:
|
||||||
response.BadRequest(c, "OIDC Token Auth Method must be one of client_secret_post/client_secret_basic/none")
|
response.BadRequest(c, "OIDC Token Auth Method must be one of client_secret_post/client_secret_basic/none")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if req.OIDCConnectTokenAuthMethod == "none" && !req.OIDCConnectUsePKCE {
|
|
||||||
response.BadRequest(c, "OIDC PKCE must be enabled when token_auth_method=none")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if req.OIDCConnectClockSkewSeconds < 0 || req.OIDCConnectClockSkewSeconds > 600 {
|
if req.OIDCConnectClockSkewSeconds < 0 || req.OIDCConnectClockSkewSeconds > 600 {
|
||||||
response.BadRequest(c, "OIDC clock skew seconds must be between 0 and 600")
|
response.BadRequest(c, "OIDC clock skew seconds must be between 0 and 600")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if req.OIDCConnectValidateIDToken {
|
|
||||||
if req.OIDCConnectAllowedSigningAlgs == "" {
|
if req.OIDCConnectAllowedSigningAlgs == "" {
|
||||||
response.BadRequest(c, "OIDC Allowed Signing Algs is required when validate_id_token=true")
|
response.BadRequest(c, "OIDC Allowed Signing Algs is required when validate_id_token=true")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if req.OIDCConnectJWKSURL != "" {
|
if req.OIDCConnectJWKSURL != "" {
|
||||||
if err := config.ValidateAbsoluteHTTPURL(req.OIDCConnectJWKSURL); err != nil {
|
if err := config.ValidateAbsoluteHTTPURL(req.OIDCConnectJWKSURL); err != nil {
|
||||||
response.BadRequest(c, "OIDC JWKS URL must be an absolute http(s) URL")
|
response.BadRequest(c, "OIDC JWKS URL must be an absolute http(s) URL")
|
||||||
@@ -805,6 +1018,22 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
|
|||||||
LinuxDoConnectClientID: req.LinuxDoConnectClientID,
|
LinuxDoConnectClientID: req.LinuxDoConnectClientID,
|
||||||
LinuxDoConnectClientSecret: req.LinuxDoConnectClientSecret,
|
LinuxDoConnectClientSecret: req.LinuxDoConnectClientSecret,
|
||||||
LinuxDoConnectRedirectURL: req.LinuxDoConnectRedirectURL,
|
LinuxDoConnectRedirectURL: req.LinuxDoConnectRedirectURL,
|
||||||
|
WeChatConnectEnabled: req.WeChatConnectEnabled,
|
||||||
|
WeChatConnectAppID: req.WeChatConnectAppID,
|
||||||
|
WeChatConnectAppSecret: req.WeChatConnectAppSecret,
|
||||||
|
WeChatConnectOpenAppID: req.WeChatConnectOpenAppID,
|
||||||
|
WeChatConnectOpenAppSecret: req.WeChatConnectOpenAppSecret,
|
||||||
|
WeChatConnectMPAppID: req.WeChatConnectMPAppID,
|
||||||
|
WeChatConnectMPAppSecret: req.WeChatConnectMPAppSecret,
|
||||||
|
WeChatConnectMobileAppID: req.WeChatConnectMobileAppID,
|
||||||
|
WeChatConnectMobileAppSecret: req.WeChatConnectMobileAppSecret,
|
||||||
|
WeChatConnectOpenEnabled: req.WeChatConnectOpenEnabled,
|
||||||
|
WeChatConnectMPEnabled: req.WeChatConnectMPEnabled,
|
||||||
|
WeChatConnectMobileEnabled: req.WeChatConnectMobileEnabled,
|
||||||
|
WeChatConnectMode: req.WeChatConnectMode,
|
||||||
|
WeChatConnectScopes: req.WeChatConnectScopes,
|
||||||
|
WeChatConnectRedirectURL: req.WeChatConnectRedirectURL,
|
||||||
|
WeChatConnectFrontendRedirectURL: req.WeChatConnectFrontendRedirectURL,
|
||||||
OIDCConnectEnabled: req.OIDCConnectEnabled,
|
OIDCConnectEnabled: req.OIDCConnectEnabled,
|
||||||
OIDCConnectProviderName: req.OIDCConnectProviderName,
|
OIDCConnectProviderName: req.OIDCConnectProviderName,
|
||||||
OIDCConnectClientID: req.OIDCConnectClientID,
|
OIDCConnectClientID: req.OIDCConnectClientID,
|
||||||
@@ -897,6 +1126,36 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
return previousSettings.EnableCCHSigning
|
return previousSettings.EnableCCHSigning
|
||||||
}(),
|
}(),
|
||||||
|
PaymentVisibleMethodAlipaySource: func() string {
|
||||||
|
if req.PaymentVisibleMethodAlipaySource != nil {
|
||||||
|
return strings.TrimSpace(*req.PaymentVisibleMethodAlipaySource)
|
||||||
|
}
|
||||||
|
return previousSettings.PaymentVisibleMethodAlipaySource
|
||||||
|
}(),
|
||||||
|
PaymentVisibleMethodWxpaySource: func() string {
|
||||||
|
if req.PaymentVisibleMethodWxpaySource != nil {
|
||||||
|
return strings.TrimSpace(*req.PaymentVisibleMethodWxpaySource)
|
||||||
|
}
|
||||||
|
return previousSettings.PaymentVisibleMethodWxpaySource
|
||||||
|
}(),
|
||||||
|
PaymentVisibleMethodAlipayEnabled: func() bool {
|
||||||
|
if req.PaymentVisibleMethodAlipayEnabled != nil {
|
||||||
|
return *req.PaymentVisibleMethodAlipayEnabled
|
||||||
|
}
|
||||||
|
return previousSettings.PaymentVisibleMethodAlipayEnabled
|
||||||
|
}(),
|
||||||
|
PaymentVisibleMethodWxpayEnabled: func() bool {
|
||||||
|
if req.PaymentVisibleMethodWxpayEnabled != nil {
|
||||||
|
return *req.PaymentVisibleMethodWxpayEnabled
|
||||||
|
}
|
||||||
|
return previousSettings.PaymentVisibleMethodWxpayEnabled
|
||||||
|
}(),
|
||||||
|
OpenAIAdvancedSchedulerEnabled: func() bool {
|
||||||
|
if req.OpenAIAdvancedSchedulerEnabled != nil {
|
||||||
|
return *req.OpenAIAdvancedSchedulerEnabled
|
||||||
|
}
|
||||||
|
return previousSettings.OpenAIAdvancedSchedulerEnabled
|
||||||
|
}(),
|
||||||
BalanceLowNotifyEnabled: func() bool {
|
BalanceLowNotifyEnabled: func() bool {
|
||||||
if req.BalanceLowNotifyEnabled != nil {
|
if req.BalanceLowNotifyEnabled != nil {
|
||||||
return *req.BalanceLowNotifyEnabled
|
return *req.BalanceLowNotifyEnabled
|
||||||
@@ -929,7 +1188,38 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
|
|||||||
}(),
|
}(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := h.settingService.UpdateSettings(c.Request.Context(), settings); err != nil {
|
authSourceDefaults := &service.AuthSourceDefaultSettings{
|
||||||
|
Email: service.ProviderDefaultGrantSettings{
|
||||||
|
Balance: float64ValueOrDefault(req.AuthSourceDefaultEmailBalance, previousAuthSourceDefaults.Email.Balance),
|
||||||
|
Concurrency: intValueOrDefault(req.AuthSourceDefaultEmailConcurrency, previousAuthSourceDefaults.Email.Concurrency),
|
||||||
|
Subscriptions: defaultSubscriptionsValueOrDefault(req.AuthSourceDefaultEmailSubscriptions, previousAuthSourceDefaults.Email.Subscriptions),
|
||||||
|
GrantOnSignup: boolValueOrDefault(req.AuthSourceDefaultEmailGrantOnSignup, previousAuthSourceDefaults.Email.GrantOnSignup),
|
||||||
|
GrantOnFirstBind: boolValueOrDefault(req.AuthSourceDefaultEmailGrantOnFirstBind, previousAuthSourceDefaults.Email.GrantOnFirstBind),
|
||||||
|
},
|
||||||
|
LinuxDo: service.ProviderDefaultGrantSettings{
|
||||||
|
Balance: float64ValueOrDefault(req.AuthSourceDefaultLinuxDoBalance, previousAuthSourceDefaults.LinuxDo.Balance),
|
||||||
|
Concurrency: intValueOrDefault(req.AuthSourceDefaultLinuxDoConcurrency, previousAuthSourceDefaults.LinuxDo.Concurrency),
|
||||||
|
Subscriptions: defaultSubscriptionsValueOrDefault(req.AuthSourceDefaultLinuxDoSubscriptions, previousAuthSourceDefaults.LinuxDo.Subscriptions),
|
||||||
|
GrantOnSignup: boolValueOrDefault(req.AuthSourceDefaultLinuxDoGrantOnSignup, previousAuthSourceDefaults.LinuxDo.GrantOnSignup),
|
||||||
|
GrantOnFirstBind: boolValueOrDefault(req.AuthSourceDefaultLinuxDoGrantOnFirstBind, previousAuthSourceDefaults.LinuxDo.GrantOnFirstBind),
|
||||||
|
},
|
||||||
|
OIDC: service.ProviderDefaultGrantSettings{
|
||||||
|
Balance: float64ValueOrDefault(req.AuthSourceDefaultOIDCBalance, previousAuthSourceDefaults.OIDC.Balance),
|
||||||
|
Concurrency: intValueOrDefault(req.AuthSourceDefaultOIDCConcurrency, previousAuthSourceDefaults.OIDC.Concurrency),
|
||||||
|
Subscriptions: defaultSubscriptionsValueOrDefault(req.AuthSourceDefaultOIDCSubscriptions, previousAuthSourceDefaults.OIDC.Subscriptions),
|
||||||
|
GrantOnSignup: boolValueOrDefault(req.AuthSourceDefaultOIDCGrantOnSignup, previousAuthSourceDefaults.OIDC.GrantOnSignup),
|
||||||
|
GrantOnFirstBind: boolValueOrDefault(req.AuthSourceDefaultOIDCGrantOnFirstBind, previousAuthSourceDefaults.OIDC.GrantOnFirstBind),
|
||||||
|
},
|
||||||
|
WeChat: service.ProviderDefaultGrantSettings{
|
||||||
|
Balance: float64ValueOrDefault(req.AuthSourceDefaultWeChatBalance, previousAuthSourceDefaults.WeChat.Balance),
|
||||||
|
Concurrency: intValueOrDefault(req.AuthSourceDefaultWeChatConcurrency, previousAuthSourceDefaults.WeChat.Concurrency),
|
||||||
|
Subscriptions: defaultSubscriptionsValueOrDefault(req.AuthSourceDefaultWeChatSubscriptions, previousAuthSourceDefaults.WeChat.Subscriptions),
|
||||||
|
GrantOnSignup: boolValueOrDefault(req.AuthSourceDefaultWeChatGrantOnSignup, previousAuthSourceDefaults.WeChat.GrantOnSignup),
|
||||||
|
GrantOnFirstBind: boolValueOrDefault(req.AuthSourceDefaultWeChatGrantOnFirstBind, previousAuthSourceDefaults.WeChat.GrantOnFirstBind),
|
||||||
|
},
|
||||||
|
ForceEmailOnThirdPartySignup: boolValueOrDefault(req.ForceEmailOnThirdPartySignup, previousAuthSourceDefaults.ForceEmailOnThirdPartySignup),
|
||||||
|
}
|
||||||
|
if err := h.settingService.UpdateSettingsWithAuthSourceDefaults(c.Request.Context(), settings, authSourceDefaults); err != nil {
|
||||||
response.ErrorFrom(c, err)
|
response.ErrorFrom(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -969,7 +1259,7 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
h.auditSettingsUpdate(c, previousSettings, settings, req)
|
h.auditSettingsUpdate(c, previousSettings, settings, previousAuthSourceDefaults, authSourceDefaults, req)
|
||||||
|
|
||||||
// 重新获取设置返回
|
// 重新获取设置返回
|
||||||
updatedSettings, err := h.settingService.GetAllSettings(c.Request.Context())
|
updatedSettings, err := h.settingService.GetAllSettings(c.Request.Context())
|
||||||
@@ -977,6 +1267,11 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
|
|||||||
response.ErrorFrom(c, err)
|
response.ErrorFrom(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
updatedAuthSourceDefaults, err := h.settingService.GetAuthSourceDefaultSettings(c.Request.Context())
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
updatedDefaultSubscriptions := make([]dto.DefaultSubscriptionSetting, 0, len(updatedSettings.DefaultSubscriptions))
|
updatedDefaultSubscriptions := make([]dto.DefaultSubscriptionSetting, 0, len(updatedSettings.DefaultSubscriptions))
|
||||||
for _, sub := range updatedSettings.DefaultSubscriptions {
|
for _, sub := range updatedSettings.DefaultSubscriptions {
|
||||||
updatedDefaultSubscriptions = append(updatedDefaultSubscriptions, dto.DefaultSubscriptionSetting{
|
updatedDefaultSubscriptions = append(updatedDefaultSubscriptions, dto.DefaultSubscriptionSetting{
|
||||||
@@ -994,7 +1289,7 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
|
|||||||
updatedPaymentCfg = &service.PaymentConfig{}
|
updatedPaymentCfg = &service.PaymentConfig{}
|
||||||
}
|
}
|
||||||
|
|
||||||
response.Success(c, dto.SystemSettings{
|
payload := dto.SystemSettings{
|
||||||
RegistrationEnabled: updatedSettings.RegistrationEnabled,
|
RegistrationEnabled: updatedSettings.RegistrationEnabled,
|
||||||
EmailVerifyEnabled: updatedSettings.EmailVerifyEnabled,
|
EmailVerifyEnabled: updatedSettings.EmailVerifyEnabled,
|
||||||
RegistrationEmailSuffixWhitelist: updatedSettings.RegistrationEmailSuffixWhitelist,
|
RegistrationEmailSuffixWhitelist: updatedSettings.RegistrationEmailSuffixWhitelist,
|
||||||
@@ -1018,6 +1313,22 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
|
|||||||
LinuxDoConnectClientID: updatedSettings.LinuxDoConnectClientID,
|
LinuxDoConnectClientID: updatedSettings.LinuxDoConnectClientID,
|
||||||
LinuxDoConnectClientSecretConfigured: updatedSettings.LinuxDoConnectClientSecretConfigured,
|
LinuxDoConnectClientSecretConfigured: updatedSettings.LinuxDoConnectClientSecretConfigured,
|
||||||
LinuxDoConnectRedirectURL: updatedSettings.LinuxDoConnectRedirectURL,
|
LinuxDoConnectRedirectURL: updatedSettings.LinuxDoConnectRedirectURL,
|
||||||
|
WeChatConnectEnabled: updatedSettings.WeChatConnectEnabled,
|
||||||
|
WeChatConnectAppID: updatedSettings.WeChatConnectAppID,
|
||||||
|
WeChatConnectAppSecretConfigured: updatedSettings.WeChatConnectAppSecretConfigured,
|
||||||
|
WeChatConnectOpenAppID: updatedSettings.WeChatConnectOpenAppID,
|
||||||
|
WeChatConnectOpenAppSecretConfigured: updatedSettings.WeChatConnectOpenAppSecretConfigured,
|
||||||
|
WeChatConnectMPAppID: updatedSettings.WeChatConnectMPAppID,
|
||||||
|
WeChatConnectMPAppSecretConfigured: updatedSettings.WeChatConnectMPAppSecretConfigured,
|
||||||
|
WeChatConnectMobileAppID: updatedSettings.WeChatConnectMobileAppID,
|
||||||
|
WeChatConnectMobileAppSecretConfigured: updatedSettings.WeChatConnectMobileAppSecretConfigured,
|
||||||
|
WeChatConnectOpenEnabled: updatedSettings.WeChatConnectOpenEnabled,
|
||||||
|
WeChatConnectMPEnabled: updatedSettings.WeChatConnectMPEnabled,
|
||||||
|
WeChatConnectMobileEnabled: updatedSettings.WeChatConnectMobileEnabled,
|
||||||
|
WeChatConnectMode: updatedSettings.WeChatConnectMode,
|
||||||
|
WeChatConnectScopes: updatedSettings.WeChatConnectScopes,
|
||||||
|
WeChatConnectRedirectURL: updatedSettings.WeChatConnectRedirectURL,
|
||||||
|
WeChatConnectFrontendRedirectURL: updatedSettings.WeChatConnectFrontendRedirectURL,
|
||||||
OIDCConnectEnabled: updatedSettings.OIDCConnectEnabled,
|
OIDCConnectEnabled: updatedSettings.OIDCConnectEnabled,
|
||||||
OIDCConnectProviderName: updatedSettings.OIDCConnectProviderName,
|
OIDCConnectProviderName: updatedSettings.OIDCConnectProviderName,
|
||||||
OIDCConnectClientID: updatedSettings.OIDCConnectClientID,
|
OIDCConnectClientID: updatedSettings.OIDCConnectClientID,
|
||||||
@@ -1075,6 +1386,11 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
|
|||||||
EnableFingerprintUnification: updatedSettings.EnableFingerprintUnification,
|
EnableFingerprintUnification: updatedSettings.EnableFingerprintUnification,
|
||||||
EnableMetadataPassthrough: updatedSettings.EnableMetadataPassthrough,
|
EnableMetadataPassthrough: updatedSettings.EnableMetadataPassthrough,
|
||||||
EnableCCHSigning: updatedSettings.EnableCCHSigning,
|
EnableCCHSigning: updatedSettings.EnableCCHSigning,
|
||||||
|
PaymentVisibleMethodAlipaySource: updatedSettings.PaymentVisibleMethodAlipaySource,
|
||||||
|
PaymentVisibleMethodWxpaySource: updatedSettings.PaymentVisibleMethodWxpaySource,
|
||||||
|
PaymentVisibleMethodAlipayEnabled: updatedSettings.PaymentVisibleMethodAlipayEnabled,
|
||||||
|
PaymentVisibleMethodWxpayEnabled: updatedSettings.PaymentVisibleMethodWxpayEnabled,
|
||||||
|
OpenAIAdvancedSchedulerEnabled: updatedSettings.OpenAIAdvancedSchedulerEnabled,
|
||||||
BalanceLowNotifyEnabled: updatedSettings.BalanceLowNotifyEnabled,
|
BalanceLowNotifyEnabled: updatedSettings.BalanceLowNotifyEnabled,
|
||||||
BalanceLowNotifyThreshold: updatedSettings.BalanceLowNotifyThreshold,
|
BalanceLowNotifyThreshold: updatedSettings.BalanceLowNotifyThreshold,
|
||||||
BalanceLowNotifyRechargeURL: updatedSettings.BalanceLowNotifyRechargeURL,
|
BalanceLowNotifyRechargeURL: updatedSettings.BalanceLowNotifyRechargeURL,
|
||||||
@@ -1100,7 +1416,8 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
|
|||||||
PaymentCancelRateLimitWindow: updatedPaymentCfg.CancelRateLimitWindow,
|
PaymentCancelRateLimitWindow: updatedPaymentCfg.CancelRateLimitWindow,
|
||||||
PaymentCancelRateLimitUnit: updatedPaymentCfg.CancelRateLimitUnit,
|
PaymentCancelRateLimitUnit: updatedPaymentCfg.CancelRateLimitUnit,
|
||||||
PaymentCancelRateLimitMode: updatedPaymentCfg.CancelRateLimitMode,
|
PaymentCancelRateLimitMode: updatedPaymentCfg.CancelRateLimitMode,
|
||||||
})
|
}
|
||||||
|
response.Success(c, systemSettingsResponseData(payload, updatedAuthSourceDefaults))
|
||||||
}
|
}
|
||||||
|
|
||||||
// hasPaymentFields returns true if any payment-related field was explicitly provided.
|
// hasPaymentFields returns true if any payment-related field was explicitly provided.
|
||||||
@@ -1117,12 +1434,12 @@ func hasPaymentFields(req UpdateSettingsRequest) bool {
|
|||||||
req.PaymentCancelRateLimitUnit != nil || req.PaymentCancelRateLimitMode != nil
|
req.PaymentCancelRateLimitUnit != nil || req.PaymentCancelRateLimitMode != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *SettingHandler) auditSettingsUpdate(c *gin.Context, before *service.SystemSettings, after *service.SystemSettings, req UpdateSettingsRequest) {
|
func (h *SettingHandler) auditSettingsUpdate(c *gin.Context, before *service.SystemSettings, after *service.SystemSettings, beforeAuthSourceDefaults *service.AuthSourceDefaultSettings, afterAuthSourceDefaults *service.AuthSourceDefaultSettings, req UpdateSettingsRequest) {
|
||||||
if before == nil || after == nil {
|
if before == nil || after == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
changed := diffSettings(before, after, req)
|
changed := diffSettings(before, after, beforeAuthSourceDefaults, afterAuthSourceDefaults, req)
|
||||||
if len(changed) == 0 {
|
if len(changed) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -1137,7 +1454,7 @@ func (h *SettingHandler) auditSettingsUpdate(c *gin.Context, before *service.Sys
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func diffSettings(before *service.SystemSettings, after *service.SystemSettings, req UpdateSettingsRequest) []string {
|
func diffSettings(before *service.SystemSettings, after *service.SystemSettings, beforeAuthSourceDefaults *service.AuthSourceDefaultSettings, afterAuthSourceDefaults *service.AuthSourceDefaultSettings, req UpdateSettingsRequest) []string {
|
||||||
changed := make([]string, 0, 20)
|
changed := make([]string, 0, 20)
|
||||||
if before.RegistrationEnabled != after.RegistrationEnabled {
|
if before.RegistrationEnabled != after.RegistrationEnabled {
|
||||||
changed = append(changed, "registration_enabled")
|
changed = append(changed, "registration_enabled")
|
||||||
@@ -1205,6 +1522,54 @@ func diffSettings(before *service.SystemSettings, after *service.SystemSettings,
|
|||||||
if before.LinuxDoConnectRedirectURL != after.LinuxDoConnectRedirectURL {
|
if before.LinuxDoConnectRedirectURL != after.LinuxDoConnectRedirectURL {
|
||||||
changed = append(changed, "linuxdo_connect_redirect_url")
|
changed = append(changed, "linuxdo_connect_redirect_url")
|
||||||
}
|
}
|
||||||
|
if before.WeChatConnectEnabled != after.WeChatConnectEnabled {
|
||||||
|
changed = append(changed, "wechat_connect_enabled")
|
||||||
|
}
|
||||||
|
if before.WeChatConnectAppID != after.WeChatConnectAppID {
|
||||||
|
changed = append(changed, "wechat_connect_app_id")
|
||||||
|
}
|
||||||
|
if req.WeChatConnectAppSecret != "" {
|
||||||
|
changed = append(changed, "wechat_connect_app_secret")
|
||||||
|
}
|
||||||
|
if before.WeChatConnectOpenAppID != after.WeChatConnectOpenAppID {
|
||||||
|
changed = append(changed, "wechat_connect_open_app_id")
|
||||||
|
}
|
||||||
|
if req.WeChatConnectOpenAppSecret != "" {
|
||||||
|
changed = append(changed, "wechat_connect_open_app_secret")
|
||||||
|
}
|
||||||
|
if before.WeChatConnectMPAppID != after.WeChatConnectMPAppID {
|
||||||
|
changed = append(changed, "wechat_connect_mp_app_id")
|
||||||
|
}
|
||||||
|
if req.WeChatConnectMPAppSecret != "" {
|
||||||
|
changed = append(changed, "wechat_connect_mp_app_secret")
|
||||||
|
}
|
||||||
|
if before.WeChatConnectMobileAppID != after.WeChatConnectMobileAppID {
|
||||||
|
changed = append(changed, "wechat_connect_mobile_app_id")
|
||||||
|
}
|
||||||
|
if req.WeChatConnectMobileAppSecret != "" {
|
||||||
|
changed = append(changed, "wechat_connect_mobile_app_secret")
|
||||||
|
}
|
||||||
|
if before.WeChatConnectOpenEnabled != after.WeChatConnectOpenEnabled {
|
||||||
|
changed = append(changed, "wechat_connect_open_enabled")
|
||||||
|
}
|
||||||
|
if before.WeChatConnectMPEnabled != after.WeChatConnectMPEnabled {
|
||||||
|
changed = append(changed, "wechat_connect_mp_enabled")
|
||||||
|
}
|
||||||
|
if before.WeChatConnectMobileEnabled != after.WeChatConnectMobileEnabled {
|
||||||
|
changed = append(changed, "wechat_connect_mobile_enabled")
|
||||||
|
}
|
||||||
|
if before.WeChatConnectMode != after.WeChatConnectMode {
|
||||||
|
changed = append(changed, "wechat_connect_mode")
|
||||||
|
}
|
||||||
|
if before.WeChatConnectScopes != after.WeChatConnectScopes {
|
||||||
|
changed = append(changed, "wechat_connect_scopes")
|
||||||
|
}
|
||||||
|
if before.WeChatConnectRedirectURL != after.WeChatConnectRedirectURL {
|
||||||
|
changed = append(changed, "wechat_connect_redirect_url")
|
||||||
|
}
|
||||||
|
if before.WeChatConnectFrontendRedirectURL != after.WeChatConnectFrontendRedirectURL {
|
||||||
|
changed = append(changed, "wechat_connect_frontend_redirect_url")
|
||||||
|
}
|
||||||
if before.OIDCConnectEnabled != after.OIDCConnectEnabled {
|
if before.OIDCConnectEnabled != after.OIDCConnectEnabled {
|
||||||
changed = append(changed, "oidc_connect_enabled")
|
changed = append(changed, "oidc_connect_enabled")
|
||||||
}
|
}
|
||||||
@@ -1376,6 +1741,21 @@ func diffSettings(before *service.SystemSettings, after *service.SystemSettings,
|
|||||||
if before.EnableCCHSigning != after.EnableCCHSigning {
|
if before.EnableCCHSigning != after.EnableCCHSigning {
|
||||||
changed = append(changed, "enable_cch_signing")
|
changed = append(changed, "enable_cch_signing")
|
||||||
}
|
}
|
||||||
|
if before.PaymentVisibleMethodAlipaySource != after.PaymentVisibleMethodAlipaySource {
|
||||||
|
changed = append(changed, "payment_visible_method_alipay_source")
|
||||||
|
}
|
||||||
|
if before.PaymentVisibleMethodWxpaySource != after.PaymentVisibleMethodWxpaySource {
|
||||||
|
changed = append(changed, "payment_visible_method_wxpay_source")
|
||||||
|
}
|
||||||
|
if before.PaymentVisibleMethodAlipayEnabled != after.PaymentVisibleMethodAlipayEnabled {
|
||||||
|
changed = append(changed, "payment_visible_method_alipay_enabled")
|
||||||
|
}
|
||||||
|
if before.PaymentVisibleMethodWxpayEnabled != after.PaymentVisibleMethodWxpayEnabled {
|
||||||
|
changed = append(changed, "payment_visible_method_wxpay_enabled")
|
||||||
|
}
|
||||||
|
if before.OpenAIAdvancedSchedulerEnabled != after.OpenAIAdvancedSchedulerEnabled {
|
||||||
|
changed = append(changed, "openai_advanced_scheduler_enabled")
|
||||||
|
}
|
||||||
// Balance & quota notification
|
// Balance & quota notification
|
||||||
if before.BalanceLowNotifyEnabled != after.BalanceLowNotifyEnabled {
|
if before.BalanceLowNotifyEnabled != after.BalanceLowNotifyEnabled {
|
||||||
changed = append(changed, "balance_low_notify_enabled")
|
changed = append(changed, "balance_low_notify_enabled")
|
||||||
@@ -1392,6 +1772,50 @@ func diffSettings(before *service.SystemSettings, after *service.SystemSettings,
|
|||||||
if !equalNotifyEmailEntries(before.AccountQuotaNotifyEmails, after.AccountQuotaNotifyEmails) {
|
if !equalNotifyEmailEntries(before.AccountQuotaNotifyEmails, after.AccountQuotaNotifyEmails) {
|
||||||
changed = append(changed, "account_quota_notify_emails")
|
changed = append(changed, "account_quota_notify_emails")
|
||||||
}
|
}
|
||||||
|
changed = appendAuthSourceDefaultChanges(changed, beforeAuthSourceDefaults, afterAuthSourceDefaults)
|
||||||
|
return changed
|
||||||
|
}
|
||||||
|
|
||||||
|
func appendAuthSourceDefaultChanges(changed []string, before *service.AuthSourceDefaultSettings, after *service.AuthSourceDefaultSettings) []string {
|
||||||
|
if before == nil {
|
||||||
|
before = &service.AuthSourceDefaultSettings{}
|
||||||
|
}
|
||||||
|
if after == nil {
|
||||||
|
after = &service.AuthSourceDefaultSettings{}
|
||||||
|
}
|
||||||
|
|
||||||
|
type providerDefaultGrantField struct {
|
||||||
|
name string
|
||||||
|
before service.ProviderDefaultGrantSettings
|
||||||
|
after service.ProviderDefaultGrantSettings
|
||||||
|
}
|
||||||
|
|
||||||
|
fields := []providerDefaultGrantField{
|
||||||
|
{name: "email", before: before.Email, after: after.Email},
|
||||||
|
{name: "linuxdo", before: before.LinuxDo, after: after.LinuxDo},
|
||||||
|
{name: "oidc", before: before.OIDC, after: after.OIDC},
|
||||||
|
{name: "wechat", before: before.WeChat, after: after.WeChat},
|
||||||
|
}
|
||||||
|
for _, field := range fields {
|
||||||
|
if field.before.Balance != field.after.Balance {
|
||||||
|
changed = append(changed, "auth_source_default_"+field.name+"_balance")
|
||||||
|
}
|
||||||
|
if field.before.Concurrency != field.after.Concurrency {
|
||||||
|
changed = append(changed, "auth_source_default_"+field.name+"_concurrency")
|
||||||
|
}
|
||||||
|
if !equalDefaultSubscriptions(field.before.Subscriptions, field.after.Subscriptions) {
|
||||||
|
changed = append(changed, "auth_source_default_"+field.name+"_subscriptions")
|
||||||
|
}
|
||||||
|
if field.before.GrantOnSignup != field.after.GrantOnSignup {
|
||||||
|
changed = append(changed, "auth_source_default_"+field.name+"_grant_on_signup")
|
||||||
|
}
|
||||||
|
if field.before.GrantOnFirstBind != field.after.GrantOnFirstBind {
|
||||||
|
changed = append(changed, "auth_source_default_"+field.name+"_grant_on_first_bind")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if before.ForceEmailOnThirdPartySignup != after.ForceEmailOnThirdPartySignup {
|
||||||
|
changed = append(changed, "force_email_on_third_party_signup")
|
||||||
|
}
|
||||||
return changed
|
return changed
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1412,6 +1836,84 @@ func normalizeDefaultSubscriptions(input []dto.DefaultSubscriptionSetting) []dto
|
|||||||
return normalized
|
return normalized
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func normalizeOptionalDefaultSubscriptions(input *[]dto.DefaultSubscriptionSetting) *[]dto.DefaultSubscriptionSetting {
|
||||||
|
if input == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
normalized := normalizeDefaultSubscriptions(*input)
|
||||||
|
return &normalized
|
||||||
|
}
|
||||||
|
|
||||||
|
func float64ValueOrDefault(value *float64, fallback float64) float64 {
|
||||||
|
if value == nil {
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
return *value
|
||||||
|
}
|
||||||
|
|
||||||
|
func intValueOrDefault(value *int, fallback int) int {
|
||||||
|
if value == nil {
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
return *value
|
||||||
|
}
|
||||||
|
|
||||||
|
func boolValueOrDefault(value *bool, fallback bool) bool {
|
||||||
|
if value == nil {
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
return *value
|
||||||
|
}
|
||||||
|
|
||||||
|
func defaultSubscriptionsValueOrDefault(input *[]dto.DefaultSubscriptionSetting, fallback []service.DefaultSubscriptionSetting) []service.DefaultSubscriptionSetting {
|
||||||
|
if input == nil {
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
result := make([]service.DefaultSubscriptionSetting, 0, len(*input))
|
||||||
|
for _, item := range *input {
|
||||||
|
result = append(result, service.DefaultSubscriptionSetting{
|
||||||
|
GroupID: item.GroupID,
|
||||||
|
ValidityDays: item.ValidityDays,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func systemSettingsResponseData(settings dto.SystemSettings, authSourceDefaults *service.AuthSourceDefaultSettings) map[string]any {
|
||||||
|
data := make(map[string]any)
|
||||||
|
raw, err := json.Marshal(settings)
|
||||||
|
if err == nil {
|
||||||
|
_ = json.Unmarshal(raw, &data)
|
||||||
|
}
|
||||||
|
if authSourceDefaults == nil {
|
||||||
|
authSourceDefaults = &service.AuthSourceDefaultSettings{}
|
||||||
|
}
|
||||||
|
|
||||||
|
data["auth_source_default_email_balance"] = authSourceDefaults.Email.Balance
|
||||||
|
data["auth_source_default_email_concurrency"] = authSourceDefaults.Email.Concurrency
|
||||||
|
data["auth_source_default_email_subscriptions"] = authSourceDefaults.Email.Subscriptions
|
||||||
|
data["auth_source_default_email_grant_on_signup"] = authSourceDefaults.Email.GrantOnSignup
|
||||||
|
data["auth_source_default_email_grant_on_first_bind"] = authSourceDefaults.Email.GrantOnFirstBind
|
||||||
|
data["auth_source_default_linuxdo_balance"] = authSourceDefaults.LinuxDo.Balance
|
||||||
|
data["auth_source_default_linuxdo_concurrency"] = authSourceDefaults.LinuxDo.Concurrency
|
||||||
|
data["auth_source_default_linuxdo_subscriptions"] = authSourceDefaults.LinuxDo.Subscriptions
|
||||||
|
data["auth_source_default_linuxdo_grant_on_signup"] = authSourceDefaults.LinuxDo.GrantOnSignup
|
||||||
|
data["auth_source_default_linuxdo_grant_on_first_bind"] = authSourceDefaults.LinuxDo.GrantOnFirstBind
|
||||||
|
data["auth_source_default_oidc_balance"] = authSourceDefaults.OIDC.Balance
|
||||||
|
data["auth_source_default_oidc_concurrency"] = authSourceDefaults.OIDC.Concurrency
|
||||||
|
data["auth_source_default_oidc_subscriptions"] = authSourceDefaults.OIDC.Subscriptions
|
||||||
|
data["auth_source_default_oidc_grant_on_signup"] = authSourceDefaults.OIDC.GrantOnSignup
|
||||||
|
data["auth_source_default_oidc_grant_on_first_bind"] = authSourceDefaults.OIDC.GrantOnFirstBind
|
||||||
|
data["auth_source_default_wechat_balance"] = authSourceDefaults.WeChat.Balance
|
||||||
|
data["auth_source_default_wechat_concurrency"] = authSourceDefaults.WeChat.Concurrency
|
||||||
|
data["auth_source_default_wechat_subscriptions"] = authSourceDefaults.WeChat.Subscriptions
|
||||||
|
data["auth_source_default_wechat_grant_on_signup"] = authSourceDefaults.WeChat.GrantOnSignup
|
||||||
|
data["auth_source_default_wechat_grant_on_first_bind"] = authSourceDefaults.WeChat.GrantOnFirstBind
|
||||||
|
data["force_email_on_third_party_signup"] = authSourceDefaults.ForceEmailOnThirdPartySignup
|
||||||
|
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
func equalStringSlice(a, b []string) bool {
|
func equalStringSlice(a, b []string) bool {
|
||||||
if len(a) != len(b) {
|
if len(a) != len(b) {
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -0,0 +1,346 @@
|
|||||||
|
package admin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/Wei-Shaw/sub2api/internal/config"
|
||||||
|
"github.com/Wei-Shaw/sub2api/internal/pkg/response"
|
||||||
|
"github.com/Wei-Shaw/sub2api/internal/service"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
type settingHandlerRepoStub struct {
|
||||||
|
values map[string]string
|
||||||
|
lastUpdates map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *settingHandlerRepoStub) Get(ctx context.Context, key string) (*service.Setting, error) {
|
||||||
|
panic("unexpected Get call")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *settingHandlerRepoStub) GetValue(ctx context.Context, key string) (string, error) {
|
||||||
|
panic("unexpected GetValue call")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *settingHandlerRepoStub) Set(ctx context.Context, key, value string) error {
|
||||||
|
panic("unexpected Set call")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *settingHandlerRepoStub) GetMultiple(ctx context.Context, keys []string) (map[string]string, error) {
|
||||||
|
out := make(map[string]string, len(keys))
|
||||||
|
for _, key := range keys {
|
||||||
|
if value, ok := s.values[key]; ok {
|
||||||
|
out[key] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *settingHandlerRepoStub) SetMultiple(ctx context.Context, settings map[string]string) error {
|
||||||
|
s.lastUpdates = make(map[string]string, len(settings))
|
||||||
|
for key, value := range settings {
|
||||||
|
s.lastUpdates[key] = value
|
||||||
|
if s.values == nil {
|
||||||
|
s.values = map[string]string{}
|
||||||
|
}
|
||||||
|
s.values[key] = value
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *settingHandlerRepoStub) GetAll(ctx context.Context) (map[string]string, error) {
|
||||||
|
out := make(map[string]string, len(s.values))
|
||||||
|
for key, value := range s.values {
|
||||||
|
out[key] = value
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *settingHandlerRepoStub) Delete(ctx context.Context, key string) error {
|
||||||
|
panic("unexpected Delete call")
|
||||||
|
}
|
||||||
|
|
||||||
|
type failingAuthSourceSettingsRepoStub struct {
|
||||||
|
values map[string]string
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *failingAuthSourceSettingsRepoStub) Get(ctx context.Context, key string) (*service.Setting, error) {
|
||||||
|
panic("unexpected Get call")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *failingAuthSourceSettingsRepoStub) GetValue(ctx context.Context, key string) (string, error) {
|
||||||
|
panic("unexpected GetValue call")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *failingAuthSourceSettingsRepoStub) Set(ctx context.Context, key, value string) error {
|
||||||
|
panic("unexpected Set call")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *failingAuthSourceSettingsRepoStub) GetMultiple(ctx context.Context, keys []string) (map[string]string, error) {
|
||||||
|
out := make(map[string]string, len(keys))
|
||||||
|
for _, key := range keys {
|
||||||
|
if value, ok := s.values[key]; ok {
|
||||||
|
out[key] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *failingAuthSourceSettingsRepoStub) SetMultiple(ctx context.Context, settings map[string]string) error {
|
||||||
|
if _, ok := settings[service.SettingKeyAuthSourceDefaultEmailBalance]; ok {
|
||||||
|
return s.err
|
||||||
|
}
|
||||||
|
for key, value := range settings {
|
||||||
|
if s.values == nil {
|
||||||
|
s.values = map[string]string{}
|
||||||
|
}
|
||||||
|
s.values[key] = value
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *failingAuthSourceSettingsRepoStub) GetAll(ctx context.Context) (map[string]string, error) {
|
||||||
|
out := make(map[string]string, len(s.values))
|
||||||
|
for key, value := range s.values {
|
||||||
|
out[key] = value
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *failingAuthSourceSettingsRepoStub) Delete(ctx context.Context, key string) error {
|
||||||
|
panic("unexpected Delete call")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSettingHandler_GetSettings_InjectsAuthSourceDefaults(t *testing.T) {
|
||||||
|
gin.SetMode(gin.TestMode)
|
||||||
|
repo := &settingHandlerRepoStub{
|
||||||
|
values: map[string]string{
|
||||||
|
service.SettingKeyRegistrationEnabled: "true",
|
||||||
|
service.SettingKeyPromoCodeEnabled: "true",
|
||||||
|
service.SettingKeyAuthSourceDefaultEmailBalance: "9.5",
|
||||||
|
service.SettingKeyAuthSourceDefaultEmailConcurrency: "8",
|
||||||
|
service.SettingKeyAuthSourceDefaultEmailSubscriptions: `[{"group_id":31,"validity_days":15}]`,
|
||||||
|
service.SettingKeyForceEmailOnThirdPartySignup: "true",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
svc := service.NewSettingService(repo, &config.Config{Default: config.DefaultConfig{UserConcurrency: 5}})
|
||||||
|
handler := NewSettingHandler(svc, nil, nil, nil, nil, nil)
|
||||||
|
|
||||||
|
rec := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(rec)
|
||||||
|
c.Request = httptest.NewRequest(http.MethodGet, "/api/v1/admin/settings", nil)
|
||||||
|
|
||||||
|
handler.GetSettings(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusOK, rec.Code)
|
||||||
|
var resp response.Response
|
||||||
|
require.NoError(t, json.Unmarshal(rec.Body.Bytes(), &resp))
|
||||||
|
data, ok := resp.Data.(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, 9.5, data["auth_source_default_email_balance"])
|
||||||
|
require.Equal(t, float64(8), data["auth_source_default_email_concurrency"])
|
||||||
|
require.Equal(t, true, data["force_email_on_third_party_signup"])
|
||||||
|
|
||||||
|
subscriptions, ok := data["auth_source_default_email_subscriptions"].([]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Len(t, subscriptions, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSettingHandler_UpdateSettings_PreservesOmittedAuthSourceDefaults(t *testing.T) {
|
||||||
|
gin.SetMode(gin.TestMode)
|
||||||
|
repo := &settingHandlerRepoStub{
|
||||||
|
values: map[string]string{
|
||||||
|
service.SettingKeyRegistrationEnabled: "false",
|
||||||
|
service.SettingKeyPromoCodeEnabled: "true",
|
||||||
|
service.SettingKeyAuthSourceDefaultEmailBalance: "9.5",
|
||||||
|
service.SettingKeyAuthSourceDefaultEmailConcurrency: "8",
|
||||||
|
service.SettingKeyAuthSourceDefaultEmailSubscriptions: `[{"group_id":31,"validity_days":15}]`,
|
||||||
|
service.SettingKeyAuthSourceDefaultEmailGrantOnSignup: "true",
|
||||||
|
service.SettingKeyAuthSourceDefaultEmailGrantOnFirstBind: "false",
|
||||||
|
service.SettingKeyForceEmailOnThirdPartySignup: "true",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
svc := service.NewSettingService(repo, &config.Config{Default: config.DefaultConfig{UserConcurrency: 5}})
|
||||||
|
handler := NewSettingHandler(svc, nil, nil, nil, nil, nil)
|
||||||
|
|
||||||
|
body := map[string]any{
|
||||||
|
"registration_enabled": true,
|
||||||
|
"promo_code_enabled": true,
|
||||||
|
"auth_source_default_email_balance": 12.75,
|
||||||
|
}
|
||||||
|
rawBody, err := json.Marshal(body)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
rec := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(rec)
|
||||||
|
c.Request = httptest.NewRequest(http.MethodPut, "/api/v1/admin/settings", bytes.NewReader(rawBody))
|
||||||
|
c.Request.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
handler.UpdateSettings(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusOK, rec.Code)
|
||||||
|
require.Equal(t, "12.75000000", repo.values[service.SettingKeyAuthSourceDefaultEmailBalance])
|
||||||
|
require.Equal(t, "8", repo.values[service.SettingKeyAuthSourceDefaultEmailConcurrency])
|
||||||
|
require.Equal(t, `[{"group_id":31,"validity_days":15}]`, repo.values[service.SettingKeyAuthSourceDefaultEmailSubscriptions])
|
||||||
|
require.Equal(t, "true", repo.values[service.SettingKeyForceEmailOnThirdPartySignup])
|
||||||
|
|
||||||
|
var resp response.Response
|
||||||
|
require.NoError(t, json.Unmarshal(rec.Body.Bytes(), &resp))
|
||||||
|
data, ok := resp.Data.(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, 12.75, data["auth_source_default_email_balance"])
|
||||||
|
require.Equal(t, float64(8), data["auth_source_default_email_concurrency"])
|
||||||
|
require.Equal(t, true, data["force_email_on_third_party_signup"])
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSettingHandler_UpdateSettings_PersistsPaymentVisibleMethodsAndAdvancedScheduler(t *testing.T) {
|
||||||
|
gin.SetMode(gin.TestMode)
|
||||||
|
repo := &settingHandlerRepoStub{
|
||||||
|
values: map[string]string{
|
||||||
|
service.SettingKeyPromoCodeEnabled: "true",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
svc := service.NewSettingService(repo, &config.Config{Default: config.DefaultConfig{UserConcurrency: 5}})
|
||||||
|
handler := NewSettingHandler(svc, nil, nil, nil, nil, nil)
|
||||||
|
|
||||||
|
body := map[string]any{
|
||||||
|
"promo_code_enabled": true,
|
||||||
|
"payment_visible_method_alipay_source": "easypay",
|
||||||
|
"payment_visible_method_wxpay_source": "wxpay",
|
||||||
|
"payment_visible_method_alipay_enabled": true,
|
||||||
|
"payment_visible_method_wxpay_enabled": false,
|
||||||
|
"openai_advanced_scheduler_enabled": true,
|
||||||
|
}
|
||||||
|
rawBody, err := json.Marshal(body)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
rec := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(rec)
|
||||||
|
c.Request = httptest.NewRequest(http.MethodPut, "/api/v1/admin/settings", bytes.NewReader(rawBody))
|
||||||
|
c.Request.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
handler.UpdateSettings(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusOK, rec.Code)
|
||||||
|
require.Equal(t, service.VisibleMethodSourceEasyPayAlipay, repo.values[service.SettingPaymentVisibleMethodAlipaySource])
|
||||||
|
require.Equal(t, service.VisibleMethodSourceOfficialWechat, repo.values[service.SettingPaymentVisibleMethodWxpaySource])
|
||||||
|
require.Equal(t, "true", repo.values[service.SettingPaymentVisibleMethodAlipayEnabled])
|
||||||
|
require.Equal(t, "false", repo.values[service.SettingPaymentVisibleMethodWxpayEnabled])
|
||||||
|
require.Equal(t, "true", repo.values["openai_advanced_scheduler_enabled"])
|
||||||
|
|
||||||
|
var resp response.Response
|
||||||
|
require.NoError(t, json.Unmarshal(rec.Body.Bytes(), &resp))
|
||||||
|
data, ok := resp.Data.(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, service.VisibleMethodSourceEasyPayAlipay, data["payment_visible_method_alipay_source"])
|
||||||
|
require.Equal(t, service.VisibleMethodSourceOfficialWechat, data["payment_visible_method_wxpay_source"])
|
||||||
|
require.Equal(t, true, data["payment_visible_method_alipay_enabled"])
|
||||||
|
require.Equal(t, false, data["payment_visible_method_wxpay_enabled"])
|
||||||
|
require.Equal(t, true, data["openai_advanced_scheduler_enabled"])
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSettingHandler_UpdateSettings_RejectsInvalidPaymentVisibleMethodSource(t *testing.T) {
|
||||||
|
gin.SetMode(gin.TestMode)
|
||||||
|
repo := &settingHandlerRepoStub{
|
||||||
|
values: map[string]string{
|
||||||
|
service.SettingKeyPromoCodeEnabled: "true",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
svc := service.NewSettingService(repo, &config.Config{Default: config.DefaultConfig{UserConcurrency: 5}})
|
||||||
|
handler := NewSettingHandler(svc, nil, nil, nil, nil, nil)
|
||||||
|
|
||||||
|
body := map[string]any{
|
||||||
|
"promo_code_enabled": true,
|
||||||
|
"payment_visible_method_alipay_source": "bogus",
|
||||||
|
}
|
||||||
|
rawBody, err := json.Marshal(body)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
rec := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(rec)
|
||||||
|
c.Request = httptest.NewRequest(http.MethodPut, "/api/v1/admin/settings", bytes.NewReader(rawBody))
|
||||||
|
c.Request.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
handler.UpdateSettings(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusBadRequest, rec.Code)
|
||||||
|
require.NotContains(t, repo.values, service.SettingPaymentVisibleMethodAlipaySource)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSettingHandler_UpdateSettings_DoesNotPersistPartialSystemSettingsWhenAuthSourceDefaultsFail(t *testing.T) {
|
||||||
|
gin.SetMode(gin.TestMode)
|
||||||
|
repo := &failingAuthSourceSettingsRepoStub{
|
||||||
|
values: map[string]string{
|
||||||
|
service.SettingKeyRegistrationEnabled: "false",
|
||||||
|
service.SettingKeyPromoCodeEnabled: "true",
|
||||||
|
service.SettingKeyAuthSourceDefaultEmailBalance: "9.5",
|
||||||
|
service.SettingKeyAuthSourceDefaultEmailConcurrency: "8",
|
||||||
|
service.SettingKeyAuthSourceDefaultEmailSubscriptions: `[{"group_id":31,"validity_days":15}]`,
|
||||||
|
},
|
||||||
|
err: errors.New("write auth source defaults failed"),
|
||||||
|
}
|
||||||
|
svc := service.NewSettingService(repo, &config.Config{Default: config.DefaultConfig{UserConcurrency: 5}})
|
||||||
|
handler := NewSettingHandler(svc, nil, nil, nil, nil, nil)
|
||||||
|
|
||||||
|
body := map[string]any{
|
||||||
|
"registration_enabled": true,
|
||||||
|
"promo_code_enabled": true,
|
||||||
|
"auth_source_default_email_balance": 12.75,
|
||||||
|
}
|
||||||
|
rawBody, err := json.Marshal(body)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
rec := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(rec)
|
||||||
|
c.Request = httptest.NewRequest(http.MethodPut, "/api/v1/admin/settings", bytes.NewReader(rawBody))
|
||||||
|
c.Request.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
handler.UpdateSettings(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusInternalServerError, rec.Code)
|
||||||
|
require.Equal(t, "false", repo.values[service.SettingKeyRegistrationEnabled])
|
||||||
|
require.Equal(t, "9.5", repo.values[service.SettingKeyAuthSourceDefaultEmailBalance])
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDiffSettings_IncludesAuthSourceDefaultsAndForceEmail(t *testing.T) {
|
||||||
|
changed := diffSettings(
|
||||||
|
&service.SystemSettings{},
|
||||||
|
&service.SystemSettings{},
|
||||||
|
&service.AuthSourceDefaultSettings{
|
||||||
|
Email: service.ProviderDefaultGrantSettings{
|
||||||
|
Balance: 0,
|
||||||
|
Concurrency: 5,
|
||||||
|
Subscriptions: nil,
|
||||||
|
GrantOnSignup: true,
|
||||||
|
GrantOnFirstBind: false,
|
||||||
|
},
|
||||||
|
ForceEmailOnThirdPartySignup: false,
|
||||||
|
},
|
||||||
|
&service.AuthSourceDefaultSettings{
|
||||||
|
Email: service.ProviderDefaultGrantSettings{
|
||||||
|
Balance: 12.5,
|
||||||
|
Concurrency: 7,
|
||||||
|
Subscriptions: []service.DefaultSubscriptionSetting{{GroupID: 21, ValidityDays: 30}},
|
||||||
|
GrantOnSignup: false,
|
||||||
|
GrantOnFirstBind: true,
|
||||||
|
},
|
||||||
|
ForceEmailOnThirdPartySignup: true,
|
||||||
|
},
|
||||||
|
UpdateSettingsRequest{},
|
||||||
|
)
|
||||||
|
|
||||||
|
require.Contains(t, changed, "auth_source_default_email_balance")
|
||||||
|
require.Contains(t, changed, "auth_source_default_email_concurrency")
|
||||||
|
require.Contains(t, changed, "auth_source_default_email_subscriptions")
|
||||||
|
require.Contains(t, changed, "auth_source_default_email_grant_on_signup")
|
||||||
|
require.Contains(t, changed, "auth_source_default_email_grant_on_first_bind")
|
||||||
|
require.Contains(t, changed, "force_email_on_third_party_signup")
|
||||||
|
}
|
||||||
@@ -66,6 +66,22 @@ type UpdateBalanceRequest struct {
|
|||||||
Notes string `json:"notes"`
|
Notes string `json:"notes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BindUserAuthIdentityRequest struct {
|
||||||
|
ProviderType string `json:"provider_type"`
|
||||||
|
ProviderKey string `json:"provider_key"`
|
||||||
|
ProviderSubject string `json:"provider_subject"`
|
||||||
|
Issuer *string `json:"issuer"`
|
||||||
|
Metadata map[string]any `json:"metadata"`
|
||||||
|
Channel *BindUserAuthIdentityChannelRequest `json:"channel"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type BindUserAuthIdentityChannelRequest struct {
|
||||||
|
Channel string `json:"channel"`
|
||||||
|
ChannelAppID string `json:"channel_app_id"`
|
||||||
|
ChannelSubject string `json:"channel_subject"`
|
||||||
|
Metadata map[string]any `json:"metadata"`
|
||||||
|
}
|
||||||
|
|
||||||
// List handles listing all users with pagination
|
// List handles listing all users with pagination
|
||||||
// GET /api/v1/admin/users
|
// GET /api/v1/admin/users
|
||||||
// Query params:
|
// Query params:
|
||||||
@@ -172,6 +188,45 @@ func (h *UserHandler) GetByID(c *gin.Context) {
|
|||||||
response.Success(c, dto.UserFromServiceAdmin(user))
|
response.Success(c, dto.UserFromServiceAdmin(user))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BindAuthIdentity manually binds a canonical auth identity to a user.
|
||||||
|
// POST /api/v1/admin/users/:id/auth-identities
|
||||||
|
func (h *UserHandler) BindAuthIdentity(c *gin.Context) {
|
||||||
|
userID, err := strconv.ParseInt(c.Param("id"), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
response.BadRequest(c, "Invalid user ID")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var req BindUserAuthIdentityRequest
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
response.BadRequest(c, "Invalid request: "+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
input := service.AdminBindAuthIdentityInput{
|
||||||
|
ProviderType: req.ProviderType,
|
||||||
|
ProviderKey: req.ProviderKey,
|
||||||
|
ProviderSubject: req.ProviderSubject,
|
||||||
|
Issuer: req.Issuer,
|
||||||
|
Metadata: req.Metadata,
|
||||||
|
}
|
||||||
|
if req.Channel != nil {
|
||||||
|
input.Channel = &service.AdminBindAuthIdentityChannelInput{
|
||||||
|
Channel: req.Channel.Channel,
|
||||||
|
ChannelAppID: req.Channel.ChannelAppID,
|
||||||
|
ChannelSubject: req.Channel.ChannelSubject,
|
||||||
|
Metadata: req.Channel.Metadata,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := h.adminService.BindUserAuthIdentity(c.Request.Context(), userID, input)
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.Success(c, result)
|
||||||
|
}
|
||||||
|
|
||||||
// Create handles creating a new user
|
// Create handles creating a new user
|
||||||
// POST /api/v1/admin/users
|
// POST /api/v1/admin/users
|
||||||
func (h *UserHandler) Create(c *gin.Context) {
|
func (h *UserHandler) Create(c *gin.Context) {
|
||||||
|
|||||||
@@ -0,0 +1,114 @@
|
|||||||
|
//go:build unit
|
||||||
|
|
||||||
|
package admin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/Wei-Shaw/sub2api/internal/service"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestUserHandlerListIncludesActivityFieldsAndSortParams(t *testing.T) {
|
||||||
|
gin.SetMode(gin.TestMode)
|
||||||
|
|
||||||
|
lastLoginAt := time.Date(2026, 4, 20, 8, 0, 0, 0, time.UTC)
|
||||||
|
lastActiveAt := lastLoginAt.Add(30 * time.Minute)
|
||||||
|
lastUsedAt := lastLoginAt.Add(90 * time.Minute)
|
||||||
|
|
||||||
|
adminSvc := newStubAdminService()
|
||||||
|
adminSvc.users = []service.User{
|
||||||
|
{
|
||||||
|
ID: 7,
|
||||||
|
Email: "activity@example.com",
|
||||||
|
Username: "activity-user",
|
||||||
|
Role: service.RoleUser,
|
||||||
|
Status: service.StatusActive,
|
||||||
|
LastActiveAt: &lastActiveAt,
|
||||||
|
LastUsedAt: &lastUsedAt,
|
||||||
|
CreatedAt: lastLoginAt.Add(-24 * time.Hour),
|
||||||
|
UpdatedAt: lastLoginAt,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
handler := NewUserHandler(adminSvc, nil)
|
||||||
|
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(recorder)
|
||||||
|
c.Request = httptest.NewRequest(
|
||||||
|
http.MethodGet,
|
||||||
|
"/api/v1/admin/users?sort_by=last_used_at&sort_order=asc&search=activity",
|
||||||
|
nil,
|
||||||
|
)
|
||||||
|
|
||||||
|
handler.List(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusOK, recorder.Code)
|
||||||
|
require.Equal(t, "last_used_at", adminSvc.lastListUsers.sortBy)
|
||||||
|
require.Equal(t, "asc", adminSvc.lastListUsers.sortOrder)
|
||||||
|
require.Equal(t, "activity", adminSvc.lastListUsers.filters.Search)
|
||||||
|
|
||||||
|
var resp struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Data struct {
|
||||||
|
Items []struct {
|
||||||
|
LastActiveAt *time.Time `json:"last_active_at"`
|
||||||
|
LastUsedAt *time.Time `json:"last_used_at"`
|
||||||
|
} `json:"items"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
require.NoError(t, json.Unmarshal(recorder.Body.Bytes(), &resp))
|
||||||
|
require.Equal(t, 0, resp.Code)
|
||||||
|
require.Len(t, resp.Data.Items, 1)
|
||||||
|
require.WithinDuration(t, lastActiveAt, *resp.Data.Items[0].LastActiveAt, time.Second)
|
||||||
|
require.WithinDuration(t, lastUsedAt, *resp.Data.Items[0].LastUsedAt, time.Second)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUserHandlerGetByIDIncludesActivityFields(t *testing.T) {
|
||||||
|
gin.SetMode(gin.TestMode)
|
||||||
|
|
||||||
|
lastLoginAt := time.Date(2026, 4, 20, 8, 0, 0, 0, time.UTC)
|
||||||
|
lastActiveAt := lastLoginAt.Add(30 * time.Minute)
|
||||||
|
lastUsedAt := lastLoginAt.Add(90 * time.Minute)
|
||||||
|
|
||||||
|
adminSvc := newStubAdminService()
|
||||||
|
adminSvc.users = []service.User{
|
||||||
|
{
|
||||||
|
ID: 8,
|
||||||
|
Email: "detail@example.com",
|
||||||
|
Username: "detail-user",
|
||||||
|
Role: service.RoleUser,
|
||||||
|
Status: service.StatusActive,
|
||||||
|
LastActiveAt: &lastActiveAt,
|
||||||
|
LastUsedAt: &lastUsedAt,
|
||||||
|
CreatedAt: lastLoginAt.Add(-24 * time.Hour),
|
||||||
|
UpdatedAt: lastLoginAt,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
handler := NewUserHandler(adminSvc, nil)
|
||||||
|
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(recorder)
|
||||||
|
c.Params = gin.Params{{Key: "id", Value: "8"}}
|
||||||
|
c.Request = httptest.NewRequest(http.MethodGet, "/api/v1/admin/users/8", nil)
|
||||||
|
|
||||||
|
handler.GetByID(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusOK, recorder.Code)
|
||||||
|
|
||||||
|
var resp struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Data struct {
|
||||||
|
LastActiveAt *time.Time `json:"last_active_at"`
|
||||||
|
LastUsedAt *time.Time `json:"last_used_at"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
require.NoError(t, json.Unmarshal(recorder.Body.Bytes(), &resp))
|
||||||
|
require.Equal(t, 0, resp.Code)
|
||||||
|
require.WithinDuration(t, lastActiveAt, *resp.Data.LastActiveAt, time.Second)
|
||||||
|
require.WithinDuration(t, lastUsedAt, *resp.Data.LastUsedAt, time.Second)
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
//go:build unit
|
||||||
|
|
||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
middleware2 "github.com/Wei-Shaw/sub2api/internal/server/middleware"
|
||||||
|
"github.com/Wei-Shaw/sub2api/internal/service"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAuthHandlerGetCurrentUserReturnsProfileCompatibilityFields(t *testing.T) {
|
||||||
|
gin.SetMode(gin.TestMode)
|
||||||
|
|
||||||
|
verifiedAt := time.Date(2026, 4, 20, 8, 30, 0, 0, time.UTC)
|
||||||
|
repo := &userHandlerRepoStub{
|
||||||
|
user: &service.User{
|
||||||
|
ID: 31,
|
||||||
|
Email: "me@example.com",
|
||||||
|
Username: "linuxdo-handle",
|
||||||
|
Role: service.RoleUser,
|
||||||
|
Status: service.StatusActive,
|
||||||
|
AvatarURL: "https://cdn.example.com/linuxdo.png",
|
||||||
|
AvatarSource: "remote_url",
|
||||||
|
},
|
||||||
|
identities: []service.UserAuthIdentityRecord{
|
||||||
|
{
|
||||||
|
ProviderType: "linuxdo",
|
||||||
|
ProviderKey: "linuxdo",
|
||||||
|
ProviderSubject: "linuxdo-subject-31",
|
||||||
|
VerifiedAt: &verifiedAt,
|
||||||
|
Metadata: map[string]any{
|
||||||
|
"username": "linuxdo-handle",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
handler := &AuthHandler{
|
||||||
|
userService: service.NewUserService(repo, nil, nil, nil),
|
||||||
|
}
|
||||||
|
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(recorder)
|
||||||
|
c.Request = httptest.NewRequest(http.MethodGet, "/api/v1/auth/me", nil)
|
||||||
|
c.Set(string(middleware2.ContextKeyUser), middleware2.AuthSubject{UserID: 31})
|
||||||
|
|
||||||
|
handler.GetCurrentUser(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusOK, recorder.Code)
|
||||||
|
|
||||||
|
var resp struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Data map[string]any `json:"data"`
|
||||||
|
}
|
||||||
|
require.NoError(t, json.Unmarshal(recorder.Body.Bytes(), &resp))
|
||||||
|
require.Equal(t, 0, resp.Code)
|
||||||
|
require.Equal(t, true, resp.Data["email_bound"])
|
||||||
|
require.Equal(t, true, resp.Data["linuxdo_bound"])
|
||||||
|
require.Equal(t, "https://cdn.example.com/linuxdo.png", resp.Data["avatar_url"])
|
||||||
|
|
||||||
|
authBindings, ok := resp.Data["auth_bindings"].(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
linuxdoBinding, ok := authBindings["linuxdo"].(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, true, linuxdoBinding["bound"])
|
||||||
|
|
||||||
|
avatarSource, ok := resp.Data["avatar_source"].(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, "linuxdo", avatarSource["provider"])
|
||||||
|
require.Equal(t, "linuxdo", avatarSource["source"])
|
||||||
|
|
||||||
|
profileSources, ok := resp.Data["profile_sources"].(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
usernameSource, ok := profileSources["username"].(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, "linuxdo", usernameSource["provider"])
|
||||||
|
require.Equal(t, "linuxdo", usernameSource["source"])
|
||||||
|
}
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/Wei-Shaw/sub2api/internal/config"
|
"github.com/Wei-Shaw/sub2api/internal/config"
|
||||||
"github.com/Wei-Shaw/sub2api/internal/handler/dto"
|
"github.com/Wei-Shaw/sub2api/internal/handler/dto"
|
||||||
|
infraerrors "github.com/Wei-Shaw/sub2api/internal/pkg/errors"
|
||||||
"github.com/Wei-Shaw/sub2api/internal/pkg/ip"
|
"github.com/Wei-Shaw/sub2api/internal/pkg/ip"
|
||||||
"github.com/Wei-Shaw/sub2api/internal/pkg/response"
|
"github.com/Wei-Shaw/sub2api/internal/pkg/response"
|
||||||
middleware2 "github.com/Wei-Shaw/sub2api/internal/server/middleware"
|
middleware2 "github.com/Wei-Shaw/sub2api/internal/server/middleware"
|
||||||
@@ -104,6 +106,34 @@ func (h *AuthHandler) respondWithTokenPair(c *gin.Context, user *service.User) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *AuthHandler) ensureBackendModeAllowsUser(ctx context.Context, user *service.User) error {
|
||||||
|
if user == nil {
|
||||||
|
return infraerrors.Unauthorized("INVALID_USER", "user not found")
|
||||||
|
}
|
||||||
|
if h == nil || !h.isBackendModeEnabled(ctx) || user.IsAdmin() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return infraerrors.Forbidden("BACKEND_MODE_ADMIN_ONLY", "Backend mode is active. Only admin login is allowed.")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *AuthHandler) ensureBackendModeAllowsNewUserLogin(ctx context.Context) error {
|
||||||
|
if h == nil || !h.isBackendModeEnabled(ctx) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return infraerrors.Forbidden("BACKEND_MODE_ADMIN_ONLY", "Backend mode is active. Only admin login is allowed.")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *AuthHandler) isBackendModeEnabled(ctx context.Context) bool {
|
||||||
|
if h == nil || h.settingSvc == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
settings, err := h.settingSvc.GetPublicSettings(ctx)
|
||||||
|
if err == nil && settings != nil {
|
||||||
|
return settings.BackendModeEnabled
|
||||||
|
}
|
||||||
|
return h.settingSvc.IsBackendModeEnabled(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
// Register handles user registration
|
// Register handles user registration
|
||||||
// POST /api/v1/auth/register
|
// POST /api/v1/auth/register
|
||||||
func (h *AuthHandler) Register(c *gin.Context) {
|
func (h *AuthHandler) Register(c *gin.Context) {
|
||||||
@@ -177,6 +207,11 @@ func (h *AuthHandler) Login(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
_ = token // token 由 authService.Login 返回但此处由 respondWithTokenPair 重新生成
|
_ = token // token 由 authService.Login 返回但此处由 respondWithTokenPair 重新生成
|
||||||
|
|
||||||
|
if err := h.ensureBackendModeAllowsUser(c.Request.Context(), user); err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Check if TOTP 2FA is enabled for this user
|
// Check if TOTP 2FA is enabled for this user
|
||||||
if h.totpService != nil && h.settingSvc.IsTotpEnabled(c.Request.Context()) && user.TotpEnabled {
|
if h.totpService != nil && h.settingSvc.IsTotpEnabled(c.Request.Context()) && user.TotpEnabled {
|
||||||
// Create a temporary login session for 2FA
|
// Create a temporary login session for 2FA
|
||||||
@@ -194,11 +229,7 @@ func (h *AuthHandler) Login(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Backend mode: only admin can login
|
h.authService.RecordSuccessfulLogin(c.Request.Context(), user.ID)
|
||||||
if h.settingSvc.IsBackendModeEnabled(c.Request.Context()) && !user.IsAdmin() {
|
|
||||||
response.Forbidden(c, "Backend mode is active. Only admin login is allowed.")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
h.respondWithTokenPair(c, user)
|
h.respondWithTokenPair(c, user)
|
||||||
}
|
}
|
||||||
@@ -263,15 +294,75 @@ func (h *AuthHandler) Login2FA(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Backend mode: only admin can login (check BEFORE deleting session)
|
if err := h.ensureBackendModeAllowsUser(c.Request.Context(), user); err != nil {
|
||||||
if h.settingSvc.IsBackendModeEnabled(c.Request.Context()) && !user.IsAdmin() {
|
response.ErrorFrom(c, err)
|
||||||
response.Forbidden(c, "Backend mode is active. Only admin login is allowed.")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if session.PendingOAuthBind != nil {
|
||||||
|
pendingSvc, err := h.pendingIdentityService()
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
pendingSession, err := pendingSvc.GetBrowserSession(
|
||||||
|
c.Request.Context(),
|
||||||
|
session.PendingOAuthBind.PendingSessionToken,
|
||||||
|
session.PendingOAuthBind.BrowserSessionKey,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
decision, err := h.ensurePendingOAuthAdoptionDecision(c, pendingSession.ID, oauthAdoptionDecisionRequest{})
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := applyPendingOAuthBinding(
|
||||||
|
c.Request.Context(),
|
||||||
|
h.entClient(),
|
||||||
|
h.authService,
|
||||||
|
h.userService,
|
||||||
|
pendingSession,
|
||||||
|
decision,
|
||||||
|
&user.ID,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
); err != nil {
|
||||||
|
response.ErrorFrom(c, infraerrors.InternalServer("PENDING_AUTH_BIND_APPLY_FAILED", "failed to bind pending oauth identity").WithCause(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if _, err := pendingSvc.ConsumeBrowserSession(
|
||||||
|
c.Request.Context(),
|
||||||
|
pendingSession.SessionToken,
|
||||||
|
pendingSession.BrowserSessionKey,
|
||||||
|
); err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
secureCookie := isRequestHTTPS(c)
|
||||||
|
clearOAuthPendingSessionCookie(c, secureCookie)
|
||||||
|
clearOAuthPendingBrowserCookie(c, secureCookie)
|
||||||
|
h.authService.RecordSuccessfulLogin(c.Request.Context(), user.ID)
|
||||||
|
|
||||||
|
user, err = h.userService.GetByID(c.Request.Context(), session.UserID)
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Delete the login session (only after all checks pass)
|
// Delete the login session (only after all checks pass)
|
||||||
_ = h.totpService.DeleteLoginSession(c.Request.Context(), req.TempToken)
|
_ = h.totpService.DeleteLoginSession(c.Request.Context(), req.TempToken)
|
||||||
|
|
||||||
|
if session.PendingOAuthBind == nil {
|
||||||
|
h.authService.RecordSuccessfulLogin(c.Request.Context(), user.ID)
|
||||||
|
}
|
||||||
|
|
||||||
h.respondWithTokenPair(c, user)
|
h.respondWithTokenPair(c, user)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,8 +381,14 @@ func (h *AuthHandler) GetCurrentUser(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
identities, err := h.userService.GetProfileIdentitySummaries(c.Request.Context(), subject.UserID, user)
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
type UserResponse struct {
|
type UserResponse struct {
|
||||||
*dto.User
|
userProfileResponse
|
||||||
RunMode string `json:"run_mode"`
|
RunMode string `json:"run_mode"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,7 +397,10 @@ func (h *AuthHandler) GetCurrentUser(c *gin.Context) {
|
|||||||
runMode = h.cfg.RunMode
|
runMode = h.cfg.RunMode
|
||||||
}
|
}
|
||||||
|
|
||||||
response.Success(c, UserResponse{User: dto.UserFromService(user), RunMode: runMode})
|
response.Success(c, UserResponse{
|
||||||
|
userProfileResponse: userProfileResponseFromService(user, identities),
|
||||||
|
RunMode: runMode,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidatePromoCodeRequest 验证优惠码请求
|
// ValidatePromoCodeRequest 验证优惠码请求
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package handler
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/hmac"
|
||||||
|
"crypto/sha256"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -13,10 +15,13 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
|
dbent "github.com/Wei-Shaw/sub2api/ent"
|
||||||
|
dbuser "github.com/Wei-Shaw/sub2api/ent/user"
|
||||||
"github.com/Wei-Shaw/sub2api/internal/config"
|
"github.com/Wei-Shaw/sub2api/internal/config"
|
||||||
infraerrors "github.com/Wei-Shaw/sub2api/internal/pkg/errors"
|
infraerrors "github.com/Wei-Shaw/sub2api/internal/pkg/errors"
|
||||||
"github.com/Wei-Shaw/sub2api/internal/pkg/oauth"
|
"github.com/Wei-Shaw/sub2api/internal/pkg/oauth"
|
||||||
"github.com/Wei-Shaw/sub2api/internal/pkg/response"
|
"github.com/Wei-Shaw/sub2api/internal/pkg/response"
|
||||||
|
servermiddleware "github.com/Wei-Shaw/sub2api/internal/server/middleware"
|
||||||
"github.com/Wei-Shaw/sub2api/internal/service"
|
"github.com/Wei-Shaw/sub2api/internal/service"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -26,9 +31,13 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
linuxDoOAuthCookiePath = "/api/v1/auth/oauth/linuxdo"
|
linuxDoOAuthCookiePath = "/api/v1/auth/oauth/linuxdo"
|
||||||
|
oauthBindAccessTokenCookiePath = "/api/v1/auth/oauth"
|
||||||
linuxDoOAuthStateCookieName = "linuxdo_oauth_state"
|
linuxDoOAuthStateCookieName = "linuxdo_oauth_state"
|
||||||
linuxDoOAuthVerifierCookie = "linuxdo_oauth_verifier"
|
linuxDoOAuthVerifierCookie = "linuxdo_oauth_verifier"
|
||||||
linuxDoOAuthRedirectCookie = "linuxdo_oauth_redirect"
|
linuxDoOAuthRedirectCookie = "linuxdo_oauth_redirect"
|
||||||
|
linuxDoOAuthIntentCookieName = "linuxdo_oauth_intent"
|
||||||
|
linuxDoOAuthBindUserCookieName = "linuxdo_oauth_bind_user"
|
||||||
|
oauthBindAccessTokenCookieName = "oauth_bind_access_token"
|
||||||
linuxDoOAuthCookieMaxAgeSec = 10 * 60 // 10 minutes
|
linuxDoOAuthCookieMaxAgeSec = 10 * 60 // 10 minutes
|
||||||
linuxDoOAuthDefaultRedirectTo = "/dashboard"
|
linuxDoOAuthDefaultRedirectTo = "/dashboard"
|
||||||
linuxDoOAuthDefaultFrontendCB = "/auth/linuxdo/callback"
|
linuxDoOAuthDefaultFrontendCB = "/auth/linuxdo/callback"
|
||||||
@@ -36,6 +45,9 @@ const (
|
|||||||
linuxDoOAuthMaxRedirectLen = 2048
|
linuxDoOAuthMaxRedirectLen = 2048
|
||||||
linuxDoOAuthMaxFragmentValueLen = 512
|
linuxDoOAuthMaxFragmentValueLen = 512
|
||||||
linuxDoOAuthMaxSubjectLen = 64 - len("linuxdo-")
|
linuxDoOAuthMaxSubjectLen = 64 - len("linuxdo-")
|
||||||
|
|
||||||
|
oauthIntentLogin = "login"
|
||||||
|
oauthIntentBindCurrentUser = "bind_current_user"
|
||||||
)
|
)
|
||||||
|
|
||||||
type linuxDoTokenResponse struct {
|
type linuxDoTokenResponse struct {
|
||||||
@@ -87,20 +99,37 @@ func (h *AuthHandler) LinuxDoOAuthStart(c *gin.Context) {
|
|||||||
redirectTo = linuxDoOAuthDefaultRedirectTo
|
redirectTo = linuxDoOAuthDefaultRedirectTo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
browserSessionKey, err := generateOAuthPendingBrowserSession()
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, infraerrors.InternalServer("OAUTH_BROWSER_SESSION_GEN_FAILED", "failed to generate oauth browser session").WithCause(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
secureCookie := isRequestHTTPS(c)
|
secureCookie := isRequestHTTPS(c)
|
||||||
setCookie(c, linuxDoOAuthStateCookieName, encodeCookieValue(state), linuxDoOAuthCookieMaxAgeSec, secureCookie)
|
setCookie(c, linuxDoOAuthStateCookieName, encodeCookieValue(state), linuxDoOAuthCookieMaxAgeSec, secureCookie)
|
||||||
setCookie(c, linuxDoOAuthRedirectCookie, encodeCookieValue(redirectTo), linuxDoOAuthCookieMaxAgeSec, secureCookie)
|
setCookie(c, linuxDoOAuthRedirectCookie, encodeCookieValue(redirectTo), linuxDoOAuthCookieMaxAgeSec, secureCookie)
|
||||||
|
intent := normalizeOAuthIntent(c.Query("intent"))
|
||||||
|
setCookie(c, linuxDoOAuthIntentCookieName, encodeCookieValue(intent), linuxDoOAuthCookieMaxAgeSec, secureCookie)
|
||||||
|
setOAuthPendingBrowserCookie(c, browserSessionKey, secureCookie)
|
||||||
|
clearOAuthPendingSessionCookie(c, secureCookie)
|
||||||
|
if intent == oauthIntentBindCurrentUser {
|
||||||
|
bindCookieValue, err := h.buildOAuthBindUserCookieFromContext(c)
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setCookie(c, linuxDoOAuthBindUserCookieName, encodeCookieValue(bindCookieValue), linuxDoOAuthCookieMaxAgeSec, secureCookie)
|
||||||
|
} else {
|
||||||
|
clearCookie(c, linuxDoOAuthBindUserCookieName, secureCookie)
|
||||||
|
}
|
||||||
|
|
||||||
codeChallenge := ""
|
|
||||||
if cfg.UsePKCE {
|
|
||||||
verifier, err := oauth.GenerateCodeVerifier()
|
verifier, err := oauth.GenerateCodeVerifier()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.ErrorFrom(c, infraerrors.InternalServer("OAUTH_PKCE_GEN_FAILED", "failed to generate pkce verifier").WithCause(err))
|
response.ErrorFrom(c, infraerrors.InternalServer("OAUTH_PKCE_GEN_FAILED", "failed to generate pkce verifier").WithCause(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
codeChallenge = oauth.GenerateCodeChallenge(verifier)
|
codeChallenge := oauth.GenerateCodeChallenge(verifier)
|
||||||
setCookie(c, linuxDoOAuthVerifierCookie, encodeCookieValue(verifier), linuxDoOAuthCookieMaxAgeSec, secureCookie)
|
setCookie(c, linuxDoOAuthVerifierCookie, encodeCookieValue(verifier), linuxDoOAuthCookieMaxAgeSec, secureCookie)
|
||||||
}
|
|
||||||
|
|
||||||
redirectURI := strings.TrimSpace(cfg.RedirectURL)
|
redirectURI := strings.TrimSpace(cfg.RedirectURL)
|
||||||
if redirectURI == "" {
|
if redirectURI == "" {
|
||||||
@@ -148,6 +177,8 @@ func (h *AuthHandler) LinuxDoOAuthCallback(c *gin.Context) {
|
|||||||
clearCookie(c, linuxDoOAuthStateCookieName, secureCookie)
|
clearCookie(c, linuxDoOAuthStateCookieName, secureCookie)
|
||||||
clearCookie(c, linuxDoOAuthVerifierCookie, secureCookie)
|
clearCookie(c, linuxDoOAuthVerifierCookie, secureCookie)
|
||||||
clearCookie(c, linuxDoOAuthRedirectCookie, secureCookie)
|
clearCookie(c, linuxDoOAuthRedirectCookie, secureCookie)
|
||||||
|
clearCookie(c, linuxDoOAuthIntentCookieName, secureCookie)
|
||||||
|
clearCookie(c, linuxDoOAuthBindUserCookieName, secureCookie)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
expectedState, err := readCookieDecoded(c, linuxDoOAuthStateCookieName)
|
expectedState, err := readCookieDecoded(c, linuxDoOAuthStateCookieName)
|
||||||
@@ -161,15 +192,19 @@ func (h *AuthHandler) LinuxDoOAuthCallback(c *gin.Context) {
|
|||||||
if redirectTo == "" {
|
if redirectTo == "" {
|
||||||
redirectTo = linuxDoOAuthDefaultRedirectTo
|
redirectTo = linuxDoOAuthDefaultRedirectTo
|
||||||
}
|
}
|
||||||
|
browserSessionKey, _ := readOAuthPendingBrowserCookie(c)
|
||||||
|
if strings.TrimSpace(browserSessionKey) == "" {
|
||||||
|
redirectOAuthError(c, frontendCallback, "missing_browser_session", "missing oauth browser session", "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
intent, _ := readCookieDecoded(c, linuxDoOAuthIntentCookieName)
|
||||||
|
intent = normalizeOAuthIntent(intent)
|
||||||
|
|
||||||
codeVerifier := ""
|
codeVerifier, _ := readCookieDecoded(c, linuxDoOAuthVerifierCookie)
|
||||||
if cfg.UsePKCE {
|
|
||||||
codeVerifier, _ = readCookieDecoded(c, linuxDoOAuthVerifierCookie)
|
|
||||||
if codeVerifier == "" {
|
if codeVerifier == "" {
|
||||||
redirectOAuthError(c, frontendCallback, "missing_verifier", "missing pkce verifier", "")
|
redirectOAuthError(c, frontendCallback, "missing_verifier", "missing pkce verifier", "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
redirectURI := strings.TrimSpace(cfg.RedirectURL)
|
redirectURI := strings.TrimSpace(cfg.RedirectURL)
|
||||||
if redirectURI == "" {
|
if redirectURI == "" {
|
||||||
@@ -198,52 +233,202 @@ func (h *AuthHandler) LinuxDoOAuthCallback(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
email, username, subject, err := linuxDoFetchUserInfo(c.Request.Context(), cfg, tokenResp)
|
email, username, subject, displayName, avatarURL, err := linuxDoFetchUserInfo(c.Request.Context(), cfg, tokenResp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("[LinuxDo OAuth] userinfo fetch failed: %v", err)
|
log.Printf("[LinuxDo OAuth] userinfo fetch failed: %v", err)
|
||||||
redirectOAuthError(c, frontendCallback, "userinfo_failed", "failed to fetch user info", "")
|
redirectOAuthError(c, frontendCallback, "userinfo_failed", "failed to fetch user info", "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
compatEmail := strings.TrimSpace(email)
|
||||||
|
|
||||||
// 安全考虑:不要把第三方返回的 email 直接映射到本地账号(可能与本地邮箱用户冲突导致账号被接管)。
|
// 安全考虑:不要把第三方返回的 email 直接映射到本地账号(可能与本地邮箱用户冲突导致账号被接管)。
|
||||||
// 统一使用基于 subject 的稳定合成邮箱来做账号绑定。
|
// 统一使用基于 subject 的稳定合成邮箱来做账号绑定。
|
||||||
if subject != "" {
|
if subject != "" {
|
||||||
email = linuxDoSyntheticEmail(subject)
|
email = linuxDoSyntheticEmail(subject)
|
||||||
}
|
}
|
||||||
|
identityKey := service.PendingAuthIdentityKey{
|
||||||
// 传入空邀请码;如果需要邀请码,服务层返回 ErrOAuthInvitationRequired
|
ProviderType: "linuxdo",
|
||||||
tokenPair, _, err := h.authService.LoginOrRegisterOAuthWithTokenPair(c.Request.Context(), email, username, "")
|
ProviderKey: "linuxdo",
|
||||||
|
ProviderSubject: subject,
|
||||||
|
}
|
||||||
|
upstreamClaims := map[string]any{
|
||||||
|
"email": email,
|
||||||
|
"username": username,
|
||||||
|
"subject": subject,
|
||||||
|
"suggested_display_name": displayName,
|
||||||
|
"suggested_avatar_url": avatarURL,
|
||||||
|
}
|
||||||
|
if compatEmail != "" && !strings.EqualFold(strings.TrimSpace(compatEmail), strings.TrimSpace(email)) {
|
||||||
|
upstreamClaims["compat_email"] = compatEmail
|
||||||
|
}
|
||||||
|
if intent == oauthIntentBindCurrentUser {
|
||||||
|
targetUserID, err := h.readOAuthBindUserIDFromCookie(c, linuxDoOAuthBindUserCookieName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, service.ErrOAuthInvitationRequired) {
|
redirectOAuthError(c, frontendCallback, "invalid_state", "invalid oauth bind target", "")
|
||||||
pendingToken, tokenErr := h.authService.CreatePendingOAuthToken(email, username)
|
|
||||||
if tokenErr != nil {
|
|
||||||
redirectOAuthError(c, frontendCallback, "login_failed", "service_error", "")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fragment := url.Values{}
|
if err := h.createOAuthPendingSession(c, oauthPendingSessionPayload{
|
||||||
fragment.Set("error", "invitation_required")
|
Intent: oauthIntentBindCurrentUser,
|
||||||
fragment.Set("pending_oauth_token", pendingToken)
|
Identity: identityKey,
|
||||||
fragment.Set("redirect", redirectTo)
|
TargetUserID: &targetUserID,
|
||||||
redirectWithFragment(c, frontendCallback, fragment)
|
ResolvedEmail: email,
|
||||||
|
RedirectTo: redirectTo,
|
||||||
|
BrowserSessionKey: browserSessionKey,
|
||||||
|
UpstreamIdentityClaims: upstreamClaims,
|
||||||
|
CompletionResponse: map[string]any{
|
||||||
|
"redirect": redirectTo,
|
||||||
|
},
|
||||||
|
}); err != nil {
|
||||||
|
redirectOAuthError(c, frontendCallback, "session_error", "failed to continue oauth bind", "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 避免把内部细节泄露给客户端;给前端保留结构化原因与提示信息即可。
|
redirectToFrontendCallback(c, frontendCallback)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
existingIdentityUser, err := h.findOAuthIdentityUser(c.Request.Context(), identityKey)
|
||||||
|
if err != nil {
|
||||||
|
redirectOAuthError(c, frontendCallback, "session_error", infraerrors.Reason(err), infraerrors.Message(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if existingIdentityUser != nil {
|
||||||
|
tokenPair, user, err := h.authService.LoginOrRegisterOAuthWithTokenPair(c.Request.Context(), existingIdentityUser.Email, username, "")
|
||||||
|
if err != nil {
|
||||||
redirectOAuthError(c, frontendCallback, "login_failed", infraerrors.Reason(err), infraerrors.Message(err))
|
redirectOAuthError(c, frontendCallback, "login_failed", infraerrors.Reason(err), infraerrors.Message(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if err := h.createOAuthPendingSession(c, oauthPendingSessionPayload{
|
||||||
|
Intent: oauthIntentLogin,
|
||||||
|
Identity: identityKey,
|
||||||
|
TargetUserID: &user.ID,
|
||||||
|
ResolvedEmail: existingIdentityUser.Email,
|
||||||
|
RedirectTo: redirectTo,
|
||||||
|
BrowserSessionKey: browserSessionKey,
|
||||||
|
UpstreamIdentityClaims: upstreamClaims,
|
||||||
|
CompletionResponse: map[string]any{
|
||||||
|
"access_token": tokenPair.AccessToken,
|
||||||
|
"refresh_token": tokenPair.RefreshToken,
|
||||||
|
"expires_in": tokenPair.ExpiresIn,
|
||||||
|
"token_type": "Bearer",
|
||||||
|
"redirect": redirectTo,
|
||||||
|
},
|
||||||
|
}); err != nil {
|
||||||
|
redirectOAuthError(c, frontendCallback, "session_error", "failed to continue oauth login", "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
redirectToFrontendCallback(c, frontendCallback)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
fragment := url.Values{}
|
compatEmailUser, err := h.findLinuxDoCompatEmailUser(c.Request.Context(), compatEmail)
|
||||||
fragment.Set("access_token", tokenPair.AccessToken)
|
if err != nil {
|
||||||
fragment.Set("refresh_token", tokenPair.RefreshToken)
|
redirectOAuthError(c, frontendCallback, "session_error", infraerrors.Reason(err), infraerrors.Message(err))
|
||||||
fragment.Set("expires_in", fmt.Sprintf("%d", tokenPair.ExpiresIn))
|
return
|
||||||
fragment.Set("token_type", "Bearer")
|
}
|
||||||
fragment.Set("redirect", redirectTo)
|
if err := h.createLinuxDoOAuthChoicePendingSession(
|
||||||
redirectWithFragment(c, frontendCallback, fragment)
|
c,
|
||||||
|
identityKey,
|
||||||
|
email,
|
||||||
|
email,
|
||||||
|
redirectTo,
|
||||||
|
browserSessionKey,
|
||||||
|
upstreamClaims,
|
||||||
|
compatEmail,
|
||||||
|
compatEmailUser,
|
||||||
|
h.isForceEmailOnThirdPartySignup(c.Request.Context()),
|
||||||
|
); err != nil {
|
||||||
|
redirectOAuthError(c, frontendCallback, "session_error", "failed to continue oauth login", "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
redirectToFrontendCallback(c, frontendCallback)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *AuthHandler) findLinuxDoCompatEmailUser(ctx context.Context, email string) (*dbent.User, error) {
|
||||||
|
client := h.entClient()
|
||||||
|
if client == nil {
|
||||||
|
return nil, infraerrors.ServiceUnavailable("PENDING_AUTH_NOT_READY", "pending auth service is not ready")
|
||||||
|
}
|
||||||
|
|
||||||
|
email = strings.TrimSpace(strings.ToLower(email))
|
||||||
|
if email == "" ||
|
||||||
|
strings.HasSuffix(email, service.LinuxDoConnectSyntheticEmailDomain) ||
|
||||||
|
strings.HasSuffix(email, service.OIDCConnectSyntheticEmailDomain) ||
|
||||||
|
strings.HasSuffix(email, service.WeChatConnectSyntheticEmailDomain) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
userEntity, err := client.User.Query().
|
||||||
|
Where(dbuser.EmailEqualFold(email)).
|
||||||
|
Only(ctx)
|
||||||
|
if err != nil {
|
||||||
|
if dbent.IsNotFound(err) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return nil, infraerrors.InternalServer("COMPAT_EMAIL_LOOKUP_FAILED", "failed to look up compat email user").WithCause(err)
|
||||||
|
}
|
||||||
|
return userEntity, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *AuthHandler) createLinuxDoOAuthChoicePendingSession(
|
||||||
|
c *gin.Context,
|
||||||
|
identity service.PendingAuthIdentityKey,
|
||||||
|
suggestedEmail string,
|
||||||
|
resolvedEmail string,
|
||||||
|
redirectTo string,
|
||||||
|
browserSessionKey string,
|
||||||
|
upstreamClaims map[string]any,
|
||||||
|
compatEmail string,
|
||||||
|
compatEmailUser *dbent.User,
|
||||||
|
forceEmailOnSignup bool,
|
||||||
|
) error {
|
||||||
|
suggestionEmail := strings.TrimSpace(suggestedEmail)
|
||||||
|
canonicalEmail := strings.TrimSpace(resolvedEmail)
|
||||||
|
if suggestionEmail == "" {
|
||||||
|
suggestionEmail = canonicalEmail
|
||||||
|
}
|
||||||
|
|
||||||
|
completionResponse := map[string]any{
|
||||||
|
"step": oauthPendingChoiceStep,
|
||||||
|
"adoption_required": true,
|
||||||
|
"redirect": strings.TrimSpace(redirectTo),
|
||||||
|
"email": suggestionEmail,
|
||||||
|
"resolved_email": canonicalEmail,
|
||||||
|
"existing_account_email": "",
|
||||||
|
"existing_account_bindable": false,
|
||||||
|
"create_account_allowed": true,
|
||||||
|
"force_email_on_signup": forceEmailOnSignup,
|
||||||
|
"choice_reason": "third_party_signup",
|
||||||
|
}
|
||||||
|
if strings.TrimSpace(compatEmail) != "" {
|
||||||
|
completionResponse["compat_email"] = strings.TrimSpace(compatEmail)
|
||||||
|
}
|
||||||
|
resolvedChoiceEmail := suggestionEmail
|
||||||
|
if compatEmailUser != nil {
|
||||||
|
completionResponse["email"] = strings.TrimSpace(compatEmailUser.Email)
|
||||||
|
completionResponse["existing_account_email"] = strings.TrimSpace(compatEmailUser.Email)
|
||||||
|
completionResponse["existing_account_bindable"] = true
|
||||||
|
completionResponse["choice_reason"] = "compat_email_match"
|
||||||
|
resolvedChoiceEmail = strings.TrimSpace(compatEmailUser.Email)
|
||||||
|
}
|
||||||
|
if forceEmailOnSignup && compatEmailUser == nil {
|
||||||
|
completionResponse["choice_reason"] = "force_email_on_signup"
|
||||||
|
}
|
||||||
|
|
||||||
|
return h.createOAuthPendingSession(c, oauthPendingSessionPayload{
|
||||||
|
Intent: oauthIntentLogin,
|
||||||
|
Identity: identity,
|
||||||
|
ResolvedEmail: resolvedChoiceEmail,
|
||||||
|
RedirectTo: redirectTo,
|
||||||
|
BrowserSessionKey: browserSessionKey,
|
||||||
|
UpstreamIdentityClaims: upstreamClaims,
|
||||||
|
CompletionResponse: completionResponse,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type completeLinuxDoOAuthRequest struct {
|
type completeLinuxDoOAuthRequest struct {
|
||||||
PendingOAuthToken string `json:"pending_oauth_token" binding:"required"`
|
|
||||||
InvitationCode string `json:"invitation_code" binding:"required"`
|
InvitationCode string `json:"invitation_code" binding:"required"`
|
||||||
|
AdoptDisplayName *bool `json:"adopt_display_name,omitempty"`
|
||||||
|
AdoptAvatar *bool `json:"adopt_avatar,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CompleteLinuxDoOAuthRegistration completes a pending OAuth registration by validating
|
// CompleteLinuxDoOAuthRegistration completes a pending OAuth registration by validating
|
||||||
@@ -256,17 +441,75 @@ func (h *AuthHandler) CompleteLinuxDoOAuthRegistration(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
email, username, err := h.authService.VerifyPendingOAuthToken(req.PendingOAuthToken)
|
secureCookie := isRequestHTTPS(c)
|
||||||
|
sessionToken, err := readOAuthPendingSessionCookie(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "INVALID_TOKEN", "message": "invalid or expired registration token"})
|
clearOAuthPendingSessionCookie(c, secureCookie)
|
||||||
|
clearOAuthPendingBrowserCookie(c, secureCookie)
|
||||||
|
response.ErrorFrom(c, service.ErrPendingAuthSessionNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
browserSessionKey, err := readOAuthPendingBrowserCookie(c)
|
||||||
tokenPair, _, err := h.authService.LoginOrRegisterOAuthWithTokenPair(c.Request.Context(), email, username, req.InvitationCode)
|
if err != nil {
|
||||||
|
clearOAuthPendingSessionCookie(c, secureCookie)
|
||||||
|
clearOAuthPendingBrowserCookie(c, secureCookie)
|
||||||
|
response.ErrorFrom(c, service.ErrPendingAuthBrowserMismatch)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
pendingSvc, err := h.pendingIdentityService()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.ErrorFrom(c, err)
|
response.ErrorFrom(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
session, err := pendingSvc.GetBrowserSession(c.Request.Context(), sessionToken, browserSessionKey)
|
||||||
|
if err != nil {
|
||||||
|
clearOAuthPendingSessionCookie(c, secureCookie)
|
||||||
|
clearOAuthPendingBrowserCookie(c, secureCookie)
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := ensurePendingOAuthCompleteRegistrationSession(session); err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := h.ensureBackendModeAllowsNewUserLogin(c.Request.Context()); err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
email := strings.TrimSpace(session.ResolvedEmail)
|
||||||
|
username := pendingSessionStringValue(session.UpstreamIdentityClaims, "username")
|
||||||
|
if email == "" || username == "" {
|
||||||
|
response.ErrorFrom(c, infraerrors.BadRequest("PENDING_AUTH_SESSION_INVALID", "pending auth registration context is invalid"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tokenPair, user, err := h.authService.LoginOrRegisterOAuthWithTokenPair(c.Request.Context(), email, username, req.InvitationCode)
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
decision, err := h.upsertPendingOAuthAdoptionDecision(c, session.ID, oauthAdoptionDecisionRequest{
|
||||||
|
AdoptDisplayName: req.AdoptDisplayName,
|
||||||
|
AdoptAvatar: req.AdoptAvatar,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := applyPendingOAuthAdoption(c.Request.Context(), h.entClient(), h.authService, h.userService, session, decision, &user.ID); err != nil {
|
||||||
|
response.ErrorFrom(c, infraerrors.InternalServer("PENDING_AUTH_ADOPTION_APPLY_FAILED", "failed to apply oauth profile adoption").WithCause(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
h.authService.RecordSuccessfulLogin(c.Request.Context(), user.ID)
|
||||||
|
if _, err := pendingSvc.ConsumeBrowserSession(c.Request.Context(), sessionToken, browserSessionKey); err != nil {
|
||||||
|
clearOAuthPendingSessionCookie(c, secureCookie)
|
||||||
|
clearOAuthPendingBrowserCookie(c, secureCookie)
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
clearOAuthPendingSessionCookie(c, secureCookie)
|
||||||
|
clearOAuthPendingBrowserCookie(c, secureCookie)
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"access_token": tokenPair.AccessToken,
|
"access_token": tokenPair.AccessToken,
|
||||||
@@ -303,9 +546,7 @@ func linuxDoExchangeCode(
|
|||||||
form.Set("client_id", cfg.ClientID)
|
form.Set("client_id", cfg.ClientID)
|
||||||
form.Set("code", code)
|
form.Set("code", code)
|
||||||
form.Set("redirect_uri", redirectURI)
|
form.Set("redirect_uri", redirectURI)
|
||||||
if cfg.UsePKCE {
|
|
||||||
form.Set("code_verifier", codeVerifier)
|
form.Set("code_verifier", codeVerifier)
|
||||||
}
|
|
||||||
|
|
||||||
r := client.R().
|
r := client.R().
|
||||||
SetContext(ctx).
|
SetContext(ctx).
|
||||||
@@ -353,11 +594,11 @@ func linuxDoFetchUserInfo(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
cfg config.LinuxDoConnectConfig,
|
cfg config.LinuxDoConnectConfig,
|
||||||
token *linuxDoTokenResponse,
|
token *linuxDoTokenResponse,
|
||||||
) (email string, username string, subject string, err error) {
|
) (email string, username string, subject string, displayName string, avatarURL string, err error) {
|
||||||
client := req.C().SetTimeout(30 * time.Second)
|
client := req.C().SetTimeout(30 * time.Second)
|
||||||
authorization, err := buildBearerAuthorization(token.TokenType, token.AccessToken)
|
authorization, err := buildBearerAuthorization(token.TokenType, token.AccessToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", "", fmt.Errorf("invalid token for userinfo request: %w", err)
|
return "", "", "", "", "", fmt.Errorf("invalid token for userinfo request: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := client.R().
|
resp, err := client.R().
|
||||||
@@ -366,16 +607,16 @@ func linuxDoFetchUserInfo(
|
|||||||
SetHeader("Authorization", authorization).
|
SetHeader("Authorization", authorization).
|
||||||
Get(cfg.UserInfoURL)
|
Get(cfg.UserInfoURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", "", fmt.Errorf("request userinfo: %w", err)
|
return "", "", "", "", "", fmt.Errorf("request userinfo: %w", err)
|
||||||
}
|
}
|
||||||
if !resp.IsSuccessState() {
|
if !resp.IsSuccessState() {
|
||||||
return "", "", "", fmt.Errorf("userinfo status=%d", resp.StatusCode)
|
return "", "", "", "", "", fmt.Errorf("userinfo status=%d", resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
return linuxDoParseUserInfo(resp.String(), cfg)
|
return linuxDoParseUserInfo(resp.String(), cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func linuxDoParseUserInfo(body string, cfg config.LinuxDoConnectConfig) (email string, username string, subject string, err error) {
|
func linuxDoParseUserInfo(body string, cfg config.LinuxDoConnectConfig) (email string, username string, subject string, displayName string, avatarURL string, err error) {
|
||||||
email = firstNonEmpty(
|
email = firstNonEmpty(
|
||||||
getGJSON(body, cfg.UserInfoEmailPath),
|
getGJSON(body, cfg.UserInfoEmailPath),
|
||||||
getGJSON(body, "email"),
|
getGJSON(body, "email"),
|
||||||
@@ -400,12 +641,29 @@ func linuxDoParseUserInfo(body string, cfg config.LinuxDoConnectConfig) (email s
|
|||||||
getGJSON(body, "user.id"),
|
getGJSON(body, "user.id"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
displayName = firstNonEmpty(
|
||||||
|
getGJSON(body, "name"),
|
||||||
|
getGJSON(body, "nickname"),
|
||||||
|
getGJSON(body, "display_name"),
|
||||||
|
getGJSON(body, "user.name"),
|
||||||
|
getGJSON(body, "user.username"),
|
||||||
|
username,
|
||||||
|
)
|
||||||
|
avatarURL = firstNonEmpty(
|
||||||
|
getGJSON(body, "avatar_url"),
|
||||||
|
getGJSON(body, "avatar"),
|
||||||
|
getGJSON(body, "picture"),
|
||||||
|
getGJSON(body, "profile_image_url"),
|
||||||
|
getGJSON(body, "user.avatar"),
|
||||||
|
getGJSON(body, "user.avatar_url"),
|
||||||
|
)
|
||||||
|
|
||||||
subject = strings.TrimSpace(subject)
|
subject = strings.TrimSpace(subject)
|
||||||
if subject == "" {
|
if subject == "" {
|
||||||
return "", "", "", errors.New("userinfo missing id field")
|
return "", "", "", "", "", errors.New("userinfo missing id field")
|
||||||
}
|
}
|
||||||
if !isSafeLinuxDoSubject(subject) {
|
if !isSafeLinuxDoSubject(subject) {
|
||||||
return "", "", "", errors.New("userinfo returned invalid id field")
|
return "", "", "", "", "", errors.New("userinfo returned invalid id field")
|
||||||
}
|
}
|
||||||
|
|
||||||
email = strings.TrimSpace(email)
|
email = strings.TrimSpace(email)
|
||||||
@@ -418,8 +676,13 @@ func linuxDoParseUserInfo(body string, cfg config.LinuxDoConnectConfig) (email s
|
|||||||
if username == "" {
|
if username == "" {
|
||||||
username = "linuxdo_" + subject
|
username = "linuxdo_" + subject
|
||||||
}
|
}
|
||||||
|
displayName = strings.TrimSpace(displayName)
|
||||||
|
if displayName == "" {
|
||||||
|
displayName = username
|
||||||
|
}
|
||||||
|
avatarURL = strings.TrimSpace(avatarURL)
|
||||||
|
|
||||||
return email, username, subject, nil
|
return email, username, subject, displayName, avatarURL, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildLinuxDoAuthorizeURL(cfg config.LinuxDoConnectConfig, state string, codeChallenge string, redirectURI string) (string, error) {
|
func buildLinuxDoAuthorizeURL(cfg config.LinuxDoConnectConfig, state string, codeChallenge string, redirectURI string) (string, error) {
|
||||||
@@ -436,10 +699,8 @@ func buildLinuxDoAuthorizeURL(cfg config.LinuxDoConnectConfig, state string, cod
|
|||||||
q.Set("scope", cfg.Scopes)
|
q.Set("scope", cfg.Scopes)
|
||||||
}
|
}
|
||||||
q.Set("state", state)
|
q.Set("state", state)
|
||||||
if cfg.UsePKCE {
|
|
||||||
q.Set("code_challenge", codeChallenge)
|
q.Set("code_challenge", codeChallenge)
|
||||||
q.Set("code_challenge_method", "S256")
|
q.Set("code_challenge_method", "S256")
|
||||||
}
|
|
||||||
|
|
||||||
u.RawQuery = q.Encode()
|
u.RawQuery = q.Encode()
|
||||||
return u.String(), nil
|
return u.String(), nil
|
||||||
@@ -670,6 +931,18 @@ func clearCookie(c *gin.Context, name string, secure bool) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func clearOAuthBindAccessTokenCookie(c *gin.Context, secure bool) {
|
||||||
|
http.SetCookie(c.Writer, &http.Cookie{
|
||||||
|
Name: oauthBindAccessTokenCookieName,
|
||||||
|
Value: "",
|
||||||
|
Path: oauthBindAccessTokenCookiePath,
|
||||||
|
MaxAge: -1,
|
||||||
|
HttpOnly: false,
|
||||||
|
Secure: secure,
|
||||||
|
SameSite: http.SameSiteLaxMode,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func truncateFragmentValue(value string) string {
|
func truncateFragmentValue(value string) string {
|
||||||
value = strings.TrimSpace(value)
|
value = strings.TrimSpace(value)
|
||||||
if value == "" {
|
if value == "" {
|
||||||
@@ -728,3 +1001,107 @@ func linuxDoSyntheticEmail(subject string) string {
|
|||||||
}
|
}
|
||||||
return "linuxdo-" + subject + service.LinuxDoConnectSyntheticEmailDomain
|
return "linuxdo-" + subject + service.LinuxDoConnectSyntheticEmailDomain
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func normalizeOAuthIntent(raw string) string {
|
||||||
|
switch strings.ToLower(strings.TrimSpace(raw)) {
|
||||||
|
case "", oauthIntentLogin:
|
||||||
|
return oauthIntentLogin
|
||||||
|
case "bind", oauthIntentBindCurrentUser:
|
||||||
|
return oauthIntentBindCurrentUser
|
||||||
|
default:
|
||||||
|
return oauthIntentLogin
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *AuthHandler) buildOAuthBindUserCookieFromContext(c *gin.Context) (string, error) {
|
||||||
|
userID, err := h.resolveOAuthBindTargetUserID(c)
|
||||||
|
if err != nil || userID == nil || *userID <= 0 {
|
||||||
|
return "", infraerrors.Unauthorized("UNAUTHORIZED", "authentication required")
|
||||||
|
}
|
||||||
|
return buildOAuthBindUserCookieValue(*userID, h.oauthBindCookieSecret())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *AuthHandler) resolveOAuthBindTargetUserID(c *gin.Context) (*int64, error) {
|
||||||
|
if subject, ok := servermiddleware.GetAuthSubjectFromContext(c); ok && subject.UserID > 0 {
|
||||||
|
return &subject.UserID, nil
|
||||||
|
}
|
||||||
|
if h == nil || h.authService == nil || h.userService == nil {
|
||||||
|
return nil, service.ErrInvalidToken
|
||||||
|
}
|
||||||
|
|
||||||
|
ck, err := c.Request.Cookie(oauthBindAccessTokenCookieName)
|
||||||
|
clearOAuthBindAccessTokenCookie(c, isRequestHTTPS(c))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
tokenString, err := url.QueryUnescape(strings.TrimSpace(ck.Value))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if tokenString == "" {
|
||||||
|
return nil, service.ErrInvalidToken
|
||||||
|
}
|
||||||
|
|
||||||
|
claims, err := h.authService.ValidateToken(tokenString)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
user, err := h.userService.GetByID(c.Request.Context(), claims.UserID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if user == nil || !user.IsActive() || claims.TokenVersion != user.TokenVersion {
|
||||||
|
return nil, service.ErrInvalidToken
|
||||||
|
}
|
||||||
|
return &user.ID, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *AuthHandler) readOAuthBindUserIDFromCookie(c *gin.Context, cookieName string) (int64, error) {
|
||||||
|
value, err := readCookieDecoded(c, cookieName)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return parseOAuthBindUserCookieValue(value, h.oauthBindCookieSecret())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *AuthHandler) oauthBindCookieSecret() string {
|
||||||
|
if h == nil || h.cfg == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(h.cfg.JWT.Secret)
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildOAuthBindUserCookieValue(userID int64, secret string) (string, error) {
|
||||||
|
secret = strings.TrimSpace(secret)
|
||||||
|
if userID <= 0 || secret == "" {
|
||||||
|
return "", errors.New("invalid oauth bind cookie input")
|
||||||
|
}
|
||||||
|
payload := strconv.FormatInt(userID, 10)
|
||||||
|
mac := hmac.New(sha256.New, []byte(secret))
|
||||||
|
_, _ = mac.Write([]byte(payload))
|
||||||
|
signature := base64.RawURLEncoding.EncodeToString(mac.Sum(nil))
|
||||||
|
return payload + "." + signature, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseOAuthBindUserCookieValue(value string, secret string) (int64, error) {
|
||||||
|
secret = strings.TrimSpace(secret)
|
||||||
|
if secret == "" {
|
||||||
|
return 0, errors.New("missing oauth bind cookie secret")
|
||||||
|
}
|
||||||
|
payload, signature, ok := strings.Cut(strings.TrimSpace(value), ".")
|
||||||
|
if !ok || payload == "" || signature == "" {
|
||||||
|
return 0, errors.New("invalid oauth bind cookie")
|
||||||
|
}
|
||||||
|
mac := hmac.New(sha256.New, []byte(secret))
|
||||||
|
_, _ = mac.Write([]byte(payload))
|
||||||
|
expectedSignature := base64.RawURLEncoding.EncodeToString(mac.Sum(nil))
|
||||||
|
if !hmac.Equal([]byte(signature), []byte(expectedSignature)) {
|
||||||
|
return 0, errors.New("invalid oauth bind cookie signature")
|
||||||
|
}
|
||||||
|
userID, err := strconv.ParseInt(payload, 10, 64)
|
||||||
|
if err != nil || userID <= 0 {
|
||||||
|
return 0, errors.New("invalid oauth bind cookie user")
|
||||||
|
}
|
||||||
|
return userID, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,10 +1,23 @@
|
|||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
dbent "github.com/Wei-Shaw/sub2api/ent"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/authidentity"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/identityadoptiondecision"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/pendingauthsession"
|
||||||
|
dbuser "github.com/Wei-Shaw/sub2api/ent/user"
|
||||||
"github.com/Wei-Shaw/sub2api/internal/config"
|
"github.com/Wei-Shaw/sub2api/internal/config"
|
||||||
|
servermiddleware "github.com/Wei-Shaw/sub2api/internal/server/middleware"
|
||||||
|
"github.com/Wei-Shaw/sub2api/internal/service"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -41,11 +54,13 @@ func TestLinuxDoParseUserInfoParsesIDAndUsername(t *testing.T) {
|
|||||||
UserInfoURL: "https://connect.linux.do/api/user",
|
UserInfoURL: "https://connect.linux.do/api/user",
|
||||||
}
|
}
|
||||||
|
|
||||||
email, username, subject, err := linuxDoParseUserInfo(`{"id":123,"username":"alice"}`, cfg)
|
email, username, subject, displayName, avatarURL, err := linuxDoParseUserInfo(`{"id":123,"username":"alice","name":"Alice","avatar_url":"https://cdn.example/avatar.png"}`, cfg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, "123", subject)
|
require.Equal(t, "123", subject)
|
||||||
require.Equal(t, "alice", username)
|
require.Equal(t, "alice", username)
|
||||||
require.Equal(t, "linuxdo-123@linuxdo-connect.invalid", email)
|
require.Equal(t, "linuxdo-123@linuxdo-connect.invalid", email)
|
||||||
|
require.Equal(t, "Alice", displayName)
|
||||||
|
require.Equal(t, "https://cdn.example/avatar.png", avatarURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLinuxDoParseUserInfoDefaultsUsername(t *testing.T) {
|
func TestLinuxDoParseUserInfoDefaultsUsername(t *testing.T) {
|
||||||
@@ -53,11 +68,13 @@ func TestLinuxDoParseUserInfoDefaultsUsername(t *testing.T) {
|
|||||||
UserInfoURL: "https://connect.linux.do/api/user",
|
UserInfoURL: "https://connect.linux.do/api/user",
|
||||||
}
|
}
|
||||||
|
|
||||||
email, username, subject, err := linuxDoParseUserInfo(`{"id":"123"}`, cfg)
|
email, username, subject, displayName, avatarURL, err := linuxDoParseUserInfo(`{"id":"123"}`, cfg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, "123", subject)
|
require.Equal(t, "123", subject)
|
||||||
require.Equal(t, "linuxdo_123", username)
|
require.Equal(t, "linuxdo_123", username)
|
||||||
require.Equal(t, "linuxdo-123@linuxdo-connect.invalid", email)
|
require.Equal(t, "linuxdo-123@linuxdo-connect.invalid", email)
|
||||||
|
require.Equal(t, "linuxdo_123", displayName)
|
||||||
|
require.Equal(t, "", avatarURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLinuxDoParseUserInfoRejectsUnsafeSubject(t *testing.T) {
|
func TestLinuxDoParseUserInfoRejectsUnsafeSubject(t *testing.T) {
|
||||||
@@ -65,11 +82,11 @@ func TestLinuxDoParseUserInfoRejectsUnsafeSubject(t *testing.T) {
|
|||||||
UserInfoURL: "https://connect.linux.do/api/user",
|
UserInfoURL: "https://connect.linux.do/api/user",
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _, _, err := linuxDoParseUserInfo(`{"id":"123@456"}`, cfg)
|
_, _, _, _, _, err := linuxDoParseUserInfo(`{"id":"123@456"}`, cfg)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
tooLong := strings.Repeat("a", linuxDoOAuthMaxSubjectLen+1)
|
tooLong := strings.Repeat("a", linuxDoOAuthMaxSubjectLen+1)
|
||||||
_, _, _, err = linuxDoParseUserInfo(`{"id":"`+tooLong+`"}`, cfg)
|
_, _, _, _, _, err = linuxDoParseUserInfo(`{"id":"`+tooLong+`"}`, cfg)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,3 +123,559 @@ func TestSingleLineStripsWhitespace(t *testing.T) {
|
|||||||
require.Equal(t, "hello world", singleLine("hello\r\nworld"))
|
require.Equal(t, "hello world", singleLine("hello\r\nworld"))
|
||||||
require.Equal(t, "", singleLine("\n\t\r"))
|
require.Equal(t, "", singleLine("\n\t\r"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLinuxDoOAuthBindStartRedirectsAndSetsBindCookies(t *testing.T) {
|
||||||
|
handler := newLinuxDoOAuthTestHandler(t, false, config.LinuxDoConnectConfig{
|
||||||
|
Enabled: true,
|
||||||
|
ClientID: "linuxdo-client",
|
||||||
|
ClientSecret: "linuxdo-secret",
|
||||||
|
AuthorizeURL: "https://connect.linux.do/oauth/authorize",
|
||||||
|
TokenURL: "https://connect.linux.do/oauth/token",
|
||||||
|
UserInfoURL: "https://connect.linux.do/api/user",
|
||||||
|
Scopes: "read",
|
||||||
|
RedirectURL: "https://api.example.com/api/v1/auth/oauth/linuxdo/callback",
|
||||||
|
FrontendRedirectURL: "/auth/linuxdo/callback",
|
||||||
|
TokenAuthMethod: "client_secret_post",
|
||||||
|
UsePKCE: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(recorder)
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/api/v1/auth/oauth/linuxdo/bind/start?intent=bind_current_user&redirect=/settings/connections", nil)
|
||||||
|
c.Request = req
|
||||||
|
c.Set(string(servermiddleware.ContextKeyUser), servermiddleware.AuthSubject{UserID: 42})
|
||||||
|
|
||||||
|
handler.LinuxDoOAuthStart(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusFound, recorder.Code)
|
||||||
|
location := recorder.Header().Get("Location")
|
||||||
|
require.Contains(t, location, "connect.linux.do/oauth/authorize")
|
||||||
|
require.Contains(t, location, "client_id=linuxdo-client")
|
||||||
|
require.Contains(t, location, "code_challenge=")
|
||||||
|
|
||||||
|
cookies := recorder.Result().Cookies()
|
||||||
|
require.NotNil(t, findCookie(cookies, linuxDoOAuthStateCookieName))
|
||||||
|
require.NotNil(t, findCookie(cookies, linuxDoOAuthRedirectCookie))
|
||||||
|
require.NotNil(t, findCookie(cookies, linuxDoOAuthVerifierCookie))
|
||||||
|
require.NotNil(t, findCookie(cookies, oauthPendingBrowserCookieName))
|
||||||
|
|
||||||
|
intentCookie := findCookie(cookies, linuxDoOAuthIntentCookieName)
|
||||||
|
require.NotNil(t, intentCookie)
|
||||||
|
require.Equal(t, oauthIntentBindCurrentUser, decodeCookieValueForTest(t, intentCookie.Value))
|
||||||
|
|
||||||
|
bindCookie := findCookie(cookies, linuxDoOAuthBindUserCookieName)
|
||||||
|
require.NotNil(t, bindCookie)
|
||||||
|
userID, err := parseOAuthBindUserCookieValue(decodeCookieValueForTest(t, bindCookie.Value), "test-secret")
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, int64(42), userID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLinuxDoOAuthBindStartAcceptsAccessTokenCookie(t *testing.T) {
|
||||||
|
handler, client := newLinuxDoOAuthHandlerAndClient(t, false, config.LinuxDoConnectConfig{
|
||||||
|
Enabled: true,
|
||||||
|
ClientID: "linuxdo-client",
|
||||||
|
ClientSecret: "linuxdo-secret",
|
||||||
|
AuthorizeURL: "https://connect.linux.do/oauth/authorize",
|
||||||
|
TokenURL: "https://connect.linux.do/oauth/token",
|
||||||
|
UserInfoURL: "https://connect.linux.do/api/user",
|
||||||
|
Scopes: "read",
|
||||||
|
RedirectURL: "https://api.example.com/api/v1/auth/oauth/linuxdo/callback",
|
||||||
|
FrontendRedirectURL: "/auth/linuxdo/callback",
|
||||||
|
TokenAuthMethod: "client_secret_post",
|
||||||
|
UsePKCE: true,
|
||||||
|
})
|
||||||
|
t.Cleanup(func() { _ = client.Close() })
|
||||||
|
|
||||||
|
user, err := client.User.Create().
|
||||||
|
SetEmail("bind-cookie@example.com").
|
||||||
|
SetUsername("bind-cookie-user").
|
||||||
|
SetPasswordHash("hash").
|
||||||
|
SetRole(service.RoleUser).
|
||||||
|
SetStatus(service.StatusActive).
|
||||||
|
Save(context.Background())
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
token, err := handler.authService.GenerateToken(&service.User{
|
||||||
|
ID: user.ID,
|
||||||
|
Email: user.Email,
|
||||||
|
Username: user.Username,
|
||||||
|
PasswordHash: user.PasswordHash,
|
||||||
|
Role: user.Role,
|
||||||
|
Status: user.Status,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(recorder)
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/api/v1/auth/oauth/linuxdo/start?intent=bind_current_user&redirect=/settings/connections", nil)
|
||||||
|
req.AddCookie(&http.Cookie{Name: oauthBindAccessTokenCookieName, Value: token, Path: oauthBindAccessTokenCookiePath})
|
||||||
|
c.Request = req
|
||||||
|
|
||||||
|
handler.LinuxDoOAuthStart(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusFound, recorder.Code)
|
||||||
|
|
||||||
|
bindCookie := findCookie(recorder.Result().Cookies(), linuxDoOAuthBindUserCookieName)
|
||||||
|
require.NotNil(t, bindCookie)
|
||||||
|
userID, err := parseOAuthBindUserCookieValue(decodeCookieValueForTest(t, bindCookie.Value), "test-secret")
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, user.ID, userID)
|
||||||
|
|
||||||
|
accessTokenCookie := findCookie(recorder.Result().Cookies(), oauthBindAccessTokenCookieName)
|
||||||
|
require.NotNil(t, accessTokenCookie)
|
||||||
|
require.Equal(t, -1, accessTokenCookie.MaxAge)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLinuxDoOAuthCallbackCreatesLoginPendingSessionForExistingIdentityUser(t *testing.T) {
|
||||||
|
upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
switch r.URL.Path {
|
||||||
|
case "/token":
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
_, _ = w.Write([]byte(`{"access_token":"linuxdo-access","token_type":"Bearer","expires_in":3600}`))
|
||||||
|
case "/userinfo":
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
_, _ = w.Write([]byte(`{"id":"321","username":"linuxdo_user","name":"LinuxDo Display","avatar_url":"https://cdn.example/linuxdo.png"}`))
|
||||||
|
default:
|
||||||
|
http.NotFound(w, r)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
defer upstream.Close()
|
||||||
|
|
||||||
|
handler, client := newLinuxDoOAuthHandlerAndClient(t, false, config.LinuxDoConnectConfig{
|
||||||
|
Enabled: true,
|
||||||
|
ClientID: "linuxdo-client",
|
||||||
|
ClientSecret: "linuxdo-secret",
|
||||||
|
AuthorizeURL: upstream.URL + "/authorize",
|
||||||
|
TokenURL: upstream.URL + "/token",
|
||||||
|
UserInfoURL: upstream.URL + "/userinfo",
|
||||||
|
Scopes: "read",
|
||||||
|
RedirectURL: "https://api.example.com/api/v1/auth/oauth/linuxdo/callback",
|
||||||
|
FrontendRedirectURL: "/auth/linuxdo/callback",
|
||||||
|
TokenAuthMethod: "client_secret_post",
|
||||||
|
UsePKCE: true,
|
||||||
|
})
|
||||||
|
t.Cleanup(func() { _ = client.Close() })
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
existingUser, err := client.User.Create().
|
||||||
|
SetEmail(linuxDoSyntheticEmail("321")).
|
||||||
|
SetUsername("legacy-user").
|
||||||
|
SetPasswordHash("hash").
|
||||||
|
SetRole(service.RoleUser).
|
||||||
|
SetStatus(service.StatusActive).
|
||||||
|
Save(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
_, err = client.AuthIdentity.Create().
|
||||||
|
SetUserID(existingUser.ID).
|
||||||
|
SetProviderType("linuxdo").
|
||||||
|
SetProviderKey("linuxdo").
|
||||||
|
SetProviderSubject("321").
|
||||||
|
SetMetadata(map[string]any{"username": "legacy-user"}).
|
||||||
|
Save(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(recorder)
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/api/v1/auth/oauth/linuxdo/callback?code=code-123&state=state-123", nil)
|
||||||
|
req.AddCookie(encodedCookie(linuxDoOAuthStateCookieName, "state-123"))
|
||||||
|
req.AddCookie(encodedCookie(linuxDoOAuthRedirectCookie, "/dashboard"))
|
||||||
|
req.AddCookie(encodedCookie(linuxDoOAuthVerifierCookie, "verifier-123"))
|
||||||
|
req.AddCookie(encodedCookie(linuxDoOAuthIntentCookieName, oauthIntentLogin))
|
||||||
|
req.AddCookie(encodedCookie(oauthPendingBrowserCookieName, "browser-123"))
|
||||||
|
c.Request = req
|
||||||
|
|
||||||
|
handler.LinuxDoOAuthCallback(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusFound, recorder.Code)
|
||||||
|
require.Equal(t, "/auth/linuxdo/callback", recorder.Header().Get("Location"))
|
||||||
|
|
||||||
|
sessionCookie := findCookie(recorder.Result().Cookies(), oauthPendingSessionCookieName)
|
||||||
|
require.NotNil(t, sessionCookie)
|
||||||
|
|
||||||
|
session, err := client.PendingAuthSession.Query().
|
||||||
|
Where(pendingauthsession.SessionTokenEQ(decodeCookieValueForTest(t, sessionCookie.Value))).
|
||||||
|
Only(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, oauthIntentLogin, session.Intent)
|
||||||
|
require.NotNil(t, session.TargetUserID)
|
||||||
|
require.Equal(t, existingUser.ID, *session.TargetUserID)
|
||||||
|
require.Equal(t, linuxDoSyntheticEmail("321"), session.ResolvedEmail)
|
||||||
|
require.Equal(t, "LinuxDo Display", session.UpstreamIdentityClaims["suggested_display_name"])
|
||||||
|
|
||||||
|
completion, ok := session.LocalFlowState[oauthCompletionResponseKey].(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, "/dashboard", completion["redirect"])
|
||||||
|
require.NotEmpty(t, completion["access_token"])
|
||||||
|
require.Nil(t, completion["error"])
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLinuxDoOAuthCallbackCreatesBindPendingSessionForCompatEmailUser(t *testing.T) {
|
||||||
|
upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
switch r.URL.Path {
|
||||||
|
case "/token":
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
_, _ = w.Write([]byte(`{"access_token":"linuxdo-access","token_type":"Bearer","expires_in":3600}`))
|
||||||
|
case "/userinfo":
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
_, _ = w.Write([]byte(`{"id":"321","email":"legacy@example.com","username":"linuxdo_user","name":"LinuxDo Display","avatar_url":"https://cdn.example/linuxdo.png"}`))
|
||||||
|
default:
|
||||||
|
http.NotFound(w, r)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
defer upstream.Close()
|
||||||
|
|
||||||
|
handler, client := newLinuxDoOAuthHandlerAndClient(t, false, config.LinuxDoConnectConfig{
|
||||||
|
Enabled: true,
|
||||||
|
ClientID: "linuxdo-client",
|
||||||
|
ClientSecret: "linuxdo-secret",
|
||||||
|
AuthorizeURL: upstream.URL + "/authorize",
|
||||||
|
TokenURL: upstream.URL + "/token",
|
||||||
|
UserInfoURL: upstream.URL + "/userinfo",
|
||||||
|
Scopes: "read",
|
||||||
|
RedirectURL: "https://api.example.com/api/v1/auth/oauth/linuxdo/callback",
|
||||||
|
FrontendRedirectURL: "/auth/linuxdo/callback",
|
||||||
|
TokenAuthMethod: "client_secret_post",
|
||||||
|
UsePKCE: true,
|
||||||
|
})
|
||||||
|
t.Cleanup(func() { _ = client.Close() })
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
existingUser, err := client.User.Create().
|
||||||
|
SetEmail("legacy@example.com").
|
||||||
|
SetUsername("legacy-user").
|
||||||
|
SetPasswordHash("hash").
|
||||||
|
SetRole(service.RoleUser).
|
||||||
|
SetStatus(service.StatusActive).
|
||||||
|
Save(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(recorder)
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/api/v1/auth/oauth/linuxdo/callback?code=code-compat&state=state-compat", nil)
|
||||||
|
req.AddCookie(encodedCookie(linuxDoOAuthStateCookieName, "state-compat"))
|
||||||
|
req.AddCookie(encodedCookie(linuxDoOAuthRedirectCookie, "/dashboard"))
|
||||||
|
req.AddCookie(encodedCookie(linuxDoOAuthVerifierCookie, "verifier-compat"))
|
||||||
|
req.AddCookie(encodedCookie(linuxDoOAuthIntentCookieName, oauthIntentLogin))
|
||||||
|
req.AddCookie(encodedCookie(oauthPendingBrowserCookieName, "browser-compat"))
|
||||||
|
c.Request = req
|
||||||
|
|
||||||
|
handler.LinuxDoOAuthCallback(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusFound, recorder.Code)
|
||||||
|
require.Equal(t, "/auth/linuxdo/callback", recorder.Header().Get("Location"))
|
||||||
|
|
||||||
|
sessionCookie := findCookie(recorder.Result().Cookies(), oauthPendingSessionCookieName)
|
||||||
|
require.NotNil(t, sessionCookie)
|
||||||
|
|
||||||
|
session, err := client.PendingAuthSession.Query().
|
||||||
|
Where(pendingauthsession.SessionTokenEQ(decodeCookieValueForTest(t, sessionCookie.Value))).
|
||||||
|
Only(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, oauthIntentLogin, session.Intent)
|
||||||
|
require.Nil(t, session.TargetUserID)
|
||||||
|
require.Equal(t, existingUser.Email, session.ResolvedEmail)
|
||||||
|
require.Equal(t, "legacy@example.com", session.UpstreamIdentityClaims["compat_email"])
|
||||||
|
|
||||||
|
completion, ok := session.LocalFlowState[oauthCompletionResponseKey].(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, "/dashboard", completion["redirect"])
|
||||||
|
require.Equal(t, oauthPendingChoiceStep, completion["step"])
|
||||||
|
require.Equal(t, existingUser.Email, completion["email"])
|
||||||
|
require.Equal(t, existingUser.Email, completion["existing_account_email"])
|
||||||
|
require.Equal(t, true, completion["existing_account_bindable"])
|
||||||
|
require.Equal(t, "compat_email_match", completion["choice_reason"])
|
||||||
|
_, hasAccessToken := completion["access_token"]
|
||||||
|
require.False(t, hasAccessToken)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLinuxDoOAuthCallbackCreatesChoicePendingSessionWhenSignupRequiresInvite(t *testing.T) {
|
||||||
|
upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
switch r.URL.Path {
|
||||||
|
case "/token":
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
_, _ = w.Write([]byte(`{"access_token":"linuxdo-access","token_type":"Bearer","expires_in":3600}`))
|
||||||
|
case "/userinfo":
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
_, _ = w.Write([]byte(`{"id":"654","username":"linuxdo_invite","name":"Need Invite","avatar_url":"https://cdn.example/invite.png"}`))
|
||||||
|
default:
|
||||||
|
http.NotFound(w, r)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
defer upstream.Close()
|
||||||
|
|
||||||
|
handler, client := newLinuxDoOAuthHandlerAndClient(t, true, config.LinuxDoConnectConfig{
|
||||||
|
Enabled: true,
|
||||||
|
ClientID: "linuxdo-client",
|
||||||
|
ClientSecret: "linuxdo-secret",
|
||||||
|
AuthorizeURL: upstream.URL + "/authorize",
|
||||||
|
TokenURL: upstream.URL + "/token",
|
||||||
|
UserInfoURL: upstream.URL + "/userinfo",
|
||||||
|
Scopes: "read",
|
||||||
|
RedirectURL: "https://api.example.com/api/v1/auth/oauth/linuxdo/callback",
|
||||||
|
FrontendRedirectURL: "/auth/linuxdo/callback",
|
||||||
|
TokenAuthMethod: "client_secret_post",
|
||||||
|
UsePKCE: true,
|
||||||
|
})
|
||||||
|
t.Cleanup(func() { _ = client.Close() })
|
||||||
|
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(recorder)
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/api/v1/auth/oauth/linuxdo/callback?code=code-456&state=state-456", nil)
|
||||||
|
req.AddCookie(encodedCookie(linuxDoOAuthStateCookieName, "state-456"))
|
||||||
|
req.AddCookie(encodedCookie(linuxDoOAuthRedirectCookie, "/dashboard"))
|
||||||
|
req.AddCookie(encodedCookie(linuxDoOAuthVerifierCookie, "verifier-456"))
|
||||||
|
req.AddCookie(encodedCookie(linuxDoOAuthIntentCookieName, oauthIntentLogin))
|
||||||
|
req.AddCookie(encodedCookie(oauthPendingBrowserCookieName, "browser-456"))
|
||||||
|
c.Request = req
|
||||||
|
|
||||||
|
handler.LinuxDoOAuthCallback(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusFound, recorder.Code)
|
||||||
|
require.Equal(t, "/auth/linuxdo/callback", recorder.Header().Get("Location"))
|
||||||
|
|
||||||
|
sessionCookie := findCookie(recorder.Result().Cookies(), oauthPendingSessionCookieName)
|
||||||
|
require.NotNil(t, sessionCookie)
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
session, err := client.PendingAuthSession.Query().
|
||||||
|
Where(pendingauthsession.SessionTokenEQ(decodeCookieValueForTest(t, sessionCookie.Value))).
|
||||||
|
Only(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, oauthIntentLogin, session.Intent)
|
||||||
|
require.Nil(t, session.TargetUserID)
|
||||||
|
|
||||||
|
completion, ok := session.LocalFlowState[oauthCompletionResponseKey].(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, oauthPendingChoiceStep, completion["step"])
|
||||||
|
require.Equal(t, "/dashboard", completion["redirect"])
|
||||||
|
require.Equal(t, "third_party_signup", completion["choice_reason"])
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLinuxDoOAuthCallbackCreatesBindPendingSessionForCurrentUser(t *testing.T) {
|
||||||
|
upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
switch r.URL.Path {
|
||||||
|
case "/token":
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
_, _ = w.Write([]byte(`{"access_token":"linuxdo-access","token_type":"Bearer","expires_in":3600}`))
|
||||||
|
case "/userinfo":
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
_, _ = w.Write([]byte(`{"id":"999","username":"bind_user","name":"Bind Display","avatar_url":"https://cdn.example/bind.png"}`))
|
||||||
|
default:
|
||||||
|
http.NotFound(w, r)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
defer upstream.Close()
|
||||||
|
|
||||||
|
handler, client := newLinuxDoOAuthHandlerAndClient(t, false, config.LinuxDoConnectConfig{
|
||||||
|
Enabled: true,
|
||||||
|
ClientID: "linuxdo-client",
|
||||||
|
ClientSecret: "linuxdo-secret",
|
||||||
|
AuthorizeURL: upstream.URL + "/authorize",
|
||||||
|
TokenURL: upstream.URL + "/token",
|
||||||
|
UserInfoURL: upstream.URL + "/userinfo",
|
||||||
|
Scopes: "read",
|
||||||
|
RedirectURL: "https://api.example.com/api/v1/auth/oauth/linuxdo/callback",
|
||||||
|
FrontendRedirectURL: "/auth/linuxdo/callback",
|
||||||
|
TokenAuthMethod: "client_secret_post",
|
||||||
|
UsePKCE: true,
|
||||||
|
})
|
||||||
|
t.Cleanup(func() { _ = client.Close() })
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
currentUser, err := client.User.Create().
|
||||||
|
SetEmail("current@example.com").
|
||||||
|
SetUsername("current-user").
|
||||||
|
SetPasswordHash("hash").
|
||||||
|
SetRole(service.RoleUser).
|
||||||
|
SetStatus(service.StatusActive).
|
||||||
|
Save(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(recorder)
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/api/v1/auth/oauth/linuxdo/callback?code=code-bind&state=state-bind", nil)
|
||||||
|
req.AddCookie(encodedCookie(linuxDoOAuthStateCookieName, "state-bind"))
|
||||||
|
req.AddCookie(encodedCookie(linuxDoOAuthRedirectCookie, "/settings/connections"))
|
||||||
|
req.AddCookie(encodedCookie(linuxDoOAuthVerifierCookie, "verifier-bind"))
|
||||||
|
req.AddCookie(encodedCookie(linuxDoOAuthIntentCookieName, oauthIntentBindCurrentUser))
|
||||||
|
req.AddCookie(encodedCookie(linuxDoOAuthBindUserCookieName, buildEncodedOAuthBindUserCookie(t, currentUser.ID, "test-secret")))
|
||||||
|
req.AddCookie(encodedCookie(oauthPendingBrowserCookieName, "browser-bind"))
|
||||||
|
c.Request = req
|
||||||
|
|
||||||
|
handler.LinuxDoOAuthCallback(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusFound, recorder.Code)
|
||||||
|
require.Equal(t, "/auth/linuxdo/callback", recorder.Header().Get("Location"))
|
||||||
|
|
||||||
|
sessionCookie := findCookie(recorder.Result().Cookies(), oauthPendingSessionCookieName)
|
||||||
|
require.NotNil(t, sessionCookie)
|
||||||
|
|
||||||
|
session, err := client.PendingAuthSession.Query().
|
||||||
|
Where(pendingauthsession.SessionTokenEQ(decodeCookieValueForTest(t, sessionCookie.Value))).
|
||||||
|
Only(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, oauthIntentBindCurrentUser, session.Intent)
|
||||||
|
require.NotNil(t, session.TargetUserID)
|
||||||
|
require.Equal(t, currentUser.ID, *session.TargetUserID)
|
||||||
|
require.Equal(t, linuxDoSyntheticEmail("999"), session.ResolvedEmail)
|
||||||
|
|
||||||
|
completion, ok := session.LocalFlowState[oauthCompletionResponseKey].(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, "/settings/connections", completion["redirect"])
|
||||||
|
require.Empty(t, completion["access_token"])
|
||||||
|
require.Equal(t, "Bind Display", session.UpstreamIdentityClaims["suggested_display_name"])
|
||||||
|
|
||||||
|
userCount, err := client.User.Query().Count(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, 1, userCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCompleteLinuxDoOAuthRegistrationAppliesPendingAdoptionDecision(t *testing.T) {
|
||||||
|
handler, client := newOAuthPendingFlowTestHandler(t, false)
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
session, err := client.PendingAuthSession.Create().
|
||||||
|
SetSessionToken("linuxdo-complete-session").
|
||||||
|
SetIntent("login").
|
||||||
|
SetProviderType("linuxdo").
|
||||||
|
SetProviderKey("linuxdo").
|
||||||
|
SetProviderSubject("linuxdo-subject-1").
|
||||||
|
SetResolvedEmail("linuxdo-subject-1@linuxdo-connect.invalid").
|
||||||
|
SetBrowserSessionKey("linuxdo-browser").
|
||||||
|
SetUpstreamIdentityClaims(map[string]any{
|
||||||
|
"username": "linuxdo_user",
|
||||||
|
"suggested_display_name": "LinuxDo Display",
|
||||||
|
"suggested_avatar_url": "https://cdn.example/linuxdo.png",
|
||||||
|
}).
|
||||||
|
SetExpiresAt(time.Now().UTC().Add(10 * time.Minute)).
|
||||||
|
Save(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
_, err = service.NewAuthPendingIdentityService(client).UpsertAdoptionDecision(ctx, service.PendingIdentityAdoptionDecisionInput{
|
||||||
|
PendingAuthSessionID: session.ID,
|
||||||
|
AdoptAvatar: true,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
body := bytes.NewBufferString(`{"invitation_code":"invite-1","adopt_display_name":true}`)
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(recorder)
|
||||||
|
req := httptest.NewRequest(http.MethodPost, "/api/v1/auth/oauth/linuxdo/complete-registration", body)
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
req.AddCookie(&http.Cookie{Name: oauthPendingSessionCookieName, Value: encodeCookieValue(session.SessionToken)})
|
||||||
|
req.AddCookie(&http.Cookie{Name: oauthPendingBrowserCookieName, Value: encodeCookieValue("linuxdo-browser")})
|
||||||
|
c.Request = req
|
||||||
|
|
||||||
|
handler.CompleteLinuxDoOAuthRegistration(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusOK, recorder.Code)
|
||||||
|
responseData := decodeJSONBody(t, recorder)
|
||||||
|
require.NotEmpty(t, responseData["access_token"])
|
||||||
|
|
||||||
|
userEntity, err := client.User.Query().
|
||||||
|
Where(dbuser.EmailEQ(session.ResolvedEmail)).
|
||||||
|
Only(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, "LinuxDo Display", userEntity.Username)
|
||||||
|
|
||||||
|
identity, err := client.AuthIdentity.Query().
|
||||||
|
Where(
|
||||||
|
authidentity.ProviderTypeEQ("linuxdo"),
|
||||||
|
authidentity.ProviderKeyEQ("linuxdo"),
|
||||||
|
authidentity.ProviderSubjectEQ("linuxdo-subject-1"),
|
||||||
|
).
|
||||||
|
Only(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, userEntity.ID, identity.UserID)
|
||||||
|
require.Equal(t, "LinuxDo Display", identity.Metadata["display_name"])
|
||||||
|
require.Equal(t, "https://cdn.example/linuxdo.png", identity.Metadata["avatar_url"])
|
||||||
|
|
||||||
|
decision, err := client.IdentityAdoptionDecision.Query().
|
||||||
|
Where(identityadoptiondecision.PendingAuthSessionIDEQ(session.ID)).
|
||||||
|
Only(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, decision.IdentityID)
|
||||||
|
require.Equal(t, identity.ID, *decision.IdentityID)
|
||||||
|
require.True(t, decision.AdoptDisplayName)
|
||||||
|
require.True(t, decision.AdoptAvatar)
|
||||||
|
|
||||||
|
consumed, err := client.PendingAuthSession.Query().
|
||||||
|
Where(pendingauthsession.IDEQ(session.ID)).
|
||||||
|
Only(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, consumed.ConsumedAt)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCompleteLinuxDoOAuthRegistrationRejectsAdoptExistingUserSession(t *testing.T) {
|
||||||
|
handler, client := newOAuthPendingFlowTestHandler(t, false)
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
existingUser, err := client.User.Create().
|
||||||
|
SetEmail("owner@example.com").
|
||||||
|
SetUsername("owner-user").
|
||||||
|
SetPasswordHash("hash").
|
||||||
|
SetRole(service.RoleUser).
|
||||||
|
SetStatus(service.StatusActive).
|
||||||
|
Save(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
session, err := client.PendingAuthSession.Create().
|
||||||
|
SetSessionToken("linuxdo-complete-invalid-session").
|
||||||
|
SetIntent("adopt_existing_user_by_email").
|
||||||
|
SetProviderType("linuxdo").
|
||||||
|
SetProviderKey("linuxdo").
|
||||||
|
SetProviderSubject("linuxdo-invalid-subject-1").
|
||||||
|
SetTargetUserID(existingUser.ID).
|
||||||
|
SetResolvedEmail(existingUser.Email).
|
||||||
|
SetBrowserSessionKey("linuxdo-invalid-browser").
|
||||||
|
SetUpstreamIdentityClaims(map[string]any{
|
||||||
|
"username": "linuxdo_user",
|
||||||
|
}).
|
||||||
|
SetLocalFlowState(map[string]any{
|
||||||
|
oauthCompletionResponseKey: map[string]any{
|
||||||
|
"step": "bind_login_required",
|
||||||
|
},
|
||||||
|
}).
|
||||||
|
SetExpiresAt(time.Now().UTC().Add(10 * time.Minute)).
|
||||||
|
Save(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
body := bytes.NewBufferString(`{"invitation_code":"invite-1"}`)
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(recorder)
|
||||||
|
req := httptest.NewRequest(http.MethodPost, "/api/v1/auth/oauth/linuxdo/complete-registration", body)
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
req.AddCookie(&http.Cookie{Name: oauthPendingSessionCookieName, Value: encodeCookieValue(session.SessionToken)})
|
||||||
|
req.AddCookie(&http.Cookie{Name: oauthPendingBrowserCookieName, Value: encodeCookieValue("linuxdo-invalid-browser")})
|
||||||
|
c.Request = req
|
||||||
|
|
||||||
|
handler.CompleteLinuxDoOAuthRegistration(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusBadRequest, recorder.Code)
|
||||||
|
|
||||||
|
storedSession, err := client.PendingAuthSession.Get(ctx, session.ID)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Nil(t, storedSession.ConsumedAt)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newLinuxDoOAuthTestHandler(t *testing.T, invitationEnabled bool, oauthCfg config.LinuxDoConnectConfig) *AuthHandler {
|
||||||
|
t.Helper()
|
||||||
|
handler, _ := newLinuxDoOAuthHandlerAndClient(t, invitationEnabled, oauthCfg)
|
||||||
|
return handler
|
||||||
|
}
|
||||||
|
|
||||||
|
func newLinuxDoOAuthHandlerAndClient(t *testing.T, invitationEnabled bool, oauthCfg config.LinuxDoConnectConfig) (*AuthHandler, *dbent.Client) {
|
||||||
|
t.Helper()
|
||||||
|
handler, client := newOAuthPendingFlowTestHandler(t, invitationEnabled)
|
||||||
|
handler.settingSvc = nil
|
||||||
|
handler.cfg = &config.Config{
|
||||||
|
JWT: config.JWTConfig{
|
||||||
|
Secret: "test-secret",
|
||||||
|
ExpireHour: 1,
|
||||||
|
AccessTokenExpireMinutes: 60,
|
||||||
|
RefreshTokenExpireDays: 7,
|
||||||
|
},
|
||||||
|
LinuxDo: oauthCfg,
|
||||||
|
}
|
||||||
|
return handler, client
|
||||||
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,39 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func buildEncodedOAuthBindUserCookie(t *testing.T, userID int64, secret string) string {
|
||||||
|
t.Helper()
|
||||||
|
value, err := buildOAuthBindUserCookieValue(userID, secret)
|
||||||
|
require.NoError(t, err)
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodedCookie(name, value string) *http.Cookie {
|
||||||
|
return &http.Cookie{
|
||||||
|
Name: name,
|
||||||
|
Value: encodeCookieValue(value),
|
||||||
|
Path: "/",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func findCookie(cookies []*http.Cookie, name string) *http.Cookie {
|
||||||
|
for _, cookie := range cookies {
|
||||||
|
if cookie.Name == name {
|
||||||
|
return cookie
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeCookieValueForTest(t *testing.T, value string) string {
|
||||||
|
t.Helper()
|
||||||
|
decoded, err := decodeCookieValue(value)
|
||||||
|
require.NoError(t, err)
|
||||||
|
return decoded
|
||||||
|
}
|
||||||
@@ -19,6 +19,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
dbent "github.com/Wei-Shaw/sub2api/ent"
|
||||||
"github.com/Wei-Shaw/sub2api/internal/config"
|
"github.com/Wei-Shaw/sub2api/internal/config"
|
||||||
infraerrors "github.com/Wei-Shaw/sub2api/internal/pkg/errors"
|
infraerrors "github.com/Wei-Shaw/sub2api/internal/pkg/errors"
|
||||||
"github.com/Wei-Shaw/sub2api/internal/pkg/oauth"
|
"github.com/Wei-Shaw/sub2api/internal/pkg/oauth"
|
||||||
@@ -37,6 +38,8 @@ const (
|
|||||||
oidcOAuthVerifierCookie = "oidc_oauth_verifier"
|
oidcOAuthVerifierCookie = "oidc_oauth_verifier"
|
||||||
oidcOAuthRedirectCookie = "oidc_oauth_redirect"
|
oidcOAuthRedirectCookie = "oidc_oauth_redirect"
|
||||||
oidcOAuthNonceCookie = "oidc_oauth_nonce"
|
oidcOAuthNonceCookie = "oidc_oauth_nonce"
|
||||||
|
oidcOAuthIntentCookieName = "oidc_oauth_intent"
|
||||||
|
oidcOAuthBindUserCookieName = "oidc_oauth_bind_user"
|
||||||
oidcOAuthCookieMaxAgeSec = 10 * 60 // 10 minutes
|
oidcOAuthCookieMaxAgeSec = 10 * 60 // 10 minutes
|
||||||
oidcOAuthDefaultRedirectTo = "/dashboard"
|
oidcOAuthDefaultRedirectTo = "/dashboard"
|
||||||
oidcOAuthDefaultFrontendCB = "/auth/oidc/callback"
|
oidcOAuthDefaultFrontendCB = "/auth/oidc/callback"
|
||||||
@@ -87,6 +90,8 @@ type oidcUserInfoClaims struct {
|
|||||||
Username string
|
Username string
|
||||||
Subject string
|
Subject string
|
||||||
EmailVerified *bool
|
EmailVerified *bool
|
||||||
|
DisplayName string
|
||||||
|
AvatarURL string
|
||||||
}
|
}
|
||||||
|
|
||||||
type oidcJWKSet struct {
|
type oidcJWKSet struct {
|
||||||
@@ -127,12 +132,31 @@ func (h *AuthHandler) OIDCOAuthStart(c *gin.Context) {
|
|||||||
redirectTo = oidcOAuthDefaultRedirectTo
|
redirectTo = oidcOAuthDefaultRedirectTo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
browserSessionKey, err := generateOAuthPendingBrowserSession()
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, infraerrors.InternalServer("OAUTH_BROWSER_SESSION_GEN_FAILED", "failed to generate oauth browser session").WithCause(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
secureCookie := isRequestHTTPS(c)
|
secureCookie := isRequestHTTPS(c)
|
||||||
oidcSetCookie(c, oidcOAuthStateCookieName, encodeCookieValue(state), oidcOAuthCookieMaxAgeSec, secureCookie)
|
oidcSetCookie(c, oidcOAuthStateCookieName, encodeCookieValue(state), oidcOAuthCookieMaxAgeSec, secureCookie)
|
||||||
oidcSetCookie(c, oidcOAuthRedirectCookie, encodeCookieValue(redirectTo), oidcOAuthCookieMaxAgeSec, secureCookie)
|
oidcSetCookie(c, oidcOAuthRedirectCookie, encodeCookieValue(redirectTo), oidcOAuthCookieMaxAgeSec, secureCookie)
|
||||||
|
intent := normalizeOAuthIntent(c.Query("intent"))
|
||||||
|
oidcSetCookie(c, oidcOAuthIntentCookieName, encodeCookieValue(intent), oidcOAuthCookieMaxAgeSec, secureCookie)
|
||||||
|
setOAuthPendingBrowserCookie(c, browserSessionKey, secureCookie)
|
||||||
|
clearOAuthPendingSessionCookie(c, secureCookie)
|
||||||
|
if intent == oauthIntentBindCurrentUser {
|
||||||
|
bindCookieValue, err := h.buildOAuthBindUserCookieFromContext(c)
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
oidcSetCookie(c, oidcOAuthBindUserCookieName, encodeCookieValue(bindCookieValue), oidcOAuthCookieMaxAgeSec, secureCookie)
|
||||||
|
} else {
|
||||||
|
oidcClearCookie(c, oidcOAuthBindUserCookieName, secureCookie)
|
||||||
|
}
|
||||||
|
|
||||||
codeChallenge := ""
|
codeChallenge := ""
|
||||||
if cfg.UsePKCE {
|
|
||||||
verifier, genErr := oauth.GenerateCodeVerifier()
|
verifier, genErr := oauth.GenerateCodeVerifier()
|
||||||
if genErr != nil {
|
if genErr != nil {
|
||||||
response.ErrorFrom(c, infraerrors.InternalServer("OAUTH_PKCE_GEN_FAILED", "failed to generate pkce verifier").WithCause(genErr))
|
response.ErrorFrom(c, infraerrors.InternalServer("OAUTH_PKCE_GEN_FAILED", "failed to generate pkce verifier").WithCause(genErr))
|
||||||
@@ -140,17 +164,14 @@ func (h *AuthHandler) OIDCOAuthStart(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
codeChallenge = oauth.GenerateCodeChallenge(verifier)
|
codeChallenge = oauth.GenerateCodeChallenge(verifier)
|
||||||
oidcSetCookie(c, oidcOAuthVerifierCookie, encodeCookieValue(verifier), oidcOAuthCookieMaxAgeSec, secureCookie)
|
oidcSetCookie(c, oidcOAuthVerifierCookie, encodeCookieValue(verifier), oidcOAuthCookieMaxAgeSec, secureCookie)
|
||||||
}
|
|
||||||
|
|
||||||
nonce := ""
|
nonce := ""
|
||||||
if cfg.ValidateIDToken {
|
|
||||||
nonce, err = oauth.GenerateState()
|
nonce, err = oauth.GenerateState()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.ErrorFrom(c, infraerrors.InternalServer("OAUTH_NONCE_GEN_FAILED", "failed to generate oauth nonce").WithCause(err))
|
response.ErrorFrom(c, infraerrors.InternalServer("OAUTH_NONCE_GEN_FAILED", "failed to generate oauth nonce").WithCause(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
oidcSetCookie(c, oidcOAuthNonceCookie, encodeCookieValue(nonce), oidcOAuthCookieMaxAgeSec, secureCookie)
|
oidcSetCookie(c, oidcOAuthNonceCookie, encodeCookieValue(nonce), oidcOAuthCookieMaxAgeSec, secureCookie)
|
||||||
}
|
|
||||||
|
|
||||||
redirectURI := strings.TrimSpace(cfg.RedirectURL)
|
redirectURI := strings.TrimSpace(cfg.RedirectURL)
|
||||||
if redirectURI == "" {
|
if redirectURI == "" {
|
||||||
@@ -199,6 +220,8 @@ func (h *AuthHandler) OIDCOAuthCallback(c *gin.Context) {
|
|||||||
oidcClearCookie(c, oidcOAuthVerifierCookie, secureCookie)
|
oidcClearCookie(c, oidcOAuthVerifierCookie, secureCookie)
|
||||||
oidcClearCookie(c, oidcOAuthRedirectCookie, secureCookie)
|
oidcClearCookie(c, oidcOAuthRedirectCookie, secureCookie)
|
||||||
oidcClearCookie(c, oidcOAuthNonceCookie, secureCookie)
|
oidcClearCookie(c, oidcOAuthNonceCookie, secureCookie)
|
||||||
|
oidcClearCookie(c, oidcOAuthIntentCookieName, secureCookie)
|
||||||
|
oidcClearCookie(c, oidcOAuthBindUserCookieName, secureCookie)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
expectedState, err := readCookieDecoded(c, oidcOAuthStateCookieName)
|
expectedState, err := readCookieDecoded(c, oidcOAuthStateCookieName)
|
||||||
@@ -212,24 +235,27 @@ func (h *AuthHandler) OIDCOAuthCallback(c *gin.Context) {
|
|||||||
if redirectTo == "" {
|
if redirectTo == "" {
|
||||||
redirectTo = oidcOAuthDefaultRedirectTo
|
redirectTo = oidcOAuthDefaultRedirectTo
|
||||||
}
|
}
|
||||||
|
browserSessionKey, _ := readOAuthPendingBrowserCookie(c)
|
||||||
|
if strings.TrimSpace(browserSessionKey) == "" {
|
||||||
|
redirectOAuthError(c, frontendCallback, "missing_browser_session", "missing oauth browser session", "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
intent, _ := readCookieDecoded(c, oidcOAuthIntentCookieName)
|
||||||
|
intent = normalizeOAuthIntent(intent)
|
||||||
|
|
||||||
codeVerifier := ""
|
codeVerifier := ""
|
||||||
if cfg.UsePKCE {
|
|
||||||
codeVerifier, _ = readCookieDecoded(c, oidcOAuthVerifierCookie)
|
codeVerifier, _ = readCookieDecoded(c, oidcOAuthVerifierCookie)
|
||||||
if codeVerifier == "" {
|
if codeVerifier == "" {
|
||||||
redirectOAuthError(c, frontendCallback, "missing_verifier", "missing pkce verifier", "")
|
redirectOAuthError(c, frontendCallback, "missing_verifier", "missing pkce verifier", "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
expectedNonce := ""
|
expectedNonce := ""
|
||||||
if cfg.ValidateIDToken {
|
|
||||||
expectedNonce, _ = readCookieDecoded(c, oidcOAuthNonceCookie)
|
expectedNonce, _ = readCookieDecoded(c, oidcOAuthNonceCookie)
|
||||||
if expectedNonce == "" {
|
if expectedNonce == "" {
|
||||||
redirectOAuthError(c, frontendCallback, "missing_nonce", "missing oauth nonce", "")
|
redirectOAuthError(c, frontendCallback, "missing_nonce", "missing oauth nonce", "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
redirectURI := strings.TrimSpace(cfg.RedirectURL)
|
redirectURI := strings.TrimSpace(cfg.RedirectURL)
|
||||||
if redirectURI == "" {
|
if redirectURI == "" {
|
||||||
@@ -258,7 +284,7 @@ func (h *AuthHandler) OIDCOAuthCallback(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.ValidateIDToken && strings.TrimSpace(tokenResp.IDToken) == "" {
|
if strings.TrimSpace(tokenResp.IDToken) == "" {
|
||||||
redirectOAuthError(c, frontendCallback, "missing_id_token", "missing id_token", "")
|
redirectOAuthError(c, frontendCallback, "missing_id_token", "missing id_token", "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -298,6 +324,103 @@ func (h *AuthHandler) OIDCOAuthCallback(c *gin.Context) {
|
|||||||
if emailVerified == nil {
|
if emailVerified == nil {
|
||||||
emailVerified = idClaims.EmailVerified
|
emailVerified = idClaims.EmailVerified
|
||||||
}
|
}
|
||||||
|
if userInfoClaims.Subject != "" && idClaims.Subject != "" && strings.TrimSpace(userInfoClaims.Subject) != strings.TrimSpace(idClaims.Subject) {
|
||||||
|
redirectOAuthError(c, frontendCallback, "subject_mismatch", "userinfo subject does not match id_token", "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
identityKey := oidcIdentityKey(issuer, subject)
|
||||||
|
compatEmail := strings.TrimSpace(firstNonEmpty(userInfoClaims.Email, idClaims.Email))
|
||||||
|
email := oidcSyntheticEmailFromIdentityKey(identityKey)
|
||||||
|
username := firstNonEmpty(
|
||||||
|
userInfoClaims.Username,
|
||||||
|
idClaims.PreferredUsername,
|
||||||
|
idClaims.Name,
|
||||||
|
oidcFallbackUsername(subject),
|
||||||
|
)
|
||||||
|
identityRef := service.PendingAuthIdentityKey{
|
||||||
|
ProviderType: "oidc",
|
||||||
|
ProviderKey: issuer,
|
||||||
|
ProviderSubject: subject,
|
||||||
|
}
|
||||||
|
upstreamClaims := map[string]any{
|
||||||
|
"email": email,
|
||||||
|
"username": username,
|
||||||
|
"subject": subject,
|
||||||
|
"issuer": issuer,
|
||||||
|
"email_verified": emailVerified != nil && *emailVerified,
|
||||||
|
"provider_fallback": strings.TrimSpace(cfg.ProviderName),
|
||||||
|
"suggested_display_name": firstNonEmpty(userInfoClaims.DisplayName, idClaims.Name, username),
|
||||||
|
"suggested_avatar_url": userInfoClaims.AvatarURL,
|
||||||
|
}
|
||||||
|
if compatEmail != "" && !strings.EqualFold(strings.TrimSpace(compatEmail), strings.TrimSpace(email)) {
|
||||||
|
upstreamClaims["compat_email"] = compatEmail
|
||||||
|
}
|
||||||
|
if intent == oauthIntentBindCurrentUser {
|
||||||
|
targetUserID, err := h.readOAuthBindUserIDFromCookie(c, oidcOAuthBindUserCookieName)
|
||||||
|
if err != nil {
|
||||||
|
redirectOAuthError(c, frontendCallback, "invalid_state", "invalid oauth bind target", "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := h.createOAuthPendingSession(c, oauthPendingSessionPayload{
|
||||||
|
Intent: oauthIntentBindCurrentUser,
|
||||||
|
Identity: identityRef,
|
||||||
|
TargetUserID: &targetUserID,
|
||||||
|
ResolvedEmail: email,
|
||||||
|
RedirectTo: redirectTo,
|
||||||
|
BrowserSessionKey: browserSessionKey,
|
||||||
|
UpstreamIdentityClaims: upstreamClaims,
|
||||||
|
CompletionResponse: map[string]any{
|
||||||
|
"redirect": redirectTo,
|
||||||
|
},
|
||||||
|
}); err != nil {
|
||||||
|
redirectOAuthError(c, frontendCallback, "session_error", "failed to continue oauth bind", "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
redirectToFrontendCallback(c, frontendCallback)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
existingIdentityUser, err := h.findOAuthIdentityUser(c.Request.Context(), identityRef)
|
||||||
|
if err != nil {
|
||||||
|
redirectOAuthError(c, frontendCallback, "session_error", infraerrors.Reason(err), infraerrors.Message(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if existingIdentityUser != nil {
|
||||||
|
tokenPair, user, err := h.authService.LoginOrRegisterOAuthWithTokenPair(c.Request.Context(), existingIdentityUser.Email, username, "")
|
||||||
|
if err != nil {
|
||||||
|
redirectOAuthError(c, frontendCallback, "login_failed", infraerrors.Reason(err), infraerrors.Message(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := h.createOAuthPendingSession(c, oauthPendingSessionPayload{
|
||||||
|
Intent: oauthIntentLogin,
|
||||||
|
Identity: identityRef,
|
||||||
|
TargetUserID: &user.ID,
|
||||||
|
ResolvedEmail: existingIdentityUser.Email,
|
||||||
|
RedirectTo: redirectTo,
|
||||||
|
BrowserSessionKey: browserSessionKey,
|
||||||
|
UpstreamIdentityClaims: upstreamClaims,
|
||||||
|
CompletionResponse: map[string]any{
|
||||||
|
"access_token": tokenPair.AccessToken,
|
||||||
|
"refresh_token": tokenPair.RefreshToken,
|
||||||
|
"expires_in": tokenPair.ExpiresIn,
|
||||||
|
"token_type": "Bearer",
|
||||||
|
"redirect": redirectTo,
|
||||||
|
},
|
||||||
|
}); err != nil {
|
||||||
|
redirectOAuthError(c, frontendCallback, "session_error", "failed to continue oauth login", "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
redirectToFrontendCallback(c, frontendCallback)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
compatEmailUser, err := h.findOIDCCompatEmailUser(c.Request.Context(), compatEmail)
|
||||||
|
if err != nil {
|
||||||
|
redirectOAuthError(c, frontendCallback, "session_error", infraerrors.Reason(err), infraerrors.Message(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if cfg.RequireEmailVerified {
|
if cfg.RequireEmailVerified {
|
||||||
if emailVerified == nil || !*emailVerified {
|
if emailVerified == nil || !*emailVerified {
|
||||||
redirectOAuthError(c, frontendCallback, "email_not_verified", "email is not verified", "")
|
redirectOAuthError(c, frontendCallback, "email_not_verified", "email is not verified", "")
|
||||||
@@ -305,47 +428,131 @@ func (h *AuthHandler) OIDCOAuthCallback(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
identityKey := oidcIdentityKey(issuer, subject)
|
if h.isForceEmailOnThirdPartySignup(c.Request.Context()) {
|
||||||
email := oidcSelectLoginEmail(userInfoClaims.Email, idClaims.Email, identityKey)
|
if err := h.createOIDCOAuthChoicePendingSession(
|
||||||
username := firstNonEmpty(
|
c,
|
||||||
userInfoClaims.Username,
|
identityRef,
|
||||||
idClaims.PreferredUsername,
|
email,
|
||||||
idClaims.Name,
|
email,
|
||||||
oidcFallbackUsername(subject),
|
redirectTo,
|
||||||
)
|
browserSessionKey,
|
||||||
|
upstreamClaims,
|
||||||
|
compatEmail,
|
||||||
|
compatEmailUser,
|
||||||
|
true,
|
||||||
|
); err != nil {
|
||||||
|
redirectOAuthError(c, frontendCallback, "session_error", "failed to continue oauth login", "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
redirectToFrontendCallback(c, frontendCallback)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 传入空邀请码;如果需要邀请码,服务层返回 ErrOAuthInvitationRequired
|
if err := h.createOIDCOAuthChoicePendingSession(
|
||||||
tokenPair, _, err := h.authService.LoginOrRegisterOAuthWithTokenPair(c.Request.Context(), email, username, "")
|
c,
|
||||||
|
identityRef,
|
||||||
|
email,
|
||||||
|
email,
|
||||||
|
redirectTo,
|
||||||
|
browserSessionKey,
|
||||||
|
upstreamClaims,
|
||||||
|
compatEmail,
|
||||||
|
compatEmailUser,
|
||||||
|
h.isForceEmailOnThirdPartySignup(c.Request.Context()),
|
||||||
|
); err != nil {
|
||||||
|
redirectOAuthError(c, frontendCallback, "session_error", "failed to continue oauth login", "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
redirectToFrontendCallback(c, frontendCallback)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *AuthHandler) findOIDCCompatEmailUser(ctx context.Context, email string) (*dbent.User, error) {
|
||||||
|
client := h.entClient()
|
||||||
|
if client == nil {
|
||||||
|
return nil, infraerrors.ServiceUnavailable("PENDING_AUTH_NOT_READY", "pending auth service is not ready")
|
||||||
|
}
|
||||||
|
|
||||||
|
email = strings.TrimSpace(strings.ToLower(email))
|
||||||
|
if email == "" ||
|
||||||
|
strings.HasSuffix(email, service.LinuxDoConnectSyntheticEmailDomain) ||
|
||||||
|
strings.HasSuffix(email, service.OIDCConnectSyntheticEmailDomain) ||
|
||||||
|
strings.HasSuffix(email, service.WeChatConnectSyntheticEmailDomain) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
userEntity, err := findUserByNormalizedEmail(ctx, client, email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, service.ErrOAuthInvitationRequired) {
|
if errors.Is(err, service.ErrUserNotFound) {
|
||||||
pendingToken, tokenErr := h.authService.CreatePendingOAuthToken(email, username)
|
return nil, nil
|
||||||
if tokenErr != nil {
|
|
||||||
redirectOAuthError(c, frontendCallback, "login_failed", "service_error", "")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
fragment := url.Values{}
|
return nil, infraerrors.InternalServer("COMPAT_EMAIL_LOOKUP_FAILED", "failed to look up compat email user").WithCause(err)
|
||||||
fragment.Set("error", "invitation_required")
|
|
||||||
fragment.Set("pending_oauth_token", pendingToken)
|
|
||||||
fragment.Set("redirect", redirectTo)
|
|
||||||
redirectWithFragment(c, frontendCallback, fragment)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
redirectOAuthError(c, frontendCallback, "login_failed", infraerrors.Reason(err), infraerrors.Message(err))
|
return userEntity, nil
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fragment := url.Values{}
|
func (h *AuthHandler) createOIDCOAuthChoicePendingSession(
|
||||||
fragment.Set("access_token", tokenPair.AccessToken)
|
c *gin.Context,
|
||||||
fragment.Set("refresh_token", tokenPair.RefreshToken)
|
identity service.PendingAuthIdentityKey,
|
||||||
fragment.Set("expires_in", fmt.Sprintf("%d", tokenPair.ExpiresIn))
|
suggestedEmail string,
|
||||||
fragment.Set("token_type", "Bearer")
|
resolvedEmail string,
|
||||||
fragment.Set("redirect", redirectTo)
|
redirectTo string,
|
||||||
redirectWithFragment(c, frontendCallback, fragment)
|
browserSessionKey string,
|
||||||
|
upstreamClaims map[string]any,
|
||||||
|
compatEmail string,
|
||||||
|
compatEmailUser *dbent.User,
|
||||||
|
forceEmailOnSignup bool,
|
||||||
|
) error {
|
||||||
|
suggestionEmail := strings.TrimSpace(suggestedEmail)
|
||||||
|
canonicalEmail := strings.TrimSpace(resolvedEmail)
|
||||||
|
if suggestionEmail == "" {
|
||||||
|
suggestionEmail = canonicalEmail
|
||||||
|
}
|
||||||
|
|
||||||
|
completionResponse := map[string]any{
|
||||||
|
"step": oauthPendingChoiceStep,
|
||||||
|
"adoption_required": true,
|
||||||
|
"redirect": strings.TrimSpace(redirectTo),
|
||||||
|
"email": suggestionEmail,
|
||||||
|
"resolved_email": canonicalEmail,
|
||||||
|
"existing_account_email": "",
|
||||||
|
"existing_account_bindable": false,
|
||||||
|
"create_account_allowed": true,
|
||||||
|
"force_email_on_signup": forceEmailOnSignup,
|
||||||
|
"choice_reason": "third_party_signup",
|
||||||
|
}
|
||||||
|
if strings.TrimSpace(compatEmail) != "" {
|
||||||
|
completionResponse["compat_email"] = strings.TrimSpace(compatEmail)
|
||||||
|
}
|
||||||
|
if compatEmailUser != nil {
|
||||||
|
completionResponse["email"] = strings.TrimSpace(compatEmailUser.Email)
|
||||||
|
completionResponse["existing_account_email"] = strings.TrimSpace(compatEmailUser.Email)
|
||||||
|
completionResponse["existing_account_bindable"] = true
|
||||||
|
completionResponse["choice_reason"] = "compat_email_match"
|
||||||
|
}
|
||||||
|
if forceEmailOnSignup && compatEmailUser == nil {
|
||||||
|
completionResponse["choice_reason"] = "force_email_on_signup"
|
||||||
|
}
|
||||||
|
|
||||||
|
resolvedChoiceEmail := suggestionEmail
|
||||||
|
if compatEmailUser != nil {
|
||||||
|
resolvedChoiceEmail = strings.TrimSpace(compatEmailUser.Email)
|
||||||
|
}
|
||||||
|
|
||||||
|
return h.createOAuthPendingSession(c, oauthPendingSessionPayload{
|
||||||
|
Intent: oauthIntentLogin,
|
||||||
|
Identity: identity,
|
||||||
|
ResolvedEmail: resolvedChoiceEmail,
|
||||||
|
RedirectTo: redirectTo,
|
||||||
|
BrowserSessionKey: browserSessionKey,
|
||||||
|
UpstreamIdentityClaims: upstreamClaims,
|
||||||
|
CompletionResponse: completionResponse,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type completeOIDCOAuthRequest struct {
|
type completeOIDCOAuthRequest struct {
|
||||||
PendingOAuthToken string `json:"pending_oauth_token" binding:"required"`
|
|
||||||
InvitationCode string `json:"invitation_code" binding:"required"`
|
InvitationCode string `json:"invitation_code" binding:"required"`
|
||||||
|
AdoptDisplayName *bool `json:"adopt_display_name,omitempty"`
|
||||||
|
AdoptAvatar *bool `json:"adopt_avatar,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CompleteOIDCOAuthRegistration completes a pending OAuth registration by validating
|
// CompleteOIDCOAuthRegistration completes a pending OAuth registration by validating
|
||||||
@@ -358,17 +565,75 @@ func (h *AuthHandler) CompleteOIDCOAuthRegistration(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
email, username, err := h.authService.VerifyPendingOAuthToken(req.PendingOAuthToken)
|
secureCookie := isRequestHTTPS(c)
|
||||||
|
sessionToken, err := readOAuthPendingSessionCookie(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "INVALID_TOKEN", "message": "invalid or expired registration token"})
|
clearOAuthPendingSessionCookie(c, secureCookie)
|
||||||
|
clearOAuthPendingBrowserCookie(c, secureCookie)
|
||||||
|
response.ErrorFrom(c, service.ErrPendingAuthSessionNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
browserSessionKey, err := readOAuthPendingBrowserCookie(c)
|
||||||
tokenPair, _, err := h.authService.LoginOrRegisterOAuthWithTokenPair(c.Request.Context(), email, username, req.InvitationCode)
|
if err != nil {
|
||||||
|
clearOAuthPendingSessionCookie(c, secureCookie)
|
||||||
|
clearOAuthPendingBrowserCookie(c, secureCookie)
|
||||||
|
response.ErrorFrom(c, service.ErrPendingAuthBrowserMismatch)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
pendingSvc, err := h.pendingIdentityService()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.ErrorFrom(c, err)
|
response.ErrorFrom(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
session, err := pendingSvc.GetBrowserSession(c.Request.Context(), sessionToken, browserSessionKey)
|
||||||
|
if err != nil {
|
||||||
|
clearOAuthPendingSessionCookie(c, secureCookie)
|
||||||
|
clearOAuthPendingBrowserCookie(c, secureCookie)
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := ensurePendingOAuthCompleteRegistrationSession(session); err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := h.ensureBackendModeAllowsNewUserLogin(c.Request.Context()); err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
email := strings.TrimSpace(session.ResolvedEmail)
|
||||||
|
username := pendingSessionStringValue(session.UpstreamIdentityClaims, "username")
|
||||||
|
if email == "" || username == "" {
|
||||||
|
response.ErrorFrom(c, infraerrors.BadRequest("PENDING_AUTH_SESSION_INVALID", "pending auth registration context is invalid"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tokenPair, user, err := h.authService.LoginOrRegisterOAuthWithTokenPair(c.Request.Context(), email, username, req.InvitationCode)
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
decision, err := h.upsertPendingOAuthAdoptionDecision(c, session.ID, oauthAdoptionDecisionRequest{
|
||||||
|
AdoptDisplayName: req.AdoptDisplayName,
|
||||||
|
AdoptAvatar: req.AdoptAvatar,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := applyPendingOAuthAdoption(c.Request.Context(), h.entClient(), h.authService, h.userService, session, decision, &user.ID); err != nil {
|
||||||
|
response.ErrorFrom(c, infraerrors.InternalServer("PENDING_AUTH_ADOPTION_APPLY_FAILED", "failed to apply oauth profile adoption").WithCause(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
h.authService.RecordSuccessfulLogin(c.Request.Context(), user.ID)
|
||||||
|
if _, err := pendingSvc.ConsumeBrowserSession(c.Request.Context(), sessionToken, browserSessionKey); err != nil {
|
||||||
|
clearOAuthPendingSessionCookie(c, secureCookie)
|
||||||
|
clearOAuthPendingBrowserCookie(c, secureCookie)
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
clearOAuthPendingSessionCookie(c, secureCookie)
|
||||||
|
clearOAuthPendingBrowserCookie(c, secureCookie)
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"access_token": tokenPair.AccessToken,
|
"access_token": tokenPair.AccessToken,
|
||||||
@@ -405,9 +670,7 @@ func oidcExchangeCode(
|
|||||||
form.Set("client_id", cfg.ClientID)
|
form.Set("client_id", cfg.ClientID)
|
||||||
form.Set("code", code)
|
form.Set("code", code)
|
||||||
form.Set("redirect_uri", redirectURI)
|
form.Set("redirect_uri", redirectURI)
|
||||||
if cfg.UsePKCE {
|
|
||||||
form.Set("code_verifier", codeVerifier)
|
form.Set("code_verifier", codeVerifier)
|
||||||
}
|
|
||||||
|
|
||||||
r := client.R().
|
r := client.R().
|
||||||
SetContext(ctx).
|
SetContext(ctx).
|
||||||
@@ -560,9 +823,26 @@ func oidcParseUserInfo(body string, cfg config.OIDCConnectConfig) *oidcUserInfoC
|
|||||||
if verified, ok := getGJSONBool(body, "email_verified"); ok {
|
if verified, ok := getGJSONBool(body, "email_verified"); ok {
|
||||||
claims.EmailVerified = &verified
|
claims.EmailVerified = &verified
|
||||||
}
|
}
|
||||||
|
claims.DisplayName = firstNonEmpty(
|
||||||
|
getGJSON(body, "name"),
|
||||||
|
getGJSON(body, "nickname"),
|
||||||
|
getGJSON(body, "display_name"),
|
||||||
|
getGJSON(body, "preferred_username"),
|
||||||
|
getGJSON(body, "username"),
|
||||||
|
)
|
||||||
|
claims.AvatarURL = firstNonEmpty(
|
||||||
|
getGJSON(body, "picture"),
|
||||||
|
getGJSON(body, "avatar_url"),
|
||||||
|
getGJSON(body, "avatar"),
|
||||||
|
getGJSON(body, "profile_image_url"),
|
||||||
|
getGJSON(body, "user.avatar"),
|
||||||
|
getGJSON(body, "user.avatar_url"),
|
||||||
|
)
|
||||||
claims.Email = strings.TrimSpace(claims.Email)
|
claims.Email = strings.TrimSpace(claims.Email)
|
||||||
claims.Username = strings.TrimSpace(claims.Username)
|
claims.Username = strings.TrimSpace(claims.Username)
|
||||||
claims.Subject = strings.TrimSpace(claims.Subject)
|
claims.Subject = strings.TrimSpace(claims.Subject)
|
||||||
|
claims.DisplayName = strings.TrimSpace(claims.DisplayName)
|
||||||
|
claims.AvatarURL = strings.TrimSpace(claims.AvatarURL)
|
||||||
return claims
|
return claims
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -592,13 +872,9 @@ func buildOIDCAuthorizeURL(cfg config.OIDCConnectConfig, state, nonce, codeChall
|
|||||||
q.Set("scope", cfg.Scopes)
|
q.Set("scope", cfg.Scopes)
|
||||||
}
|
}
|
||||||
q.Set("state", state)
|
q.Set("state", state)
|
||||||
if strings.TrimSpace(nonce) != "" {
|
|
||||||
q.Set("nonce", nonce)
|
q.Set("nonce", nonce)
|
||||||
}
|
|
||||||
if cfg.UsePKCE {
|
|
||||||
q.Set("code_challenge", codeChallenge)
|
q.Set("code_challenge", codeChallenge)
|
||||||
q.Set("code_challenge_method", "S256")
|
q.Set("code_challenge_method", "S256")
|
||||||
}
|
|
||||||
|
|
||||||
u.RawQuery = q.Encode()
|
u.RawQuery = q.Encode()
|
||||||
return u.String(), nil
|
return u.String(), nil
|
||||||
@@ -831,14 +1107,6 @@ func oidcSyntheticEmailFromIdentityKey(identityKey string) string {
|
|||||||
return "oidc-" + hex.EncodeToString(sum[:16]) + service.OIDCConnectSyntheticEmailDomain
|
return "oidc-" + hex.EncodeToString(sum[:16]) + service.OIDCConnectSyntheticEmailDomain
|
||||||
}
|
}
|
||||||
|
|
||||||
func oidcSelectLoginEmail(userInfoEmail, idTokenEmail, identityKey string) string {
|
|
||||||
email := strings.TrimSpace(firstNonEmpty(userInfoEmail, idTokenEmail))
|
|
||||||
if email != "" {
|
|
||||||
return email
|
|
||||||
}
|
|
||||||
return oidcSyntheticEmailFromIdentityKey(identityKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
func oidcFallbackUsername(subject string) string {
|
func oidcFallbackUsername(subject string) string {
|
||||||
subject = strings.TrimSpace(subject)
|
subject = strings.TrimSpace(subject)
|
||||||
if subject == "" {
|
if subject == "" {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
@@ -12,7 +13,15 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
dbent "github.com/Wei-Shaw/sub2api/ent"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/authidentity"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/identityadoptiondecision"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/pendingauthsession"
|
||||||
|
dbuser "github.com/Wei-Shaw/sub2api/ent/user"
|
||||||
"github.com/Wei-Shaw/sub2api/internal/config"
|
"github.com/Wei-Shaw/sub2api/internal/config"
|
||||||
|
servermiddleware "github.com/Wei-Shaw/sub2api/internal/server/middleware"
|
||||||
|
"github.com/Wei-Shaw/sub2api/internal/service"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/golang-jwt/jwt/v5"
|
"github.com/golang-jwt/jwt/v5"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@@ -30,26 +39,11 @@ func TestOIDCSyntheticEmailStableAndDistinct(t *testing.T) {
|
|||||||
require.Contains(t, e1, "@oidc-connect.invalid")
|
require.Contains(t, e1, "@oidc-connect.invalid")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOIDCSelectLoginEmailPrefersRealEmail(t *testing.T) {
|
|
||||||
identityKey := oidcIdentityKey("https://issuer.example.com", "subject-a")
|
|
||||||
|
|
||||||
email := oidcSelectLoginEmail("user@example.com", "idtoken@example.com", identityKey)
|
|
||||||
require.Equal(t, "user@example.com", email)
|
|
||||||
|
|
||||||
email = oidcSelectLoginEmail("", "idtoken@example.com", identityKey)
|
|
||||||
require.Equal(t, "idtoken@example.com", email)
|
|
||||||
|
|
||||||
email = oidcSelectLoginEmail("", "", identityKey)
|
|
||||||
require.Contains(t, email, "@oidc-connect.invalid")
|
|
||||||
require.Equal(t, oidcSyntheticEmailFromIdentityKey(identityKey), email)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBuildOIDCAuthorizeURLIncludesNonceAndPKCE(t *testing.T) {
|
func TestBuildOIDCAuthorizeURLIncludesNonceAndPKCE(t *testing.T) {
|
||||||
cfg := config.OIDCConnectConfig{
|
cfg := config.OIDCConnectConfig{
|
||||||
AuthorizeURL: "https://issuer.example.com/auth",
|
AuthorizeURL: "https://issuer.example.com/auth",
|
||||||
ClientID: "cid",
|
ClientID: "cid",
|
||||||
Scopes: "openid email profile",
|
Scopes: "openid email profile",
|
||||||
UsePKCE: true,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u, err := buildOIDCAuthorizeURL(cfg, "state123", "nonce123", "challenge123", "https://app.example.com/callback")
|
u, err := buildOIDCAuthorizeURL(cfg, "state123", "nonce123", "challenge123", "https://app.example.com/callback")
|
||||||
@@ -106,6 +100,26 @@ func TestOIDCParseAndValidateIDToken(t *testing.T) {
|
|||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestOIDCParseUserInfoIncludesSuggestedProfile(t *testing.T) {
|
||||||
|
cfg := config.OIDCConnectConfig{}
|
||||||
|
|
||||||
|
claims := oidcParseUserInfo(`{
|
||||||
|
"sub":"subject-1",
|
||||||
|
"preferred_username":"alice",
|
||||||
|
"name":"Alice Example",
|
||||||
|
"picture":"https://cdn.example/avatar.png",
|
||||||
|
"email":"alice@example.com",
|
||||||
|
"email_verified":true
|
||||||
|
}`, cfg)
|
||||||
|
|
||||||
|
require.Equal(t, "subject-1", claims.Subject)
|
||||||
|
require.Equal(t, "alice", claims.Username)
|
||||||
|
require.Equal(t, "Alice Example", claims.DisplayName)
|
||||||
|
require.Equal(t, "https://cdn.example/avatar.png", claims.AvatarURL)
|
||||||
|
require.NotNil(t, claims.EmailVerified)
|
||||||
|
require.True(t, *claims.EmailVerified)
|
||||||
|
}
|
||||||
|
|
||||||
func buildRSAJWK(kid string, pub *rsa.PublicKey) oidcJWK {
|
func buildRSAJWK(kid string, pub *rsa.PublicKey) oidcJWK {
|
||||||
n := base64.RawURLEncoding.EncodeToString(pub.N.Bytes())
|
n := base64.RawURLEncoding.EncodeToString(pub.N.Bytes())
|
||||||
e := base64.RawURLEncoding.EncodeToString(big.NewInt(int64(pub.E)).Bytes())
|
e := base64.RawURLEncoding.EncodeToString(big.NewInt(int64(pub.E)).Bytes())
|
||||||
@@ -118,3 +132,589 @@ func buildRSAJWK(kid string, pub *rsa.PublicKey) oidcJWK {
|
|||||||
E: e,
|
E: e,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestOIDCOAuthBindStartRedirectsAndSetsBindCookies(t *testing.T) {
|
||||||
|
handler := newOIDCOAuthTestHandler(t, false, config.OIDCConnectConfig{
|
||||||
|
Enabled: true,
|
||||||
|
ClientID: "oidc-client",
|
||||||
|
ClientSecret: "oidc-secret",
|
||||||
|
IssuerURL: "https://issuer.example.com",
|
||||||
|
AuthorizeURL: "https://issuer.example.com/oauth/authorize",
|
||||||
|
TokenURL: "https://issuer.example.com/oauth/token",
|
||||||
|
UserInfoURL: "https://issuer.example.com/oauth/userinfo",
|
||||||
|
JWKSURL: "https://issuer.example.com/oauth/jwks",
|
||||||
|
Scopes: "openid profile email",
|
||||||
|
RedirectURL: "https://api.example.com/api/v1/auth/oauth/oidc/callback",
|
||||||
|
FrontendRedirectURL: "/auth/oidc/callback",
|
||||||
|
TokenAuthMethod: "client_secret_post",
|
||||||
|
UsePKCE: true,
|
||||||
|
ValidateIDToken: true,
|
||||||
|
AllowedSigningAlgs: "RS256",
|
||||||
|
ClockSkewSeconds: 120,
|
||||||
|
RequireEmailVerified: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(recorder)
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/api/v1/auth/oauth/oidc/bind/start?intent=bind_current_user&redirect=/settings/connections", nil)
|
||||||
|
c.Request = req
|
||||||
|
c.Set(string(servermiddleware.ContextKeyUser), servermiddleware.AuthSubject{UserID: 84})
|
||||||
|
|
||||||
|
handler.OIDCOAuthStart(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusFound, recorder.Code)
|
||||||
|
location := recorder.Header().Get("Location")
|
||||||
|
require.Contains(t, location, "issuer.example.com/oauth/authorize")
|
||||||
|
require.Contains(t, location, "client_id=oidc-client")
|
||||||
|
require.Contains(t, location, "nonce=")
|
||||||
|
|
||||||
|
cookies := recorder.Result().Cookies()
|
||||||
|
require.NotNil(t, findCookie(cookies, oidcOAuthStateCookieName))
|
||||||
|
require.NotNil(t, findCookie(cookies, oidcOAuthRedirectCookie))
|
||||||
|
require.NotNil(t, findCookie(cookies, oidcOAuthVerifierCookie))
|
||||||
|
require.NotNil(t, findCookie(cookies, oidcOAuthNonceCookie))
|
||||||
|
require.NotNil(t, findCookie(cookies, oauthPendingBrowserCookieName))
|
||||||
|
|
||||||
|
intentCookie := findCookie(cookies, oidcOAuthIntentCookieName)
|
||||||
|
require.NotNil(t, intentCookie)
|
||||||
|
require.Equal(t, oauthIntentBindCurrentUser, decodeCookieValueForTest(t, intentCookie.Value))
|
||||||
|
|
||||||
|
bindCookie := findCookie(cookies, oidcOAuthBindUserCookieName)
|
||||||
|
require.NotNil(t, bindCookie)
|
||||||
|
userID, err := parseOAuthBindUserCookieValue(decodeCookieValueForTest(t, bindCookie.Value), "test-secret")
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, int64(84), userID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOIDCOAuthCallbackCreatesLoginPendingSessionForExistingIdentityUser(t *testing.T) {
|
||||||
|
cfg, cleanup := newOIDCTestProvider(t, oidcProviderFixture{
|
||||||
|
Subject: "oidc-subject-login",
|
||||||
|
PreferredUsername: "oidc_login",
|
||||||
|
DisplayName: "OIDC Login Display",
|
||||||
|
AvatarURL: "https://cdn.example/oidc-login.png",
|
||||||
|
Email: "oidc-login@example.com",
|
||||||
|
EmailVerified: true,
|
||||||
|
})
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
handler, client := newOIDCOAuthHandlerAndClient(t, false, cfg)
|
||||||
|
t.Cleanup(func() { _ = client.Close() })
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
existingUser, err := client.User.Create().
|
||||||
|
SetEmail(oidcSyntheticEmailFromIdentityKey(oidcIdentityKey(cfg.IssuerURL, "oidc-subject-login"))).
|
||||||
|
SetUsername("legacy-user").
|
||||||
|
SetPasswordHash("hash").
|
||||||
|
SetRole(service.RoleUser).
|
||||||
|
SetStatus(service.StatusActive).
|
||||||
|
Save(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
_, err = client.AuthIdentity.Create().
|
||||||
|
SetUserID(existingUser.ID).
|
||||||
|
SetProviderType("oidc").
|
||||||
|
SetProviderKey(cfg.IssuerURL).
|
||||||
|
SetProviderSubject("oidc-subject-login").
|
||||||
|
SetMetadata(map[string]any{"username": "legacy-user"}).
|
||||||
|
Save(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(recorder)
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/api/v1/auth/oauth/oidc/callback?code=oidc-code&state=state-123", nil)
|
||||||
|
req.AddCookie(encodedCookie(oidcOAuthStateCookieName, "state-123"))
|
||||||
|
req.AddCookie(encodedCookie(oidcOAuthRedirectCookie, "/dashboard"))
|
||||||
|
req.AddCookie(encodedCookie(oidcOAuthVerifierCookie, "verifier-123"))
|
||||||
|
req.AddCookie(encodedCookie(oidcOAuthNonceCookie, "nonce-oidc-subject-login"))
|
||||||
|
req.AddCookie(encodedCookie(oidcOAuthIntentCookieName, oauthIntentLogin))
|
||||||
|
req.AddCookie(encodedCookie(oauthPendingBrowserCookieName, "browser-123"))
|
||||||
|
c.Request = req
|
||||||
|
|
||||||
|
handler.OIDCOAuthCallback(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusFound, recorder.Code)
|
||||||
|
require.Equal(t, "/auth/oidc/callback", recorder.Header().Get("Location"))
|
||||||
|
|
||||||
|
sessionCookie := findCookie(recorder.Result().Cookies(), oauthPendingSessionCookieName)
|
||||||
|
require.NotNil(t, sessionCookie)
|
||||||
|
|
||||||
|
session, err := client.PendingAuthSession.Query().
|
||||||
|
Where(pendingauthsession.SessionTokenEQ(decodeCookieValueForTest(t, sessionCookie.Value))).
|
||||||
|
Only(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, oauthIntentLogin, session.Intent)
|
||||||
|
require.NotNil(t, session.TargetUserID)
|
||||||
|
require.Equal(t, existingUser.ID, *session.TargetUserID)
|
||||||
|
require.Equal(t, cfg.IssuerURL, session.ProviderKey)
|
||||||
|
require.Equal(t, "OIDC Login Display", session.UpstreamIdentityClaims["suggested_display_name"])
|
||||||
|
|
||||||
|
completion, ok := session.LocalFlowState[oauthCompletionResponseKey].(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, "/dashboard", completion["redirect"])
|
||||||
|
require.NotEmpty(t, completion["access_token"])
|
||||||
|
require.Nil(t, completion["error"])
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOIDCOAuthCallbackCreatesBindPendingSessionForCompatEmailUser(t *testing.T) {
|
||||||
|
cfg, cleanup := newOIDCTestProvider(t, oidcProviderFixture{
|
||||||
|
Subject: "oidc-subject-compat",
|
||||||
|
PreferredUsername: "oidc_compat",
|
||||||
|
DisplayName: "OIDC Compat Display",
|
||||||
|
AvatarURL: "https://cdn.example/oidc-compat.png",
|
||||||
|
Email: "legacy@example.com",
|
||||||
|
EmailVerified: true,
|
||||||
|
})
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
handler, client := newOIDCOAuthHandlerAndClient(t, false, cfg)
|
||||||
|
t.Cleanup(func() { _ = client.Close() })
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
existingUser, err := client.User.Create().
|
||||||
|
SetEmail("legacy@example.com").
|
||||||
|
SetUsername("legacy-user").
|
||||||
|
SetPasswordHash("hash").
|
||||||
|
SetRole(service.RoleUser).
|
||||||
|
SetStatus(service.StatusActive).
|
||||||
|
Save(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(recorder)
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/api/v1/auth/oauth/oidc/callback?code=oidc-code&state=state-compat", nil)
|
||||||
|
req.AddCookie(encodedCookie(oidcOAuthStateCookieName, "state-compat"))
|
||||||
|
req.AddCookie(encodedCookie(oidcOAuthRedirectCookie, "/dashboard"))
|
||||||
|
req.AddCookie(encodedCookie(oidcOAuthVerifierCookie, "verifier-compat"))
|
||||||
|
req.AddCookie(encodedCookie(oidcOAuthNonceCookie, "nonce-oidc-subject-compat"))
|
||||||
|
req.AddCookie(encodedCookie(oidcOAuthIntentCookieName, oauthIntentLogin))
|
||||||
|
req.AddCookie(encodedCookie(oauthPendingBrowserCookieName, "browser-compat"))
|
||||||
|
c.Request = req
|
||||||
|
|
||||||
|
handler.OIDCOAuthCallback(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusFound, recorder.Code)
|
||||||
|
require.Equal(t, "/auth/oidc/callback", recorder.Header().Get("Location"))
|
||||||
|
|
||||||
|
sessionCookie := findCookie(recorder.Result().Cookies(), oauthPendingSessionCookieName)
|
||||||
|
require.NotNil(t, sessionCookie)
|
||||||
|
|
||||||
|
session, err := client.PendingAuthSession.Query().
|
||||||
|
Where(pendingauthsession.SessionTokenEQ(decodeCookieValueForTest(t, sessionCookie.Value))).
|
||||||
|
Only(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, oauthIntentLogin, session.Intent)
|
||||||
|
require.Nil(t, session.TargetUserID)
|
||||||
|
require.Equal(t, existingUser.Email, session.ResolvedEmail)
|
||||||
|
require.Equal(t, "legacy@example.com", session.UpstreamIdentityClaims["compat_email"])
|
||||||
|
|
||||||
|
completion, ok := session.LocalFlowState[oauthCompletionResponseKey].(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, "/dashboard", completion["redirect"])
|
||||||
|
require.Equal(t, oauthPendingChoiceStep, completion["step"])
|
||||||
|
require.Equal(t, existingUser.Email, completion["email"])
|
||||||
|
require.Equal(t, existingUser.Email, completion["existing_account_email"])
|
||||||
|
require.Equal(t, true, completion["existing_account_bindable"])
|
||||||
|
require.Equal(t, "compat_email_match", completion["choice_reason"])
|
||||||
|
_, hasAccessToken := completion["access_token"]
|
||||||
|
require.False(t, hasAccessToken)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOIDCOAuthCallbackAllowsCompatEmailBindWhenUpstreamEmailIsUnverified(t *testing.T) {
|
||||||
|
cfg, cleanup := newOIDCTestProvider(t, oidcProviderFixture{
|
||||||
|
Subject: "oidc-subject-unverified-compat",
|
||||||
|
PreferredUsername: "oidc_unverified",
|
||||||
|
DisplayName: "OIDC Unverified Compat Display",
|
||||||
|
AvatarURL: "https://cdn.example/oidc-unverified.png",
|
||||||
|
Email: "owner@example.com",
|
||||||
|
EmailVerified: false,
|
||||||
|
})
|
||||||
|
defer cleanup()
|
||||||
|
cfg.RequireEmailVerified = true
|
||||||
|
|
||||||
|
handler, client := newOIDCOAuthHandlerAndClient(t, false, cfg)
|
||||||
|
t.Cleanup(func() { _ = client.Close() })
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
_, err := client.User.Create().
|
||||||
|
SetEmail("owner@example.com").
|
||||||
|
SetUsername("owner-user").
|
||||||
|
SetPasswordHash("hash").
|
||||||
|
SetRole(service.RoleUser).
|
||||||
|
SetStatus(service.StatusActive).
|
||||||
|
Save(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(recorder)
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/api/v1/auth/oauth/oidc/callback?code=oidc-code&state=state-unverified-compat", nil)
|
||||||
|
req.AddCookie(encodedCookie(oidcOAuthStateCookieName, "state-unverified-compat"))
|
||||||
|
req.AddCookie(encodedCookie(oidcOAuthRedirectCookie, "/settings/connections"))
|
||||||
|
req.AddCookie(encodedCookie(oidcOAuthVerifierCookie, "verifier-unverified-compat"))
|
||||||
|
req.AddCookie(encodedCookie(oidcOAuthNonceCookie, "nonce-oidc-subject-unverified-compat"))
|
||||||
|
req.AddCookie(encodedCookie(oidcOAuthIntentCookieName, oauthIntentLogin))
|
||||||
|
req.AddCookie(encodedCookie(oauthPendingBrowserCookieName, "browser-unverified-compat"))
|
||||||
|
c.Request = req
|
||||||
|
|
||||||
|
handler.OIDCOAuthCallback(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusFound, recorder.Code)
|
||||||
|
require.Equal(t, "/auth/oidc/callback#error=email_not_verified&error_message=email+is+not+verified", recorder.Header().Get("Location"))
|
||||||
|
require.Nil(t, findCookie(recorder.Result().Cookies(), oauthPendingSessionCookieName))
|
||||||
|
|
||||||
|
count, err := client.PendingAuthSession.Query().Count(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Zero(t, count)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOIDCOAuthCallbackCreatesChoicePendingSessionWhenSignupRequiresInvite(t *testing.T) {
|
||||||
|
cfg, cleanup := newOIDCTestProvider(t, oidcProviderFixture{
|
||||||
|
Subject: "oidc-subject-invite",
|
||||||
|
PreferredUsername: "oidc_invite",
|
||||||
|
DisplayName: "OIDC Invite Display",
|
||||||
|
AvatarURL: "https://cdn.example/oidc-invite.png",
|
||||||
|
Email: "oidc-invite@example.com",
|
||||||
|
EmailVerified: true,
|
||||||
|
})
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
handler, client := newOIDCOAuthHandlerAndClient(t, true, cfg)
|
||||||
|
t.Cleanup(func() { _ = client.Close() })
|
||||||
|
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(recorder)
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/api/v1/auth/oauth/oidc/callback?code=oidc-code&state=state-456", nil)
|
||||||
|
req.AddCookie(encodedCookie(oidcOAuthStateCookieName, "state-456"))
|
||||||
|
req.AddCookie(encodedCookie(oidcOAuthRedirectCookie, "/dashboard"))
|
||||||
|
req.AddCookie(encodedCookie(oidcOAuthVerifierCookie, "verifier-456"))
|
||||||
|
req.AddCookie(encodedCookie(oidcOAuthNonceCookie, "nonce-oidc-subject-invite"))
|
||||||
|
req.AddCookie(encodedCookie(oidcOAuthIntentCookieName, oauthIntentLogin))
|
||||||
|
req.AddCookie(encodedCookie(oauthPendingBrowserCookieName, "browser-456"))
|
||||||
|
c.Request = req
|
||||||
|
|
||||||
|
handler.OIDCOAuthCallback(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusFound, recorder.Code)
|
||||||
|
require.Equal(t, "/auth/oidc/callback", recorder.Header().Get("Location"))
|
||||||
|
|
||||||
|
sessionCookie := findCookie(recorder.Result().Cookies(), oauthPendingSessionCookieName)
|
||||||
|
require.NotNil(t, sessionCookie)
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
session, err := client.PendingAuthSession.Query().
|
||||||
|
Where(pendingauthsession.SessionTokenEQ(decodeCookieValueForTest(t, sessionCookie.Value))).
|
||||||
|
Only(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, oauthIntentLogin, session.Intent)
|
||||||
|
require.Nil(t, session.TargetUserID)
|
||||||
|
|
||||||
|
completion, ok := session.LocalFlowState[oauthCompletionResponseKey].(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, oauthPendingChoiceStep, completion["step"])
|
||||||
|
require.Equal(t, "/dashboard", completion["redirect"])
|
||||||
|
require.Equal(t, "third_party_signup", completion["choice_reason"])
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOIDCOAuthCallbackCreatesBindPendingSessionForCurrentUser(t *testing.T) {
|
||||||
|
cfg, cleanup := newOIDCTestProvider(t, oidcProviderFixture{
|
||||||
|
Subject: "oidc-subject-bind",
|
||||||
|
PreferredUsername: "oidc_bind",
|
||||||
|
DisplayName: "OIDC Bind Display",
|
||||||
|
AvatarURL: "https://cdn.example/oidc-bind.png",
|
||||||
|
Email: "oidc-bind@example.com",
|
||||||
|
EmailVerified: true,
|
||||||
|
})
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
handler, client := newOIDCOAuthHandlerAndClient(t, false, cfg)
|
||||||
|
t.Cleanup(func() { _ = client.Close() })
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
currentUser, err := client.User.Create().
|
||||||
|
SetEmail("current@example.com").
|
||||||
|
SetUsername("current-user").
|
||||||
|
SetPasswordHash("hash").
|
||||||
|
SetRole(service.RoleUser).
|
||||||
|
SetStatus(service.StatusActive).
|
||||||
|
Save(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(recorder)
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/api/v1/auth/oauth/oidc/callback?code=oidc-code&state=state-bind", nil)
|
||||||
|
req.AddCookie(encodedCookie(oidcOAuthStateCookieName, "state-bind"))
|
||||||
|
req.AddCookie(encodedCookie(oidcOAuthRedirectCookie, "/settings/connections"))
|
||||||
|
req.AddCookie(encodedCookie(oidcOAuthVerifierCookie, "verifier-bind"))
|
||||||
|
req.AddCookie(encodedCookie(oidcOAuthNonceCookie, "nonce-oidc-subject-bind"))
|
||||||
|
req.AddCookie(encodedCookie(oidcOAuthIntentCookieName, oauthIntentBindCurrentUser))
|
||||||
|
req.AddCookie(encodedCookie(oidcOAuthBindUserCookieName, buildEncodedOAuthBindUserCookie(t, currentUser.ID, "test-secret")))
|
||||||
|
req.AddCookie(encodedCookie(oauthPendingBrowserCookieName, "browser-bind"))
|
||||||
|
c.Request = req
|
||||||
|
|
||||||
|
handler.OIDCOAuthCallback(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusFound, recorder.Code)
|
||||||
|
require.Equal(t, "/auth/oidc/callback", recorder.Header().Get("Location"))
|
||||||
|
|
||||||
|
sessionCookie := findCookie(recorder.Result().Cookies(), oauthPendingSessionCookieName)
|
||||||
|
require.NotNil(t, sessionCookie)
|
||||||
|
|
||||||
|
session, err := client.PendingAuthSession.Query().
|
||||||
|
Where(pendingauthsession.SessionTokenEQ(decodeCookieValueForTest(t, sessionCookie.Value))).
|
||||||
|
Only(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, oauthIntentBindCurrentUser, session.Intent)
|
||||||
|
require.NotNil(t, session.TargetUserID)
|
||||||
|
require.Equal(t, currentUser.ID, *session.TargetUserID)
|
||||||
|
require.Equal(t, cfg.IssuerURL, session.ProviderKey)
|
||||||
|
require.Equal(t, "OIDC Bind Display", session.UpstreamIdentityClaims["suggested_display_name"])
|
||||||
|
|
||||||
|
completion, ok := session.LocalFlowState[oauthCompletionResponseKey].(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, "/settings/connections", completion["redirect"])
|
||||||
|
require.Empty(t, completion["access_token"])
|
||||||
|
|
||||||
|
userCount, err := client.User.Query().Count(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, 1, userCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCompleteOIDCOAuthRegistrationAppliesPendingAdoptionDecision(t *testing.T) {
|
||||||
|
handler, client := newOAuthPendingFlowTestHandler(t, false)
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
session, err := client.PendingAuthSession.Create().
|
||||||
|
SetSessionToken("oidc-complete-session").
|
||||||
|
SetIntent("login").
|
||||||
|
SetProviderType("oidc").
|
||||||
|
SetProviderKey("https://issuer.example.com").
|
||||||
|
SetProviderSubject("oidc-subject-1").
|
||||||
|
SetResolvedEmail("93a310f4c1944c5bbd2e246df1f76485@oidc-connect.invalid").
|
||||||
|
SetBrowserSessionKey("oidc-browser").
|
||||||
|
SetUpstreamIdentityClaims(map[string]any{
|
||||||
|
"username": "oidc_user",
|
||||||
|
"issuer": "https://issuer.example.com",
|
||||||
|
"suggested_display_name": "OIDC Display",
|
||||||
|
"suggested_avatar_url": "https://cdn.example/oidc.png",
|
||||||
|
}).
|
||||||
|
SetExpiresAt(time.Now().UTC().Add(10 * time.Minute)).
|
||||||
|
Save(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
_, err = service.NewAuthPendingIdentityService(client).UpsertAdoptionDecision(ctx, service.PendingIdentityAdoptionDecisionInput{
|
||||||
|
PendingAuthSessionID: session.ID,
|
||||||
|
AdoptAvatar: true,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
body := bytes.NewBufferString(`{"invitation_code":"invite-1","adopt_display_name":true}`)
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(recorder)
|
||||||
|
req := httptest.NewRequest(http.MethodPost, "/api/v1/auth/oauth/oidc/complete-registration", body)
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
req.AddCookie(&http.Cookie{Name: oauthPendingSessionCookieName, Value: encodeCookieValue(session.SessionToken)})
|
||||||
|
req.AddCookie(&http.Cookie{Name: oauthPendingBrowserCookieName, Value: encodeCookieValue("oidc-browser")})
|
||||||
|
c.Request = req
|
||||||
|
|
||||||
|
handler.CompleteOIDCOAuthRegistration(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusOK, recorder.Code)
|
||||||
|
responseData := decodeJSONBody(t, recorder)
|
||||||
|
require.NotEmpty(t, responseData["access_token"])
|
||||||
|
|
||||||
|
userEntity, err := client.User.Query().
|
||||||
|
Where(dbuser.EmailEQ(session.ResolvedEmail)).
|
||||||
|
Only(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, "OIDC Display", userEntity.Username)
|
||||||
|
|
||||||
|
identity, err := client.AuthIdentity.Query().
|
||||||
|
Where(
|
||||||
|
authidentity.ProviderTypeEQ("oidc"),
|
||||||
|
authidentity.ProviderKeyEQ("https://issuer.example.com"),
|
||||||
|
authidentity.ProviderSubjectEQ("oidc-subject-1"),
|
||||||
|
).
|
||||||
|
Only(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, userEntity.ID, identity.UserID)
|
||||||
|
require.Equal(t, "OIDC Display", identity.Metadata["display_name"])
|
||||||
|
require.Equal(t, "https://cdn.example/oidc.png", identity.Metadata["avatar_url"])
|
||||||
|
|
||||||
|
decision, err := client.IdentityAdoptionDecision.Query().
|
||||||
|
Where(identityadoptiondecision.PendingAuthSessionIDEQ(session.ID)).
|
||||||
|
Only(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, decision.IdentityID)
|
||||||
|
require.Equal(t, identity.ID, *decision.IdentityID)
|
||||||
|
require.True(t, decision.AdoptDisplayName)
|
||||||
|
require.True(t, decision.AdoptAvatar)
|
||||||
|
|
||||||
|
consumed, err := client.PendingAuthSession.Query().
|
||||||
|
Where(pendingauthsession.IDEQ(session.ID)).
|
||||||
|
Only(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, consumed.ConsumedAt)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCompleteOIDCOAuthRegistrationRejectsAdoptExistingUserSession(t *testing.T) {
|
||||||
|
handler, client := newOAuthPendingFlowTestHandler(t, false)
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
existingUser, err := client.User.Create().
|
||||||
|
SetEmail("owner@example.com").
|
||||||
|
SetUsername("owner-user").
|
||||||
|
SetPasswordHash("hash").
|
||||||
|
SetRole(service.RoleUser).
|
||||||
|
SetStatus(service.StatusActive).
|
||||||
|
Save(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
session, err := client.PendingAuthSession.Create().
|
||||||
|
SetSessionToken("oidc-complete-invalid-session").
|
||||||
|
SetIntent("adopt_existing_user_by_email").
|
||||||
|
SetProviderType("oidc").
|
||||||
|
SetProviderKey("https://issuer.example.com").
|
||||||
|
SetProviderSubject("oidc-invalid-subject-1").
|
||||||
|
SetTargetUserID(existingUser.ID).
|
||||||
|
SetResolvedEmail(existingUser.Email).
|
||||||
|
SetBrowserSessionKey("oidc-invalid-browser").
|
||||||
|
SetUpstreamIdentityClaims(map[string]any{
|
||||||
|
"username": "oidc_user",
|
||||||
|
}).
|
||||||
|
SetLocalFlowState(map[string]any{
|
||||||
|
oauthCompletionResponseKey: map[string]any{
|
||||||
|
"step": "bind_login_required",
|
||||||
|
},
|
||||||
|
}).
|
||||||
|
SetExpiresAt(time.Now().UTC().Add(10 * time.Minute)).
|
||||||
|
Save(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
body := bytes.NewBufferString(`{"invitation_code":"invite-1"}`)
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(recorder)
|
||||||
|
req := httptest.NewRequest(http.MethodPost, "/api/v1/auth/oauth/oidc/complete-registration", body)
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
req.AddCookie(&http.Cookie{Name: oauthPendingSessionCookieName, Value: encodeCookieValue(session.SessionToken)})
|
||||||
|
req.AddCookie(&http.Cookie{Name: oauthPendingBrowserCookieName, Value: encodeCookieValue("oidc-invalid-browser")})
|
||||||
|
c.Request = req
|
||||||
|
|
||||||
|
handler.CompleteOIDCOAuthRegistration(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusBadRequest, recorder.Code)
|
||||||
|
|
||||||
|
storedSession, err := client.PendingAuthSession.Get(ctx, session.ID)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Nil(t, storedSession.ConsumedAt)
|
||||||
|
}
|
||||||
|
|
||||||
|
type oidcProviderFixture struct {
|
||||||
|
Subject string
|
||||||
|
PreferredUsername string
|
||||||
|
DisplayName string
|
||||||
|
AvatarURL string
|
||||||
|
Email string
|
||||||
|
EmailVerified bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func newOIDCOAuthTestHandler(t *testing.T, invitationEnabled bool, oauthCfg config.OIDCConnectConfig) *AuthHandler {
|
||||||
|
t.Helper()
|
||||||
|
handler, _ := newOIDCOAuthHandlerAndClient(t, invitationEnabled, oauthCfg)
|
||||||
|
return handler
|
||||||
|
}
|
||||||
|
|
||||||
|
func newOIDCOAuthHandlerAndClient(t *testing.T, invitationEnabled bool, oauthCfg config.OIDCConnectConfig) (*AuthHandler, *dbent.Client) {
|
||||||
|
t.Helper()
|
||||||
|
handler, client := newOAuthPendingFlowTestHandler(t, invitationEnabled)
|
||||||
|
handler.settingSvc = nil
|
||||||
|
handler.cfg = &config.Config{
|
||||||
|
JWT: config.JWTConfig{
|
||||||
|
Secret: "test-secret",
|
||||||
|
ExpireHour: 1,
|
||||||
|
AccessTokenExpireMinutes: 60,
|
||||||
|
RefreshTokenExpireDays: 7,
|
||||||
|
},
|
||||||
|
OIDC: oauthCfg,
|
||||||
|
}
|
||||||
|
return handler, client
|
||||||
|
}
|
||||||
|
|
||||||
|
func newOIDCTestProvider(t *testing.T, fixture oidcProviderFixture) (config.OIDCConnectConfig, func()) {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
kid := "test-kid"
|
||||||
|
jwks := oidcJWKSet{Keys: []oidcJWK{buildRSAJWK(kid, &privateKey.PublicKey)}}
|
||||||
|
tokenResponse := oidcTokenResponse{
|
||||||
|
AccessToken: "oidc-access-token",
|
||||||
|
TokenType: "Bearer",
|
||||||
|
ExpiresIn: 3600,
|
||||||
|
}
|
||||||
|
|
||||||
|
userInfoPayload := map[string]any{
|
||||||
|
"sub": fixture.Subject,
|
||||||
|
"preferred_username": fixture.PreferredUsername,
|
||||||
|
"name": fixture.DisplayName,
|
||||||
|
"picture": fixture.AvatarURL,
|
||||||
|
"email": fixture.Email,
|
||||||
|
"email_verified": fixture.EmailVerified,
|
||||||
|
}
|
||||||
|
|
||||||
|
var issuer string
|
||||||
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
switch r.URL.Path {
|
||||||
|
case "/token":
|
||||||
|
require.NoError(t, json.NewEncoder(w).Encode(tokenResponse))
|
||||||
|
case "/userinfo":
|
||||||
|
require.NoError(t, json.NewEncoder(w).Encode(userInfoPayload))
|
||||||
|
case "/jwks":
|
||||||
|
require.NoError(t, json.NewEncoder(w).Encode(jwks))
|
||||||
|
default:
|
||||||
|
http.NotFound(w, r)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
|
issuer = server.URL
|
||||||
|
now := time.Now()
|
||||||
|
claims := oidcIDTokenClaims{
|
||||||
|
Email: fixture.Email,
|
||||||
|
EmailVerified: boolPtr(fixture.EmailVerified),
|
||||||
|
PreferredUsername: fixture.PreferredUsername,
|
||||||
|
Name: fixture.DisplayName,
|
||||||
|
Nonce: "nonce-" + fixture.Subject,
|
||||||
|
RegisteredClaims: jwt.RegisteredClaims{
|
||||||
|
Issuer: issuer,
|
||||||
|
Subject: fixture.Subject,
|
||||||
|
Audience: jwt.ClaimStrings{"oidc-client"},
|
||||||
|
IssuedAt: jwt.NewNumericDate(now),
|
||||||
|
NotBefore: jwt.NewNumericDate(now.Add(-30 * time.Second)),
|
||||||
|
ExpiresAt: jwt.NewNumericDate(now.Add(5 * time.Minute)),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
token := jwt.NewWithClaims(jwt.SigningMethodRS256, claims)
|
||||||
|
token.Header["kid"] = kid
|
||||||
|
tokenResponse.IDToken, err = token.SignedString(privateKey)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
cfg := config.OIDCConnectConfig{
|
||||||
|
Enabled: true,
|
||||||
|
ProviderName: "Test OIDC",
|
||||||
|
ClientID: "oidc-client",
|
||||||
|
ClientSecret: "oidc-secret",
|
||||||
|
IssuerURL: issuer,
|
||||||
|
AuthorizeURL: issuer + "/authorize",
|
||||||
|
TokenURL: issuer + "/token",
|
||||||
|
UserInfoURL: issuer + "/userinfo",
|
||||||
|
JWKSURL: issuer + "/jwks",
|
||||||
|
Scopes: "openid profile email",
|
||||||
|
RedirectURL: "https://api.example.com/api/v1/auth/oauth/oidc/callback",
|
||||||
|
FrontendRedirectURL: "/auth/oidc/callback",
|
||||||
|
TokenAuthMethod: "client_secret_post",
|
||||||
|
UsePKCE: true,
|
||||||
|
ValidateIDToken: true,
|
||||||
|
AllowedSigningAlgs: "RS256",
|
||||||
|
ClockSkewSeconds: 120,
|
||||||
|
RequireEmailVerified: false,
|
||||||
|
}
|
||||||
|
return cfg, server.Close
|
||||||
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -21,6 +21,7 @@ func UserFromServiceShallow(u *service.User) *User {
|
|||||||
Concurrency: u.Concurrency,
|
Concurrency: u.Concurrency,
|
||||||
Status: u.Status,
|
Status: u.Status,
|
||||||
AllowedGroups: u.AllowedGroups,
|
AllowedGroups: u.AllowedGroups,
|
||||||
|
LastActiveAt: u.LastActiveAt,
|
||||||
CreatedAt: u.CreatedAt,
|
CreatedAt: u.CreatedAt,
|
||||||
UpdatedAt: u.UpdatedAt,
|
UpdatedAt: u.UpdatedAt,
|
||||||
BalanceNotifyEnabled: u.BalanceNotifyEnabled,
|
BalanceNotifyEnabled: u.BalanceNotifyEnabled,
|
||||||
@@ -66,6 +67,7 @@ func UserFromServiceAdmin(u *service.User) *AdminUser {
|
|||||||
return &AdminUser{
|
return &AdminUser{
|
||||||
User: *base,
|
User: *base,
|
||||||
Notes: u.Notes,
|
Notes: u.Notes,
|
||||||
|
LastUsedAt: u.LastUsedAt,
|
||||||
GroupRates: u.GroupRates,
|
GroupRates: u.GroupRates,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,23 @@ type SystemSettings struct {
|
|||||||
LinuxDoConnectClientSecretConfigured bool `json:"linuxdo_connect_client_secret_configured"`
|
LinuxDoConnectClientSecretConfigured bool `json:"linuxdo_connect_client_secret_configured"`
|
||||||
LinuxDoConnectRedirectURL string `json:"linuxdo_connect_redirect_url"`
|
LinuxDoConnectRedirectURL string `json:"linuxdo_connect_redirect_url"`
|
||||||
|
|
||||||
|
WeChatConnectEnabled bool `json:"wechat_connect_enabled"`
|
||||||
|
WeChatConnectAppID string `json:"wechat_connect_app_id"`
|
||||||
|
WeChatConnectAppSecretConfigured bool `json:"wechat_connect_app_secret_configured"`
|
||||||
|
WeChatConnectOpenAppID string `json:"wechat_connect_open_app_id"`
|
||||||
|
WeChatConnectOpenAppSecretConfigured bool `json:"wechat_connect_open_app_secret_configured"`
|
||||||
|
WeChatConnectMPAppID string `json:"wechat_connect_mp_app_id"`
|
||||||
|
WeChatConnectMPAppSecretConfigured bool `json:"wechat_connect_mp_app_secret_configured"`
|
||||||
|
WeChatConnectMobileAppID string `json:"wechat_connect_mobile_app_id"`
|
||||||
|
WeChatConnectMobileAppSecretConfigured bool `json:"wechat_connect_mobile_app_secret_configured"`
|
||||||
|
WeChatConnectOpenEnabled bool `json:"wechat_connect_open_enabled"`
|
||||||
|
WeChatConnectMPEnabled bool `json:"wechat_connect_mp_enabled"`
|
||||||
|
WeChatConnectMobileEnabled bool `json:"wechat_connect_mobile_enabled"`
|
||||||
|
WeChatConnectMode string `json:"wechat_connect_mode"`
|
||||||
|
WeChatConnectScopes string `json:"wechat_connect_scopes"`
|
||||||
|
WeChatConnectRedirectURL string `json:"wechat_connect_redirect_url"`
|
||||||
|
WeChatConnectFrontendRedirectURL string `json:"wechat_connect_frontend_redirect_url"`
|
||||||
|
|
||||||
OIDCConnectEnabled bool `json:"oidc_connect_enabled"`
|
OIDCConnectEnabled bool `json:"oidc_connect_enabled"`
|
||||||
OIDCConnectProviderName string `json:"oidc_connect_provider_name"`
|
OIDCConnectProviderName string `json:"oidc_connect_provider_name"`
|
||||||
OIDCConnectClientID string `json:"oidc_connect_client_id"`
|
OIDCConnectClientID string `json:"oidc_connect_client_id"`
|
||||||
@@ -127,6 +144,15 @@ type SystemSettings struct {
|
|||||||
// Web Search Emulation
|
// Web Search Emulation
|
||||||
WebSearchEmulationEnabled bool `json:"web_search_emulation_enabled"`
|
WebSearchEmulationEnabled bool `json:"web_search_emulation_enabled"`
|
||||||
|
|
||||||
|
// Payment visible method routing
|
||||||
|
PaymentVisibleMethodAlipaySource string `json:"payment_visible_method_alipay_source"`
|
||||||
|
PaymentVisibleMethodWxpaySource string `json:"payment_visible_method_wxpay_source"`
|
||||||
|
PaymentVisibleMethodAlipayEnabled bool `json:"payment_visible_method_alipay_enabled"`
|
||||||
|
PaymentVisibleMethodWxpayEnabled bool `json:"payment_visible_method_wxpay_enabled"`
|
||||||
|
|
||||||
|
// OpenAI account scheduling
|
||||||
|
OpenAIAdvancedSchedulerEnabled bool `json:"openai_advanced_scheduler_enabled"`
|
||||||
|
|
||||||
// Payment configuration
|
// Payment configuration
|
||||||
PaymentEnabled bool `json:"payment_enabled"`
|
PaymentEnabled bool `json:"payment_enabled"`
|
||||||
PaymentMinAmount float64 `json:"payment_min_amount"`
|
PaymentMinAmount float64 `json:"payment_min_amount"`
|
||||||
@@ -167,6 +193,7 @@ type DefaultSubscriptionSetting struct {
|
|||||||
type PublicSettings struct {
|
type PublicSettings struct {
|
||||||
RegistrationEnabled bool `json:"registration_enabled"`
|
RegistrationEnabled bool `json:"registration_enabled"`
|
||||||
EmailVerifyEnabled bool `json:"email_verify_enabled"`
|
EmailVerifyEnabled bool `json:"email_verify_enabled"`
|
||||||
|
ForceEmailOnThirdPartySignup bool `json:"force_email_on_third_party_signup"`
|
||||||
RegistrationEmailSuffixWhitelist []string `json:"registration_email_suffix_whitelist"`
|
RegistrationEmailSuffixWhitelist []string `json:"registration_email_suffix_whitelist"`
|
||||||
PromoCodeEnabled bool `json:"promo_code_enabled"`
|
PromoCodeEnabled bool `json:"promo_code_enabled"`
|
||||||
PasswordResetEnabled bool `json:"password_reset_enabled"`
|
PasswordResetEnabled bool `json:"password_reset_enabled"`
|
||||||
@@ -189,6 +216,10 @@ type PublicSettings struct {
|
|||||||
CustomMenuItems []CustomMenuItem `json:"custom_menu_items"`
|
CustomMenuItems []CustomMenuItem `json:"custom_menu_items"`
|
||||||
CustomEndpoints []CustomEndpoint `json:"custom_endpoints"`
|
CustomEndpoints []CustomEndpoint `json:"custom_endpoints"`
|
||||||
LinuxDoOAuthEnabled bool `json:"linuxdo_oauth_enabled"`
|
LinuxDoOAuthEnabled bool `json:"linuxdo_oauth_enabled"`
|
||||||
|
WeChatOAuthEnabled bool `json:"wechat_oauth_enabled"`
|
||||||
|
WeChatOAuthOpenEnabled bool `json:"wechat_oauth_open_enabled"`
|
||||||
|
WeChatOAuthMPEnabled bool `json:"wechat_oauth_mp_enabled"`
|
||||||
|
WeChatOAuthMobileEnabled bool `json:"wechat_oauth_mobile_enabled"`
|
||||||
OIDCOAuthEnabled bool `json:"oidc_oauth_enabled"`
|
OIDCOAuthEnabled bool `json:"oidc_oauth_enabled"`
|
||||||
OIDCOAuthProviderName string `json:"oidc_oauth_provider_name"`
|
OIDCOAuthProviderName string `json:"oidc_oauth_provider_name"`
|
||||||
SoraClientEnabled bool `json:"sora_client_enabled"`
|
SoraClientEnabled bool `json:"sora_client_enabled"`
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ type User struct {
|
|||||||
Concurrency int `json:"concurrency"`
|
Concurrency int `json:"concurrency"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
AllowedGroups []int64 `json:"allowed_groups"`
|
AllowedGroups []int64 `json:"allowed_groups"`
|
||||||
|
LastActiveAt *time.Time `json:"last_active_at,omitempty"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
|
|
||||||
@@ -35,6 +36,7 @@ type AdminUser struct {
|
|||||||
User
|
User
|
||||||
|
|
||||||
Notes string `json:"notes"`
|
Notes string `json:"notes"`
|
||||||
|
LastUsedAt *time.Time `json:"last_used_at"`
|
||||||
// GroupRates 用户专属分组倍率配置
|
// GroupRates 用户专属分组倍率配置
|
||||||
// map[groupID]rateMultiplier
|
// map[groupID]rateMultiplier
|
||||||
GroupRates map[int64]float64 `json:"group_rates,omitempty"`
|
GroupRates map[int64]float64 `json:"group_rates,omitempty"`
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package dto
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/Wei-Shaw/sub2api/internal/service"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestUserFromServiceAdmin_MapsActivityTimestamps(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
lastLoginAt := time.Date(2026, time.April, 20, 10, 0, 0, 0, time.UTC)
|
||||||
|
lastActiveAt := lastLoginAt.Add(15 * time.Minute)
|
||||||
|
lastUsedAt := lastLoginAt.Add(45 * time.Minute)
|
||||||
|
|
||||||
|
out := UserFromServiceAdmin(&service.User{
|
||||||
|
ID: 42,
|
||||||
|
Email: "admin@example.com",
|
||||||
|
Username: "admin",
|
||||||
|
Role: service.RoleAdmin,
|
||||||
|
Status: service.StatusActive,
|
||||||
|
LastActiveAt: &lastActiveAt,
|
||||||
|
LastUsedAt: &lastUsedAt,
|
||||||
|
})
|
||||||
|
|
||||||
|
require.NotNil(t, out)
|
||||||
|
require.NotNil(t, out.LastActiveAt)
|
||||||
|
require.NotNil(t, out.LastUsedAt)
|
||||||
|
require.WithinDuration(t, lastActiveAt, *out.LastActiveAt, time.Second)
|
||||||
|
require.WithinDuration(t, lastUsedAt, *out.LastUsedAt, time.Second)
|
||||||
|
}
|
||||||
@@ -187,6 +187,11 @@ func (h *OpenAIGatewayHandler) Responses(c *gin.Context) {
|
|||||||
h.errorResponse(c, http.StatusBadRequest, "invalid_request_error", "previous_response_id must be a response.id (resp_*), not a message id")
|
h.errorResponse(c, http.StatusBadRequest, "invalid_request_error", "previous_response_id must be a response.id (resp_*), not a message id")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
reqLog.Warn("openai.request_validation_failed",
|
||||||
|
zap.String("reason", "previous_response_id_requires_wsv2"),
|
||||||
|
)
|
||||||
|
h.errorResponse(c, http.StatusBadRequest, "invalid_request_error", "previous_response_id is only supported on Responses WebSocket v2")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
setOpsRequestContext(c, reqModel, reqStream, body)
|
setOpsRequestContext(c, reqModel, reqStream, body)
|
||||||
@@ -856,7 +861,7 @@ func (h *OpenAIGatewayHandler) validateFunctionCallOutputRequest(c *gin.Context,
|
|||||||
reqLog.Warn("openai.request_validation_failed",
|
reqLog.Warn("openai.request_validation_failed",
|
||||||
zap.String("reason", "function_call_output_missing_call_id"),
|
zap.String("reason", "function_call_output_missing_call_id"),
|
||||||
)
|
)
|
||||||
h.errorResponse(c, http.StatusBadRequest, "invalid_request_error", "function_call_output requires call_id or previous_response_id; if relying on history, ensure store=true and reuse previous_response_id")
|
h.errorResponse(c, http.StatusBadRequest, "invalid_request_error", "function_call_output requires call_id on HTTP requests; continuation via previous_response_id is only supported on Responses WebSocket v2")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if validation.HasItemReferenceForAllCallIDs {
|
if validation.HasItemReferenceForAllCallIDs {
|
||||||
@@ -866,7 +871,7 @@ func (h *OpenAIGatewayHandler) validateFunctionCallOutputRequest(c *gin.Context,
|
|||||||
reqLog.Warn("openai.request_validation_failed",
|
reqLog.Warn("openai.request_validation_failed",
|
||||||
zap.String("reason", "function_call_output_missing_item_reference"),
|
zap.String("reason", "function_call_output_missing_item_reference"),
|
||||||
)
|
)
|
||||||
h.errorResponse(c, http.StatusBadRequest, "invalid_request_error", "function_call_output requires item_reference ids matching each call_id, or previous_response_id/tool_call context; if relying on history, ensure store=true and reuse previous_response_id")
|
h.errorResponse(c, http.StatusBadRequest, "invalid_request_error", "function_call_output requires item_reference ids matching each call_id on HTTP requests; continuation via previous_response_id is only supported on Responses WebSocket v2")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -494,6 +494,64 @@ func TestOpenAIResponses_RejectsMessageIDAsPreviousResponseID(t *testing.T) {
|
|||||||
require.Contains(t, w.Body.String(), "previous_response_id must be a response.id")
|
require.Contains(t, w.Body.String(), "previous_response_id must be a response.id")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestOpenAIResponses_RejectsHTTPContinuationPreviousResponseID(t *testing.T) {
|
||||||
|
gin.SetMode(gin.TestMode)
|
||||||
|
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(w)
|
||||||
|
c.Request = httptest.NewRequest(http.MethodPost, "/openai/v1/responses", strings.NewReader(
|
||||||
|
`{"model":"gpt-5.1","stream":false,"previous_response_id":"resp_123456","input":[{"type":"input_text","text":"hello"}]}`,
|
||||||
|
))
|
||||||
|
c.Request.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
groupID := int64(2)
|
||||||
|
c.Set(string(middleware.ContextKeyAPIKey), &service.APIKey{
|
||||||
|
ID: 101,
|
||||||
|
GroupID: &groupID,
|
||||||
|
User: &service.User{ID: 1},
|
||||||
|
})
|
||||||
|
c.Set(string(middleware.ContextKeyUser), middleware.AuthSubject{
|
||||||
|
UserID: 1,
|
||||||
|
Concurrency: 1,
|
||||||
|
})
|
||||||
|
|
||||||
|
h := newOpenAIHandlerForPreviousResponseIDValidation(t, nil)
|
||||||
|
h.Responses(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusBadRequest, w.Code)
|
||||||
|
require.Contains(t, w.Body.String(), "Responses WebSocket v2")
|
||||||
|
require.Contains(t, w.Body.String(), "previous_response_id")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOpenAIResponses_FunctionCallOutputHTTPGuidanceDoesNotSuggestPreviousResponseReuse(t *testing.T) {
|
||||||
|
gin.SetMode(gin.TestMode)
|
||||||
|
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(w)
|
||||||
|
c.Request = httptest.NewRequest(http.MethodPost, "/openai/v1/responses", strings.NewReader(
|
||||||
|
`{"model":"gpt-5.1","stream":false,"input":[{"type":"function_call_output","output":"{}"}]}`,
|
||||||
|
))
|
||||||
|
c.Request.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
groupID := int64(2)
|
||||||
|
c.Set(string(middleware.ContextKeyAPIKey), &service.APIKey{
|
||||||
|
ID: 101,
|
||||||
|
GroupID: &groupID,
|
||||||
|
User: &service.User{ID: 1},
|
||||||
|
})
|
||||||
|
c.Set(string(middleware.ContextKeyUser), middleware.AuthSubject{
|
||||||
|
UserID: 1,
|
||||||
|
Concurrency: 1,
|
||||||
|
})
|
||||||
|
|
||||||
|
h := newOpenAIHandlerForPreviousResponseIDValidation(t, nil)
|
||||||
|
h.Responses(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusBadRequest, w.Code)
|
||||||
|
require.Contains(t, w.Body.String(), "Responses WebSocket v2")
|
||||||
|
require.NotContains(t, w.Body.String(), "reuse previous_response_id")
|
||||||
|
}
|
||||||
|
|
||||||
func TestOpenAIResponsesWebSocket_SetsClientTransportWSWhenUpgradeValid(t *testing.T) {
|
func TestOpenAIResponsesWebSocket_SetsClientTransportWSWhenUpgradeValid(t *testing.T) {
|
||||||
gin.SetMode(gin.TestMode)
|
gin.SetMode(gin.TestMode)
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
dbent "github.com/Wei-Shaw/sub2api/ent"
|
||||||
|
"github.com/Wei-Shaw/sub2api/internal/payment"
|
||||||
|
infraerrors "github.com/Wei-Shaw/sub2api/internal/pkg/errors"
|
||||||
"github.com/Wei-Shaw/sub2api/internal/pkg/pagination"
|
"github.com/Wei-Shaw/sub2api/internal/pkg/pagination"
|
||||||
"github.com/Wei-Shaw/sub2api/internal/pkg/response"
|
"github.com/Wei-Shaw/sub2api/internal/pkg/response"
|
||||||
middleware2 "github.com/Wei-Shaw/sub2api/internal/server/middleware"
|
middleware2 "github.com/Wei-Shaw/sub2api/internal/server/middleware"
|
||||||
@@ -204,6 +209,10 @@ func (h *PaymentHandler) GetLimits(c *gin.Context) {
|
|||||||
type CreateOrderRequest struct {
|
type CreateOrderRequest struct {
|
||||||
Amount float64 `json:"amount"`
|
Amount float64 `json:"amount"`
|
||||||
PaymentType string `json:"payment_type" binding:"required"`
|
PaymentType string `json:"payment_type" binding:"required"`
|
||||||
|
OpenID string `json:"openid"`
|
||||||
|
WechatResumeToken string `json:"wechat_resume_token"`
|
||||||
|
ReturnURL string `json:"return_url"`
|
||||||
|
PaymentSource string `json:"payment_source"`
|
||||||
OrderType string `json:"order_type"`
|
OrderType string `json:"order_type"`
|
||||||
PlanID int64 `json:"plan_id"`
|
PlanID int64 `json:"plan_id"`
|
||||||
// IsMobile lets the frontend declare its mobile status directly. When
|
// IsMobile lets the frontend declare its mobile status directly. When
|
||||||
@@ -225,6 +234,17 @@ func (h *PaymentHandler) CreateOrder(c *gin.Context) {
|
|||||||
response.BadRequest(c, "Invalid request: "+err.Error())
|
response.BadRequest(c, "Invalid request: "+err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if strings.TrimSpace(req.WechatResumeToken) != "" {
|
||||||
|
claims, err := h.paymentService.ParseWeChatPaymentResumeToken(req.WechatResumeToken)
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := applyWeChatPaymentResumeClaims(&req, claims); err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mobile := isMobile(c)
|
mobile := isMobile(c)
|
||||||
if req.IsMobile != nil {
|
if req.IsMobile != nil {
|
||||||
@@ -234,10 +254,14 @@ func (h *PaymentHandler) CreateOrder(c *gin.Context) {
|
|||||||
UserID: subject.UserID,
|
UserID: subject.UserID,
|
||||||
Amount: req.Amount,
|
Amount: req.Amount,
|
||||||
PaymentType: req.PaymentType,
|
PaymentType: req.PaymentType,
|
||||||
|
OpenID: req.OpenID,
|
||||||
ClientIP: c.ClientIP(),
|
ClientIP: c.ClientIP(),
|
||||||
IsMobile: mobile,
|
IsMobile: mobile,
|
||||||
|
IsWeChatBrowser: isWeChatBrowser(c),
|
||||||
SrcHost: c.Request.Host,
|
SrcHost: c.Request.Host,
|
||||||
SrcURL: c.Request.Referer(),
|
SrcURL: c.Request.Referer(),
|
||||||
|
ReturnURL: req.ReturnURL,
|
||||||
|
PaymentSource: req.PaymentSource,
|
||||||
OrderType: req.OrderType,
|
OrderType: req.OrderType,
|
||||||
PlanID: req.PlanID,
|
PlanID: req.PlanID,
|
||||||
})
|
})
|
||||||
@@ -248,6 +272,44 @@ func (h *PaymentHandler) CreateOrder(c *gin.Context) {
|
|||||||
response.Success(c, result)
|
response.Success(c, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func applyWeChatPaymentResumeClaims(req *CreateOrderRequest, claims *service.WeChatPaymentResumeClaims) error {
|
||||||
|
if req == nil || claims == nil {
|
||||||
|
return infraerrors.BadRequest("INVALID_WECHAT_PAYMENT_RESUME_TOKEN", "wechat payment resume context is missing")
|
||||||
|
}
|
||||||
|
openid := strings.TrimSpace(claims.OpenID)
|
||||||
|
if openid == "" {
|
||||||
|
return infraerrors.BadRequest("INVALID_WECHAT_PAYMENT_RESUME_TOKEN", "wechat payment resume token missing openid")
|
||||||
|
}
|
||||||
|
|
||||||
|
paymentType := service.NormalizeVisibleMethod(claims.PaymentType)
|
||||||
|
if paymentType == "" {
|
||||||
|
paymentType = payment.TypeWxpay
|
||||||
|
}
|
||||||
|
if req.PaymentType != "" {
|
||||||
|
requestPaymentType := service.NormalizeVisibleMethod(req.PaymentType)
|
||||||
|
if requestPaymentType != "" && requestPaymentType != paymentType {
|
||||||
|
return infraerrors.BadRequest("INVALID_WECHAT_PAYMENT_RESUME_TOKEN", "wechat payment resume token payment type mismatch")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
req.PaymentType = paymentType
|
||||||
|
req.OpenID = openid
|
||||||
|
|
||||||
|
if strings.TrimSpace(claims.Amount) != "" {
|
||||||
|
amount, err := strconv.ParseFloat(strings.TrimSpace(claims.Amount), 64)
|
||||||
|
if err != nil || amount <= 0 {
|
||||||
|
return infraerrors.BadRequest("INVALID_WECHAT_PAYMENT_RESUME_TOKEN", fmt.Sprintf("invalid resume amount: %s", claims.Amount))
|
||||||
|
}
|
||||||
|
req.Amount = amount
|
||||||
|
}
|
||||||
|
if claims.OrderType != "" {
|
||||||
|
req.OrderType = claims.OrderType
|
||||||
|
}
|
||||||
|
if claims.PlanID > 0 {
|
||||||
|
req.PlanID = claims.PlanID
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetMyOrders returns the authenticated user's orders.
|
// GetMyOrders returns the authenticated user's orders.
|
||||||
// GET /api/v1/payment/orders/my
|
// GET /api/v1/payment/orders/my
|
||||||
func (h *PaymentHandler) GetMyOrders(c *gin.Context) {
|
func (h *PaymentHandler) GetMyOrders(c *gin.Context) {
|
||||||
@@ -268,7 +330,7 @@ func (h *PaymentHandler) GetMyOrders(c *gin.Context) {
|
|||||||
response.ErrorFrom(c, err)
|
response.ErrorFrom(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
response.Paginated(c, orders, int64(total), page, pageSize)
|
response.Paginated(c, sanitizePaymentOrdersForResponse(orders), int64(total), page, pageSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOrder returns a single order for the authenticated user.
|
// GetOrder returns a single order for the authenticated user.
|
||||||
@@ -290,7 +352,7 @@ func (h *PaymentHandler) GetOrder(c *gin.Context) {
|
|||||||
response.ErrorFrom(c, err)
|
response.ErrorFrom(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
response.Success(c, order)
|
response.Success(c, sanitizePaymentOrderForResponse(order))
|
||||||
}
|
}
|
||||||
|
|
||||||
// CancelOrder cancels a pending order for the authenticated user.
|
// CancelOrder cancels a pending order for the authenticated user.
|
||||||
@@ -362,6 +424,10 @@ type VerifyOrderRequest struct {
|
|||||||
OutTradeNo string `json:"out_trade_no" binding:"required"`
|
OutTradeNo string `json:"out_trade_no" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ResolveOrderByResumeTokenRequest struct {
|
||||||
|
ResumeToken string `json:"resume_token" binding:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
// VerifyOrder actively queries the upstream payment provider to check
|
// VerifyOrder actively queries the upstream payment provider to check
|
||||||
// if payment was made, and processes it if so.
|
// if payment was made, and processes it if so.
|
||||||
// POST /api/v1/payment/orders/verify
|
// POST /api/v1/payment/orders/verify
|
||||||
@@ -382,7 +448,7 @@ func (h *PaymentHandler) VerifyOrder(c *gin.Context) {
|
|||||||
response.ErrorFrom(c, err)
|
response.ErrorFrom(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
response.Success(c, order)
|
response.Success(c, sanitizePaymentOrderForResponse(order))
|
||||||
}
|
}
|
||||||
|
|
||||||
// PublicOrderResult is the limited order info returned by the public verify endpoint.
|
// PublicOrderResult is the limited order info returned by the public verify endpoint.
|
||||||
@@ -397,16 +463,32 @@ type PublicOrderResult struct {
|
|||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// VerifyOrderPublic verifies payment status without requiring authentication.
|
var errPaymentPublicOrderVerifyRemoved = infraerrors.New(
|
||||||
// Returns limited order info (no user details) to prevent information leakage.
|
http.StatusGone,
|
||||||
|
"PAYMENT_PUBLIC_ORDER_VERIFY_REMOVED",
|
||||||
|
"public payment order verification by out_trade_no has been removed; use resume_token recovery instead",
|
||||||
|
).WithMetadata(map[string]string{
|
||||||
|
"replacement_endpoint": "/api/v1/payment/public/orders/resolve",
|
||||||
|
"replacement_field": "resume_token",
|
||||||
|
})
|
||||||
|
|
||||||
|
// VerifyOrderPublic is kept as a compatibility shim for the removed anonymous
|
||||||
|
// out_trade_no lookup endpoint and always returns HTTP 410 Gone.
|
||||||
// POST /api/v1/payment/public/orders/verify
|
// POST /api/v1/payment/public/orders/verify
|
||||||
func (h *PaymentHandler) VerifyOrderPublic(c *gin.Context) {
|
func (h *PaymentHandler) VerifyOrderPublic(c *gin.Context) {
|
||||||
var req VerifyOrderRequest
|
response.ErrorFrom(c, errPaymentPublicOrderVerifyRemoved)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResolveOrderPublicByResumeToken resolves a payment order from a signed resume token.
|
||||||
|
// POST /api/v1/payment/public/orders/resolve
|
||||||
|
func (h *PaymentHandler) ResolveOrderPublicByResumeToken(c *gin.Context) {
|
||||||
|
var req ResolveOrderByResumeTokenRequest
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
response.BadRequest(c, "Invalid request: "+err.Error())
|
response.BadRequest(c, "Invalid request: "+err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
order, err := h.paymentService.VerifyOrderPublic(c.Request.Context(), req.OutTradeNo)
|
|
||||||
|
order, err := h.paymentService.GetPublicOrderByResumeToken(c.Request.Context(), req.ResumeToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.ErrorFrom(c, err)
|
response.ErrorFrom(c, err)
|
||||||
return
|
return
|
||||||
@@ -443,3 +525,27 @@ func isMobile(c *gin.Context) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sanitizePaymentOrdersForResponse(orders []*dbent.PaymentOrder) []*dbent.PaymentOrder {
|
||||||
|
if len(orders) == 0 {
|
||||||
|
return orders
|
||||||
|
}
|
||||||
|
out := make([]*dbent.PaymentOrder, 0, len(orders))
|
||||||
|
for _, order := range orders {
|
||||||
|
out = append(out, sanitizePaymentOrderForResponse(order))
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func sanitizePaymentOrderForResponse(order *dbent.PaymentOrder) *dbent.PaymentOrder {
|
||||||
|
if order == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
cloned := *order
|
||||||
|
cloned.ProviderSnapshot = nil
|
||||||
|
return &cloned
|
||||||
|
}
|
||||||
|
|
||||||
|
func isWeChatBrowser(c *gin.Context) bool {
|
||||||
|
return strings.Contains(strings.ToLower(c.GetHeader("User-Agent")), "micromessenger")
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,114 @@
|
|||||||
|
//go:build unit
|
||||||
|
|
||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"database/sql"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
dbent "github.com/Wei-Shaw/sub2api/ent"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/enttest"
|
||||||
|
"github.com/Wei-Shaw/sub2api/internal/payment"
|
||||||
|
"github.com/Wei-Shaw/sub2api/internal/pkg/response"
|
||||||
|
"github.com/Wei-Shaw/sub2api/internal/service"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
entsql "entgo.io/ent/dialect/sql"
|
||||||
|
_ "modernc.org/sqlite"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestApplyWeChatPaymentResumeClaims(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
req := CreateOrderRequest{
|
||||||
|
Amount: 0,
|
||||||
|
PaymentType: payment.TypeWxpay,
|
||||||
|
OrderType: payment.OrderTypeBalance,
|
||||||
|
}
|
||||||
|
|
||||||
|
err := applyWeChatPaymentResumeClaims(&req, &service.WeChatPaymentResumeClaims{
|
||||||
|
OpenID: "openid-123",
|
||||||
|
PaymentType: payment.TypeWxpay,
|
||||||
|
Amount: "12.50",
|
||||||
|
OrderType: payment.OrderTypeSubscription,
|
||||||
|
PlanID: 7,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("applyWeChatPaymentResumeClaims returned error: %v", err)
|
||||||
|
}
|
||||||
|
if req.OpenID != "openid-123" {
|
||||||
|
t.Fatalf("openid = %q, want %q", req.OpenID, "openid-123")
|
||||||
|
}
|
||||||
|
if req.Amount != 12.5 {
|
||||||
|
t.Fatalf("amount = %v, want 12.5", req.Amount)
|
||||||
|
}
|
||||||
|
if req.OrderType != payment.OrderTypeSubscription {
|
||||||
|
t.Fatalf("order_type = %q, want %q", req.OrderType, payment.OrderTypeSubscription)
|
||||||
|
}
|
||||||
|
if req.PlanID != 7 {
|
||||||
|
t.Fatalf("plan_id = %d, want 7", req.PlanID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestApplyWeChatPaymentResumeClaimsRejectsPaymentTypeMismatch(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
req := CreateOrderRequest{
|
||||||
|
PaymentType: payment.TypeAlipay,
|
||||||
|
}
|
||||||
|
|
||||||
|
err := applyWeChatPaymentResumeClaims(&req, &service.WeChatPaymentResumeClaims{
|
||||||
|
OpenID: "openid-123",
|
||||||
|
PaymentType: payment.TypeWxpay,
|
||||||
|
Amount: "12.50",
|
||||||
|
OrderType: payment.OrderTypeBalance,
|
||||||
|
})
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("applyWeChatPaymentResumeClaims should reject mismatched payment types")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestVerifyOrderPublicReturnsGone(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
gin.SetMode(gin.TestMode)
|
||||||
|
|
||||||
|
db, err := sql.Open("sqlite", "file:payment_handler_public_verify?mode=memory&cache=shared")
|
||||||
|
require.NoError(t, err)
|
||||||
|
t.Cleanup(func() { _ = db.Close() })
|
||||||
|
|
||||||
|
_, err = db.Exec("PRAGMA foreign_keys = ON")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
drv := entsql.OpenDB(dialect.SQLite, db)
|
||||||
|
client := enttest.NewClient(t, enttest.WithOptions(dbent.Driver(drv)))
|
||||||
|
t.Cleanup(func() { _ = client.Close() })
|
||||||
|
|
||||||
|
paymentSvc := service.NewPaymentService(client, payment.NewRegistry(), nil, nil, nil, nil, nil, nil)
|
||||||
|
h := NewPaymentHandler(paymentSvc, nil, nil)
|
||||||
|
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
ctx, _ := gin.CreateTestContext(recorder)
|
||||||
|
ctx.Request = httptest.NewRequest(
|
||||||
|
http.MethodPost,
|
||||||
|
"/api/v1/payment/public/orders/verify",
|
||||||
|
bytes.NewBufferString(`{"out_trade_no":"legacy-order-no"}`),
|
||||||
|
)
|
||||||
|
ctx.Request.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
h.VerifyOrderPublic(ctx)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusGone, recorder.Code)
|
||||||
|
|
||||||
|
var resp response.Response
|
||||||
|
require.NoError(t, json.Unmarshal(recorder.Body.Bytes(), &resp))
|
||||||
|
require.Equal(t, http.StatusGone, resp.Code)
|
||||||
|
require.Equal(t, "PAYMENT_PUBLIC_ORDER_VERIFY_REMOVED", resp.Reason)
|
||||||
|
require.Contains(t, resp.Message, "removed")
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -77,9 +79,13 @@ func (h *PaymentWebhookHandler) handleNotify(c *gin.Context, providerKey string)
|
|||||||
// This is needed when multiple instances of the same provider exist (e.g. multiple EasyPay accounts).
|
// This is needed when multiple instances of the same provider exist (e.g. multiple EasyPay accounts).
|
||||||
outTradeNo := extractOutTradeNo(rawBody, providerKey)
|
outTradeNo := extractOutTradeNo(rawBody, providerKey)
|
||||||
|
|
||||||
provider, err := h.paymentService.GetWebhookProvider(c.Request.Context(), providerKey, outTradeNo)
|
providers, err := h.paymentService.GetWebhookProviders(c.Request.Context(), providerKey, outTradeNo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Warn("[Payment Webhook] provider not found", "provider", providerKey, "outTradeNo", outTradeNo, "error", err)
|
slog.Warn("[Payment Webhook] provider not found", "provider", providerKey, "outTradeNo", outTradeNo, "error", err)
|
||||||
|
if providerKey == payment.TypeWxpay {
|
||||||
|
c.String(http.StatusBadRequest, "verify failed")
|
||||||
|
return
|
||||||
|
}
|
||||||
writeSuccessResponse(c, providerKey)
|
writeSuccessResponse(c, providerKey)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -89,7 +95,7 @@ func (h *PaymentWebhookHandler) handleNotify(c *gin.Context, providerKey string)
|
|||||||
headers[strings.ToLower(k)] = c.GetHeader(k)
|
headers[strings.ToLower(k)] = c.GetHeader(k)
|
||||||
}
|
}
|
||||||
|
|
||||||
notification, err := provider.VerifyNotification(c.Request.Context(), rawBody, headers)
|
resolvedProviderKey, notification, err := verifyNotificationWithProviders(c.Request.Context(), providers, rawBody, headers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
truncatedBody := rawBody
|
truncatedBody := rawBody
|
||||||
if len(truncatedBody) > webhookLogTruncateLen {
|
if len(truncatedBody) > webhookLogTruncateLen {
|
||||||
@@ -103,24 +109,24 @@ func (h *PaymentWebhookHandler) handleNotify(c *gin.Context, providerKey string)
|
|||||||
|
|
||||||
// nil notification means irrelevant event (e.g. Stripe non-payment event); return success.
|
// nil notification means irrelevant event (e.g. Stripe non-payment event); return success.
|
||||||
if notification == nil {
|
if notification == nil {
|
||||||
writeSuccessResponse(c, providerKey)
|
writeSuccessResponse(c, resolvedProviderKey)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := h.paymentService.HandlePaymentNotification(c.Request.Context(), notification, providerKey); err != nil {
|
if err := h.paymentService.HandlePaymentNotification(c.Request.Context(), notification, resolvedProviderKey); err != nil {
|
||||||
slog.Error("[Payment Webhook] handle notification failed", "provider", providerKey, "error", err)
|
slog.Error("[Payment Webhook] handle notification failed", "provider", resolvedProviderKey, "error", err)
|
||||||
c.String(http.StatusInternalServerError, "handle failed")
|
c.String(http.StatusInternalServerError, "handle failed")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
writeSuccessResponse(c, providerKey)
|
writeSuccessResponse(c, resolvedProviderKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
// extractOutTradeNo parses the webhook body to find the out_trade_no.
|
// extractOutTradeNo parses the webhook body to find the out_trade_no.
|
||||||
// This allows looking up the correct provider instance before verification.
|
// This allows looking up the correct provider instance before verification.
|
||||||
func extractOutTradeNo(rawBody, providerKey string) string {
|
func extractOutTradeNo(rawBody, providerKey string) string {
|
||||||
switch providerKey {
|
switch providerKey {
|
||||||
case payment.TypeEasyPay:
|
case payment.TypeEasyPay, payment.TypeAlipay:
|
||||||
values, err := url.ParseQuery(rawBody)
|
values, err := url.ParseQuery(rawBody)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return values.Get("out_trade_no")
|
return values.Get("out_trade_no")
|
||||||
@@ -131,6 +137,25 @@ func extractOutTradeNo(rawBody, providerKey string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func verifyNotificationWithProviders(ctx context.Context, providers []payment.Provider, rawBody string, headers map[string]string) (string, *payment.PaymentNotification, error) {
|
||||||
|
var lastErr error
|
||||||
|
for _, provider := range providers {
|
||||||
|
if provider == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
notification, err := provider.VerifyNotification(ctx, rawBody, headers)
|
||||||
|
if err != nil {
|
||||||
|
lastErr = err
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return provider.ProviderKey(), notification, nil
|
||||||
|
}
|
||||||
|
if lastErr != nil {
|
||||||
|
return "", nil, lastErr
|
||||||
|
}
|
||||||
|
return "", nil, fmt.Errorf("no webhook provider could verify notification")
|
||||||
|
}
|
||||||
|
|
||||||
// wxpaySuccessResponse is the JSON response expected by WeChat Pay webhook.
|
// wxpaySuccessResponse is the JSON response expected by WeChat Pay webhook.
|
||||||
type wxpaySuccessResponse struct {
|
type wxpaySuccessResponse struct {
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
|
|||||||
@@ -3,11 +3,14 @@
|
|||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/Wei-Shaw/sub2api/internal/payment"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@@ -97,3 +100,104 @@ func TestWebhookConstants(t *testing.T) {
|
|||||||
assert.Equal(t, 200, webhookLogTruncateLen)
|
assert.Equal(t, 200, webhookLogTruncateLen)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestExtractOutTradeNo(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
providerKey string
|
||||||
|
rawBody string
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "easypay query payload",
|
||||||
|
providerKey: "easypay",
|
||||||
|
rawBody: "out_trade_no=sub2_123&trade_status=TRADE_SUCCESS",
|
||||||
|
want: "sub2_123",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "alipay query payload",
|
||||||
|
providerKey: "alipay",
|
||||||
|
rawBody: "notify_time=2026-04-20+12%3A00%3A00&out_trade_no=sub2_456",
|
||||||
|
want: "sub2_456",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "unknown provider",
|
||||||
|
providerKey: "wxpay",
|
||||||
|
rawBody: "{}",
|
||||||
|
want: "",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
assert.Equal(t, tt.want, extractOutTradeNo(tt.rawBody, tt.providerKey))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestVerifyNotificationWithProvidersReturnsMatchedProvider(t *testing.T) {
|
||||||
|
firstErr := errors.New("wrong provider")
|
||||||
|
providers := []payment.Provider{
|
||||||
|
webhookHandlerProviderStub{
|
||||||
|
key: payment.TypeWxpay,
|
||||||
|
verifyErr: firstErr,
|
||||||
|
},
|
||||||
|
webhookHandlerProviderStub{
|
||||||
|
key: payment.TypeWxpay,
|
||||||
|
notification: &payment.PaymentNotification{
|
||||||
|
OrderID: "sub2_42",
|
||||||
|
TradeNo: "trade-42",
|
||||||
|
Status: payment.NotificationStatusSuccess,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
providerKey, notification, err := verifyNotificationWithProviders(context.Background(), providers, "{}", map[string]string{"wechatpay-signature": "sig"})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, payment.TypeWxpay, providerKey)
|
||||||
|
require.NotNil(t, notification)
|
||||||
|
require.Equal(t, "sub2_42", notification.OrderID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestVerifyNotificationWithProvidersFailsWhenAllProvidersReject(t *testing.T) {
|
||||||
|
providers := []payment.Provider{
|
||||||
|
webhookHandlerProviderStub{
|
||||||
|
key: payment.TypeWxpay,
|
||||||
|
verifyErr: errors.New("verify failed a"),
|
||||||
|
},
|
||||||
|
webhookHandlerProviderStub{
|
||||||
|
key: payment.TypeWxpay,
|
||||||
|
verifyErr: errors.New("verify failed b"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _, err := verifyNotificationWithProviders(context.Background(), providers, "{}", nil)
|
||||||
|
require.Error(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
type webhookHandlerProviderStub struct {
|
||||||
|
key string
|
||||||
|
notification *payment.PaymentNotification
|
||||||
|
verifyErr error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p webhookHandlerProviderStub) Name() string { return p.key }
|
||||||
|
func (p webhookHandlerProviderStub) ProviderKey() string { return p.key }
|
||||||
|
func (p webhookHandlerProviderStub) SupportedTypes() []payment.PaymentType {
|
||||||
|
return []payment.PaymentType{payment.PaymentType(p.key)}
|
||||||
|
}
|
||||||
|
func (p webhookHandlerProviderStub) CreatePayment(context.Context, payment.CreatePaymentRequest) (*payment.CreatePaymentResponse, error) {
|
||||||
|
panic("unexpected call")
|
||||||
|
}
|
||||||
|
func (p webhookHandlerProviderStub) QueryOrder(context.Context, string) (*payment.QueryOrderResponse, error) {
|
||||||
|
panic("unexpected call")
|
||||||
|
}
|
||||||
|
func (p webhookHandlerProviderStub) VerifyNotification(context.Context, string, map[string]string) (*payment.PaymentNotification, error) {
|
||||||
|
if p.verifyErr != nil {
|
||||||
|
return nil, p.verifyErr
|
||||||
|
}
|
||||||
|
return p.notification, nil
|
||||||
|
}
|
||||||
|
func (p webhookHandlerProviderStub) Refund(context.Context, payment.RefundRequest) (*payment.RefundResponse, error) {
|
||||||
|
panic("unexpected call")
|
||||||
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ func (h *SettingHandler) GetPublicSettings(c *gin.Context) {
|
|||||||
response.Success(c, dto.PublicSettings{
|
response.Success(c, dto.PublicSettings{
|
||||||
RegistrationEnabled: settings.RegistrationEnabled,
|
RegistrationEnabled: settings.RegistrationEnabled,
|
||||||
EmailVerifyEnabled: settings.EmailVerifyEnabled,
|
EmailVerifyEnabled: settings.EmailVerifyEnabled,
|
||||||
|
ForceEmailOnThirdPartySignup: settings.ForceEmailOnThirdPartySignup,
|
||||||
RegistrationEmailSuffixWhitelist: settings.RegistrationEmailSuffixWhitelist,
|
RegistrationEmailSuffixWhitelist: settings.RegistrationEmailSuffixWhitelist,
|
||||||
PromoCodeEnabled: settings.PromoCodeEnabled,
|
PromoCodeEnabled: settings.PromoCodeEnabled,
|
||||||
PasswordResetEnabled: settings.PasswordResetEnabled,
|
PasswordResetEnabled: settings.PasswordResetEnabled,
|
||||||
@@ -56,6 +57,10 @@ func (h *SettingHandler) GetPublicSettings(c *gin.Context) {
|
|||||||
CustomMenuItems: dto.ParseUserVisibleMenuItems(settings.CustomMenuItems),
|
CustomMenuItems: dto.ParseUserVisibleMenuItems(settings.CustomMenuItems),
|
||||||
CustomEndpoints: dto.ParseCustomEndpoints(settings.CustomEndpoints),
|
CustomEndpoints: dto.ParseCustomEndpoints(settings.CustomEndpoints),
|
||||||
LinuxDoOAuthEnabled: settings.LinuxDoOAuthEnabled,
|
LinuxDoOAuthEnabled: settings.LinuxDoOAuthEnabled,
|
||||||
|
WeChatOAuthEnabled: settings.WeChatOAuthEnabled,
|
||||||
|
WeChatOAuthOpenEnabled: settings.WeChatOAuthOpenEnabled,
|
||||||
|
WeChatOAuthMPEnabled: settings.WeChatOAuthMPEnabled,
|
||||||
|
WeChatOAuthMobileEnabled: settings.WeChatOAuthMobileEnabled,
|
||||||
OIDCOAuthEnabled: settings.OIDCOAuthEnabled,
|
OIDCOAuthEnabled: settings.OIDCOAuthEnabled,
|
||||||
OIDCOAuthProviderName: settings.OIDCOAuthProviderName,
|
OIDCOAuthProviderName: settings.OIDCOAuthProviderName,
|
||||||
BackendModeEnabled: settings.BackendModeEnabled,
|
BackendModeEnabled: settings.BackendModeEnabled,
|
||||||
|
|||||||
@@ -0,0 +1,122 @@
|
|||||||
|
//go:build unit
|
||||||
|
|
||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/Wei-Shaw/sub2api/internal/config"
|
||||||
|
"github.com/Wei-Shaw/sub2api/internal/service"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
type settingHandlerPublicRepoStub struct {
|
||||||
|
values map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *settingHandlerPublicRepoStub) Get(ctx context.Context, key string) (*service.Setting, error) {
|
||||||
|
panic("unexpected Get call")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *settingHandlerPublicRepoStub) GetValue(ctx context.Context, key string) (string, error) {
|
||||||
|
panic("unexpected GetValue call")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *settingHandlerPublicRepoStub) Set(ctx context.Context, key, value string) error {
|
||||||
|
panic("unexpected Set call")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *settingHandlerPublicRepoStub) GetMultiple(ctx context.Context, keys []string) (map[string]string, error) {
|
||||||
|
out := make(map[string]string, len(keys))
|
||||||
|
for _, key := range keys {
|
||||||
|
if value, ok := s.values[key]; ok {
|
||||||
|
out[key] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *settingHandlerPublicRepoStub) SetMultiple(ctx context.Context, settings map[string]string) error {
|
||||||
|
panic("unexpected SetMultiple call")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *settingHandlerPublicRepoStub) GetAll(ctx context.Context) (map[string]string, error) {
|
||||||
|
panic("unexpected GetAll call")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *settingHandlerPublicRepoStub) Delete(ctx context.Context, key string) error {
|
||||||
|
panic("unexpected Delete call")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSettingHandler_GetPublicSettings_ExposesForceEmailOnThirdPartySignup(t *testing.T) {
|
||||||
|
gin.SetMode(gin.TestMode)
|
||||||
|
|
||||||
|
repo := &settingHandlerPublicRepoStub{
|
||||||
|
values: map[string]string{
|
||||||
|
service.SettingKeyForceEmailOnThirdPartySignup: "true",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
h := NewSettingHandler(service.NewSettingService(repo, &config.Config{}), "test-version")
|
||||||
|
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(recorder)
|
||||||
|
c.Request = httptest.NewRequest(http.MethodGet, "/api/v1/settings/public", nil)
|
||||||
|
|
||||||
|
h.GetPublicSettings(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusOK, recorder.Code)
|
||||||
|
|
||||||
|
var resp struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Data struct {
|
||||||
|
ForceEmailOnThirdPartySignup bool `json:"force_email_on_third_party_signup"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
require.NoError(t, json.Unmarshal(recorder.Body.Bytes(), &resp))
|
||||||
|
require.Equal(t, 0, resp.Code)
|
||||||
|
require.True(t, resp.Data.ForceEmailOnThirdPartySignup)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSettingHandler_GetPublicSettings_ExposesWeChatOAuthModeCapabilities(t *testing.T) {
|
||||||
|
gin.SetMode(gin.TestMode)
|
||||||
|
h := NewSettingHandler(service.NewSettingService(&settingHandlerPublicRepoStub{
|
||||||
|
values: map[string]string{
|
||||||
|
service.SettingKeyWeChatConnectEnabled: "true",
|
||||||
|
service.SettingKeyWeChatConnectAppID: "wx-mp-app",
|
||||||
|
service.SettingKeyWeChatConnectAppSecret: "wx-mp-secret",
|
||||||
|
service.SettingKeyWeChatConnectMode: "mp",
|
||||||
|
service.SettingKeyWeChatConnectScopes: "snsapi_base",
|
||||||
|
service.SettingKeyWeChatConnectOpenEnabled: "true",
|
||||||
|
service.SettingKeyWeChatConnectMPEnabled: "true",
|
||||||
|
service.SettingKeyWeChatConnectRedirectURL: "https://api.example.com/api/v1/auth/oauth/wechat/callback",
|
||||||
|
service.SettingKeyWeChatConnectFrontendRedirectURL: "/auth/wechat/callback",
|
||||||
|
},
|
||||||
|
}, &config.Config{}), "test-version")
|
||||||
|
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(recorder)
|
||||||
|
c.Request = httptest.NewRequest(http.MethodGet, "/api/v1/settings/public", nil)
|
||||||
|
|
||||||
|
h.GetPublicSettings(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusOK, recorder.Code)
|
||||||
|
|
||||||
|
var resp struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Data struct {
|
||||||
|
WeChatOAuthEnabled bool `json:"wechat_oauth_enabled"`
|
||||||
|
WeChatOAuthOpenEnabled bool `json:"wechat_oauth_open_enabled"`
|
||||||
|
WeChatOAuthMPEnabled bool `json:"wechat_oauth_mp_enabled"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
require.NoError(t, json.Unmarshal(recorder.Body.Bytes(), &resp))
|
||||||
|
require.Equal(t, 0, resp.Code)
|
||||||
|
require.True(t, resp.Data.WeChatOAuthEnabled)
|
||||||
|
require.True(t, resp.Data.WeChatOAuthOpenEnabled)
|
||||||
|
require.True(t, resp.Data.WeChatOAuthMPEnabled)
|
||||||
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/Wei-Shaw/sub2api/internal/handler/dto"
|
"github.com/Wei-Shaw/sub2api/internal/handler/dto"
|
||||||
"github.com/Wei-Shaw/sub2api/internal/pkg/response"
|
"github.com/Wei-Shaw/sub2api/internal/pkg/response"
|
||||||
middleware2 "github.com/Wei-Shaw/sub2api/internal/server/middleware"
|
middleware2 "github.com/Wei-Shaw/sub2api/internal/server/middleware"
|
||||||
@@ -12,14 +15,21 @@ import (
|
|||||||
// UserHandler handles user-related requests
|
// UserHandler handles user-related requests
|
||||||
type UserHandler struct {
|
type UserHandler struct {
|
||||||
userService *service.UserService
|
userService *service.UserService
|
||||||
|
authService *service.AuthService
|
||||||
emailService *service.EmailService
|
emailService *service.EmailService
|
||||||
emailCache service.EmailCache
|
emailCache service.EmailCache
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewUserHandler creates a new UserHandler
|
// NewUserHandler creates a new UserHandler
|
||||||
func NewUserHandler(userService *service.UserService, emailService *service.EmailService, emailCache service.EmailCache) *UserHandler {
|
func NewUserHandler(
|
||||||
|
userService *service.UserService,
|
||||||
|
authService *service.AuthService,
|
||||||
|
emailService *service.EmailService,
|
||||||
|
emailCache service.EmailCache,
|
||||||
|
) *UserHandler {
|
||||||
return &UserHandler{
|
return &UserHandler{
|
||||||
userService: userService,
|
userService: userService,
|
||||||
|
authService: authService,
|
||||||
emailService: emailService,
|
emailService: emailService,
|
||||||
emailCache: emailCache,
|
emailCache: emailCache,
|
||||||
}
|
}
|
||||||
@@ -34,10 +44,33 @@ type ChangePasswordRequest struct {
|
|||||||
// UpdateProfileRequest represents the update profile request payload
|
// UpdateProfileRequest represents the update profile request payload
|
||||||
type UpdateProfileRequest struct {
|
type UpdateProfileRequest struct {
|
||||||
Username *string `json:"username"`
|
Username *string `json:"username"`
|
||||||
|
AvatarURL *string `json:"avatar_url"`
|
||||||
BalanceNotifyEnabled *bool `json:"balance_notify_enabled"`
|
BalanceNotifyEnabled *bool `json:"balance_notify_enabled"`
|
||||||
BalanceNotifyThreshold *float64 `json:"balance_notify_threshold"`
|
BalanceNotifyThreshold *float64 `json:"balance_notify_threshold"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type userProfileResponse struct {
|
||||||
|
dto.User
|
||||||
|
AvatarURL string `json:"avatar_url,omitempty"`
|
||||||
|
AvatarSource *userProfileSourceContext `json:"avatar_source,omitempty"`
|
||||||
|
UsernameSource *userProfileSourceContext `json:"username_source,omitempty"`
|
||||||
|
DisplayNameSource *userProfileSourceContext `json:"display_name_source,omitempty"`
|
||||||
|
NicknameSource *userProfileSourceContext `json:"nickname_source,omitempty"`
|
||||||
|
ProfileSources map[string]*userProfileSourceContext `json:"profile_sources,omitempty"`
|
||||||
|
Identities service.UserIdentitySummarySet `json:"identities"`
|
||||||
|
AuthBindings map[string]service.UserIdentitySummary `json:"auth_bindings"`
|
||||||
|
IdentityBindings map[string]service.UserIdentitySummary `json:"identity_bindings"`
|
||||||
|
EmailBound bool `json:"email_bound"`
|
||||||
|
LinuxDoBound bool `json:"linuxdo_bound"`
|
||||||
|
OIDCBound bool `json:"oidc_bound"`
|
||||||
|
WeChatBound bool `json:"wechat_bound"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type userProfileSourceContext struct {
|
||||||
|
Provider string `json:"provider,omitempty"`
|
||||||
|
Source string `json:"source,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// GetProfile handles getting user profile
|
// GetProfile handles getting user profile
|
||||||
// GET /api/v1/users/me
|
// GET /api/v1/users/me
|
||||||
func (h *UserHandler) GetProfile(c *gin.Context) {
|
func (h *UserHandler) GetProfile(c *gin.Context) {
|
||||||
@@ -47,13 +80,19 @@ func (h *UserHandler) GetProfile(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
userData, err := h.userService.GetByID(c.Request.Context(), subject.UserID)
|
userData, err := h.userService.GetProfile(c.Request.Context(), subject.UserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.ErrorFrom(c, err)
|
response.ErrorFrom(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
response.Success(c, dto.UserFromService(userData))
|
profileResp, err := h.buildUserProfileResponse(c.Request.Context(), subject.UserID, userData)
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
response.Success(c, profileResp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChangePassword handles changing user password
|
// ChangePassword handles changing user password
|
||||||
@@ -101,6 +140,7 @@ func (h *UserHandler) UpdateProfile(c *gin.Context) {
|
|||||||
|
|
||||||
svcReq := service.UpdateProfileRequest{
|
svcReq := service.UpdateProfileRequest{
|
||||||
Username: req.Username,
|
Username: req.Username,
|
||||||
|
AvatarURL: req.AvatarURL,
|
||||||
BalanceNotifyEnabled: req.BalanceNotifyEnabled,
|
BalanceNotifyEnabled: req.BalanceNotifyEnabled,
|
||||||
BalanceNotifyThreshold: req.BalanceNotifyThreshold,
|
BalanceNotifyThreshold: req.BalanceNotifyThreshold,
|
||||||
}
|
}
|
||||||
@@ -110,7 +150,149 @@ func (h *UserHandler) UpdateProfile(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
response.Success(c, dto.UserFromService(updatedUser))
|
profileResp, err := h.buildUserProfileResponse(c.Request.Context(), subject.UserID, updatedUser)
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
response.Success(c, profileResp)
|
||||||
|
}
|
||||||
|
|
||||||
|
type StartIdentityBindingRequest struct {
|
||||||
|
Provider string `json:"provider" binding:"required"`
|
||||||
|
RedirectTo string `json:"redirect_to"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type BindEmailIdentityRequest struct {
|
||||||
|
Email string `json:"email" binding:"required,email"`
|
||||||
|
VerifyCode string `json:"verify_code" binding:"required"`
|
||||||
|
Password string `json:"password" binding:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SendEmailBindingCodeRequest struct {
|
||||||
|
Email string `json:"email" binding:"required,email"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// StartIdentityBinding returns the backend authorize URL for starting a third-party identity bind flow.
|
||||||
|
// POST /api/v1/user/auth-identities/bind/start
|
||||||
|
func (h *UserHandler) StartIdentityBinding(c *gin.Context) {
|
||||||
|
if _, ok := middleware2.GetAuthSubjectFromContext(c); !ok {
|
||||||
|
response.Unauthorized(c, "User not authenticated")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var req StartIdentityBindingRequest
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
response.BadRequest(c, "Invalid request: "+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := h.userService.PrepareIdentityBindingStart(c.Request.Context(), service.StartUserIdentityBindingRequest{
|
||||||
|
Provider: req.Provider,
|
||||||
|
RedirectTo: req.RedirectTo,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
response.Success(c, result)
|
||||||
|
}
|
||||||
|
|
||||||
|
// BindEmailIdentity verifies and binds a local email identity for the current user.
|
||||||
|
// POST /api/v1/user/account-bindings/email
|
||||||
|
func (h *UserHandler) BindEmailIdentity(c *gin.Context) {
|
||||||
|
subject, ok := middleware2.GetAuthSubjectFromContext(c)
|
||||||
|
if !ok {
|
||||||
|
response.Unauthorized(c, "User not authenticated")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if h.authService == nil {
|
||||||
|
response.InternalError(c, "Auth service not configured")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var req BindEmailIdentityRequest
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
response.BadRequest(c, "Invalid request: "+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
updatedUser, err := h.authService.BindEmailIdentity(
|
||||||
|
c.Request.Context(),
|
||||||
|
subject.UserID,
|
||||||
|
req.Email,
|
||||||
|
req.VerifyCode,
|
||||||
|
req.Password,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
profileResp, err := h.buildUserProfileResponse(c.Request.Context(), subject.UserID, updatedUser)
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
response.Success(c, profileResp)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnbindIdentity removes a third-party sign-in provider from the current user.
|
||||||
|
// DELETE /api/v1/user/account-bindings/:provider
|
||||||
|
func (h *UserHandler) UnbindIdentity(c *gin.Context) {
|
||||||
|
subject, ok := middleware2.GetAuthSubjectFromContext(c)
|
||||||
|
if !ok {
|
||||||
|
response.Unauthorized(c, "User not authenticated")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
updatedUser, err := h.userService.UnbindUserAuthProvider(
|
||||||
|
c.Request.Context(),
|
||||||
|
subject.UserID,
|
||||||
|
c.Param("provider"),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
profileResp, err := h.buildUserProfileResponse(c.Request.Context(), subject.UserID, updatedUser)
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
response.Success(c, profileResp)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendEmailBindingCode sends a verification code for the current user's email binding flow.
|
||||||
|
// POST /api/v1/user/account-bindings/email/send-code
|
||||||
|
func (h *UserHandler) SendEmailBindingCode(c *gin.Context) {
|
||||||
|
subject, ok := middleware2.GetAuthSubjectFromContext(c)
|
||||||
|
if !ok {
|
||||||
|
response.Unauthorized(c, "User not authenticated")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if h.authService == nil {
|
||||||
|
response.InternalError(c, "Auth service not configured")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var req SendEmailBindingCodeRequest
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
response.BadRequest(c, "Invalid request: "+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := h.authService.SendEmailIdentityBindCode(c.Request.Context(), subject.UserID, req.Email); err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
response.Success(c, gin.H{"message": "Verification code sent successfully"})
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendNotifyEmailCodeRequest represents the request to send notify email verification code
|
// SendNotifyEmailCodeRequest represents the request to send notify email verification code
|
||||||
@@ -176,7 +358,13 @@ func (h *UserHandler) VerifyNotifyEmail(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
response.Success(c, dto.UserFromService(updatedUser))
|
profileResp, err := h.buildUserProfileResponse(c.Request.Context(), subject.UserID, updatedUser)
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
response.Success(c, profileResp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveNotifyEmailRequest represents the request to remove a notify email
|
// RemoveNotifyEmailRequest represents the request to remove a notify email
|
||||||
@@ -212,7 +400,13 @@ func (h *UserHandler) RemoveNotifyEmail(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
response.Success(c, dto.UserFromService(updatedUser))
|
profileResp, err := h.buildUserProfileResponse(c.Request.Context(), subject.UserID, updatedUser)
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
response.Success(c, profileResp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToggleNotifyEmailRequest represents the request to toggle a notify email's disabled state
|
// ToggleNotifyEmailRequest represents the request to toggle a notify email's disabled state
|
||||||
@@ -248,5 +442,116 @@ func (h *UserHandler) ToggleNotifyEmail(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
response.Success(c, dto.UserFromService(updatedUser))
|
profileResp, err := h.buildUserProfileResponse(c.Request.Context(), subject.UserID, updatedUser)
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
response.Success(c, profileResp)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *UserHandler) buildUserProfileResponse(ctx context.Context, userID int64, user *service.User) (userProfileResponse, error) {
|
||||||
|
identities, err := h.userService.GetProfileIdentitySummaries(ctx, userID, user)
|
||||||
|
if err != nil {
|
||||||
|
return userProfileResponse{}, err
|
||||||
|
}
|
||||||
|
return userProfileResponseFromService(user, identities), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func userProfileResponseFromService(user *service.User, identities service.UserIdentitySummarySet) userProfileResponse {
|
||||||
|
base := dto.UserFromService(user)
|
||||||
|
if base == nil {
|
||||||
|
return userProfileResponse{}
|
||||||
|
}
|
||||||
|
bindings := userProfileBindingMap(identities)
|
||||||
|
profileSources, avatarSource, usernameSource := inferUserProfileSources(user, identities)
|
||||||
|
return userProfileResponse{
|
||||||
|
User: *base,
|
||||||
|
AvatarURL: user.AvatarURL,
|
||||||
|
AvatarSource: avatarSource,
|
||||||
|
UsernameSource: usernameSource,
|
||||||
|
DisplayNameSource: usernameSource,
|
||||||
|
NicknameSource: usernameSource,
|
||||||
|
ProfileSources: profileSources,
|
||||||
|
Identities: identities,
|
||||||
|
AuthBindings: bindings,
|
||||||
|
IdentityBindings: bindings,
|
||||||
|
EmailBound: identities.Email.Bound,
|
||||||
|
LinuxDoBound: identities.LinuxDo.Bound,
|
||||||
|
OIDCBound: identities.OIDC.Bound,
|
||||||
|
WeChatBound: identities.WeChat.Bound,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func userProfileBindingMap(identities service.UserIdentitySummarySet) map[string]service.UserIdentitySummary {
|
||||||
|
return map[string]service.UserIdentitySummary{
|
||||||
|
"email": identities.Email,
|
||||||
|
"linuxdo": identities.LinuxDo,
|
||||||
|
"oidc": identities.OIDC,
|
||||||
|
"wechat": identities.WeChat,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func inferUserProfileSources(user *service.User, identities service.UserIdentitySummarySet) (
|
||||||
|
map[string]*userProfileSourceContext,
|
||||||
|
*userProfileSourceContext,
|
||||||
|
*userProfileSourceContext,
|
||||||
|
) {
|
||||||
|
if user == nil {
|
||||||
|
return nil, nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
thirdParty := thirdPartyIdentityProviders(identities)
|
||||||
|
var avatarSource *userProfileSourceContext
|
||||||
|
if strings.TrimSpace(user.AvatarURL) != "" && len(thirdParty) == 1 {
|
||||||
|
avatarSource = buildUserProfileSourceContext(thirdParty[0].Provider)
|
||||||
|
}
|
||||||
|
|
||||||
|
usernameValue := strings.TrimSpace(user.Username)
|
||||||
|
var usernameSource *userProfileSourceContext
|
||||||
|
for _, summary := range thirdParty {
|
||||||
|
if usernameValue != "" && usernameValue == strings.TrimSpace(summary.DisplayName) {
|
||||||
|
usernameSource = buildUserProfileSourceContext(summary.Provider)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if usernameSource == nil && usernameValue != "" && len(thirdParty) == 1 {
|
||||||
|
usernameSource = buildUserProfileSourceContext(thirdParty[0].Provider)
|
||||||
|
}
|
||||||
|
|
||||||
|
profileSources := map[string]*userProfileSourceContext{}
|
||||||
|
if avatarSource != nil {
|
||||||
|
profileSources["avatar"] = avatarSource
|
||||||
|
}
|
||||||
|
if usernameSource != nil {
|
||||||
|
profileSources["username"] = usernameSource
|
||||||
|
profileSources["display_name"] = usernameSource
|
||||||
|
profileSources["nickname"] = usernameSource
|
||||||
|
}
|
||||||
|
if len(profileSources) == 0 {
|
||||||
|
return nil, avatarSource, usernameSource
|
||||||
|
}
|
||||||
|
return profileSources, avatarSource, usernameSource
|
||||||
|
}
|
||||||
|
|
||||||
|
func thirdPartyIdentityProviders(identities service.UserIdentitySummarySet) []service.UserIdentitySummary {
|
||||||
|
out := make([]service.UserIdentitySummary, 0, 3)
|
||||||
|
for _, summary := range []service.UserIdentitySummary{identities.LinuxDo, identities.OIDC, identities.WeChat} {
|
||||||
|
if summary.Bound {
|
||||||
|
out = append(out, summary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildUserProfileSourceContext(provider string) *userProfileSourceContext {
|
||||||
|
provider = strings.TrimSpace(provider)
|
||||||
|
if provider == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &userProfileSourceContext{
|
||||||
|
Provider: provider,
|
||||||
|
Source: provider,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,593 @@
|
|||||||
|
//go:build unit
|
||||||
|
|
||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/Wei-Shaw/sub2api/internal/config"
|
||||||
|
"github.com/Wei-Shaw/sub2api/internal/pkg/pagination"
|
||||||
|
middleware2 "github.com/Wei-Shaw/sub2api/internal/server/middleware"
|
||||||
|
"github.com/Wei-Shaw/sub2api/internal/service"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
type userHandlerRepoStub struct {
|
||||||
|
user *service.User
|
||||||
|
identities []service.UserAuthIdentityRecord
|
||||||
|
unbound []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *userHandlerRepoStub) Create(context.Context, *service.User) error { return nil }
|
||||||
|
func (s *userHandlerRepoStub) GetByID(context.Context, int64) (*service.User, error) {
|
||||||
|
cloned := *s.user
|
||||||
|
return &cloned, nil
|
||||||
|
}
|
||||||
|
func (s *userHandlerRepoStub) GetByEmail(context.Context, string) (*service.User, error) {
|
||||||
|
cloned := *s.user
|
||||||
|
return &cloned, nil
|
||||||
|
}
|
||||||
|
func (s *userHandlerRepoStub) GetFirstAdmin(context.Context) (*service.User, error) {
|
||||||
|
cloned := *s.user
|
||||||
|
return &cloned, nil
|
||||||
|
}
|
||||||
|
func (s *userHandlerRepoStub) Update(_ context.Context, user *service.User) error {
|
||||||
|
cloned := *user
|
||||||
|
s.user = &cloned
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (s *userHandlerRepoStub) Delete(context.Context, int64) error { return nil }
|
||||||
|
func (s *userHandlerRepoStub) GetUserAvatar(context.Context, int64) (*service.UserAvatar, error) {
|
||||||
|
if s.user == nil || s.user.AvatarURL == "" {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return &service.UserAvatar{
|
||||||
|
StorageProvider: s.user.AvatarSource,
|
||||||
|
URL: s.user.AvatarURL,
|
||||||
|
ContentType: s.user.AvatarMIME,
|
||||||
|
ByteSize: s.user.AvatarByteSize,
|
||||||
|
SHA256: s.user.AvatarSHA256,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
func (s *userHandlerRepoStub) UpsertUserAvatar(_ context.Context, _ int64, input service.UpsertUserAvatarInput) (*service.UserAvatar, error) {
|
||||||
|
s.user.AvatarURL = input.URL
|
||||||
|
s.user.AvatarSource = input.StorageProvider
|
||||||
|
s.user.AvatarMIME = input.ContentType
|
||||||
|
s.user.AvatarByteSize = input.ByteSize
|
||||||
|
s.user.AvatarSHA256 = input.SHA256
|
||||||
|
return &service.UserAvatar{
|
||||||
|
StorageProvider: input.StorageProvider,
|
||||||
|
URL: input.URL,
|
||||||
|
ContentType: input.ContentType,
|
||||||
|
ByteSize: input.ByteSize,
|
||||||
|
SHA256: input.SHA256,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
func (s *userHandlerRepoStub) DeleteUserAvatar(context.Context, int64) error {
|
||||||
|
s.user.AvatarURL = ""
|
||||||
|
s.user.AvatarSource = ""
|
||||||
|
s.user.AvatarMIME = ""
|
||||||
|
s.user.AvatarByteSize = 0
|
||||||
|
s.user.AvatarSHA256 = ""
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (s *userHandlerRepoStub) List(context.Context, pagination.PaginationParams) ([]service.User, *pagination.PaginationResult, error) {
|
||||||
|
return nil, nil, nil
|
||||||
|
}
|
||||||
|
func (s *userHandlerRepoStub) ListWithFilters(context.Context, pagination.PaginationParams, service.UserListFilters) ([]service.User, *pagination.PaginationResult, error) {
|
||||||
|
return nil, nil, nil
|
||||||
|
}
|
||||||
|
func (s *userHandlerRepoStub) UpdateBalance(context.Context, int64, float64) error { return nil }
|
||||||
|
func (s *userHandlerRepoStub) DeductBalance(context.Context, int64, float64) error { return nil }
|
||||||
|
func (s *userHandlerRepoStub) UpdateConcurrency(context.Context, int64, int) error { return nil }
|
||||||
|
func (s *userHandlerRepoStub) ExistsByEmail(context.Context, string) (bool, error) { return false, nil }
|
||||||
|
func (s *userHandlerRepoStub) RemoveGroupFromAllowedGroups(context.Context, int64) (int64, error) {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
func (s *userHandlerRepoStub) AddGroupToAllowedGroups(context.Context, int64, int64) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (s *userHandlerRepoStub) GetLatestUsedAtByUserIDs(context.Context, []int64) (map[int64]*time.Time, error) {
|
||||||
|
return map[int64]*time.Time{}, nil
|
||||||
|
}
|
||||||
|
func (s *userHandlerRepoStub) GetLatestUsedAtByUserID(context.Context, int64) (*time.Time, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
func (s *userHandlerRepoStub) UpdateUserLastActiveAt(_ context.Context, _ int64, activeAt time.Time) error {
|
||||||
|
if s.user != nil {
|
||||||
|
s.user.LastActiveAt = &activeAt
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (s *userHandlerRepoStub) RemoveGroupFromUserAllowedGroups(context.Context, int64, int64) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (s *userHandlerRepoStub) UpdateTotpSecret(context.Context, int64, *string) error { return nil }
|
||||||
|
func (s *userHandlerRepoStub) EnableTotp(context.Context, int64) error { return nil }
|
||||||
|
func (s *userHandlerRepoStub) DisableTotp(context.Context, int64) error { return nil }
|
||||||
|
func (s *userHandlerRepoStub) ListUserAuthIdentities(context.Context, int64) ([]service.UserAuthIdentityRecord, error) {
|
||||||
|
out := make([]service.UserAuthIdentityRecord, len(s.identities))
|
||||||
|
copy(out, s.identities)
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
func (s *userHandlerRepoStub) UnbindUserAuthProvider(_ context.Context, _ int64, provider string) error {
|
||||||
|
s.unbound = append(s.unbound, provider)
|
||||||
|
filtered := s.identities[:0]
|
||||||
|
for _, identity := range s.identities {
|
||||||
|
if identity.ProviderType == provider {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
filtered = append(filtered, identity)
|
||||||
|
}
|
||||||
|
s.identities = append([]service.UserAuthIdentityRecord(nil), filtered...)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUserHandlerUpdateProfileReturnsAvatarURL(t *testing.T) {
|
||||||
|
gin.SetMode(gin.TestMode)
|
||||||
|
|
||||||
|
repo := &userHandlerRepoStub{
|
||||||
|
user: &service.User{
|
||||||
|
ID: 11,
|
||||||
|
Email: "handler-avatar@example.com",
|
||||||
|
Username: "handler-avatar",
|
||||||
|
Role: service.RoleUser,
|
||||||
|
Status: service.StatusActive,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
handler := NewUserHandler(service.NewUserService(repo, nil, nil, nil), nil, nil, nil)
|
||||||
|
|
||||||
|
body := []byte(`{"avatar_url":"https://cdn.example.com/avatar.png"}`)
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(recorder)
|
||||||
|
c.Request = httptest.NewRequest(http.MethodPut, "/api/v1/user", bytes.NewReader(body))
|
||||||
|
c.Request.Header.Set("Content-Type", "application/json")
|
||||||
|
c.Set(string(middleware2.ContextKeyUser), middleware2.AuthSubject{UserID: 11})
|
||||||
|
|
||||||
|
handler.UpdateProfile(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusOK, recorder.Code)
|
||||||
|
|
||||||
|
var resp struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Data struct {
|
||||||
|
AvatarURL string `json:"avatar_url"`
|
||||||
|
Username string `json:"username"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
require.NoError(t, json.Unmarshal(recorder.Body.Bytes(), &resp))
|
||||||
|
require.Equal(t, 0, resp.Code)
|
||||||
|
require.Equal(t, "https://cdn.example.com/avatar.png", resp.Data.AvatarURL)
|
||||||
|
require.Equal(t, "handler-avatar", resp.Data.Username)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUserHandlerGetProfileReturnsIdentitySummaries(t *testing.T) {
|
||||||
|
gin.SetMode(gin.TestMode)
|
||||||
|
|
||||||
|
verifiedAt := time.Date(2026, 4, 20, 8, 30, 0, 0, time.UTC)
|
||||||
|
repo := &userHandlerRepoStub{
|
||||||
|
user: &service.User{
|
||||||
|
ID: 11,
|
||||||
|
Email: "identity@example.com",
|
||||||
|
Username: "identity-user",
|
||||||
|
Role: service.RoleUser,
|
||||||
|
Status: service.StatusActive,
|
||||||
|
},
|
||||||
|
identities: []service.UserAuthIdentityRecord{
|
||||||
|
{
|
||||||
|
ProviderType: "linuxdo",
|
||||||
|
ProviderKey: "linuxdo",
|
||||||
|
ProviderSubject: "linuxdo-subject-123456",
|
||||||
|
VerifiedAt: &verifiedAt,
|
||||||
|
Metadata: map[string]any{
|
||||||
|
"username": "linuxdo-handle",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ProviderType: "oidc",
|
||||||
|
ProviderKey: "https://issuer.example.com",
|
||||||
|
ProviderSubject: "oidc-user-abc",
|
||||||
|
Metadata: map[string]any{
|
||||||
|
"suggested_display_name": "OIDC Display",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
handler := NewUserHandler(service.NewUserService(repo, nil, nil, nil), nil, nil, nil)
|
||||||
|
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(recorder)
|
||||||
|
c.Request = httptest.NewRequest(http.MethodGet, "/api/v1/user/profile", nil)
|
||||||
|
c.Set(string(middleware2.ContextKeyUser), middleware2.AuthSubject{UserID: 11})
|
||||||
|
|
||||||
|
handler.GetProfile(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusOK, recorder.Code)
|
||||||
|
|
||||||
|
var resp struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Data struct {
|
||||||
|
Identities struct {
|
||||||
|
Email struct {
|
||||||
|
Bound bool `json:"bound"`
|
||||||
|
BoundCount int `json:"bound_count"`
|
||||||
|
DisplayName string `json:"display_name"`
|
||||||
|
} `json:"email"`
|
||||||
|
LinuxDo struct {
|
||||||
|
Bound bool `json:"bound"`
|
||||||
|
BoundCount int `json:"bound_count"`
|
||||||
|
DisplayName string `json:"display_name"`
|
||||||
|
ProviderKey string `json:"provider_key"`
|
||||||
|
} `json:"linuxdo"`
|
||||||
|
OIDC struct {
|
||||||
|
Bound bool `json:"bound"`
|
||||||
|
DisplayName string `json:"display_name"`
|
||||||
|
ProviderKey string `json:"provider_key"`
|
||||||
|
} `json:"oidc"`
|
||||||
|
WeChat struct {
|
||||||
|
Bound bool `json:"bound"`
|
||||||
|
CanBind bool `json:"can_bind"`
|
||||||
|
BindStartPath string `json:"bind_start_path"`
|
||||||
|
} `json:"wechat"`
|
||||||
|
} `json:"identities"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
require.NoError(t, json.Unmarshal(recorder.Body.Bytes(), &resp))
|
||||||
|
require.Equal(t, 0, resp.Code)
|
||||||
|
require.True(t, resp.Data.Identities.Email.Bound)
|
||||||
|
require.Equal(t, 1, resp.Data.Identities.Email.BoundCount)
|
||||||
|
require.Equal(t, "identity@example.com", resp.Data.Identities.Email.DisplayName)
|
||||||
|
require.True(t, resp.Data.Identities.LinuxDo.Bound)
|
||||||
|
require.Equal(t, 1, resp.Data.Identities.LinuxDo.BoundCount)
|
||||||
|
require.Equal(t, "linuxdo-handle", resp.Data.Identities.LinuxDo.DisplayName)
|
||||||
|
require.Equal(t, "linuxdo", resp.Data.Identities.LinuxDo.ProviderKey)
|
||||||
|
require.True(t, resp.Data.Identities.OIDC.Bound)
|
||||||
|
require.Equal(t, "OIDC Display", resp.Data.Identities.OIDC.DisplayName)
|
||||||
|
require.Equal(t, "https://issuer.example.com", resp.Data.Identities.OIDC.ProviderKey)
|
||||||
|
require.False(t, resp.Data.Identities.WeChat.Bound)
|
||||||
|
require.True(t, resp.Data.Identities.WeChat.CanBind)
|
||||||
|
require.Contains(t, resp.Data.Identities.WeChat.BindStartPath, "/api/v1/auth/oauth/wechat/start")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUserHandlerGetProfileReturnsLegacyCompatibilityFields(t *testing.T) {
|
||||||
|
gin.SetMode(gin.TestMode)
|
||||||
|
|
||||||
|
verifiedAt := time.Date(2026, 4, 20, 8, 30, 0, 0, time.UTC)
|
||||||
|
repo := &userHandlerRepoStub{
|
||||||
|
user: &service.User{
|
||||||
|
ID: 21,
|
||||||
|
Email: "legacy-profile@example.com",
|
||||||
|
Username: "linuxdo-handle",
|
||||||
|
Role: service.RoleUser,
|
||||||
|
Status: service.StatusActive,
|
||||||
|
AvatarURL: "https://cdn.example.com/linuxdo.png",
|
||||||
|
AvatarSource: "remote_url",
|
||||||
|
},
|
||||||
|
identities: []service.UserAuthIdentityRecord{
|
||||||
|
{
|
||||||
|
ProviderType: "linuxdo",
|
||||||
|
ProviderKey: "linuxdo",
|
||||||
|
ProviderSubject: "linuxdo-subject-21",
|
||||||
|
VerifiedAt: &verifiedAt,
|
||||||
|
Metadata: map[string]any{
|
||||||
|
"username": "linuxdo-handle",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
handler := NewUserHandler(service.NewUserService(repo, nil, nil, nil), nil, nil, nil)
|
||||||
|
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(recorder)
|
||||||
|
c.Request = httptest.NewRequest(http.MethodGet, "/api/v1/user/profile", nil)
|
||||||
|
c.Set(string(middleware2.ContextKeyUser), middleware2.AuthSubject{UserID: 21})
|
||||||
|
|
||||||
|
handler.GetProfile(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusOK, recorder.Code)
|
||||||
|
|
||||||
|
var resp struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Data map[string]any `json:"data"`
|
||||||
|
}
|
||||||
|
require.NoError(t, json.Unmarshal(recorder.Body.Bytes(), &resp))
|
||||||
|
require.Equal(t, 0, resp.Code)
|
||||||
|
require.Equal(t, true, resp.Data["email_bound"])
|
||||||
|
require.Equal(t, true, resp.Data["linuxdo_bound"])
|
||||||
|
require.Equal(t, false, resp.Data["oidc_bound"])
|
||||||
|
require.Equal(t, false, resp.Data["wechat_bound"])
|
||||||
|
require.Equal(t, "https://cdn.example.com/linuxdo.png", resp.Data["avatar_url"])
|
||||||
|
|
||||||
|
avatarSource, ok := resp.Data["avatar_source"].(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, "linuxdo", avatarSource["provider"])
|
||||||
|
require.Equal(t, "linuxdo", avatarSource["source"])
|
||||||
|
|
||||||
|
authBindings, ok := resp.Data["auth_bindings"].(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
linuxdoBinding, ok := authBindings["linuxdo"].(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, true, linuxdoBinding["bound"])
|
||||||
|
require.Equal(t, "linuxdo", linuxdoBinding["provider"])
|
||||||
|
|
||||||
|
identityBindings, ok := resp.Data["identity_bindings"].(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
emailBinding, ok := identityBindings["email"].(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, true, emailBinding["bound"])
|
||||||
|
|
||||||
|
profileSources, ok := resp.Data["profile_sources"].(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
usernameSource, ok := profileSources["username"].(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, "linuxdo", usernameSource["provider"])
|
||||||
|
require.Equal(t, "linuxdo", usernameSource["source"])
|
||||||
|
}
|
||||||
|
|
||||||
|
type userHandlerEmailCacheStub struct {
|
||||||
|
data *service.VerificationCodeData
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *userHandlerEmailCacheStub) GetVerificationCode(context.Context, string) (*service.VerificationCodeData, error) {
|
||||||
|
return s.data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *userHandlerEmailCacheStub) SetVerificationCode(context.Context, string, *service.VerificationCodeData, time.Duration) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *userHandlerEmailCacheStub) DeleteVerificationCode(context.Context, string) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *userHandlerEmailCacheStub) GetNotifyVerifyCode(context.Context, string) (*service.VerificationCodeData, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *userHandlerEmailCacheStub) SetNotifyVerifyCode(context.Context, string, *service.VerificationCodeData, time.Duration) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *userHandlerEmailCacheStub) DeleteNotifyVerifyCode(context.Context, string) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *userHandlerEmailCacheStub) GetPasswordResetToken(context.Context, string) (*service.PasswordResetTokenData, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *userHandlerEmailCacheStub) SetPasswordResetToken(context.Context, string, *service.PasswordResetTokenData, time.Duration) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *userHandlerEmailCacheStub) DeletePasswordResetToken(context.Context, string) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *userHandlerEmailCacheStub) IsPasswordResetEmailInCooldown(context.Context, string) bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *userHandlerEmailCacheStub) SetPasswordResetEmailCooldown(context.Context, string, time.Duration) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *userHandlerEmailCacheStub) GetNotifyCodeUserRate(context.Context, int64) (int64, error) {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *userHandlerEmailCacheStub) IncrNotifyCodeUserRate(context.Context, int64, time.Duration) (int64, error) {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUserHandlerBindEmailIdentityReturnsProfileResponse(t *testing.T) {
|
||||||
|
gin.SetMode(gin.TestMode)
|
||||||
|
|
||||||
|
repo := &userHandlerRepoStub{
|
||||||
|
user: &service.User{
|
||||||
|
ID: 11,
|
||||||
|
Email: "legacy-user" + service.LinuxDoConnectSyntheticEmailDomain,
|
||||||
|
Username: "legacy-user",
|
||||||
|
Role: service.RoleUser,
|
||||||
|
Status: service.StatusActive,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
emailCache := &userHandlerEmailCacheStub{
|
||||||
|
data: &service.VerificationCodeData{
|
||||||
|
Code: "123456",
|
||||||
|
CreatedAt: time.Now().UTC(),
|
||||||
|
ExpiresAt: time.Now().UTC().Add(10 * time.Minute),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
cfg := &config.Config{
|
||||||
|
JWT: config.JWTConfig{
|
||||||
|
Secret: "test-secret",
|
||||||
|
ExpireHour: 1,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
emailService := service.NewEmailService(nil, emailCache)
|
||||||
|
authService := service.NewAuthService(nil, repo, nil, nil, cfg, nil, emailService, nil, nil, nil, nil)
|
||||||
|
handler := NewUserHandler(service.NewUserService(repo, nil, nil, nil), authService, nil, nil)
|
||||||
|
|
||||||
|
body := []byte(`{"email":"new@example.com","verify_code":"123456","password":"new-password"}`)
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(recorder)
|
||||||
|
c.Request = httptest.NewRequest(http.MethodPost, "/api/v1/user/account-bindings/email", bytes.NewReader(body))
|
||||||
|
c.Request.Header.Set("Content-Type", "application/json")
|
||||||
|
c.Params = gin.Params{{Key: "provider", Value: "email"}}
|
||||||
|
c.Set(string(middleware2.ContextKeyUser), middleware2.AuthSubject{UserID: 11})
|
||||||
|
|
||||||
|
handler.BindEmailIdentity(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusOK, recorder.Code)
|
||||||
|
|
||||||
|
var resp struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Data struct {
|
||||||
|
Email string `json:"email"`
|
||||||
|
EmailBound bool `json:"email_bound"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
require.NoError(t, json.Unmarshal(recorder.Body.Bytes(), &resp))
|
||||||
|
require.Equal(t, 0, resp.Code)
|
||||||
|
require.Equal(t, "new@example.com", resp.Data.Email)
|
||||||
|
require.True(t, resp.Data.EmailBound)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUserHandlerUnbindIdentityReturnsUpdatedProfile(t *testing.T) {
|
||||||
|
gin.SetMode(gin.TestMode)
|
||||||
|
|
||||||
|
repo := &userHandlerRepoStub{
|
||||||
|
user: &service.User{
|
||||||
|
ID: 21,
|
||||||
|
Email: "identity@example.com",
|
||||||
|
Username: "identity-user",
|
||||||
|
Role: service.RoleUser,
|
||||||
|
Status: service.StatusActive,
|
||||||
|
},
|
||||||
|
identities: []service.UserAuthIdentityRecord{
|
||||||
|
{
|
||||||
|
ProviderType: "email",
|
||||||
|
ProviderKey: "email",
|
||||||
|
ProviderSubject: "identity@example.com",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ProviderType: "linuxdo",
|
||||||
|
ProviderKey: "linuxdo",
|
||||||
|
ProviderSubject: "linuxdo-subject-21",
|
||||||
|
Metadata: map[string]any{
|
||||||
|
"username": "linuxdo-handle",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
handler := NewUserHandler(service.NewUserService(repo, nil, nil, nil), nil, nil, nil)
|
||||||
|
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(recorder)
|
||||||
|
c.Request = httptest.NewRequest(http.MethodDelete, "/api/v1/user/account-bindings/linuxdo", nil)
|
||||||
|
c.Set(string(middleware2.ContextKeyUser), middleware2.AuthSubject{UserID: 21})
|
||||||
|
c.Params = gin.Params{{Key: "provider", Value: "linuxdo"}}
|
||||||
|
|
||||||
|
handler.UnbindIdentity(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusOK, recorder.Code)
|
||||||
|
require.Equal(t, []string{"linuxdo"}, repo.unbound)
|
||||||
|
|
||||||
|
var resp struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Data map[string]any `json:"data"`
|
||||||
|
}
|
||||||
|
require.NoError(t, json.Unmarshal(recorder.Body.Bytes(), &resp))
|
||||||
|
require.Equal(t, 0, resp.Code)
|
||||||
|
|
||||||
|
authBindings, ok := resp.Data["auth_bindings"].(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
linuxdoBinding, ok := authBindings["linuxdo"].(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, false, linuxdoBinding["bound"])
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUserHandlerBindEmailIdentityRejectsWrongCurrentPasswordForBoundEmail(t *testing.T) {
|
||||||
|
gin.SetMode(gin.TestMode)
|
||||||
|
|
||||||
|
user := &service.User{
|
||||||
|
ID: 11,
|
||||||
|
Email: "current@example.com",
|
||||||
|
Username: "bound-user",
|
||||||
|
Role: service.RoleUser,
|
||||||
|
Status: service.StatusActive,
|
||||||
|
}
|
||||||
|
require.NoError(t, user.SetPassword("current-password"))
|
||||||
|
|
||||||
|
repo := &userHandlerRepoStub{user: user}
|
||||||
|
emailCache := &userHandlerEmailCacheStub{
|
||||||
|
data: &service.VerificationCodeData{
|
||||||
|
Code: "123456",
|
||||||
|
CreatedAt: time.Now().UTC(),
|
||||||
|
ExpiresAt: time.Now().UTC().Add(10 * time.Minute),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
cfg := &config.Config{
|
||||||
|
JWT: config.JWTConfig{
|
||||||
|
Secret: "test-secret",
|
||||||
|
ExpireHour: 1,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
emailService := service.NewEmailService(nil, emailCache)
|
||||||
|
authService := service.NewAuthService(nil, repo, nil, nil, cfg, nil, emailService, nil, nil, nil, nil)
|
||||||
|
handler := NewUserHandler(service.NewUserService(repo, nil, nil, nil), authService, nil, nil)
|
||||||
|
|
||||||
|
body := []byte(`{"email":"new@example.com","verify_code":"123456","password":"wrong-password"}`)
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(recorder)
|
||||||
|
c.Request = httptest.NewRequest(http.MethodPost, "/api/v1/user/account-bindings/email", bytes.NewReader(body))
|
||||||
|
c.Request.Header.Set("Content-Type", "application/json")
|
||||||
|
c.Set(string(middleware2.ContextKeyUser), middleware2.AuthSubject{UserID: 11})
|
||||||
|
|
||||||
|
handler.BindEmailIdentity(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusBadRequest, recorder.Code)
|
||||||
|
|
||||||
|
var resp struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Reason string `json:"reason"`
|
||||||
|
}
|
||||||
|
require.NoError(t, json.Unmarshal(recorder.Body.Bytes(), &resp))
|
||||||
|
require.Equal(t, http.StatusBadRequest, resp.Code)
|
||||||
|
require.Equal(t, "PASSWORD_INCORRECT", resp.Reason)
|
||||||
|
require.Equal(t, "current password is incorrect", resp.Message)
|
||||||
|
require.Equal(t, "current@example.com", repo.user.Email)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUserHandlerStartIdentityBindingReturnsAuthorizeURL(t *testing.T) {
|
||||||
|
gin.SetMode(gin.TestMode)
|
||||||
|
|
||||||
|
repo := &userHandlerRepoStub{
|
||||||
|
user: &service.User{
|
||||||
|
ID: 11,
|
||||||
|
Email: "identity@example.com",
|
||||||
|
Username: "identity-user",
|
||||||
|
Role: service.RoleUser,
|
||||||
|
Status: service.StatusActive,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
handler := NewUserHandler(service.NewUserService(repo, nil, nil, nil), nil, nil, nil)
|
||||||
|
|
||||||
|
body := []byte(`{"provider":"wechat","redirect_to":"/settings/profile"}`)
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(recorder)
|
||||||
|
c.Request = httptest.NewRequest(http.MethodPost, "/api/v1/user/auth-identities/bind/start", bytes.NewReader(body))
|
||||||
|
c.Request.Header.Set("Content-Type", "application/json")
|
||||||
|
c.Set(string(middleware2.ContextKeyUser), middleware2.AuthSubject{UserID: 11})
|
||||||
|
|
||||||
|
handler.StartIdentityBinding(c)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusOK, recorder.Code)
|
||||||
|
|
||||||
|
var resp struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Data struct {
|
||||||
|
Provider string `json:"provider"`
|
||||||
|
AuthorizeURL string `json:"authorize_url"`
|
||||||
|
Method string `json:"method"`
|
||||||
|
UseBrowserRedirect bool `json:"use_browser_redirect"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
require.NoError(t, json.Unmarshal(recorder.Body.Bytes(), &resp))
|
||||||
|
require.Equal(t, 0, resp.Code)
|
||||||
|
require.Equal(t, "wechat", resp.Data.Provider)
|
||||||
|
require.Equal(t, "GET", resp.Data.Method)
|
||||||
|
require.True(t, resp.Data.UseBrowserRedirect)
|
||||||
|
require.Contains(t, resp.Data.AuthorizeURL, "/api/v1/auth/oauth/wechat/start")
|
||||||
|
require.Contains(t, resp.Data.AuthorizeURL, "intent=bind_current_user")
|
||||||
|
require.Contains(t, resp.Data.AuthorizeURL, "redirect=%2Fsettings%2Fprofile")
|
||||||
|
}
|
||||||
@@ -45,11 +45,31 @@ type DefaultLoadBalancer struct {
|
|||||||
counter atomic.Uint64
|
counter atomic.Uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type contextKey string
|
||||||
|
|
||||||
|
const wxpayJSAPIAppIDContextKey contextKey = "payment.wxpay.jsapi_app_id"
|
||||||
|
|
||||||
// NewDefaultLoadBalancer creates a new load balancer.
|
// NewDefaultLoadBalancer creates a new load balancer.
|
||||||
func NewDefaultLoadBalancer(db *dbent.Client, encryptionKey []byte) *DefaultLoadBalancer {
|
func NewDefaultLoadBalancer(db *dbent.Client, encryptionKey []byte) *DefaultLoadBalancer {
|
||||||
return &DefaultLoadBalancer{db: db, encryptionKey: encryptionKey}
|
return &DefaultLoadBalancer{db: db, encryptionKey: encryptionKey}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WithWxpayJSAPIAppID(ctx context.Context, appID string) context.Context {
|
||||||
|
appID = strings.TrimSpace(appID)
|
||||||
|
if appID == "" {
|
||||||
|
return ctx
|
||||||
|
}
|
||||||
|
return context.WithValue(ctx, wxpayJSAPIAppIDContextKey, appID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func wxpayJSAPIAppIDFromContext(ctx context.Context) string {
|
||||||
|
if ctx == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
appID, _ := ctx.Value(wxpayJSAPIAppIDContextKey).(string)
|
||||||
|
return strings.TrimSpace(appID)
|
||||||
|
}
|
||||||
|
|
||||||
// instanceCandidate pairs an instance with its pre-fetched daily usage.
|
// instanceCandidate pairs an instance with its pre-fetched daily usage.
|
||||||
type instanceCandidate struct {
|
type instanceCandidate struct {
|
||||||
inst *dbent.PaymentProviderInstance
|
inst *dbent.PaymentProviderInstance
|
||||||
@@ -116,6 +136,7 @@ func (lb *DefaultLoadBalancer) queryEnabledInstances(
|
|||||||
}
|
}
|
||||||
|
|
||||||
var matched []*dbent.PaymentProviderInstance
|
var matched []*dbent.PaymentProviderInstance
|
||||||
|
expectedWxpayJSAPIAppID := wxpayJSAPIAppIDFromContext(ctx)
|
||||||
for _, inst := range instances {
|
for _, inst := range instances {
|
||||||
// Stripe: match by provider_key because supported_types lists sub-types (card,link,alipay,wxpay),
|
// Stripe: match by provider_key because supported_types lists sub-types (card,link,alipay,wxpay),
|
||||||
// not "stripe" itself. The checkout page aggregates all sub-types under "stripe".
|
// not "stripe" itself. The checkout page aggregates all sub-types under "stripe".
|
||||||
@@ -124,6 +145,16 @@ func (lb *DefaultLoadBalancer) queryEnabledInstances(
|
|||||||
matched = append(matched, inst)
|
matched = append(matched, inst)
|
||||||
}
|
}
|
||||||
} else if InstanceSupportsType(inst.SupportedTypes, paymentType) {
|
} else if InstanceSupportsType(inst.SupportedTypes, paymentType) {
|
||||||
|
if expectedWxpayJSAPIAppID != "" && normalizeVisibleMethodSupportType(paymentType) == TypeWxpay && inst.ProviderKey == TypeWxpay {
|
||||||
|
config, cfgErr := lb.decryptConfig(inst.Config)
|
||||||
|
if cfgErr != nil {
|
||||||
|
slog.Warn("skip wxpay instance with unreadable config during jsapi filtering", "instance_id", inst.ID, "error", cfgErr)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if resolveWxpayJSAPIAppID(config) != expectedWxpayJSAPIAppID {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
matched = append(matched, inst)
|
matched = append(matched, inst)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -231,6 +262,11 @@ func getInstanceChannelLimits(inst *dbent.PaymentProviderInstance, paymentType P
|
|||||||
if cl, ok := limits[lookupKey]; ok {
|
if cl, ok := limits[lookupKey]; ok {
|
||||||
return cl
|
return cl
|
||||||
}
|
}
|
||||||
|
if aliasKey := legacyVisibleMethodAlias(lookupKey); aliasKey != "" {
|
||||||
|
if cl, ok := limits[aliasKey]; ok {
|
||||||
|
return cl
|
||||||
|
}
|
||||||
|
}
|
||||||
return ChannelLimits{}
|
return ChannelLimits{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -344,14 +380,45 @@ func InstanceSupportsType(supportedTypes string, target PaymentType) bool {
|
|||||||
if supportedTypes == "" {
|
if supportedTypes == "" {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
normalizedTarget := normalizeVisibleMethodSupportType(target)
|
||||||
for _, t := range strings.Split(supportedTypes, ",") {
|
for _, t := range strings.Split(supportedTypes, ",") {
|
||||||
if strings.TrimSpace(t) == target {
|
supported := strings.TrimSpace(t)
|
||||||
|
if supported == target || normalizeVisibleMethodSupportType(supported) == normalizedTarget {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func normalizeVisibleMethodSupportType(paymentType PaymentType) PaymentType {
|
||||||
|
switch strings.TrimSpace(paymentType) {
|
||||||
|
case TypeAlipay, TypeAlipayDirect:
|
||||||
|
return TypeAlipay
|
||||||
|
case TypeWxpay, TypeWxpayDirect:
|
||||||
|
return TypeWxpay
|
||||||
|
default:
|
||||||
|
return strings.TrimSpace(paymentType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func legacyVisibleMethodAlias(paymentType PaymentType) PaymentType {
|
||||||
|
switch normalizeVisibleMethodSupportType(paymentType) {
|
||||||
|
case TypeAlipay:
|
||||||
|
return TypeAlipayDirect
|
||||||
|
case TypeWxpay:
|
||||||
|
return TypeWxpayDirect
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func resolveWxpayJSAPIAppID(config map[string]string) string {
|
||||||
|
if appID := strings.TrimSpace(config["mpAppId"]); appID != "" {
|
||||||
|
return appID
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(config["appId"])
|
||||||
|
}
|
||||||
|
|
||||||
// GetInstanceConfig decrypts and returns the configuration for a provider instance by ID.
|
// GetInstanceConfig decrypts and returns the configuration for a provider instance by ID.
|
||||||
func (lb *DefaultLoadBalancer) GetInstanceConfig(ctx context.Context, instanceID int64) (map[string]string, error) {
|
func (lb *DefaultLoadBalancer) GetInstanceConfig(ctx context.Context, instanceID int64) (map[string]string, error) {
|
||||||
inst, err := lb.db.PaymentProviderInstance.Get(ctx, instanceID)
|
inst, err := lb.db.PaymentProviderInstance.Get(ctx, instanceID)
|
||||||
|
|||||||
@@ -68,10 +68,16 @@ func TestInstanceSupportsType(t *testing.T) {
|
|||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "partial match should not succeed",
|
name: "legacy alipay direct supports canonical visible method",
|
||||||
supportedTypes: "alipay_direct",
|
supportedTypes: "alipay_direct",
|
||||||
target: "alipay",
|
target: "alipay",
|
||||||
expected: false,
|
expected: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "legacy wxpay direct supports canonical visible method",
|
||||||
|
supportedTypes: "wxpay_direct",
|
||||||
|
target: "wxpay",
|
||||||
|
expected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "empty supported types means all supported",
|
name: "empty supported types means all supported",
|
||||||
@@ -92,6 +98,22 @@ func TestInstanceSupportsType(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetInstanceChannelLimitsFallsBackToLegacyDirectAliases(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
inst := testInstance(1, TypeAlipay, makeLimitsJSON(TypeAlipayDirect, ChannelLimits{SingleMax: 66}))
|
||||||
|
got := getInstanceChannelLimits(inst, TypeAlipay)
|
||||||
|
if got.SingleMax != 66 {
|
||||||
|
t.Fatalf("getInstanceChannelLimits() = %+v, want SingleMax=66", got)
|
||||||
|
}
|
||||||
|
|
||||||
|
wxInst := testInstance(2, TypeWxpay, makeLimitsJSON(TypeWxpayDirect, ChannelLimits{SingleMin: 8}))
|
||||||
|
wxGot := getInstanceChannelLimits(wxInst, TypeWxpay)
|
||||||
|
if wxGot.SingleMin != 8 {
|
||||||
|
t.Fatalf("getInstanceChannelLimits() = %+v, want SingleMin=8", wxGot)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Helper to build test PaymentProviderInstance values
|
// Helper to build test PaymentProviderInstance values
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -26,6 +26,15 @@ const (
|
|||||||
alipayRefundSuffix = "-refund"
|
alipayRefundSuffix = "-refund"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
alipayTradeWapPay = func(client *alipay.Client, param alipay.TradeWapPay) (*url.URL, error) {
|
||||||
|
return client.TradeWapPay(param)
|
||||||
|
}
|
||||||
|
alipayTradePagePay = func(client *alipay.Client, param alipay.TradePagePay) (*url.URL, error) {
|
||||||
|
return client.TradePagePay(param)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
// Alipay implements payment.Provider and payment.CancelableProvider using the smartwalle/alipay SDK.
|
// Alipay implements payment.Provider and payment.CancelableProvider using the smartwalle/alipay SDK.
|
||||||
type Alipay struct {
|
type Alipay struct {
|
||||||
instanceID string
|
instanceID string
|
||||||
@@ -79,6 +88,17 @@ func (a *Alipay) SupportedTypes() []payment.PaymentType {
|
|||||||
return []payment.PaymentType{payment.TypeAlipay}
|
return []payment.PaymentType{payment.TypeAlipay}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *Alipay) MerchantIdentityMetadata() map[string]string {
|
||||||
|
if a == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
appID := strings.TrimSpace(a.config["appId"])
|
||||||
|
if appID == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return map[string]string{"app_id": appID}
|
||||||
|
}
|
||||||
|
|
||||||
// CreatePayment creates an Alipay payment using redirect-only flow:
|
// CreatePayment creates an Alipay payment using redirect-only flow:
|
||||||
// - Mobile (H5): alipay.trade.wap.pay — returns a URL the browser jumps to.
|
// - Mobile (H5): alipay.trade.wap.pay — returns a URL the browser jumps to.
|
||||||
// - PC: alipay.trade.page.pay — returns a gateway URL the browser opens in a
|
// - PC: alipay.trade.page.pay — returns a gateway URL the browser opens in a
|
||||||
@@ -115,7 +135,7 @@ func (a *Alipay) createWapTrade(client *alipay.Client, req payment.CreatePayment
|
|||||||
param.NotifyURL = notifyURL
|
param.NotifyURL = notifyURL
|
||||||
param.ReturnURL = returnURL
|
param.ReturnURL = returnURL
|
||||||
|
|
||||||
payURL, err := client.TradeWapPay(param)
|
payURL, err := alipayTradeWapPay(client, param)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("alipay TradeWapPay: %w", err)
|
return nil, fmt.Errorf("alipay TradeWapPay: %w", err)
|
||||||
}
|
}
|
||||||
@@ -134,7 +154,7 @@ func (a *Alipay) createPagePayTrade(client *alipay.Client, req payment.CreatePay
|
|||||||
param.NotifyURL = notifyURL
|
param.NotifyURL = notifyURL
|
||||||
param.ReturnURL = returnURL
|
param.ReturnURL = returnURL
|
||||||
|
|
||||||
payURL, err := client.TradePagePay(param)
|
payURL, err := alipayTradePagePay(client, param)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("alipay TradePagePay: %w", err)
|
return nil, fmt.Errorf("alipay TradePagePay: %w", err)
|
||||||
}
|
}
|
||||||
@@ -180,6 +200,7 @@ func (a *Alipay) QueryOrder(ctx context.Context, tradeNo string) (*payment.Query
|
|||||||
Status: status,
|
Status: status,
|
||||||
Amount: amount,
|
Amount: amount,
|
||||||
PaidAt: result.SendPayDate,
|
PaidAt: result.SendPayDate,
|
||||||
|
Metadata: a.MerchantIdentityMetadata(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,12 +231,21 @@ func (a *Alipay) VerifyNotification(ctx context.Context, rawBody string, _ map[s
|
|||||||
return nil, fmt.Errorf("alipay parse notification amount %q: %w", notification.TotalAmount, err)
|
return nil, fmt.Errorf("alipay parse notification amount %q: %w", notification.TotalAmount, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
metadata := a.MerchantIdentityMetadata()
|
||||||
|
if appID := strings.TrimSpace(notification.AppId); appID != "" {
|
||||||
|
if metadata == nil {
|
||||||
|
metadata = map[string]string{}
|
||||||
|
}
|
||||||
|
metadata["app_id"] = appID
|
||||||
|
}
|
||||||
|
|
||||||
return &payment.PaymentNotification{
|
return &payment.PaymentNotification{
|
||||||
TradeNo: notification.TradeNo,
|
TradeNo: notification.TradeNo,
|
||||||
OrderID: notification.OutTradeNo,
|
OrderID: notification.OutTradeNo,
|
||||||
Amount: amount,
|
Amount: amount,
|
||||||
Status: status,
|
Status: status,
|
||||||
RawData: rawBody,
|
RawData: rawBody,
|
||||||
|
Metadata: metadata,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,4 +310,5 @@ func isTradeNotExist(err error) bool {
|
|||||||
var (
|
var (
|
||||||
_ payment.Provider = (*Alipay)(nil)
|
_ payment.Provider = (*Alipay)(nil)
|
||||||
_ payment.CancelableProvider = (*Alipay)(nil)
|
_ payment.CancelableProvider = (*Alipay)(nil)
|
||||||
|
_ payment.MerchantIdentityProvider = (*Alipay)(nil)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -4,8 +4,12 @@ package provider
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/Wei-Shaw/sub2api/internal/payment"
|
||||||
|
"github.com/smartwalle/alipay/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIsTradeNotExist(t *testing.T) {
|
func TestIsTradeNotExist(t *testing.T) {
|
||||||
@@ -130,3 +134,96 @@ func TestNewAlipay(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCreateTradeUsesPagePayForDesktop(t *testing.T) {
|
||||||
|
origPagePay := alipayTradePagePay
|
||||||
|
origWapPay := alipayTradeWapPay
|
||||||
|
t.Cleanup(func() {
|
||||||
|
alipayTradePagePay = origPagePay
|
||||||
|
alipayTradeWapPay = origWapPay
|
||||||
|
})
|
||||||
|
|
||||||
|
pagePayCalls := 0
|
||||||
|
wapPayCalls := 0
|
||||||
|
alipayTradePagePay = func(client *alipay.Client, param alipay.TradePagePay) (*url.URL, error) {
|
||||||
|
pagePayCalls++
|
||||||
|
if param.OutTradeNo != "sub2_100" {
|
||||||
|
t.Fatalf("out_trade_no = %q, want %q", param.OutTradeNo, "sub2_100")
|
||||||
|
}
|
||||||
|
if param.NotifyURL != "https://merchant.example.com/api/v1/payment/webhook/alipay" {
|
||||||
|
t.Fatalf("notify_url = %q", param.NotifyURL)
|
||||||
|
}
|
||||||
|
return url.Parse("https://openapi.alipay.com/gateway.do?page-pay")
|
||||||
|
}
|
||||||
|
alipayTradeWapPay = func(client *alipay.Client, param alipay.TradeWapPay) (*url.URL, error) {
|
||||||
|
wapPayCalls++
|
||||||
|
return url.Parse("https://openapi.alipay.com/gateway.do?wap-pay")
|
||||||
|
}
|
||||||
|
|
||||||
|
provider := &Alipay{}
|
||||||
|
resp, err := provider.createPagePayTrade(&alipay.Client{}, payment.CreatePaymentRequest{
|
||||||
|
OrderID: "sub2_100",
|
||||||
|
Amount: "88.00",
|
||||||
|
Subject: "Balance recharge",
|
||||||
|
}, "https://merchant.example.com/api/v1/payment/webhook/alipay", "https://merchant.example.com/payment/result")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
if pagePayCalls != 1 {
|
||||||
|
t.Fatalf("page pay calls = %d, want 1", pagePayCalls)
|
||||||
|
}
|
||||||
|
if wapPayCalls != 0 {
|
||||||
|
t.Fatalf("wap pay calls = %d, want 0", wapPayCalls)
|
||||||
|
}
|
||||||
|
if resp.PayURL == "" {
|
||||||
|
t.Fatal("expected pay_url for desktop page pay")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCreateTradeUsesWapPayForMobile(t *testing.T) {
|
||||||
|
origWapPay := alipayTradeWapPay
|
||||||
|
t.Cleanup(func() {
|
||||||
|
alipayTradeWapPay = origWapPay
|
||||||
|
})
|
||||||
|
|
||||||
|
wapPayCalls := 0
|
||||||
|
alipayTradeWapPay = func(client *alipay.Client, param alipay.TradeWapPay) (*url.URL, error) {
|
||||||
|
wapPayCalls++
|
||||||
|
if param.ReturnURL != "https://merchant.example.com/payment/result" {
|
||||||
|
t.Fatalf("return_url = %q", param.ReturnURL)
|
||||||
|
}
|
||||||
|
return url.Parse("https://openapi.alipay.com/gateway.do?wap-pay")
|
||||||
|
}
|
||||||
|
|
||||||
|
provider := &Alipay{}
|
||||||
|
resp, err := provider.createWapTrade(&alipay.Client{}, payment.CreatePaymentRequest{
|
||||||
|
OrderID: "sub2_101",
|
||||||
|
Amount: "18.00",
|
||||||
|
Subject: "Balance recharge",
|
||||||
|
IsMobile: true,
|
||||||
|
}, "https://merchant.example.com/api/v1/payment/webhook/alipay", "https://merchant.example.com/payment/result")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
if wapPayCalls != 1 {
|
||||||
|
t.Fatalf("wap pay calls = %d, want 1", wapPayCalls)
|
||||||
|
}
|
||||||
|
if resp.PayURL == "" {
|
||||||
|
t.Fatal("expected pay_url for mobile wap pay")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAlipayMerchantIdentityMetadata(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
provider := &Alipay{
|
||||||
|
config: map[string]string{
|
||||||
|
"appId": "2021001234567890",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
metadata := provider.MerchantIdentityMetadata()
|
||||||
|
if metadata["app_id"] != "2021001234567890" {
|
||||||
|
t.Fatalf("app_id = %q, want %q", metadata["app_id"], "2021001234567890")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -59,6 +59,17 @@ func (e *EasyPay) SupportedTypes() []payment.PaymentType {
|
|||||||
return []payment.PaymentType{payment.TypeAlipay, payment.TypeWxpay}
|
return []payment.PaymentType{payment.TypeAlipay, payment.TypeWxpay}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *EasyPay) MerchantIdentityMetadata() map[string]string {
|
||||||
|
if e == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
pid := strings.TrimSpace(e.config["pid"])
|
||||||
|
if pid == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return map[string]string{"pid": pid}
|
||||||
|
}
|
||||||
|
|
||||||
func (e *EasyPay) CreatePayment(ctx context.Context, req payment.CreatePaymentRequest) (*payment.CreatePaymentResponse, error) {
|
func (e *EasyPay) CreatePayment(ctx context.Context, req payment.CreatePaymentRequest) (*payment.CreatePaymentResponse, error) {
|
||||||
// Payment mode determined by instance config, not payment type.
|
// Payment mode determined by instance config, not payment type.
|
||||||
// "popup" → hosted page (submit.php); "qrcode"/default → API call (mapi.php).
|
// "popup" → hosted page (submit.php); "qrcode"/default → API call (mapi.php).
|
||||||
@@ -178,7 +189,12 @@ func (e *EasyPay) QueryOrder(ctx context.Context, tradeNo string) (*payment.Quer
|
|||||||
status = payment.ProviderStatusPaid
|
status = payment.ProviderStatusPaid
|
||||||
}
|
}
|
||||||
amount, _ := strconv.ParseFloat(resp.Money, 64)
|
amount, _ := strconv.ParseFloat(resp.Money, 64)
|
||||||
return &payment.QueryOrderResponse{TradeNo: tradeNo, Status: status, Amount: amount}, nil
|
return &payment.QueryOrderResponse{
|
||||||
|
TradeNo: tradeNo,
|
||||||
|
Status: status,
|
||||||
|
Amount: amount,
|
||||||
|
Metadata: e.MerchantIdentityMetadata(),
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *EasyPay) VerifyNotification(_ context.Context, rawBody string, _ map[string]string) (*payment.PaymentNotification, error) {
|
func (e *EasyPay) VerifyNotification(_ context.Context, rawBody string, _ map[string]string) (*payment.PaymentNotification, error) {
|
||||||
@@ -203,9 +219,17 @@ func (e *EasyPay) VerifyNotification(_ context.Context, rawBody string, _ map[st
|
|||||||
status = payment.ProviderStatusSuccess
|
status = payment.ProviderStatusSuccess
|
||||||
}
|
}
|
||||||
amount, _ := strconv.ParseFloat(params["money"], 64)
|
amount, _ := strconv.ParseFloat(params["money"], 64)
|
||||||
|
|
||||||
|
metadata := e.MerchantIdentityMetadata()
|
||||||
|
if pid := strings.TrimSpace(params["pid"]); pid != "" {
|
||||||
|
if metadata == nil {
|
||||||
|
metadata = map[string]string{}
|
||||||
|
}
|
||||||
|
metadata["pid"] = pid
|
||||||
|
}
|
||||||
return &payment.PaymentNotification{
|
return &payment.PaymentNotification{
|
||||||
TradeNo: params["trade_no"], OrderID: params["out_trade_no"],
|
TradeNo: params["trade_no"], OrderID: params["out_trade_no"],
|
||||||
Amount: amount, Status: status, RawData: rawBody,
|
Amount: amount, Status: status, RawData: rawBody, Metadata: metadata,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -178,3 +178,18 @@ func TestEasyPayVerifySignWrongSignValue(t *testing.T) {
|
|||||||
t.Fatal("easyPayVerifySign should return false for an incorrect sign value")
|
t.Fatal("easyPayVerifySign should return false for an incorrect sign value")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEasyPayMerchantIdentityMetadata(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
provider := &EasyPay{
|
||||||
|
config: map[string]string{
|
||||||
|
"pid": "1001",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
metadata := provider.MerchantIdentityMetadata()
|
||||||
|
if metadata["pid"] != "1001" {
|
||||||
|
t.Fatalf("pid = %q, want %q", metadata["pid"], "1001")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log/slog"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -20,6 +20,7 @@ import (
|
|||||||
"github.com/wechatpay-apiv3/wechatpay-go/core/option"
|
"github.com/wechatpay-apiv3/wechatpay-go/core/option"
|
||||||
"github.com/wechatpay-apiv3/wechatpay-go/services/payments"
|
"github.com/wechatpay-apiv3/wechatpay-go/services/payments"
|
||||||
"github.com/wechatpay-apiv3/wechatpay-go/services/payments/h5"
|
"github.com/wechatpay-apiv3/wechatpay-go/services/payments/h5"
|
||||||
|
"github.com/wechatpay-apiv3/wechatpay-go/services/payments/jsapi"
|
||||||
"github.com/wechatpay-apiv3/wechatpay-go/services/payments/native"
|
"github.com/wechatpay-apiv3/wechatpay-go/services/payments/native"
|
||||||
"github.com/wechatpay-apiv3/wechatpay-go/services/refunddomestic"
|
"github.com/wechatpay-apiv3/wechatpay-go/services/refunddomestic"
|
||||||
"github.com/wechatpay-apiv3/wechatpay-go/utils"
|
"github.com/wechatpay-apiv3/wechatpay-go/utils"
|
||||||
@@ -29,6 +30,21 @@ import (
|
|||||||
const (
|
const (
|
||||||
wxpayCurrency = "CNY"
|
wxpayCurrency = "CNY"
|
||||||
wxpayH5Type = "Wap"
|
wxpayH5Type = "Wap"
|
||||||
|
wxpayResultPath = "/payment/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
wxpayMetadataAppID = "appid"
|
||||||
|
wxpayMetadataMerchantID = "mchid"
|
||||||
|
wxpayMetadataCurrency = "currency"
|
||||||
|
wxpayMetadataTradeState = "trade_state"
|
||||||
|
)
|
||||||
|
|
||||||
|
// WeChat Pay create-payment modes.
|
||||||
|
const (
|
||||||
|
wxpayModeNative = "native"
|
||||||
|
wxpayModeH5 = "h5"
|
||||||
|
wxpayModeJSAPI = "jsapi"
|
||||||
)
|
)
|
||||||
|
|
||||||
// WeChat Pay trade states.
|
// WeChat Pay trade states.
|
||||||
@@ -49,6 +65,18 @@ const (
|
|||||||
wxpayErrNoAuth = "NO_AUTH"
|
wxpayErrNoAuth = "NO_AUTH"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
wxpayNativePrepay = func(ctx context.Context, svc native.NativeApiService, req native.PrepayRequest) (*native.PrepayResponse, *core.APIResult, error) {
|
||||||
|
return svc.Prepay(ctx, req)
|
||||||
|
}
|
||||||
|
wxpayH5Prepay = func(ctx context.Context, svc h5.H5ApiService, req h5.PrepayRequest) (*h5.PrepayResponse, *core.APIResult, error) {
|
||||||
|
return svc.Prepay(ctx, req)
|
||||||
|
}
|
||||||
|
wxpayJSAPIPrepayWithRequestPayment = func(ctx context.Context, svc jsapi.JsapiApiService, req jsapi.PrepayRequest) (*jsapi.PrepayWithRequestPaymentResponse, *core.APIResult, error) {
|
||||||
|
return svc.PrepayWithRequestPayment(ctx, req)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
type Wxpay struct {
|
type Wxpay struct {
|
||||||
instanceID string
|
instanceID string
|
||||||
config map[string]string
|
config map[string]string
|
||||||
@@ -96,6 +124,16 @@ func (w *Wxpay) SupportedTypes() []payment.PaymentType {
|
|||||||
return []payment.PaymentType{payment.TypeWxpay}
|
return []payment.PaymentType{payment.TypeWxpay}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ResolveWxpayJSAPIAppID returns the AppID that JSAPI prepay will use for a
|
||||||
|
// given provider config. A dedicated MP AppID takes precedence over the base
|
||||||
|
// merchant AppID.
|
||||||
|
func ResolveWxpayJSAPIAppID(config map[string]string) string {
|
||||||
|
if appID := strings.TrimSpace(config["mpAppId"]); appID != "" {
|
||||||
|
return appID
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(config["appId"])
|
||||||
|
}
|
||||||
|
|
||||||
func formatPEM(key, keyType string) string {
|
func formatPEM(key, keyType string) string {
|
||||||
key = strings.TrimSpace(key)
|
key = strings.TrimSpace(key)
|
||||||
if strings.HasPrefix(key, "-----BEGIN") {
|
if strings.HasPrefix(key, "-----BEGIN") {
|
||||||
@@ -153,30 +191,68 @@ func (w *Wxpay) CreatePayment(ctx context.Context, req payment.CreatePaymentRequ
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("wxpay create payment: %w", err)
|
return nil, fmt.Errorf("wxpay create payment: %w", err)
|
||||||
}
|
}
|
||||||
if req.IsMobile && req.ClientIP != "" {
|
|
||||||
resp, err := w.createOrder(ctx, client, req, notifyURL, totalFen, true)
|
mode, err := resolveWxpayCreateMode(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
switch mode {
|
||||||
|
case wxpayModeJSAPI:
|
||||||
|
return w.prepayJSAPI(ctx, client, req, notifyURL, totalFen)
|
||||||
|
case wxpayModeH5:
|
||||||
|
resp, err := w.prepayH5(ctx, client, req, notifyURL, totalFen)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), wxpayErrNoAuth) {
|
if strings.Contains(err.Error(), wxpayErrNoAuth) {
|
||||||
|
return nil, fmt.Errorf("wxpay h5 payments are not authorized for this merchant: %w", err)
|
||||||
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
|
case wxpayModeNative:
|
||||||
|
return w.prepayNative(ctx, client, req, notifyURL, totalFen)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("wxpay create payment: unsupported mode %q", mode)
|
||||||
}
|
}
|
||||||
slog.Warn("wxpay H5 payment not authorized, falling back to native", "order", req.OrderID)
|
|
||||||
}
|
|
||||||
return w.createOrder(ctx, client, req, notifyURL, totalFen, false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Wxpay) createOrder(ctx context.Context, c *core.Client, req payment.CreatePaymentRequest, notifyURL string, totalFen int64, useH5 bool) (*payment.CreatePaymentResponse, error) {
|
func (w *Wxpay) prepayJSAPI(ctx context.Context, c *core.Client, req payment.CreatePaymentRequest, notifyURL string, totalFen int64) (*payment.CreatePaymentResponse, error) {
|
||||||
if useH5 {
|
svc := jsapi.JsapiApiService{Client: c}
|
||||||
return w.prepayH5(ctx, c, req, notifyURL, totalFen)
|
cur := wxpayCurrency
|
||||||
|
appID := ResolveWxpayJSAPIAppID(w.config)
|
||||||
|
prepayReq := jsapi.PrepayRequest{
|
||||||
|
Appid: core.String(appID),
|
||||||
|
Mchid: core.String(w.config["mchId"]),
|
||||||
|
Description: core.String(req.Subject),
|
||||||
|
OutTradeNo: core.String(req.OrderID),
|
||||||
|
NotifyUrl: core.String(notifyURL),
|
||||||
|
Amount: &jsapi.Amount{Total: core.Int64(totalFen), Currency: &cur},
|
||||||
|
Payer: &jsapi.Payer{Openid: core.String(strings.TrimSpace(req.OpenID))},
|
||||||
}
|
}
|
||||||
return w.prepayNative(ctx, c, req, notifyURL, totalFen)
|
if clientIP := strings.TrimSpace(req.ClientIP); clientIP != "" {
|
||||||
|
prepayReq.SceneInfo = &jsapi.SceneInfo{PayerClientIp: core.String(clientIP)}
|
||||||
|
}
|
||||||
|
resp, _, err := wxpayJSAPIPrepayWithRequestPayment(ctx, svc, prepayReq)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("wxpay jsapi prepay: %w", err)
|
||||||
|
}
|
||||||
|
return &payment.CreatePaymentResponse{
|
||||||
|
TradeNo: req.OrderID,
|
||||||
|
ResultType: payment.CreatePaymentResultJSAPIReady,
|
||||||
|
JSAPI: &payment.WechatJSAPIPayload{
|
||||||
|
AppID: wxSV(resp.Appid),
|
||||||
|
TimeStamp: wxSV(resp.TimeStamp),
|
||||||
|
NonceStr: wxSV(resp.NonceStr),
|
||||||
|
Package: wxSV(resp.Package),
|
||||||
|
SignType: wxSV(resp.SignType),
|
||||||
|
PaySign: wxSV(resp.PaySign),
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Wxpay) prepayNative(ctx context.Context, c *core.Client, req payment.CreatePaymentRequest, notifyURL string, totalFen int64) (*payment.CreatePaymentResponse, error) {
|
func (w *Wxpay) prepayNative(ctx context.Context, c *core.Client, req payment.CreatePaymentRequest, notifyURL string, totalFen int64) (*payment.CreatePaymentResponse, error) {
|
||||||
svc := native.NativeApiService{Client: c}
|
svc := native.NativeApiService{Client: c}
|
||||||
cur := wxpayCurrency
|
cur := wxpayCurrency
|
||||||
resp, _, err := svc.Prepay(ctx, native.PrepayRequest{
|
resp, _, err := wxpayNativePrepay(ctx, svc, native.PrepayRequest{
|
||||||
Appid: core.String(w.config["appId"]), Mchid: core.String(w.config["mchId"]),
|
Appid: core.String(w.config["appId"]), Mchid: core.String(w.config["mchId"]),
|
||||||
Description: core.String(req.Subject), OutTradeNo: core.String(req.OrderID),
|
Description: core.String(req.Subject), OutTradeNo: core.String(req.OrderID),
|
||||||
NotifyUrl: core.String(notifyURL),
|
NotifyUrl: core.String(notifyURL),
|
||||||
@@ -195,13 +271,12 @@ func (w *Wxpay) prepayNative(ctx context.Context, c *core.Client, req payment.Cr
|
|||||||
func (w *Wxpay) prepayH5(ctx context.Context, c *core.Client, req payment.CreatePaymentRequest, notifyURL string, totalFen int64) (*payment.CreatePaymentResponse, error) {
|
func (w *Wxpay) prepayH5(ctx context.Context, c *core.Client, req payment.CreatePaymentRequest, notifyURL string, totalFen int64) (*payment.CreatePaymentResponse, error) {
|
||||||
svc := h5.H5ApiService{Client: c}
|
svc := h5.H5ApiService{Client: c}
|
||||||
cur := wxpayCurrency
|
cur := wxpayCurrency
|
||||||
tp := wxpayH5Type
|
resp, _, err := wxpayH5Prepay(ctx, svc, h5.PrepayRequest{
|
||||||
resp, _, err := svc.Prepay(ctx, h5.PrepayRequest{
|
|
||||||
Appid: core.String(w.config["appId"]), Mchid: core.String(w.config["mchId"]),
|
Appid: core.String(w.config["appId"]), Mchid: core.String(w.config["mchId"]),
|
||||||
Description: core.String(req.Subject), OutTradeNo: core.String(req.OrderID),
|
Description: core.String(req.Subject), OutTradeNo: core.String(req.OrderID),
|
||||||
NotifyUrl: core.String(notifyURL),
|
NotifyUrl: core.String(notifyURL),
|
||||||
Amount: &h5.Amount{Total: core.Int64(totalFen), Currency: &cur},
|
Amount: &h5.Amount{Total: core.Int64(totalFen), Currency: &cur},
|
||||||
SceneInfo: &h5.SceneInfo{PayerClientIp: core.String(req.ClientIP), H5Info: &h5.H5Info{Type: &tp}},
|
SceneInfo: &h5.SceneInfo{PayerClientIp: core.String(req.ClientIP), H5Info: buildWxpayH5Info(w.config)},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("wxpay h5 prepay: %w", err)
|
return nil, fmt.Errorf("wxpay h5 prepay: %w", err)
|
||||||
@@ -210,9 +285,77 @@ func (w *Wxpay) prepayH5(ctx context.Context, c *core.Client, req payment.Create
|
|||||||
if resp.H5Url != nil {
|
if resp.H5Url != nil {
|
||||||
h5URL = *resp.H5Url
|
h5URL = *resp.H5Url
|
||||||
}
|
}
|
||||||
|
h5URL, err = appendWxpayRedirectURL(h5URL, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return &payment.CreatePaymentResponse{TradeNo: req.OrderID, PayURL: h5URL}, nil
|
return &payment.CreatePaymentResponse{TradeNo: req.OrderID, PayURL: h5URL}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func buildWxpayH5Info(config map[string]string) *h5.H5Info {
|
||||||
|
tp := wxpayH5Type
|
||||||
|
info := &h5.H5Info{Type: &tp}
|
||||||
|
if appName := strings.TrimSpace(config["h5AppName"]); appName != "" {
|
||||||
|
info.AppName = core.String(appName)
|
||||||
|
}
|
||||||
|
if appURL := strings.TrimSpace(config["h5AppUrl"]); appURL != "" {
|
||||||
|
info.AppUrl = core.String(appURL)
|
||||||
|
}
|
||||||
|
return info
|
||||||
|
}
|
||||||
|
|
||||||
|
func resolveWxpayCreateMode(req payment.CreatePaymentRequest) (string, error) {
|
||||||
|
if strings.TrimSpace(req.OpenID) != "" {
|
||||||
|
return wxpayModeJSAPI, nil
|
||||||
|
}
|
||||||
|
if req.IsMobile {
|
||||||
|
if strings.TrimSpace(req.ClientIP) == "" {
|
||||||
|
return "", fmt.Errorf("wxpay H5 payment requires client IP")
|
||||||
|
}
|
||||||
|
return wxpayModeH5, nil
|
||||||
|
}
|
||||||
|
return wxpayModeNative, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func appendWxpayRedirectURL(h5URL string, req payment.CreatePaymentRequest) (string, error) {
|
||||||
|
h5URL = strings.TrimSpace(h5URL)
|
||||||
|
returnURL := strings.TrimSpace(req.ReturnURL)
|
||||||
|
if h5URL == "" || returnURL == "" {
|
||||||
|
return h5URL, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
redirectURL, err := buildWxpayResultURL(returnURL, req)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
sep := "&"
|
||||||
|
if !strings.Contains(h5URL, "?") {
|
||||||
|
sep = "?"
|
||||||
|
}
|
||||||
|
return h5URL + sep + "redirect_url=" + url.QueryEscape(redirectURL), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildWxpayResultURL(returnURL string, req payment.CreatePaymentRequest) (string, error) {
|
||||||
|
u, err := url.Parse(returnURL)
|
||||||
|
if err != nil || !u.IsAbs() || u.Host == "" || (u.Scheme != "http" && u.Scheme != "https") {
|
||||||
|
return "", fmt.Errorf("return URL must be an absolute http(s) URL")
|
||||||
|
}
|
||||||
|
|
||||||
|
values := u.Query()
|
||||||
|
values.Set("out_trade_no", strings.TrimSpace(req.OrderID))
|
||||||
|
if paymentType := strings.TrimSpace(req.PaymentType); paymentType != "" {
|
||||||
|
values.Set("payment_type", paymentType)
|
||||||
|
}
|
||||||
|
if strings.TrimSpace(u.Path) == "" {
|
||||||
|
u.Path = wxpayResultPath
|
||||||
|
}
|
||||||
|
u.RawPath = ""
|
||||||
|
u.RawQuery = values.Encode()
|
||||||
|
u.Fragment = ""
|
||||||
|
return u.String(), nil
|
||||||
|
}
|
||||||
|
|
||||||
func wxSV(s *string) string {
|
func wxSV(s *string) string {
|
||||||
if s == nil {
|
if s == nil {
|
||||||
return ""
|
return ""
|
||||||
@@ -233,6 +376,32 @@ func mapWxState(s string) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func buildWxpayTransactionMetadata(tx *payments.Transaction) map[string]string {
|
||||||
|
if tx == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
metadata := map[string]string{}
|
||||||
|
if appID := wxSV(tx.Appid); appID != "" {
|
||||||
|
metadata[wxpayMetadataAppID] = appID
|
||||||
|
}
|
||||||
|
if merchantID := wxSV(tx.Mchid); merchantID != "" {
|
||||||
|
metadata[wxpayMetadataMerchantID] = merchantID
|
||||||
|
}
|
||||||
|
if tradeState := wxSV(tx.TradeState); tradeState != "" {
|
||||||
|
metadata[wxpayMetadataTradeState] = tradeState
|
||||||
|
}
|
||||||
|
if tx.Amount != nil {
|
||||||
|
if currency := wxSV(tx.Amount.Currency); currency != "" {
|
||||||
|
metadata[wxpayMetadataCurrency] = currency
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(metadata) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return metadata
|
||||||
|
}
|
||||||
|
|
||||||
func (w *Wxpay) QueryOrder(ctx context.Context, tradeNo string) (*payment.QueryOrderResponse, error) {
|
func (w *Wxpay) QueryOrder(ctx context.Context, tradeNo string) (*payment.QueryOrderResponse, error) {
|
||||||
c, err := w.ensureClient()
|
c, err := w.ensureClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -257,7 +426,13 @@ func (w *Wxpay) QueryOrder(ctx context.Context, tradeNo string) (*payment.QueryO
|
|||||||
if tx.SuccessTime != nil {
|
if tx.SuccessTime != nil {
|
||||||
pa = *tx.SuccessTime
|
pa = *tx.SuccessTime
|
||||||
}
|
}
|
||||||
return &payment.QueryOrderResponse{TradeNo: id, Status: mapWxState(wxSV(tx.TradeState)), Amount: amt, PaidAt: pa}, nil
|
return &payment.QueryOrderResponse{
|
||||||
|
TradeNo: id,
|
||||||
|
Status: mapWxState(wxSV(tx.TradeState)),
|
||||||
|
Amount: amt,
|
||||||
|
PaidAt: pa,
|
||||||
|
Metadata: buildWxpayTransactionMetadata(tx),
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Wxpay) VerifyNotification(ctx context.Context, rawBody string, headers map[string]string) (*payment.PaymentNotification, error) {
|
func (w *Wxpay) VerifyNotification(ctx context.Context, rawBody string, headers map[string]string) (*payment.PaymentNotification, error) {
|
||||||
@@ -289,7 +464,7 @@ func (w *Wxpay) VerifyNotification(ctx context.Context, rawBody string, headers
|
|||||||
}
|
}
|
||||||
return &payment.PaymentNotification{
|
return &payment.PaymentNotification{
|
||||||
TradeNo: wxSV(tx.TransactionId), OrderID: wxSV(tx.OutTradeNo),
|
TradeNo: wxSV(tx.TransactionId), OrderID: wxSV(tx.OutTradeNo),
|
||||||
Amount: amt, Status: st, RawData: rawBody,
|
Amount: amt, Status: st, RawData: rawBody, Metadata: buildWxpayTransactionMetadata(&tx),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user