Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
6cc7f997
Commit
6cc7f997
authored
Jan 02, 2026
by
song
Browse files
merge: 合并 upstream/main
parents
95d09f60
106e59b7
Changes
135
Expand all
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
6cc7f997
...
...
@@ -77,6 +77,7 @@ temp/
*.temp
*.log
*.bak
.cache/
# ===================
# 构建产物
...
...
backend/cmd/server/wire_gen.go
View file @
6cc7f997
...
...
@@ -87,9 +87,10 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
geminiOAuthClient
:=
repository
.
NewGeminiOAuthClient
(
configConfig
)
geminiCliCodeAssistClient
:=
repository
.
NewGeminiCliCodeAssistClient
()
geminiOAuthService
:=
service
.
NewGeminiOAuthService
(
proxyRepository
,
geminiOAuthClient
,
geminiCliCodeAssistClient
,
configConfig
)
rateLimitService
:=
service
.
NewRateLimitService
(
accountRepository
,
configConfig
)
geminiQuotaService
:=
service
.
NewGeminiQuotaService
(
configConfig
,
settingRepository
)
rateLimitService
:=
service
.
NewRateLimitService
(
accountRepository
,
usageLogRepository
,
configConfig
,
geminiQuotaService
)
claudeUsageFetcher
:=
repository
.
NewClaudeUsageFetcher
()
accountUsageService
:=
service
.
NewAccountUsageService
(
accountRepository
,
usageLogRepository
,
claudeUsageFetcher
)
accountUsageService
:=
service
.
NewAccountUsageService
(
accountRepository
,
usageLogRepository
,
claudeUsageFetcher
,
geminiQuotaService
)
geminiTokenCache
:=
repository
.
NewGeminiTokenCache
(
redisClient
)
geminiTokenProvider
:=
service
.
NewGeminiTokenProvider
(
accountRepository
,
geminiTokenCache
,
geminiOAuthService
)
gatewayCache
:=
repository
.
NewGatewayCache
(
redisClient
)
...
...
@@ -99,7 +100,7 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
antigravityGatewayService
:=
service
.
NewAntigravityGatewayService
(
accountRepository
,
gatewayCache
,
antigravityTokenProvider
,
rateLimitService
,
httpUpstream
)
accountTestService
:=
service
.
NewAccountTestService
(
accountRepository
,
oAuthService
,
openAIOAuthService
,
geminiTokenProvider
,
antigravityGatewayService
,
httpUpstream
)
concurrencyCache
:=
repository
.
ProvideConcurrencyCache
(
redisClient
,
configConfig
)
concurrencyService
:=
service
.
New
ConcurrencyService
(
concurrencyCache
)
concurrencyService
:=
service
.
Provide
ConcurrencyService
(
concurrencyCache
,
accountRepository
,
configConfig
)
crsSyncService
:=
service
.
NewCRSSyncService
(
accountRepository
,
proxyRepository
,
oAuthService
,
openAIOAuthService
,
geminiOAuthService
)
accountHandler
:=
admin
.
NewAccountHandler
(
adminService
,
oAuthService
,
openAIOAuthService
,
geminiOAuthService
,
rateLimitService
,
accountUsageService
,
accountTestService
,
concurrencyService
,
crsSyncService
)
oAuthHandler
:=
admin
.
NewOAuthHandler
(
oAuthService
)
...
...
@@ -116,7 +117,11 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
systemHandler
:=
handler
.
ProvideSystemHandler
(
updateService
)
adminSubscriptionHandler
:=
admin
.
NewSubscriptionHandler
(
subscriptionService
)
adminUsageHandler
:=
admin
.
NewUsageHandler
(
usageService
,
apiKeyService
,
adminService
)
adminHandlers
:=
handler
.
ProvideAdminHandlers
(
dashboardHandler
,
adminUserHandler
,
groupHandler
,
accountHandler
,
oAuthHandler
,
openAIOAuthHandler
,
geminiOAuthHandler
,
antigravityOAuthHandler
,
proxyHandler
,
adminRedeemHandler
,
settingHandler
,
systemHandler
,
adminSubscriptionHandler
,
adminUsageHandler
)
userAttributeDefinitionRepository
:=
repository
.
NewUserAttributeDefinitionRepository
(
client
)
userAttributeValueRepository
:=
repository
.
NewUserAttributeValueRepository
(
client
)
userAttributeService
:=
service
.
NewUserAttributeService
(
userAttributeDefinitionRepository
,
userAttributeValueRepository
)
userAttributeHandler
:=
admin
.
NewUserAttributeHandler
(
userAttributeService
)
adminHandlers
:=
handler
.
ProvideAdminHandlers
(
dashboardHandler
,
adminUserHandler
,
groupHandler
,
accountHandler
,
oAuthHandler
,
openAIOAuthHandler
,
geminiOAuthHandler
,
antigravityOAuthHandler
,
proxyHandler
,
adminRedeemHandler
,
settingHandler
,
systemHandler
,
adminSubscriptionHandler
,
adminUsageHandler
,
userAttributeHandler
)
pricingRemoteClient
:=
repository
.
NewPricingRemoteClient
()
pricingService
,
err
:=
service
.
ProvidePricingService
(
configConfig
,
pricingRemoteClient
)
if
err
!=
nil
{
...
...
@@ -127,10 +132,10 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
identityService
:=
service
.
NewIdentityService
(
identityCache
)
timingWheelService
:=
service
.
ProvideTimingWheelService
()
deferredService
:=
service
.
ProvideDeferredService
(
accountRepository
,
timingWheelService
)
gatewayService
:=
service
.
NewGatewayService
(
accountRepository
,
groupRepository
,
usageLogRepository
,
userRepository
,
userSubscriptionRepository
,
gatewayCache
,
configConfig
,
billingService
,
rateLimitService
,
billingCacheService
,
identityService
,
httpUpstream
,
deferredService
)
gatewayService
:=
service
.
NewGatewayService
(
accountRepository
,
groupRepository
,
usageLogRepository
,
userRepository
,
userSubscriptionRepository
,
gatewayCache
,
configConfig
,
concurrencyService
,
billingService
,
rateLimitService
,
billingCacheService
,
identityService
,
httpUpstream
,
deferredService
)
geminiMessagesCompatService
:=
service
.
NewGeminiMessagesCompatService
(
accountRepository
,
groupRepository
,
gatewayCache
,
geminiTokenProvider
,
rateLimitService
,
httpUpstream
,
antigravityGatewayService
)
gatewayHandler
:=
handler
.
NewGatewayHandler
(
gatewayService
,
geminiMessagesCompatService
,
antigravityGatewayService
,
userService
,
concurrencyService
,
billingCacheService
)
openAIGatewayService
:=
service
.
NewOpenAIGatewayService
(
accountRepository
,
usageLogRepository
,
userRepository
,
userSubscriptionRepository
,
gatewayCache
,
configConfig
,
billingService
,
rateLimitService
,
billingCacheService
,
httpUpstream
,
deferredService
)
openAIGatewayService
:=
service
.
NewOpenAIGatewayService
(
accountRepository
,
usageLogRepository
,
userRepository
,
userSubscriptionRepository
,
gatewayCache
,
configConfig
,
concurrencyService
,
billingService
,
rateLimitService
,
billingCacheService
,
httpUpstream
,
deferredService
)
openAIGatewayHandler
:=
handler
.
NewOpenAIGatewayHandler
(
openAIGatewayService
,
concurrencyService
,
billingCacheService
)
handlerSettingHandler
:=
handler
.
ProvideSettingHandler
(
settingService
,
buildInfo
)
handlers
:=
handler
.
ProvideHandlers
(
authHandler
,
userHandler
,
apiKeyHandler
,
usageHandler
,
redeemHandler
,
subscriptionHandler
,
adminHandlers
,
gatewayHandler
,
openAIGatewayHandler
,
handlerSettingHandler
)
...
...
backend/ent/client.go
View file @
6cc7f997
This diff is collapsed.
Click to expand it.
backend/ent/ent.go
View file @
6cc7f997
...
...
@@ -22,6 +22,8 @@ import (
"github.com/Wei-Shaw/sub2api/ent/usagelog"
"github.com/Wei-Shaw/sub2api/ent/user"
"github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
"github.com/Wei-Shaw/sub2api/ent/userattributedefinition"
"github.com/Wei-Shaw/sub2api/ent/userattributevalue"
"github.com/Wei-Shaw/sub2api/ent/usersubscription"
)
...
...
@@ -83,17 +85,19 @@ var (
func
checkColumn
(
t
,
c
string
)
error
{
initCheck
.
Do
(
func
()
{
columnCheck
=
sql
.
NewColumnCheck
(
map
[
string
]
func
(
string
)
bool
{
account
.
Table
:
account
.
ValidColumn
,
accountgroup
.
Table
:
accountgroup
.
ValidColumn
,
apikey
.
Table
:
apikey
.
ValidColumn
,
group
.
Table
:
group
.
ValidColumn
,
proxy
.
Table
:
proxy
.
ValidColumn
,
redeemcode
.
Table
:
redeemcode
.
ValidColumn
,
setting
.
Table
:
setting
.
ValidColumn
,
usagelog
.
Table
:
usagelog
.
ValidColumn
,
user
.
Table
:
user
.
ValidColumn
,
userallowedgroup
.
Table
:
userallowedgroup
.
ValidColumn
,
usersubscription
.
Table
:
usersubscription
.
ValidColumn
,
account
.
Table
:
account
.
ValidColumn
,
accountgroup
.
Table
:
accountgroup
.
ValidColumn
,
apikey
.
Table
:
apikey
.
ValidColumn
,
group
.
Table
:
group
.
ValidColumn
,
proxy
.
Table
:
proxy
.
ValidColumn
,
redeemcode
.
Table
:
redeemcode
.
ValidColumn
,
setting
.
Table
:
setting
.
ValidColumn
,
usagelog
.
Table
:
usagelog
.
ValidColumn
,
user
.
Table
:
user
.
ValidColumn
,
userallowedgroup
.
Table
:
userallowedgroup
.
ValidColumn
,
userattributedefinition
.
Table
:
userattributedefinition
.
ValidColumn
,
userattributevalue
.
Table
:
userattributevalue
.
ValidColumn
,
usersubscription
.
Table
:
usersubscription
.
ValidColumn
,
})
})
return
columnCheck
(
t
,
c
)
...
...
backend/ent/hook/hook.go
View file @
6cc7f997
...
...
@@ -129,6 +129,30 @@ func (f UserAllowedGroupFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.V
return
nil
,
fmt
.
Errorf
(
"unexpected mutation type %T. expect *ent.UserAllowedGroupMutation"
,
m
)
}
// The UserAttributeDefinitionFunc type is an adapter to allow the use of ordinary
// function as UserAttributeDefinition mutator.
type
UserAttributeDefinitionFunc
func
(
context
.
Context
,
*
ent
.
UserAttributeDefinitionMutation
)
(
ent
.
Value
,
error
)
// Mutate calls f(ctx, m).
func
(
f
UserAttributeDefinitionFunc
)
Mutate
(
ctx
context
.
Context
,
m
ent
.
Mutation
)
(
ent
.
Value
,
error
)
{
if
mv
,
ok
:=
m
.
(
*
ent
.
UserAttributeDefinitionMutation
);
ok
{
return
f
(
ctx
,
mv
)
}
return
nil
,
fmt
.
Errorf
(
"unexpected mutation type %T. expect *ent.UserAttributeDefinitionMutation"
,
m
)
}
// The UserAttributeValueFunc type is an adapter to allow the use of ordinary
// function as UserAttributeValue mutator.
type
UserAttributeValueFunc
func
(
context
.
Context
,
*
ent
.
UserAttributeValueMutation
)
(
ent
.
Value
,
error
)
// Mutate calls f(ctx, m).
func
(
f
UserAttributeValueFunc
)
Mutate
(
ctx
context
.
Context
,
m
ent
.
Mutation
)
(
ent
.
Value
,
error
)
{
if
mv
,
ok
:=
m
.
(
*
ent
.
UserAttributeValueMutation
);
ok
{
return
f
(
ctx
,
mv
)
}
return
nil
,
fmt
.
Errorf
(
"unexpected mutation type %T. expect *ent.UserAttributeValueMutation"
,
m
)
}
// The UserSubscriptionFunc type is an adapter to allow the use of ordinary
// function as UserSubscription mutator.
type
UserSubscriptionFunc
func
(
context
.
Context
,
*
ent
.
UserSubscriptionMutation
)
(
ent
.
Value
,
error
)
...
...
backend/ent/intercept/intercept.go
View file @
6cc7f997
...
...
@@ -19,6 +19,8 @@ import (
"github.com/Wei-Shaw/sub2api/ent/usagelog"
"github.com/Wei-Shaw/sub2api/ent/user"
"github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
"github.com/Wei-Shaw/sub2api/ent/userattributedefinition"
"github.com/Wei-Shaw/sub2api/ent/userattributevalue"
"github.com/Wei-Shaw/sub2api/ent/usersubscription"
)
...
...
@@ -348,6 +350,60 @@ func (f TraverseUserAllowedGroup) Traverse(ctx context.Context, q ent.Query) err
return
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.UserAllowedGroupQuery"
,
q
)
}
// The UserAttributeDefinitionFunc type is an adapter to allow the use of ordinary function as a Querier.
type
UserAttributeDefinitionFunc
func
(
context
.
Context
,
*
ent
.
UserAttributeDefinitionQuery
)
(
ent
.
Value
,
error
)
// Query calls f(ctx, q).
func
(
f
UserAttributeDefinitionFunc
)
Query
(
ctx
context
.
Context
,
q
ent
.
Query
)
(
ent
.
Value
,
error
)
{
if
q
,
ok
:=
q
.
(
*
ent
.
UserAttributeDefinitionQuery
);
ok
{
return
f
(
ctx
,
q
)
}
return
nil
,
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.UserAttributeDefinitionQuery"
,
q
)
}
// The TraverseUserAttributeDefinition type is an adapter to allow the use of ordinary function as Traverser.
type
TraverseUserAttributeDefinition
func
(
context
.
Context
,
*
ent
.
UserAttributeDefinitionQuery
)
error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func
(
f
TraverseUserAttributeDefinition
)
Intercept
(
next
ent
.
Querier
)
ent
.
Querier
{
return
next
}
// Traverse calls f(ctx, q).
func
(
f
TraverseUserAttributeDefinition
)
Traverse
(
ctx
context
.
Context
,
q
ent
.
Query
)
error
{
if
q
,
ok
:=
q
.
(
*
ent
.
UserAttributeDefinitionQuery
);
ok
{
return
f
(
ctx
,
q
)
}
return
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.UserAttributeDefinitionQuery"
,
q
)
}
// The UserAttributeValueFunc type is an adapter to allow the use of ordinary function as a Querier.
type
UserAttributeValueFunc
func
(
context
.
Context
,
*
ent
.
UserAttributeValueQuery
)
(
ent
.
Value
,
error
)
// Query calls f(ctx, q).
func
(
f
UserAttributeValueFunc
)
Query
(
ctx
context
.
Context
,
q
ent
.
Query
)
(
ent
.
Value
,
error
)
{
if
q
,
ok
:=
q
.
(
*
ent
.
UserAttributeValueQuery
);
ok
{
return
f
(
ctx
,
q
)
}
return
nil
,
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.UserAttributeValueQuery"
,
q
)
}
// The TraverseUserAttributeValue type is an adapter to allow the use of ordinary function as Traverser.
type
TraverseUserAttributeValue
func
(
context
.
Context
,
*
ent
.
UserAttributeValueQuery
)
error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func
(
f
TraverseUserAttributeValue
)
Intercept
(
next
ent
.
Querier
)
ent
.
Querier
{
return
next
}
// Traverse calls f(ctx, q).
func
(
f
TraverseUserAttributeValue
)
Traverse
(
ctx
context
.
Context
,
q
ent
.
Query
)
error
{
if
q
,
ok
:=
q
.
(
*
ent
.
UserAttributeValueQuery
);
ok
{
return
f
(
ctx
,
q
)
}
return
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.UserAttributeValueQuery"
,
q
)
}
// The UserSubscriptionFunc type is an adapter to allow the use of ordinary function as a Querier.
type
UserSubscriptionFunc
func
(
context
.
Context
,
*
ent
.
UserSubscriptionQuery
)
(
ent
.
Value
,
error
)
...
...
@@ -398,6 +454,10 @@ func NewQuery(q ent.Query) (Query, error) {
return
&
query
[
*
ent
.
UserQuery
,
predicate
.
User
,
user
.
OrderOption
]{
typ
:
ent
.
TypeUser
,
tq
:
q
},
nil
case
*
ent
.
UserAllowedGroupQuery
:
return
&
query
[
*
ent
.
UserAllowedGroupQuery
,
predicate
.
UserAllowedGroup
,
userallowedgroup
.
OrderOption
]{
typ
:
ent
.
TypeUserAllowedGroup
,
tq
:
q
},
nil
case
*
ent
.
UserAttributeDefinitionQuery
:
return
&
query
[
*
ent
.
UserAttributeDefinitionQuery
,
predicate
.
UserAttributeDefinition
,
userattributedefinition
.
OrderOption
]{
typ
:
ent
.
TypeUserAttributeDefinition
,
tq
:
q
},
nil
case
*
ent
.
UserAttributeValueQuery
:
return
&
query
[
*
ent
.
UserAttributeValueQuery
,
predicate
.
UserAttributeValue
,
userattributevalue
.
OrderOption
]{
typ
:
ent
.
TypeUserAttributeValue
,
tq
:
q
},
nil
case
*
ent
.
UserSubscriptionQuery
:
return
&
query
[
*
ent
.
UserSubscriptionQuery
,
predicate
.
UserSubscription
,
usersubscription
.
OrderOption
]{
typ
:
ent
.
TypeUserSubscription
,
tq
:
q
},
nil
default
:
...
...
backend/ent/migrate/schema.go
View file @
6cc7f997
...
...
@@ -477,7 +477,6 @@ var (
{
Name
:
"concurrency"
,
Type
:
field
.
TypeInt
,
Default
:
5
},
{
Name
:
"status"
,
Type
:
field
.
TypeString
,
Size
:
20
,
Default
:
"active"
},
{
Name
:
"username"
,
Type
:
field
.
TypeString
,
Size
:
100
,
Default
:
""
},
{
Name
:
"wechat"
,
Type
:
field
.
TypeString
,
Size
:
100
,
Default
:
""
},
{
Name
:
"notes"
,
Type
:
field
.
TypeString
,
Default
:
""
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"text"
}},
}
// UsersTable holds the schema information for the "users" table.
...
...
@@ -531,6 +530,92 @@ var (
},
},
}
// UserAttributeDefinitionsColumns holds the columns for the "user_attribute_definitions" table.
UserAttributeDefinitionsColumns
=
[]
*
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
:
"deleted_at"
,
Type
:
field
.
TypeTime
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"key"
,
Type
:
field
.
TypeString
,
Size
:
100
},
{
Name
:
"name"
,
Type
:
field
.
TypeString
,
Size
:
255
},
{
Name
:
"description"
,
Type
:
field
.
TypeString
,
Default
:
""
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"text"
}},
{
Name
:
"type"
,
Type
:
field
.
TypeString
,
Size
:
20
},
{
Name
:
"options"
,
Type
:
field
.
TypeJSON
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"jsonb"
}},
{
Name
:
"required"
,
Type
:
field
.
TypeBool
,
Default
:
false
},
{
Name
:
"validation"
,
Type
:
field
.
TypeJSON
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"jsonb"
}},
{
Name
:
"placeholder"
,
Type
:
field
.
TypeString
,
Size
:
255
,
Default
:
""
},
{
Name
:
"display_order"
,
Type
:
field
.
TypeInt
,
Default
:
0
},
{
Name
:
"enabled"
,
Type
:
field
.
TypeBool
,
Default
:
true
},
}
// UserAttributeDefinitionsTable holds the schema information for the "user_attribute_definitions" table.
UserAttributeDefinitionsTable
=
&
schema
.
Table
{
Name
:
"user_attribute_definitions"
,
Columns
:
UserAttributeDefinitionsColumns
,
PrimaryKey
:
[]
*
schema
.
Column
{
UserAttributeDefinitionsColumns
[
0
]},
Indexes
:
[]
*
schema
.
Index
{
{
Name
:
"userattributedefinition_key"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UserAttributeDefinitionsColumns
[
4
]},
},
{
Name
:
"userattributedefinition_enabled"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UserAttributeDefinitionsColumns
[
13
]},
},
{
Name
:
"userattributedefinition_display_order"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UserAttributeDefinitionsColumns
[
12
]},
},
{
Name
:
"userattributedefinition_deleted_at"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UserAttributeDefinitionsColumns
[
3
]},
},
},
}
// UserAttributeValuesColumns holds the columns for the "user_attribute_values" table.
UserAttributeValuesColumns
=
[]
*
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
:
"value"
,
Type
:
field
.
TypeString
,
Size
:
2147483647
,
Default
:
""
},
{
Name
:
"user_id"
,
Type
:
field
.
TypeInt64
},
{
Name
:
"attribute_id"
,
Type
:
field
.
TypeInt64
},
}
// UserAttributeValuesTable holds the schema information for the "user_attribute_values" table.
UserAttributeValuesTable
=
&
schema
.
Table
{
Name
:
"user_attribute_values"
,
Columns
:
UserAttributeValuesColumns
,
PrimaryKey
:
[]
*
schema
.
Column
{
UserAttributeValuesColumns
[
0
]},
ForeignKeys
:
[]
*
schema
.
ForeignKey
{
{
Symbol
:
"user_attribute_values_users_attribute_values"
,
Columns
:
[]
*
schema
.
Column
{
UserAttributeValuesColumns
[
4
]},
RefColumns
:
[]
*
schema
.
Column
{
UsersColumns
[
0
]},
OnDelete
:
schema
.
NoAction
,
},
{
Symbol
:
"user_attribute_values_user_attribute_definitions_values"
,
Columns
:
[]
*
schema
.
Column
{
UserAttributeValuesColumns
[
5
]},
RefColumns
:
[]
*
schema
.
Column
{
UserAttributeDefinitionsColumns
[
0
]},
OnDelete
:
schema
.
NoAction
,
},
},
Indexes
:
[]
*
schema
.
Index
{
{
Name
:
"userattributevalue_user_id_attribute_id"
,
Unique
:
true
,
Columns
:
[]
*
schema
.
Column
{
UserAttributeValuesColumns
[
4
],
UserAttributeValuesColumns
[
5
]},
},
{
Name
:
"userattributevalue_attribute_id"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UserAttributeValuesColumns
[
5
]},
},
},
}
// UserSubscriptionsColumns holds the columns for the "user_subscriptions" table.
UserSubscriptionsColumns
=
[]
*
schema
.
Column
{
{
Name
:
"id"
,
Type
:
field
.
TypeInt64
,
Increment
:
true
},
...
...
@@ -627,6 +712,8 @@ var (
UsageLogsTable
,
UsersTable
,
UserAllowedGroupsTable
,
UserAttributeDefinitionsTable
,
UserAttributeValuesTable
,
UserSubscriptionsTable
,
}
)
...
...
@@ -676,6 +763,14 @@ func init() {
UserAllowedGroupsTable
.
Annotation
=
&
entsql
.
Annotation
{
Table
:
"user_allowed_groups"
,
}
UserAttributeDefinitionsTable
.
Annotation
=
&
entsql
.
Annotation
{
Table
:
"user_attribute_definitions"
,
}
UserAttributeValuesTable
.
ForeignKeys
[
0
]
.
RefTable
=
UsersTable
UserAttributeValuesTable
.
ForeignKeys
[
1
]
.
RefTable
=
UserAttributeDefinitionsTable
UserAttributeValuesTable
.
Annotation
=
&
entsql
.
Annotation
{
Table
:
"user_attribute_values"
,
}
UserSubscriptionsTable
.
ForeignKeys
[
0
]
.
RefTable
=
GroupsTable
UserSubscriptionsTable
.
ForeignKeys
[
1
]
.
RefTable
=
UsersTable
UserSubscriptionsTable
.
ForeignKeys
[
2
]
.
RefTable
=
UsersTable
...
...
backend/ent/mutation.go
View file @
6cc7f997
This diff is collapsed.
Click to expand it.
backend/ent/predicate/predicate.go
View file @
6cc7f997
...
...
@@ -36,5 +36,11 @@ type User func(*sql.Selector)
// UserAllowedGroup is the predicate function for userallowedgroup builders.
type
UserAllowedGroup
func
(
*
sql
.
Selector
)
// UserAttributeDefinition is the predicate function for userattributedefinition builders.
type
UserAttributeDefinition
func
(
*
sql
.
Selector
)
// UserAttributeValue is the predicate function for userattributevalue builders.
type
UserAttributeValue
func
(
*
sql
.
Selector
)
// UserSubscription is the predicate function for usersubscription builders.
type
UserSubscription
func
(
*
sql
.
Selector
)
backend/ent/runtime/runtime.go
View file @
6cc7f997
...
...
@@ -16,6 +16,8 @@ import (
"github.com/Wei-Shaw/sub2api/ent/usagelog"
"github.com/Wei-Shaw/sub2api/ent/user"
"github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
"github.com/Wei-Shaw/sub2api/ent/userattributedefinition"
"github.com/Wei-Shaw/sub2api/ent/userattributevalue"
"github.com/Wei-Shaw/sub2api/ent/usersubscription"
)
...
...
@@ -604,14 +606,8 @@ func init() {
user
.
DefaultUsername
=
userDescUsername
.
Default
.
(
string
)
// user.UsernameValidator is a validator for the "username" field. It is called by the builders before save.
user
.
UsernameValidator
=
userDescUsername
.
Validators
[
0
]
.
(
func
(
string
)
error
)
// userDescWechat is the schema descriptor for wechat field.
userDescWechat
:=
userFields
[
7
]
.
Descriptor
()
// user.DefaultWechat holds the default value on creation for the wechat field.
user
.
DefaultWechat
=
userDescWechat
.
Default
.
(
string
)
// user.WechatValidator is a validator for the "wechat" field. It is called by the builders before save.
user
.
WechatValidator
=
userDescWechat
.
Validators
[
0
]
.
(
func
(
string
)
error
)
// userDescNotes is the schema descriptor for notes field.
userDescNotes
:=
userFields
[
8
]
.
Descriptor
()
userDescNotes
:=
userFields
[
7
]
.
Descriptor
()
// user.DefaultNotes holds the default value on creation for the notes field.
user
.
DefaultNotes
=
userDescNotes
.
Default
.
(
string
)
userallowedgroupFields
:=
schema
.
UserAllowedGroup
{}
.
Fields
()
...
...
@@ -620,6 +616,128 @@ func init() {
userallowedgroupDescCreatedAt
:=
userallowedgroupFields
[
2
]
.
Descriptor
()
// userallowedgroup.DefaultCreatedAt holds the default value on creation for the created_at field.
userallowedgroup
.
DefaultCreatedAt
=
userallowedgroupDescCreatedAt
.
Default
.
(
func
()
time
.
Time
)
userattributedefinitionMixin
:=
schema
.
UserAttributeDefinition
{}
.
Mixin
()
userattributedefinitionMixinHooks1
:=
userattributedefinitionMixin
[
1
]
.
Hooks
()
userattributedefinition
.
Hooks
[
0
]
=
userattributedefinitionMixinHooks1
[
0
]
userattributedefinitionMixinInters1
:=
userattributedefinitionMixin
[
1
]
.
Interceptors
()
userattributedefinition
.
Interceptors
[
0
]
=
userattributedefinitionMixinInters1
[
0
]
userattributedefinitionMixinFields0
:=
userattributedefinitionMixin
[
0
]
.
Fields
()
_
=
userattributedefinitionMixinFields0
userattributedefinitionFields
:=
schema
.
UserAttributeDefinition
{}
.
Fields
()
_
=
userattributedefinitionFields
// userattributedefinitionDescCreatedAt is the schema descriptor for created_at field.
userattributedefinitionDescCreatedAt
:=
userattributedefinitionMixinFields0
[
0
]
.
Descriptor
()
// userattributedefinition.DefaultCreatedAt holds the default value on creation for the created_at field.
userattributedefinition
.
DefaultCreatedAt
=
userattributedefinitionDescCreatedAt
.
Default
.
(
func
()
time
.
Time
)
// userattributedefinitionDescUpdatedAt is the schema descriptor for updated_at field.
userattributedefinitionDescUpdatedAt
:=
userattributedefinitionMixinFields0
[
1
]
.
Descriptor
()
// userattributedefinition.DefaultUpdatedAt holds the default value on creation for the updated_at field.
userattributedefinition
.
DefaultUpdatedAt
=
userattributedefinitionDescUpdatedAt
.
Default
.
(
func
()
time
.
Time
)
// userattributedefinition.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
userattributedefinition
.
UpdateDefaultUpdatedAt
=
userattributedefinitionDescUpdatedAt
.
UpdateDefault
.
(
func
()
time
.
Time
)
// userattributedefinitionDescKey is the schema descriptor for key field.
userattributedefinitionDescKey
:=
userattributedefinitionFields
[
0
]
.
Descriptor
()
// userattributedefinition.KeyValidator is a validator for the "key" field. It is called by the builders before save.
userattributedefinition
.
KeyValidator
=
func
()
func
(
string
)
error
{
validators
:=
userattributedefinitionDescKey
.
Validators
fns
:=
[
...
]
func
(
string
)
error
{
validators
[
0
]
.
(
func
(
string
)
error
),
validators
[
1
]
.
(
func
(
string
)
error
),
}
return
func
(
key
string
)
error
{
for
_
,
fn
:=
range
fns
{
if
err
:=
fn
(
key
);
err
!=
nil
{
return
err
}
}
return
nil
}
}()
// userattributedefinitionDescName is the schema descriptor for name field.
userattributedefinitionDescName
:=
userattributedefinitionFields
[
1
]
.
Descriptor
()
// userattributedefinition.NameValidator is a validator for the "name" field. It is called by the builders before save.
userattributedefinition
.
NameValidator
=
func
()
func
(
string
)
error
{
validators
:=
userattributedefinitionDescName
.
Validators
fns
:=
[
...
]
func
(
string
)
error
{
validators
[
0
]
.
(
func
(
string
)
error
),
validators
[
1
]
.
(
func
(
string
)
error
),
}
return
func
(
name
string
)
error
{
for
_
,
fn
:=
range
fns
{
if
err
:=
fn
(
name
);
err
!=
nil
{
return
err
}
}
return
nil
}
}()
// userattributedefinitionDescDescription is the schema descriptor for description field.
userattributedefinitionDescDescription
:=
userattributedefinitionFields
[
2
]
.
Descriptor
()
// userattributedefinition.DefaultDescription holds the default value on creation for the description field.
userattributedefinition
.
DefaultDescription
=
userattributedefinitionDescDescription
.
Default
.
(
string
)
// userattributedefinitionDescType is the schema descriptor for type field.
userattributedefinitionDescType
:=
userattributedefinitionFields
[
3
]
.
Descriptor
()
// userattributedefinition.TypeValidator is a validator for the "type" field. It is called by the builders before save.
userattributedefinition
.
TypeValidator
=
func
()
func
(
string
)
error
{
validators
:=
userattributedefinitionDescType
.
Validators
fns
:=
[
...
]
func
(
string
)
error
{
validators
[
0
]
.
(
func
(
string
)
error
),
validators
[
1
]
.
(
func
(
string
)
error
),
}
return
func
(
_type
string
)
error
{
for
_
,
fn
:=
range
fns
{
if
err
:=
fn
(
_type
);
err
!=
nil
{
return
err
}
}
return
nil
}
}()
// userattributedefinitionDescOptions is the schema descriptor for options field.
userattributedefinitionDescOptions
:=
userattributedefinitionFields
[
4
]
.
Descriptor
()
// userattributedefinition.DefaultOptions holds the default value on creation for the options field.
userattributedefinition
.
DefaultOptions
=
userattributedefinitionDescOptions
.
Default
.
([]
map
[
string
]
interface
{})
// userattributedefinitionDescRequired is the schema descriptor for required field.
userattributedefinitionDescRequired
:=
userattributedefinitionFields
[
5
]
.
Descriptor
()
// userattributedefinition.DefaultRequired holds the default value on creation for the required field.
userattributedefinition
.
DefaultRequired
=
userattributedefinitionDescRequired
.
Default
.
(
bool
)
// userattributedefinitionDescValidation is the schema descriptor for validation field.
userattributedefinitionDescValidation
:=
userattributedefinitionFields
[
6
]
.
Descriptor
()
// userattributedefinition.DefaultValidation holds the default value on creation for the validation field.
userattributedefinition
.
DefaultValidation
=
userattributedefinitionDescValidation
.
Default
.
(
map
[
string
]
interface
{})
// userattributedefinitionDescPlaceholder is the schema descriptor for placeholder field.
userattributedefinitionDescPlaceholder
:=
userattributedefinitionFields
[
7
]
.
Descriptor
()
// userattributedefinition.DefaultPlaceholder holds the default value on creation for the placeholder field.
userattributedefinition
.
DefaultPlaceholder
=
userattributedefinitionDescPlaceholder
.
Default
.
(
string
)
// userattributedefinition.PlaceholderValidator is a validator for the "placeholder" field. It is called by the builders before save.
userattributedefinition
.
PlaceholderValidator
=
userattributedefinitionDescPlaceholder
.
Validators
[
0
]
.
(
func
(
string
)
error
)
// userattributedefinitionDescDisplayOrder is the schema descriptor for display_order field.
userattributedefinitionDescDisplayOrder
:=
userattributedefinitionFields
[
8
]
.
Descriptor
()
// userattributedefinition.DefaultDisplayOrder holds the default value on creation for the display_order field.
userattributedefinition
.
DefaultDisplayOrder
=
userattributedefinitionDescDisplayOrder
.
Default
.
(
int
)
// userattributedefinitionDescEnabled is the schema descriptor for enabled field.
userattributedefinitionDescEnabled
:=
userattributedefinitionFields
[
9
]
.
Descriptor
()
// userattributedefinition.DefaultEnabled holds the default value on creation for the enabled field.
userattributedefinition
.
DefaultEnabled
=
userattributedefinitionDescEnabled
.
Default
.
(
bool
)
userattributevalueMixin
:=
schema
.
UserAttributeValue
{}
.
Mixin
()
userattributevalueMixinFields0
:=
userattributevalueMixin
[
0
]
.
Fields
()
_
=
userattributevalueMixinFields0
userattributevalueFields
:=
schema
.
UserAttributeValue
{}
.
Fields
()
_
=
userattributevalueFields
// userattributevalueDescCreatedAt is the schema descriptor for created_at field.
userattributevalueDescCreatedAt
:=
userattributevalueMixinFields0
[
0
]
.
Descriptor
()
// userattributevalue.DefaultCreatedAt holds the default value on creation for the created_at field.
userattributevalue
.
DefaultCreatedAt
=
userattributevalueDescCreatedAt
.
Default
.
(
func
()
time
.
Time
)
// userattributevalueDescUpdatedAt is the schema descriptor for updated_at field.
userattributevalueDescUpdatedAt
:=
userattributevalueMixinFields0
[
1
]
.
Descriptor
()
// userattributevalue.DefaultUpdatedAt holds the default value on creation for the updated_at field.
userattributevalue
.
DefaultUpdatedAt
=
userattributevalueDescUpdatedAt
.
Default
.
(
func
()
time
.
Time
)
// userattributevalue.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
userattributevalue
.
UpdateDefaultUpdatedAt
=
userattributevalueDescUpdatedAt
.
UpdateDefault
.
(
func
()
time
.
Time
)
// userattributevalueDescValue is the schema descriptor for value field.
userattributevalueDescValue
:=
userattributevalueFields
[
2
]
.
Descriptor
()
// userattributevalue.DefaultValue holds the default value on creation for the value field.
userattributevalue
.
DefaultValue
=
userattributevalueDescValue
.
Default
.
(
string
)
usersubscriptionMixin
:=
schema
.
UserSubscription
{}
.
Mixin
()
usersubscriptionMixinHooks1
:=
usersubscriptionMixin
[
1
]
.
Hooks
()
usersubscription
.
Hooks
[
0
]
=
usersubscriptionMixinHooks1
[
0
]
...
...
backend/ent/schema/user.go
View file @
6cc7f997
...
...
@@ -57,9 +57,7 @@ func (User) Fields() []ent.Field {
field
.
String
(
"username"
)
.
MaxLen
(
100
)
.
Default
(
""
),
field
.
String
(
"wechat"
)
.
MaxLen
(
100
)
.
Default
(
""
),
// wechat field migrated to user_attribute_values (see migration 019)
field
.
String
(
"notes"
)
.
SchemaType
(
map
[
string
]
string
{
dialect
.
Postgres
:
"text"
})
.
Default
(
""
),
...
...
@@ -75,6 +73,7 @@ func (User) Edges() []ent.Edge {
edge
.
To
(
"allowed_groups"
,
Group
.
Type
)
.
Through
(
"user_allowed_groups"
,
UserAllowedGroup
.
Type
),
edge
.
To
(
"usage_logs"
,
UsageLog
.
Type
),
edge
.
To
(
"attribute_values"
,
UserAttributeValue
.
Type
),
}
}
...
...
backend/ent/schema/user_attribute_definition.go
0 → 100644
View file @
6cc7f997
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"
)
// UserAttributeDefinition holds the schema definition for custom user attributes.
//
// This entity defines the metadata for user attributes, such as:
// - Attribute key (unique identifier like "company_name")
// - Display name shown in forms
// - Field type (text, number, select, etc.)
// - Validation rules
// - Whether the field is required or enabled
type
UserAttributeDefinition
struct
{
ent
.
Schema
}
func
(
UserAttributeDefinition
)
Annotations
()
[]
schema
.
Annotation
{
return
[]
schema
.
Annotation
{
entsql
.
Annotation
{
Table
:
"user_attribute_definitions"
},
}
}
func
(
UserAttributeDefinition
)
Mixin
()
[]
ent
.
Mixin
{
return
[]
ent
.
Mixin
{
mixins
.
TimeMixin
{},
mixins
.
SoftDeleteMixin
{},
}
}
func
(
UserAttributeDefinition
)
Fields
()
[]
ent
.
Field
{
return
[]
ent
.
Field
{
// key: Unique identifier for the attribute (e.g., "company_name")
// Used for programmatic reference
field
.
String
(
"key"
)
.
MaxLen
(
100
)
.
NotEmpty
(),
// name: Display name shown in forms (e.g., "Company Name")
field
.
String
(
"name"
)
.
MaxLen
(
255
)
.
NotEmpty
(),
// description: Optional description/help text for the attribute
field
.
String
(
"description"
)
.
SchemaType
(
map
[
string
]
string
{
dialect
.
Postgres
:
"text"
})
.
Default
(
""
),
// type: Attribute type - text, textarea, number, email, url, date, select, multi_select
field
.
String
(
"type"
)
.
MaxLen
(
20
)
.
NotEmpty
(),
// options: Select options for select/multi_select types (stored as JSONB)
// Format: [{"value": "xxx", "label": "XXX"}, ...]
field
.
JSON
(
"options"
,
[]
map
[
string
]
any
{})
.
Default
([]
map
[
string
]
any
{})
.
SchemaType
(
map
[
string
]
string
{
dialect
.
Postgres
:
"jsonb"
}),
// required: Whether this attribute is required when editing a user
field
.
Bool
(
"required"
)
.
Default
(
false
),
// validation: Validation rules for the attribute value (stored as JSONB)
// Format: {"min_length": 1, "max_length": 100, "min": 0, "max": 100, "pattern": "^[a-z]+$", "message": "..."}
field
.
JSON
(
"validation"
,
map
[
string
]
any
{})
.
Default
(
map
[
string
]
any
{})
.
SchemaType
(
map
[
string
]
string
{
dialect
.
Postgres
:
"jsonb"
}),
// placeholder: Placeholder text shown in input fields
field
.
String
(
"placeholder"
)
.
MaxLen
(
255
)
.
Default
(
""
),
// display_order: Order in which attributes are displayed (lower = first)
field
.
Int
(
"display_order"
)
.
Default
(
0
),
// enabled: Whether this attribute is active and shown in forms
field
.
Bool
(
"enabled"
)
.
Default
(
true
),
}
}
func
(
UserAttributeDefinition
)
Edges
()
[]
ent
.
Edge
{
return
[]
ent
.
Edge
{
// values: All user values for this attribute definition
edge
.
To
(
"values"
,
UserAttributeValue
.
Type
),
}
}
func
(
UserAttributeDefinition
)
Indexes
()
[]
ent
.
Index
{
return
[]
ent
.
Index
{
// Partial unique index on key (WHERE deleted_at IS NULL) via migration
index
.
Fields
(
"key"
),
index
.
Fields
(
"enabled"
),
index
.
Fields
(
"display_order"
),
index
.
Fields
(
"deleted_at"
),
}
}
backend/ent/schema/user_attribute_value.go
0 → 100644
View file @
6cc7f997
package
schema
import
(
"github.com/Wei-Shaw/sub2api/ent/schema/mixins"
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
// UserAttributeValue holds a user's value for a specific attribute.
//
// This entity stores the actual values that users have for each attribute definition.
// Values are stored as strings and converted to the appropriate type by the application.
type
UserAttributeValue
struct
{
ent
.
Schema
}
func
(
UserAttributeValue
)
Annotations
()
[]
schema
.
Annotation
{
return
[]
schema
.
Annotation
{
entsql
.
Annotation
{
Table
:
"user_attribute_values"
},
}
}
func
(
UserAttributeValue
)
Mixin
()
[]
ent
.
Mixin
{
return
[]
ent
.
Mixin
{
// Only use TimeMixin, no soft delete - values are hard deleted
mixins
.
TimeMixin
{},
}
}
func
(
UserAttributeValue
)
Fields
()
[]
ent
.
Field
{
return
[]
ent
.
Field
{
// user_id: References the user this value belongs to
field
.
Int64
(
"user_id"
),
// attribute_id: References the attribute definition
field
.
Int64
(
"attribute_id"
),
// value: The actual value stored as a string
// For multi_select, this is a JSON array string
field
.
Text
(
"value"
)
.
Default
(
""
),
}
}
func
(
UserAttributeValue
)
Edges
()
[]
ent
.
Edge
{
return
[]
ent
.
Edge
{
// user: The user who owns this attribute value
edge
.
From
(
"user"
,
User
.
Type
)
.
Ref
(
"attribute_values"
)
.
Field
(
"user_id"
)
.
Required
()
.
Unique
(),
// definition: The attribute definition this value is for
edge
.
From
(
"definition"
,
UserAttributeDefinition
.
Type
)
.
Ref
(
"values"
)
.
Field
(
"attribute_id"
)
.
Required
()
.
Unique
(),
}
}
func
(
UserAttributeValue
)
Indexes
()
[]
ent
.
Index
{
return
[]
ent
.
Index
{
// Unique index on (user_id, attribute_id)
index
.
Fields
(
"user_id"
,
"attribute_id"
)
.
Unique
(),
index
.
Fields
(
"attribute_id"
),
}
}
backend/ent/tx.go
View file @
6cc7f997
...
...
@@ -34,6 +34,10 @@ type Tx struct {
User
*
UserClient
// UserAllowedGroup is the client for interacting with the UserAllowedGroup builders.
UserAllowedGroup
*
UserAllowedGroupClient
// UserAttributeDefinition is the client for interacting with the UserAttributeDefinition builders.
UserAttributeDefinition
*
UserAttributeDefinitionClient
// UserAttributeValue is the client for interacting with the UserAttributeValue builders.
UserAttributeValue
*
UserAttributeValueClient
// UserSubscription is the client for interacting with the UserSubscription builders.
UserSubscription
*
UserSubscriptionClient
...
...
@@ -177,6 +181,8 @@ func (tx *Tx) init() {
tx
.
UsageLog
=
NewUsageLogClient
(
tx
.
config
)
tx
.
User
=
NewUserClient
(
tx
.
config
)
tx
.
UserAllowedGroup
=
NewUserAllowedGroupClient
(
tx
.
config
)
tx
.
UserAttributeDefinition
=
NewUserAttributeDefinitionClient
(
tx
.
config
)
tx
.
UserAttributeValue
=
NewUserAttributeValueClient
(
tx
.
config
)
tx
.
UserSubscription
=
NewUserSubscriptionClient
(
tx
.
config
)
}
...
...
backend/ent/user.go
View file @
6cc7f997
...
...
@@ -37,8 +37,6 @@ type User struct {
Status
string
`json:"status,omitempty"`
// Username holds the value of the "username" field.
Username
string
`json:"username,omitempty"`
// Wechat holds the value of the "wechat" field.
Wechat
string
`json:"wechat,omitempty"`
// Notes holds the value of the "notes" field.
Notes
string
`json:"notes,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
...
...
@@ -61,11 +59,13 @@ type UserEdges struct {
AllowedGroups
[]
*
Group
`json:"allowed_groups,omitempty"`
// UsageLogs holds the value of the usage_logs edge.
UsageLogs
[]
*
UsageLog
`json:"usage_logs,omitempty"`
// AttributeValues holds the value of the attribute_values edge.
AttributeValues
[]
*
UserAttributeValue
`json:"attribute_values,omitempty"`
// UserAllowedGroups holds the value of the user_allowed_groups edge.
UserAllowedGroups
[]
*
UserAllowedGroup
`json:"user_allowed_groups,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes
[
7
]
bool
loadedTypes
[
8
]
bool
}
// APIKeysOrErr returns the APIKeys value or an error if the edge
...
...
@@ -122,10 +122,19 @@ func (e UserEdges) UsageLogsOrErr() ([]*UsageLog, error) {
return
nil
,
&
NotLoadedError
{
edge
:
"usage_logs"
}
}
// AttributeValuesOrErr returns the AttributeValues value or an error if the edge
// was not loaded in eager-loading.
func
(
e
UserEdges
)
AttributeValuesOrErr
()
([]
*
UserAttributeValue
,
error
)
{
if
e
.
loadedTypes
[
6
]
{
return
e
.
AttributeValues
,
nil
}
return
nil
,
&
NotLoadedError
{
edge
:
"attribute_values"
}
}
// UserAllowedGroupsOrErr returns the UserAllowedGroups value or an error if the edge
// was not loaded in eager-loading.
func
(
e
UserEdges
)
UserAllowedGroupsOrErr
()
([]
*
UserAllowedGroup
,
error
)
{
if
e
.
loadedTypes
[
6
]
{
if
e
.
loadedTypes
[
7
]
{
return
e
.
UserAllowedGroups
,
nil
}
return
nil
,
&
NotLoadedError
{
edge
:
"user_allowed_groups"
}
...
...
@@ -140,7 +149,7 @@ func (*User) scanValues(columns []string) ([]any, error) {
values
[
i
]
=
new
(
sql
.
NullFloat64
)
case
user
.
FieldID
,
user
.
FieldConcurrency
:
values
[
i
]
=
new
(
sql
.
NullInt64
)
case
user
.
FieldEmail
,
user
.
FieldPasswordHash
,
user
.
FieldRole
,
user
.
FieldStatus
,
user
.
FieldUsername
,
user
.
FieldWechat
,
user
.
FieldNotes
:
case
user
.
FieldEmail
,
user
.
FieldPasswordHash
,
user
.
FieldRole
,
user
.
FieldStatus
,
user
.
FieldUsername
,
user
.
FieldNotes
:
values
[
i
]
=
new
(
sql
.
NullString
)
case
user
.
FieldCreatedAt
,
user
.
FieldUpdatedAt
,
user
.
FieldDeletedAt
:
values
[
i
]
=
new
(
sql
.
NullTime
)
...
...
@@ -226,12 +235,6 @@ func (_m *User) assignValues(columns []string, values []any) error {
}
else
if
value
.
Valid
{
_m
.
Username
=
value
.
String
}
case
user
.
FieldWechat
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullString
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field wechat"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
Wechat
=
value
.
String
}
case
user
.
FieldNotes
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullString
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field notes"
,
values
[
i
])
...
...
@@ -281,6 +284,11 @@ func (_m *User) QueryUsageLogs() *UsageLogQuery {
return
NewUserClient
(
_m
.
config
)
.
QueryUsageLogs
(
_m
)
}
// QueryAttributeValues queries the "attribute_values" edge of the User entity.
func
(
_m
*
User
)
QueryAttributeValues
()
*
UserAttributeValueQuery
{
return
NewUserClient
(
_m
.
config
)
.
QueryAttributeValues
(
_m
)
}
// QueryUserAllowedGroups queries the "user_allowed_groups" edge of the User entity.
func
(
_m
*
User
)
QueryUserAllowedGroups
()
*
UserAllowedGroupQuery
{
return
NewUserClient
(
_m
.
config
)
.
QueryUserAllowedGroups
(
_m
)
...
...
@@ -341,9 +349,6 @@ func (_m *User) String() string {
builder
.
WriteString
(
"username="
)
builder
.
WriteString
(
_m
.
Username
)
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"wechat="
)
builder
.
WriteString
(
_m
.
Wechat
)
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"notes="
)
builder
.
WriteString
(
_m
.
Notes
)
builder
.
WriteByte
(
')'
)
...
...
backend/ent/user/user.go
View file @
6cc7f997
...
...
@@ -35,8 +35,6 @@ const (
FieldStatus
=
"status"
// FieldUsername holds the string denoting the username field in the database.
FieldUsername
=
"username"
// FieldWechat holds the string denoting the wechat field in the database.
FieldWechat
=
"wechat"
// FieldNotes holds the string denoting the notes field in the database.
FieldNotes
=
"notes"
// EdgeAPIKeys holds the string denoting the api_keys edge name in mutations.
...
...
@@ -51,6 +49,8 @@ const (
EdgeAllowedGroups
=
"allowed_groups"
// EdgeUsageLogs holds the string denoting the usage_logs edge name in mutations.
EdgeUsageLogs
=
"usage_logs"
// EdgeAttributeValues holds the string denoting the attribute_values edge name in mutations.
EdgeAttributeValues
=
"attribute_values"
// EdgeUserAllowedGroups holds the string denoting the user_allowed_groups edge name in mutations.
EdgeUserAllowedGroups
=
"user_allowed_groups"
// Table holds the table name of the user in the database.
...
...
@@ -95,6 +95,13 @@ const (
UsageLogsInverseTable
=
"usage_logs"
// UsageLogsColumn is the table column denoting the usage_logs relation/edge.
UsageLogsColumn
=
"user_id"
// AttributeValuesTable is the table that holds the attribute_values relation/edge.
AttributeValuesTable
=
"user_attribute_values"
// AttributeValuesInverseTable is the table name for the UserAttributeValue entity.
// It exists in this package in order to avoid circular dependency with the "userattributevalue" package.
AttributeValuesInverseTable
=
"user_attribute_values"
// AttributeValuesColumn is the table column denoting the attribute_values relation/edge.
AttributeValuesColumn
=
"user_id"
// UserAllowedGroupsTable is the table that holds the user_allowed_groups relation/edge.
UserAllowedGroupsTable
=
"user_allowed_groups"
// UserAllowedGroupsInverseTable is the table name for the UserAllowedGroup entity.
...
...
@@ -117,7 +124,6 @@ var Columns = []string{
FieldConcurrency
,
FieldStatus
,
FieldUsername
,
FieldWechat
,
FieldNotes
,
}
...
...
@@ -171,10 +177,6 @@ var (
DefaultUsername
string
// UsernameValidator is a validator for the "username" field. It is called by the builders before save.
UsernameValidator
func
(
string
)
error
// DefaultWechat holds the default value on creation for the "wechat" field.
DefaultWechat
string
// WechatValidator is a validator for the "wechat" field. It is called by the builders before save.
WechatValidator
func
(
string
)
error
// DefaultNotes holds the default value on creation for the "notes" field.
DefaultNotes
string
)
...
...
@@ -237,11 +239,6 @@ func ByUsername(opts ...sql.OrderTermOption) OrderOption {
return
sql
.
OrderByField
(
FieldUsername
,
opts
...
)
.
ToFunc
()
}
// ByWechat orders the results by the wechat field.
func
ByWechat
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldWechat
,
opts
...
)
.
ToFunc
()
}
// ByNotes orders the results by the notes field.
func
ByNotes
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldNotes
,
opts
...
)
.
ToFunc
()
...
...
@@ -331,6 +328,20 @@ func ByUsageLogs(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
}
}
// ByAttributeValuesCount orders the results by attribute_values count.
func
ByAttributeValuesCount
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
func
(
s
*
sql
.
Selector
)
{
sqlgraph
.
OrderByNeighborsCount
(
s
,
newAttributeValuesStep
(),
opts
...
)
}
}
// ByAttributeValues orders the results by attribute_values terms.
func
ByAttributeValues
(
term
sql
.
OrderTerm
,
terms
...
sql
.
OrderTerm
)
OrderOption
{
return
func
(
s
*
sql
.
Selector
)
{
sqlgraph
.
OrderByNeighborTerms
(
s
,
newAttributeValuesStep
(),
append
([]
sql
.
OrderTerm
{
term
},
terms
...
)
...
)
}
}
// ByUserAllowedGroupsCount orders the results by user_allowed_groups count.
func
ByUserAllowedGroupsCount
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
func
(
s
*
sql
.
Selector
)
{
...
...
@@ -386,6 +397,13 @@ func newUsageLogsStep() *sqlgraph.Step {
sqlgraph
.
Edge
(
sqlgraph
.
O2M
,
false
,
UsageLogsTable
,
UsageLogsColumn
),
)
}
func
newAttributeValuesStep
()
*
sqlgraph
.
Step
{
return
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
Table
,
FieldID
),
sqlgraph
.
To
(
AttributeValuesInverseTable
,
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
O2M
,
false
,
AttributeValuesTable
,
AttributeValuesColumn
),
)
}
func
newUserAllowedGroupsStep
()
*
sqlgraph
.
Step
{
return
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
Table
,
FieldID
),
...
...
backend/ent/user/where.go
View file @
6cc7f997
...
...
@@ -105,11 +105,6 @@ func Username(v string) predicate.User {
return
predicate
.
User
(
sql
.
FieldEQ
(
FieldUsername
,
v
))
}
// Wechat applies equality check predicate on the "wechat" field. It's identical to WechatEQ.
func
Wechat
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldEQ
(
FieldWechat
,
v
))
}
// Notes applies equality check predicate on the "notes" field. It's identical to NotesEQ.
func
Notes
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldEQ
(
FieldNotes
,
v
))
...
...
@@ -650,71 +645,6 @@ func UsernameContainsFold(v string) predicate.User {
return
predicate
.
User
(
sql
.
FieldContainsFold
(
FieldUsername
,
v
))
}
// WechatEQ applies the EQ predicate on the "wechat" field.
func
WechatEQ
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldEQ
(
FieldWechat
,
v
))
}
// WechatNEQ applies the NEQ predicate on the "wechat" field.
func
WechatNEQ
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldNEQ
(
FieldWechat
,
v
))
}
// WechatIn applies the In predicate on the "wechat" field.
func
WechatIn
(
vs
...
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldIn
(
FieldWechat
,
vs
...
))
}
// WechatNotIn applies the NotIn predicate on the "wechat" field.
func
WechatNotIn
(
vs
...
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldNotIn
(
FieldWechat
,
vs
...
))
}
// WechatGT applies the GT predicate on the "wechat" field.
func
WechatGT
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldGT
(
FieldWechat
,
v
))
}
// WechatGTE applies the GTE predicate on the "wechat" field.
func
WechatGTE
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldGTE
(
FieldWechat
,
v
))
}
// WechatLT applies the LT predicate on the "wechat" field.
func
WechatLT
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldLT
(
FieldWechat
,
v
))
}
// WechatLTE applies the LTE predicate on the "wechat" field.
func
WechatLTE
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldLTE
(
FieldWechat
,
v
))
}
// WechatContains applies the Contains predicate on the "wechat" field.
func
WechatContains
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldContains
(
FieldWechat
,
v
))
}
// WechatHasPrefix applies the HasPrefix predicate on the "wechat" field.
func
WechatHasPrefix
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldHasPrefix
(
FieldWechat
,
v
))
}
// WechatHasSuffix applies the HasSuffix predicate on the "wechat" field.
func
WechatHasSuffix
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldHasSuffix
(
FieldWechat
,
v
))
}
// WechatEqualFold applies the EqualFold predicate on the "wechat" field.
func
WechatEqualFold
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldEqualFold
(
FieldWechat
,
v
))
}
// WechatContainsFold applies the ContainsFold predicate on the "wechat" field.
func
WechatContainsFold
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldContainsFold
(
FieldWechat
,
v
))
}
// NotesEQ applies the EQ predicate on the "notes" field.
func
NotesEQ
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldEQ
(
FieldNotes
,
v
))
...
...
@@ -918,6 +848,29 @@ func HasUsageLogsWith(preds ...predicate.UsageLog) predicate.User {
})
}
// HasAttributeValues applies the HasEdge predicate on the "attribute_values" edge.
func
HasAttributeValues
()
predicate
.
User
{
return
predicate
.
User
(
func
(
s
*
sql
.
Selector
)
{
step
:=
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
Table
,
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
O2M
,
false
,
AttributeValuesTable
,
AttributeValuesColumn
),
)
sqlgraph
.
HasNeighbors
(
s
,
step
)
})
}
// HasAttributeValuesWith applies the HasEdge predicate on the "attribute_values" edge with a given conditions (other predicates).
func
HasAttributeValuesWith
(
preds
...
predicate
.
UserAttributeValue
)
predicate
.
User
{
return
predicate
.
User
(
func
(
s
*
sql
.
Selector
)
{
step
:=
newAttributeValuesStep
()
sqlgraph
.
HasNeighborsWith
(
s
,
step
,
func
(
s
*
sql
.
Selector
)
{
for
_
,
p
:=
range
preds
{
p
(
s
)
}
})
})
}
// HasUserAllowedGroups applies the HasEdge predicate on the "user_allowed_groups" edge.
func
HasUserAllowedGroups
()
predicate
.
User
{
return
predicate
.
User
(
func
(
s
*
sql
.
Selector
)
{
...
...
backend/ent/user_create.go
View file @
6cc7f997
...
...
@@ -16,6 +16,7 @@ import (
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/usagelog"
"github.com/Wei-Shaw/sub2api/ent/user"
"github.com/Wei-Shaw/sub2api/ent/userattributevalue"
"github.com/Wei-Shaw/sub2api/ent/usersubscription"
)
...
...
@@ -151,20 +152,6 @@ func (_c *UserCreate) SetNillableUsername(v *string) *UserCreate {
return
_c
}
// SetWechat sets the "wechat" field.
func
(
_c
*
UserCreate
)
SetWechat
(
v
string
)
*
UserCreate
{
_c
.
mutation
.
SetWechat
(
v
)
return
_c
}
// SetNillableWechat sets the "wechat" field if the given value is not nil.
func
(
_c
*
UserCreate
)
SetNillableWechat
(
v
*
string
)
*
UserCreate
{
if
v
!=
nil
{
_c
.
SetWechat
(
*
v
)
}
return
_c
}
// SetNotes sets the "notes" field.
func
(
_c
*
UserCreate
)
SetNotes
(
v
string
)
*
UserCreate
{
_c
.
mutation
.
SetNotes
(
v
)
...
...
@@ -269,6 +256,21 @@ func (_c *UserCreate) AddUsageLogs(v ...*UsageLog) *UserCreate {
return
_c
.
AddUsageLogIDs
(
ids
...
)
}
// AddAttributeValueIDs adds the "attribute_values" edge to the UserAttributeValue entity by IDs.
func
(
_c
*
UserCreate
)
AddAttributeValueIDs
(
ids
...
int64
)
*
UserCreate
{
_c
.
mutation
.
AddAttributeValueIDs
(
ids
...
)
return
_c
}
// AddAttributeValues adds the "attribute_values" edges to the UserAttributeValue entity.
func
(
_c
*
UserCreate
)
AddAttributeValues
(
v
...*
UserAttributeValue
)
*
UserCreate
{
ids
:=
make
([]
int64
,
len
(
v
))
for
i
:=
range
v
{
ids
[
i
]
=
v
[
i
]
.
ID
}
return
_c
.
AddAttributeValueIDs
(
ids
...
)
}
// Mutation returns the UserMutation object of the builder.
func
(
_c
*
UserCreate
)
Mutation
()
*
UserMutation
{
return
_c
.
mutation
...
...
@@ -340,10 +342,6 @@ func (_c *UserCreate) defaults() error {
v
:=
user
.
DefaultUsername
_c
.
mutation
.
SetUsername
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
Wechat
();
!
ok
{
v
:=
user
.
DefaultWechat
_c
.
mutation
.
SetWechat
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
Notes
();
!
ok
{
v
:=
user
.
DefaultNotes
_c
.
mutation
.
SetNotes
(
v
)
...
...
@@ -405,14 +403,6 @@ func (_c *UserCreate) check() error {
return
&
ValidationError
{
Name
:
"username"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "User.username": %w`
,
err
)}
}
}
if
_
,
ok
:=
_c
.
mutation
.
Wechat
();
!
ok
{
return
&
ValidationError
{
Name
:
"wechat"
,
err
:
errors
.
New
(
`ent: missing required field "User.wechat"`
)}
}
if
v
,
ok
:=
_c
.
mutation
.
Wechat
();
ok
{
if
err
:=
user
.
WechatValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"wechat"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "User.wechat": %w`
,
err
)}
}
}
if
_
,
ok
:=
_c
.
mutation
.
Notes
();
!
ok
{
return
&
ValidationError
{
Name
:
"notes"
,
err
:
errors
.
New
(
`ent: missing required field "User.notes"`
)}
}
...
...
@@ -483,10 +473,6 @@ func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
_spec
.
SetField
(
user
.
FieldUsername
,
field
.
TypeString
,
value
)
_node
.
Username
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
Wechat
();
ok
{
_spec
.
SetField
(
user
.
FieldWechat
,
field
.
TypeString
,
value
)
_node
.
Wechat
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
Notes
();
ok
{
_spec
.
SetField
(
user
.
FieldNotes
,
field
.
TypeString
,
value
)
_node
.
Notes
=
value
...
...
@@ -591,6 +577,22 @@ func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
}
_spec
.
Edges
=
append
(
_spec
.
Edges
,
edge
)
}
if
nodes
:=
_c
.
mutation
.
AttributeValuesIDs
();
len
(
nodes
)
>
0
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
user
.
AttributeValuesTable
,
Columns
:
[]
string
{
user
.
AttributeValuesColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
userattributevalue
.
FieldID
,
field
.
TypeInt64
),
},
}
for
_
,
k
:=
range
nodes
{
edge
.
Target
.
Nodes
=
append
(
edge
.
Target
.
Nodes
,
k
)
}
_spec
.
Edges
=
append
(
_spec
.
Edges
,
edge
)
}
return
_node
,
_spec
}
...
...
@@ -769,18 +771,6 @@ func (u *UserUpsert) UpdateUsername() *UserUpsert {
return
u
}
// SetWechat sets the "wechat" field.
func
(
u
*
UserUpsert
)
SetWechat
(
v
string
)
*
UserUpsert
{
u
.
Set
(
user
.
FieldWechat
,
v
)
return
u
}
// UpdateWechat sets the "wechat" field to the value that was provided on create.
func
(
u
*
UserUpsert
)
UpdateWechat
()
*
UserUpsert
{
u
.
SetExcluded
(
user
.
FieldWechat
)
return
u
}
// SetNotes sets the "notes" field.
func
(
u
*
UserUpsert
)
SetNotes
(
v
string
)
*
UserUpsert
{
u
.
Set
(
user
.
FieldNotes
,
v
)
...
...
@@ -985,20 +975,6 @@ func (u *UserUpsertOne) UpdateUsername() *UserUpsertOne {
})
}
// SetWechat sets the "wechat" field.
func
(
u
*
UserUpsertOne
)
SetWechat
(
v
string
)
*
UserUpsertOne
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
SetWechat
(
v
)
})
}
// UpdateWechat sets the "wechat" field to the value that was provided on create.
func
(
u
*
UserUpsertOne
)
UpdateWechat
()
*
UserUpsertOne
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
UpdateWechat
()
})
}
// SetNotes sets the "notes" field.
func
(
u
*
UserUpsertOne
)
SetNotes
(
v
string
)
*
UserUpsertOne
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
...
...
@@ -1371,20 +1347,6 @@ func (u *UserUpsertBulk) UpdateUsername() *UserUpsertBulk {
})
}
// SetWechat sets the "wechat" field.
func
(
u
*
UserUpsertBulk
)
SetWechat
(
v
string
)
*
UserUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
SetWechat
(
v
)
})
}
// UpdateWechat sets the "wechat" field to the value that was provided on create.
func
(
u
*
UserUpsertBulk
)
UpdateWechat
()
*
UserUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
UpdateWechat
()
})
}
// SetNotes sets the "notes" field.
func
(
u
*
UserUpsertBulk
)
SetNotes
(
v
string
)
*
UserUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
...
...
backend/ent/user_query.go
View file @
6cc7f997
...
...
@@ -19,6 +19,7 @@ import (
"github.com/Wei-Shaw/sub2api/ent/usagelog"
"github.com/Wei-Shaw/sub2api/ent/user"
"github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
"github.com/Wei-Shaw/sub2api/ent/userattributevalue"
"github.com/Wei-Shaw/sub2api/ent/usersubscription"
)
...
...
@@ -35,6 +36,7 @@ type UserQuery struct {
withAssignedSubscriptions
*
UserSubscriptionQuery
withAllowedGroups
*
GroupQuery
withUsageLogs
*
UsageLogQuery
withAttributeValues
*
UserAttributeValueQuery
withUserAllowedGroups
*
UserAllowedGroupQuery
// intermediate query (i.e. traversal path).
sql
*
sql
.
Selector
...
...
@@ -204,6 +206,28 @@ func (_q *UserQuery) QueryUsageLogs() *UsageLogQuery {
return
query
}
// QueryAttributeValues chains the current query on the "attribute_values" edge.
func
(
_q
*
UserQuery
)
QueryAttributeValues
()
*
UserAttributeValueQuery
{
query
:=
(
&
UserAttributeValueClient
{
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
(
userattributevalue
.
Table
,
userattributevalue
.
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
O2M
,
false
,
user
.
AttributeValuesTable
,
user
.
AttributeValuesColumn
),
)
fromU
=
sqlgraph
.
SetNeighbors
(
_q
.
driver
.
Dialect
(),
step
)
return
fromU
,
nil
}
return
query
}
// QueryUserAllowedGroups chains the current query on the "user_allowed_groups" edge.
func
(
_q
*
UserQuery
)
QueryUserAllowedGroups
()
*
UserAllowedGroupQuery
{
query
:=
(
&
UserAllowedGroupClient
{
config
:
_q
.
config
})
.
Query
()
...
...
@@ -424,6 +448,7 @@ func (_q *UserQuery) Clone() *UserQuery {
withAssignedSubscriptions
:
_q
.
withAssignedSubscriptions
.
Clone
(),
withAllowedGroups
:
_q
.
withAllowedGroups
.
Clone
(),
withUsageLogs
:
_q
.
withUsageLogs
.
Clone
(),
withAttributeValues
:
_q
.
withAttributeValues
.
Clone
(),
withUserAllowedGroups
:
_q
.
withUserAllowedGroups
.
Clone
(),
// clone intermediate query.
sql
:
_q
.
sql
.
Clone
(),
...
...
@@ -497,6 +522,17 @@ func (_q *UserQuery) WithUsageLogs(opts ...func(*UsageLogQuery)) *UserQuery {
return
_q
}
// WithAttributeValues tells the query-builder to eager-load the nodes that are connected to
// the "attribute_values" edge. The optional arguments are used to configure the query builder of the edge.
func
(
_q
*
UserQuery
)
WithAttributeValues
(
opts
...
func
(
*
UserAttributeValueQuery
))
*
UserQuery
{
query
:=
(
&
UserAttributeValueClient
{
config
:
_q
.
config
})
.
Query
()
for
_
,
opt
:=
range
opts
{
opt
(
query
)
}
_q
.
withAttributeValues
=
query
return
_q
}
// WithUserAllowedGroups tells the query-builder to eager-load the nodes that are connected to
// the "user_allowed_groups" edge. The optional arguments are used to configure the query builder of the edge.
func
(
_q
*
UserQuery
)
WithUserAllowedGroups
(
opts
...
func
(
*
UserAllowedGroupQuery
))
*
UserQuery
{
...
...
@@ -586,13 +622,14 @@ func (_q *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e
var
(
nodes
=
[]
*
User
{}
_spec
=
_q
.
querySpec
()
loadedTypes
=
[
7
]
bool
{
loadedTypes
=
[
8
]
bool
{
_q
.
withAPIKeys
!=
nil
,
_q
.
withRedeemCodes
!=
nil
,
_q
.
withSubscriptions
!=
nil
,
_q
.
withAssignedSubscriptions
!=
nil
,
_q
.
withAllowedGroups
!=
nil
,
_q
.
withUsageLogs
!=
nil
,
_q
.
withAttributeValues
!=
nil
,
_q
.
withUserAllowedGroups
!=
nil
,
}
)
...
...
@@ -658,6 +695,13 @@ func (_q *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e
return
nil
,
err
}
}
if
query
:=
_q
.
withAttributeValues
;
query
!=
nil
{
if
err
:=
_q
.
loadAttributeValues
(
ctx
,
query
,
nodes
,
func
(
n
*
User
)
{
n
.
Edges
.
AttributeValues
=
[]
*
UserAttributeValue
{}
},
func
(
n
*
User
,
e
*
UserAttributeValue
)
{
n
.
Edges
.
AttributeValues
=
append
(
n
.
Edges
.
AttributeValues
,
e
)
});
err
!=
nil
{
return
nil
,
err
}
}
if
query
:=
_q
.
withUserAllowedGroups
;
query
!=
nil
{
if
err
:=
_q
.
loadUserAllowedGroups
(
ctx
,
query
,
nodes
,
func
(
n
*
User
)
{
n
.
Edges
.
UserAllowedGroups
=
[]
*
UserAllowedGroup
{}
},
...
...
@@ -885,6 +929,36 @@ func (_q *UserQuery) loadUsageLogs(ctx context.Context, query *UsageLogQuery, no
}
return
nil
}
func
(
_q
*
UserQuery
)
loadAttributeValues
(
ctx
context
.
Context
,
query
*
UserAttributeValueQuery
,
nodes
[]
*
User
,
init
func
(
*
User
),
assign
func
(
*
User
,
*
UserAttributeValue
))
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
(
userattributevalue
.
FieldUserID
)
}
query
.
Where
(
predicate
.
UserAttributeValue
(
func
(
s
*
sql
.
Selector
)
{
s
.
Where
(
sql
.
InValues
(
s
.
C
(
user
.
AttributeValuesColumn
),
fks
...
))
}))
neighbors
,
err
:=
query
.
All
(
ctx
)
if
err
!=
nil
{
return
err
}
for
_
,
n
:=
range
neighbors
{
fk
:=
n
.
UserID
node
,
ok
:=
nodeids
[
fk
]
if
!
ok
{
return
fmt
.
Errorf
(
`unexpected referenced foreign-key "user_id" returned %v for node %v`
,
fk
,
n
.
ID
)
}
assign
(
node
,
n
)
}
return
nil
}
func
(
_q
*
UserQuery
)
loadUserAllowedGroups
(
ctx
context
.
Context
,
query
*
UserAllowedGroupQuery
,
nodes
[]
*
User
,
init
func
(
*
User
),
assign
func
(
*
User
,
*
UserAllowedGroup
))
error
{
fks
:=
make
([]
driver
.
Value
,
0
,
len
(
nodes
))
nodeids
:=
make
(
map
[
int64
]
*
User
)
...
...
backend/ent/user_update.go
View file @
6cc7f997
...
...
@@ -17,6 +17,7 @@ import (
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/usagelog"
"github.com/Wei-Shaw/sub2api/ent/user"
"github.com/Wei-Shaw/sub2api/ent/userattributevalue"
"github.com/Wei-Shaw/sub2api/ent/usersubscription"
)
...
...
@@ -171,20 +172,6 @@ func (_u *UserUpdate) SetNillableUsername(v *string) *UserUpdate {
return
_u
}
// SetWechat sets the "wechat" field.
func
(
_u
*
UserUpdate
)
SetWechat
(
v
string
)
*
UserUpdate
{
_u
.
mutation
.
SetWechat
(
v
)
return
_u
}
// SetNillableWechat sets the "wechat" field if the given value is not nil.
func
(
_u
*
UserUpdate
)
SetNillableWechat
(
v
*
string
)
*
UserUpdate
{
if
v
!=
nil
{
_u
.
SetWechat
(
*
v
)
}
return
_u
}
// SetNotes sets the "notes" field.
func
(
_u
*
UserUpdate
)
SetNotes
(
v
string
)
*
UserUpdate
{
_u
.
mutation
.
SetNotes
(
v
)
...
...
@@ -289,6 +276,21 @@ func (_u *UserUpdate) AddUsageLogs(v ...*UsageLog) *UserUpdate {
return
_u
.
AddUsageLogIDs
(
ids
...
)
}
// AddAttributeValueIDs adds the "attribute_values" edge to the UserAttributeValue entity by IDs.
func
(
_u
*
UserUpdate
)
AddAttributeValueIDs
(
ids
...
int64
)
*
UserUpdate
{
_u
.
mutation
.
AddAttributeValueIDs
(
ids
...
)
return
_u
}
// AddAttributeValues adds the "attribute_values" edges to the UserAttributeValue entity.
func
(
_u
*
UserUpdate
)
AddAttributeValues
(
v
...*
UserAttributeValue
)
*
UserUpdate
{
ids
:=
make
([]
int64
,
len
(
v
))
for
i
:=
range
v
{
ids
[
i
]
=
v
[
i
]
.
ID
}
return
_u
.
AddAttributeValueIDs
(
ids
...
)
}
// Mutation returns the UserMutation object of the builder.
func
(
_u
*
UserUpdate
)
Mutation
()
*
UserMutation
{
return
_u
.
mutation
...
...
@@ -420,6 +422,27 @@ func (_u *UserUpdate) RemoveUsageLogs(v ...*UsageLog) *UserUpdate {
return
_u
.
RemoveUsageLogIDs
(
ids
...
)
}
// ClearAttributeValues clears all "attribute_values" edges to the UserAttributeValue entity.
func
(
_u
*
UserUpdate
)
ClearAttributeValues
()
*
UserUpdate
{
_u
.
mutation
.
ClearAttributeValues
()
return
_u
}
// RemoveAttributeValueIDs removes the "attribute_values" edge to UserAttributeValue entities by IDs.
func
(
_u
*
UserUpdate
)
RemoveAttributeValueIDs
(
ids
...
int64
)
*
UserUpdate
{
_u
.
mutation
.
RemoveAttributeValueIDs
(
ids
...
)
return
_u
}
// RemoveAttributeValues removes "attribute_values" edges to UserAttributeValue entities.
func
(
_u
*
UserUpdate
)
RemoveAttributeValues
(
v
...*
UserAttributeValue
)
*
UserUpdate
{
ids
:=
make
([]
int64
,
len
(
v
))
for
i
:=
range
v
{
ids
[
i
]
=
v
[
i
]
.
ID
}
return
_u
.
RemoveAttributeValueIDs
(
ids
...
)
}
// Save executes the query and returns the number of nodes affected by the update operation.
func
(
_u
*
UserUpdate
)
Save
(
ctx
context
.
Context
)
(
int
,
error
)
{
if
err
:=
_u
.
defaults
();
err
!=
nil
{
...
...
@@ -489,11 +512,6 @@ func (_u *UserUpdate) check() error {
return
&
ValidationError
{
Name
:
"username"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "User.username": %w`
,
err
)}
}
}
if
v
,
ok
:=
_u
.
mutation
.
Wechat
();
ok
{
if
err
:=
user
.
WechatValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"wechat"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "User.wechat": %w`
,
err
)}
}
}
return
nil
}
...
...
@@ -545,9 +563,6 @@ func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if
value
,
ok
:=
_u
.
mutation
.
Username
();
ok
{
_spec
.
SetField
(
user
.
FieldUsername
,
field
.
TypeString
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
Wechat
();
ok
{
_spec
.
SetField
(
user
.
FieldWechat
,
field
.
TypeString
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
Notes
();
ok
{
_spec
.
SetField
(
user
.
FieldNotes
,
field
.
TypeString
,
value
)
}
...
...
@@ -833,6 +848,51 @@ func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
}
_spec
.
Edges
.
Add
=
append
(
_spec
.
Edges
.
Add
,
edge
)
}
if
_u
.
mutation
.
AttributeValuesCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
user
.
AttributeValuesTable
,
Columns
:
[]
string
{
user
.
AttributeValuesColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
userattributevalue
.
FieldID
,
field
.
TypeInt64
),
},
}
_spec
.
Edges
.
Clear
=
append
(
_spec
.
Edges
.
Clear
,
edge
)
}
if
nodes
:=
_u
.
mutation
.
RemovedAttributeValuesIDs
();
len
(
nodes
)
>
0
&&
!
_u
.
mutation
.
AttributeValuesCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
user
.
AttributeValuesTable
,
Columns
:
[]
string
{
user
.
AttributeValuesColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
userattributevalue
.
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
.
AttributeValuesIDs
();
len
(
nodes
)
>
0
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
user
.
AttributeValuesTable
,
Columns
:
[]
string
{
user
.
AttributeValuesColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
userattributevalue
.
FieldID
,
field
.
TypeInt64
),
},
}
for
_
,
k
:=
range
nodes
{
edge
.
Target
.
Nodes
=
append
(
edge
.
Target
.
Nodes
,
k
)
}
_spec
.
Edges
.
Add
=
append
(
_spec
.
Edges
.
Add
,
edge
)
}
if
_node
,
err
=
sqlgraph
.
UpdateNodes
(
ctx
,
_u
.
driver
,
_spec
);
err
!=
nil
{
if
_
,
ok
:=
err
.
(
*
sqlgraph
.
NotFoundError
);
ok
{
err
=
&
NotFoundError
{
user
.
Label
}
...
...
@@ -991,20 +1051,6 @@ func (_u *UserUpdateOne) SetNillableUsername(v *string) *UserUpdateOne {
return
_u
}
// SetWechat sets the "wechat" field.
func
(
_u
*
UserUpdateOne
)
SetWechat
(
v
string
)
*
UserUpdateOne
{
_u
.
mutation
.
SetWechat
(
v
)
return
_u
}
// SetNillableWechat sets the "wechat" field if the given value is not nil.
func
(
_u
*
UserUpdateOne
)
SetNillableWechat
(
v
*
string
)
*
UserUpdateOne
{
if
v
!=
nil
{
_u
.
SetWechat
(
*
v
)
}
return
_u
}
// SetNotes sets the "notes" field.
func
(
_u
*
UserUpdateOne
)
SetNotes
(
v
string
)
*
UserUpdateOne
{
_u
.
mutation
.
SetNotes
(
v
)
...
...
@@ -1109,6 +1155,21 @@ func (_u *UserUpdateOne) AddUsageLogs(v ...*UsageLog) *UserUpdateOne {
return
_u
.
AddUsageLogIDs
(
ids
...
)
}
// AddAttributeValueIDs adds the "attribute_values" edge to the UserAttributeValue entity by IDs.
func
(
_u
*
UserUpdateOne
)
AddAttributeValueIDs
(
ids
...
int64
)
*
UserUpdateOne
{
_u
.
mutation
.
AddAttributeValueIDs
(
ids
...
)
return
_u
}
// AddAttributeValues adds the "attribute_values" edges to the UserAttributeValue entity.
func
(
_u
*
UserUpdateOne
)
AddAttributeValues
(
v
...*
UserAttributeValue
)
*
UserUpdateOne
{
ids
:=
make
([]
int64
,
len
(
v
))
for
i
:=
range
v
{
ids
[
i
]
=
v
[
i
]
.
ID
}
return
_u
.
AddAttributeValueIDs
(
ids
...
)
}
// Mutation returns the UserMutation object of the builder.
func
(
_u
*
UserUpdateOne
)
Mutation
()
*
UserMutation
{
return
_u
.
mutation
...
...
@@ -1240,6 +1301,27 @@ func (_u *UserUpdateOne) RemoveUsageLogs(v ...*UsageLog) *UserUpdateOne {
return
_u
.
RemoveUsageLogIDs
(
ids
...
)
}
// ClearAttributeValues clears all "attribute_values" edges to the UserAttributeValue entity.
func
(
_u
*
UserUpdateOne
)
ClearAttributeValues
()
*
UserUpdateOne
{
_u
.
mutation
.
ClearAttributeValues
()
return
_u
}
// RemoveAttributeValueIDs removes the "attribute_values" edge to UserAttributeValue entities by IDs.
func
(
_u
*
UserUpdateOne
)
RemoveAttributeValueIDs
(
ids
...
int64
)
*
UserUpdateOne
{
_u
.
mutation
.
RemoveAttributeValueIDs
(
ids
...
)
return
_u
}
// RemoveAttributeValues removes "attribute_values" edges to UserAttributeValue entities.
func
(
_u
*
UserUpdateOne
)
RemoveAttributeValues
(
v
...*
UserAttributeValue
)
*
UserUpdateOne
{
ids
:=
make
([]
int64
,
len
(
v
))
for
i
:=
range
v
{
ids
[
i
]
=
v
[
i
]
.
ID
}
return
_u
.
RemoveAttributeValueIDs
(
ids
...
)
}
// Where appends a list predicates to the UserUpdate builder.
func
(
_u
*
UserUpdateOne
)
Where
(
ps
...
predicate
.
User
)
*
UserUpdateOne
{
_u
.
mutation
.
Where
(
ps
...
)
...
...
@@ -1322,11 +1404,6 @@ func (_u *UserUpdateOne) check() error {
return
&
ValidationError
{
Name
:
"username"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "User.username": %w`
,
err
)}
}
}
if
v
,
ok
:=
_u
.
mutation
.
Wechat
();
ok
{
if
err
:=
user
.
WechatValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"wechat"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "User.wechat": %w`
,
err
)}
}
}
return
nil
}
...
...
@@ -1395,9 +1472,6 @@ func (_u *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
if
value
,
ok
:=
_u
.
mutation
.
Username
();
ok
{
_spec
.
SetField
(
user
.
FieldUsername
,
field
.
TypeString
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
Wechat
();
ok
{
_spec
.
SetField
(
user
.
FieldWechat
,
field
.
TypeString
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
Notes
();
ok
{
_spec
.
SetField
(
user
.
FieldNotes
,
field
.
TypeString
,
value
)
}
...
...
@@ -1683,6 +1757,51 @@ func (_u *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
}
_spec
.
Edges
.
Add
=
append
(
_spec
.
Edges
.
Add
,
edge
)
}
if
_u
.
mutation
.
AttributeValuesCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
user
.
AttributeValuesTable
,
Columns
:
[]
string
{
user
.
AttributeValuesColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
userattributevalue
.
FieldID
,
field
.
TypeInt64
),
},
}
_spec
.
Edges
.
Clear
=
append
(
_spec
.
Edges
.
Clear
,
edge
)
}
if
nodes
:=
_u
.
mutation
.
RemovedAttributeValuesIDs
();
len
(
nodes
)
>
0
&&
!
_u
.
mutation
.
AttributeValuesCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
user
.
AttributeValuesTable
,
Columns
:
[]
string
{
user
.
AttributeValuesColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
userattributevalue
.
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
.
AttributeValuesIDs
();
len
(
nodes
)
>
0
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
user
.
AttributeValuesTable
,
Columns
:
[]
string
{
user
.
AttributeValuesColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
userattributevalue
.
FieldID
,
field
.
TypeInt64
),
},
}
for
_
,
k
:=
range
nodes
{
edge
.
Target
.
Nodes
=
append
(
edge
.
Target
.
Nodes
,
k
)
}
_spec
.
Edges
.
Add
=
append
(
_spec
.
Edges
.
Add
,
edge
)
}
_node
=
&
User
{
config
:
_u
.
config
}
_spec
.
Assign
=
_node
.
assignValues
_spec
.
ScanValues
=
_node
.
scanValues
...
...
Prev
1
2
3
4
5
…
7
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment