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
0170d19f
Commit
0170d19f
authored
Feb 02, 2026
by
song
Browse files
merge upstream main
parent
7ade9baa
Changes
319
Show whitespace changes
Inline
Side-by-side
backend/ent/announcementread_create.go
0 → 100644
View file @
0170d19f
// 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/announcement"
"github.com/Wei-Shaw/sub2api/ent/announcementread"
"github.com/Wei-Shaw/sub2api/ent/user"
)
// AnnouncementReadCreate is the builder for creating a AnnouncementRead entity.
type
AnnouncementReadCreate
struct
{
config
mutation
*
AnnouncementReadMutation
hooks
[]
Hook
conflict
[]
sql
.
ConflictOption
}
// SetAnnouncementID sets the "announcement_id" field.
func
(
_c
*
AnnouncementReadCreate
)
SetAnnouncementID
(
v
int64
)
*
AnnouncementReadCreate
{
_c
.
mutation
.
SetAnnouncementID
(
v
)
return
_c
}
// SetUserID sets the "user_id" field.
func
(
_c
*
AnnouncementReadCreate
)
SetUserID
(
v
int64
)
*
AnnouncementReadCreate
{
_c
.
mutation
.
SetUserID
(
v
)
return
_c
}
// SetReadAt sets the "read_at" field.
func
(
_c
*
AnnouncementReadCreate
)
SetReadAt
(
v
time
.
Time
)
*
AnnouncementReadCreate
{
_c
.
mutation
.
SetReadAt
(
v
)
return
_c
}
// SetNillableReadAt sets the "read_at" field if the given value is not nil.
func
(
_c
*
AnnouncementReadCreate
)
SetNillableReadAt
(
v
*
time
.
Time
)
*
AnnouncementReadCreate
{
if
v
!=
nil
{
_c
.
SetReadAt
(
*
v
)
}
return
_c
}
// SetCreatedAt sets the "created_at" field.
func
(
_c
*
AnnouncementReadCreate
)
SetCreatedAt
(
v
time
.
Time
)
*
AnnouncementReadCreate
{
_c
.
mutation
.
SetCreatedAt
(
v
)
return
_c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func
(
_c
*
AnnouncementReadCreate
)
SetNillableCreatedAt
(
v
*
time
.
Time
)
*
AnnouncementReadCreate
{
if
v
!=
nil
{
_c
.
SetCreatedAt
(
*
v
)
}
return
_c
}
// SetAnnouncement sets the "announcement" edge to the Announcement entity.
func
(
_c
*
AnnouncementReadCreate
)
SetAnnouncement
(
v
*
Announcement
)
*
AnnouncementReadCreate
{
return
_c
.
SetAnnouncementID
(
v
.
ID
)
}
// SetUser sets the "user" edge to the User entity.
func
(
_c
*
AnnouncementReadCreate
)
SetUser
(
v
*
User
)
*
AnnouncementReadCreate
{
return
_c
.
SetUserID
(
v
.
ID
)
}
// Mutation returns the AnnouncementReadMutation object of the builder.
func
(
_c
*
AnnouncementReadCreate
)
Mutation
()
*
AnnouncementReadMutation
{
return
_c
.
mutation
}
// Save creates the AnnouncementRead in the database.
func
(
_c
*
AnnouncementReadCreate
)
Save
(
ctx
context
.
Context
)
(
*
AnnouncementRead
,
error
)
{
_c
.
defaults
()
return
withHooks
(
ctx
,
_c
.
sqlSave
,
_c
.
mutation
,
_c
.
hooks
)
}
// SaveX calls Save and panics if Save returns an error.
func
(
_c
*
AnnouncementReadCreate
)
SaveX
(
ctx
context
.
Context
)
*
AnnouncementRead
{
v
,
err
:=
_c
.
Save
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
v
}
// Exec executes the query.
func
(
_c
*
AnnouncementReadCreate
)
Exec
(
ctx
context
.
Context
)
error
{
_
,
err
:=
_c
.
Save
(
ctx
)
return
err
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_c
*
AnnouncementReadCreate
)
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
*
AnnouncementReadCreate
)
defaults
()
{
if
_
,
ok
:=
_c
.
mutation
.
ReadAt
();
!
ok
{
v
:=
announcementread
.
DefaultReadAt
()
_c
.
mutation
.
SetReadAt
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
CreatedAt
();
!
ok
{
v
:=
announcementread
.
DefaultCreatedAt
()
_c
.
mutation
.
SetCreatedAt
(
v
)
}
}
// check runs all checks and user-defined validators on the builder.
func
(
_c
*
AnnouncementReadCreate
)
check
()
error
{
if
_
,
ok
:=
_c
.
mutation
.
AnnouncementID
();
!
ok
{
return
&
ValidationError
{
Name
:
"announcement_id"
,
err
:
errors
.
New
(
`ent: missing required field "AnnouncementRead.announcement_id"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
UserID
();
!
ok
{
return
&
ValidationError
{
Name
:
"user_id"
,
err
:
errors
.
New
(
`ent: missing required field "AnnouncementRead.user_id"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
ReadAt
();
!
ok
{
return
&
ValidationError
{
Name
:
"read_at"
,
err
:
errors
.
New
(
`ent: missing required field "AnnouncementRead.read_at"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
CreatedAt
();
!
ok
{
return
&
ValidationError
{
Name
:
"created_at"
,
err
:
errors
.
New
(
`ent: missing required field "AnnouncementRead.created_at"`
)}
}
if
len
(
_c
.
mutation
.
AnnouncementIDs
())
==
0
{
return
&
ValidationError
{
Name
:
"announcement"
,
err
:
errors
.
New
(
`ent: missing required edge "AnnouncementRead.announcement"`
)}
}
if
len
(
_c
.
mutation
.
UserIDs
())
==
0
{
return
&
ValidationError
{
Name
:
"user"
,
err
:
errors
.
New
(
`ent: missing required edge "AnnouncementRead.user"`
)}
}
return
nil
}
func
(
_c
*
AnnouncementReadCreate
)
sqlSave
(
ctx
context
.
Context
)
(
*
AnnouncementRead
,
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
*
AnnouncementReadCreate
)
createSpec
()
(
*
AnnouncementRead
,
*
sqlgraph
.
CreateSpec
)
{
var
(
_node
=
&
AnnouncementRead
{
config
:
_c
.
config
}
_spec
=
sqlgraph
.
NewCreateSpec
(
announcementread
.
Table
,
sqlgraph
.
NewFieldSpec
(
announcementread
.
FieldID
,
field
.
TypeInt64
))
)
_spec
.
OnConflict
=
_c
.
conflict
if
value
,
ok
:=
_c
.
mutation
.
ReadAt
();
ok
{
_spec
.
SetField
(
announcementread
.
FieldReadAt
,
field
.
TypeTime
,
value
)
_node
.
ReadAt
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
CreatedAt
();
ok
{
_spec
.
SetField
(
announcementread
.
FieldCreatedAt
,
field
.
TypeTime
,
value
)
_node
.
CreatedAt
=
value
}
if
nodes
:=
_c
.
mutation
.
AnnouncementIDs
();
len
(
nodes
)
>
0
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
M2O
,
Inverse
:
true
,
Table
:
announcementread
.
AnnouncementTable
,
Columns
:
[]
string
{
announcementread
.
AnnouncementColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
announcement
.
FieldID
,
field
.
TypeInt64
),
},
}
for
_
,
k
:=
range
nodes
{
edge
.
Target
.
Nodes
=
append
(
edge
.
Target
.
Nodes
,
k
)
}
_node
.
AnnouncementID
=
nodes
[
0
]
_spec
.
Edges
=
append
(
_spec
.
Edges
,
edge
)
}
if
nodes
:=
_c
.
mutation
.
UserIDs
();
len
(
nodes
)
>
0
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
M2O
,
Inverse
:
true
,
Table
:
announcementread
.
UserTable
,
Columns
:
[]
string
{
announcementread
.
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
)
}
_node
.
UserID
=
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.AnnouncementRead.Create().
// SetAnnouncementID(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.AnnouncementReadUpsert) {
// SetAnnouncementID(v+v).
// }).
// Exec(ctx)
func
(
_c
*
AnnouncementReadCreate
)
OnConflict
(
opts
...
sql
.
ConflictOption
)
*
AnnouncementReadUpsertOne
{
_c
.
conflict
=
opts
return
&
AnnouncementReadUpsertOne
{
create
:
_c
,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.AnnouncementRead.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func
(
_c
*
AnnouncementReadCreate
)
OnConflictColumns
(
columns
...
string
)
*
AnnouncementReadUpsertOne
{
_c
.
conflict
=
append
(
_c
.
conflict
,
sql
.
ConflictColumns
(
columns
...
))
return
&
AnnouncementReadUpsertOne
{
create
:
_c
,
}
}
type
(
// AnnouncementReadUpsertOne is the builder for "upsert"-ing
// one AnnouncementRead node.
AnnouncementReadUpsertOne
struct
{
create
*
AnnouncementReadCreate
}
// AnnouncementReadUpsert is the "OnConflict" setter.
AnnouncementReadUpsert
struct
{
*
sql
.
UpdateSet
}
)
// SetAnnouncementID sets the "announcement_id" field.
func
(
u
*
AnnouncementReadUpsert
)
SetAnnouncementID
(
v
int64
)
*
AnnouncementReadUpsert
{
u
.
Set
(
announcementread
.
FieldAnnouncementID
,
v
)
return
u
}
// UpdateAnnouncementID sets the "announcement_id" field to the value that was provided on create.
func
(
u
*
AnnouncementReadUpsert
)
UpdateAnnouncementID
()
*
AnnouncementReadUpsert
{
u
.
SetExcluded
(
announcementread
.
FieldAnnouncementID
)
return
u
}
// SetUserID sets the "user_id" field.
func
(
u
*
AnnouncementReadUpsert
)
SetUserID
(
v
int64
)
*
AnnouncementReadUpsert
{
u
.
Set
(
announcementread
.
FieldUserID
,
v
)
return
u
}
// UpdateUserID sets the "user_id" field to the value that was provided on create.
func
(
u
*
AnnouncementReadUpsert
)
UpdateUserID
()
*
AnnouncementReadUpsert
{
u
.
SetExcluded
(
announcementread
.
FieldUserID
)
return
u
}
// SetReadAt sets the "read_at" field.
func
(
u
*
AnnouncementReadUpsert
)
SetReadAt
(
v
time
.
Time
)
*
AnnouncementReadUpsert
{
u
.
Set
(
announcementread
.
FieldReadAt
,
v
)
return
u
}
// UpdateReadAt sets the "read_at" field to the value that was provided on create.
func
(
u
*
AnnouncementReadUpsert
)
UpdateReadAt
()
*
AnnouncementReadUpsert
{
u
.
SetExcluded
(
announcementread
.
FieldReadAt
)
return
u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
// client.AnnouncementRead.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func
(
u
*
AnnouncementReadUpsertOne
)
UpdateNewValues
()
*
AnnouncementReadUpsertOne
{
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
(
announcementread
.
FieldCreatedAt
)
}
}))
return
u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.AnnouncementRead.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func
(
u
*
AnnouncementReadUpsertOne
)
Ignore
()
*
AnnouncementReadUpsertOne
{
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
*
AnnouncementReadUpsertOne
)
DoNothing
()
*
AnnouncementReadUpsertOne
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
DoNothing
())
return
u
}
// Update allows overriding fields `UPDATE` values. See the AnnouncementReadCreate.OnConflict
// documentation for more info.
func
(
u
*
AnnouncementReadUpsertOne
)
Update
(
set
func
(
*
AnnouncementReadUpsert
))
*
AnnouncementReadUpsertOne
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWith
(
func
(
update
*
sql
.
UpdateSet
)
{
set
(
&
AnnouncementReadUpsert
{
UpdateSet
:
update
})
}))
return
u
}
// SetAnnouncementID sets the "announcement_id" field.
func
(
u
*
AnnouncementReadUpsertOne
)
SetAnnouncementID
(
v
int64
)
*
AnnouncementReadUpsertOne
{
return
u
.
Update
(
func
(
s
*
AnnouncementReadUpsert
)
{
s
.
SetAnnouncementID
(
v
)
})
}
// UpdateAnnouncementID sets the "announcement_id" field to the value that was provided on create.
func
(
u
*
AnnouncementReadUpsertOne
)
UpdateAnnouncementID
()
*
AnnouncementReadUpsertOne
{
return
u
.
Update
(
func
(
s
*
AnnouncementReadUpsert
)
{
s
.
UpdateAnnouncementID
()
})
}
// SetUserID sets the "user_id" field.
func
(
u
*
AnnouncementReadUpsertOne
)
SetUserID
(
v
int64
)
*
AnnouncementReadUpsertOne
{
return
u
.
Update
(
func
(
s
*
AnnouncementReadUpsert
)
{
s
.
SetUserID
(
v
)
})
}
// UpdateUserID sets the "user_id" field to the value that was provided on create.
func
(
u
*
AnnouncementReadUpsertOne
)
UpdateUserID
()
*
AnnouncementReadUpsertOne
{
return
u
.
Update
(
func
(
s
*
AnnouncementReadUpsert
)
{
s
.
UpdateUserID
()
})
}
// SetReadAt sets the "read_at" field.
func
(
u
*
AnnouncementReadUpsertOne
)
SetReadAt
(
v
time
.
Time
)
*
AnnouncementReadUpsertOne
{
return
u
.
Update
(
func
(
s
*
AnnouncementReadUpsert
)
{
s
.
SetReadAt
(
v
)
})
}
// UpdateReadAt sets the "read_at" field to the value that was provided on create.
func
(
u
*
AnnouncementReadUpsertOne
)
UpdateReadAt
()
*
AnnouncementReadUpsertOne
{
return
u
.
Update
(
func
(
s
*
AnnouncementReadUpsert
)
{
s
.
UpdateReadAt
()
})
}
// Exec executes the query.
func
(
u
*
AnnouncementReadUpsertOne
)
Exec
(
ctx
context
.
Context
)
error
{
if
len
(
u
.
create
.
conflict
)
==
0
{
return
errors
.
New
(
"ent: missing options for AnnouncementReadCreate.OnConflict"
)
}
return
u
.
create
.
Exec
(
ctx
)
}
// ExecX is like Exec, but panics if an error occurs.
func
(
u
*
AnnouncementReadUpsertOne
)
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
*
AnnouncementReadUpsertOne
)
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
*
AnnouncementReadUpsertOne
)
IDX
(
ctx
context
.
Context
)
int64
{
id
,
err
:=
u
.
ID
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
id
}
// AnnouncementReadCreateBulk is the builder for creating many AnnouncementRead entities in bulk.
type
AnnouncementReadCreateBulk
struct
{
config
err
error
builders
[]
*
AnnouncementReadCreate
conflict
[]
sql
.
ConflictOption
}
// Save creates the AnnouncementRead entities in the database.
func
(
_c
*
AnnouncementReadCreateBulk
)
Save
(
ctx
context
.
Context
)
([]
*
AnnouncementRead
,
error
)
{
if
_c
.
err
!=
nil
{
return
nil
,
_c
.
err
}
specs
:=
make
([]
*
sqlgraph
.
CreateSpec
,
len
(
_c
.
builders
))
nodes
:=
make
([]
*
AnnouncementRead
,
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
.
(
*
AnnouncementReadMutation
)
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
*
AnnouncementReadCreateBulk
)
SaveX
(
ctx
context
.
Context
)
[]
*
AnnouncementRead
{
v
,
err
:=
_c
.
Save
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
v
}
// Exec executes the query.
func
(
_c
*
AnnouncementReadCreateBulk
)
Exec
(
ctx
context
.
Context
)
error
{
_
,
err
:=
_c
.
Save
(
ctx
)
return
err
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_c
*
AnnouncementReadCreateBulk
)
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.AnnouncementRead.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.AnnouncementReadUpsert) {
// SetAnnouncementID(v+v).
// }).
// Exec(ctx)
func
(
_c
*
AnnouncementReadCreateBulk
)
OnConflict
(
opts
...
sql
.
ConflictOption
)
*
AnnouncementReadUpsertBulk
{
_c
.
conflict
=
opts
return
&
AnnouncementReadUpsertBulk
{
create
:
_c
,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.AnnouncementRead.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func
(
_c
*
AnnouncementReadCreateBulk
)
OnConflictColumns
(
columns
...
string
)
*
AnnouncementReadUpsertBulk
{
_c
.
conflict
=
append
(
_c
.
conflict
,
sql
.
ConflictColumns
(
columns
...
))
return
&
AnnouncementReadUpsertBulk
{
create
:
_c
,
}
}
// AnnouncementReadUpsertBulk is the builder for "upsert"-ing
// a bulk of AnnouncementRead nodes.
type
AnnouncementReadUpsertBulk
struct
{
create
*
AnnouncementReadCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.AnnouncementRead.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func
(
u
*
AnnouncementReadUpsertBulk
)
UpdateNewValues
()
*
AnnouncementReadUpsertBulk
{
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
(
announcementread
.
FieldCreatedAt
)
}
}
}))
return
u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.AnnouncementRead.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func
(
u
*
AnnouncementReadUpsertBulk
)
Ignore
()
*
AnnouncementReadUpsertBulk
{
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
*
AnnouncementReadUpsertBulk
)
DoNothing
()
*
AnnouncementReadUpsertBulk
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
DoNothing
())
return
u
}
// Update allows overriding fields `UPDATE` values. See the AnnouncementReadCreateBulk.OnConflict
// documentation for more info.
func
(
u
*
AnnouncementReadUpsertBulk
)
Update
(
set
func
(
*
AnnouncementReadUpsert
))
*
AnnouncementReadUpsertBulk
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWith
(
func
(
update
*
sql
.
UpdateSet
)
{
set
(
&
AnnouncementReadUpsert
{
UpdateSet
:
update
})
}))
return
u
}
// SetAnnouncementID sets the "announcement_id" field.
func
(
u
*
AnnouncementReadUpsertBulk
)
SetAnnouncementID
(
v
int64
)
*
AnnouncementReadUpsertBulk
{
return
u
.
Update
(
func
(
s
*
AnnouncementReadUpsert
)
{
s
.
SetAnnouncementID
(
v
)
})
}
// UpdateAnnouncementID sets the "announcement_id" field to the value that was provided on create.
func
(
u
*
AnnouncementReadUpsertBulk
)
UpdateAnnouncementID
()
*
AnnouncementReadUpsertBulk
{
return
u
.
Update
(
func
(
s
*
AnnouncementReadUpsert
)
{
s
.
UpdateAnnouncementID
()
})
}
// SetUserID sets the "user_id" field.
func
(
u
*
AnnouncementReadUpsertBulk
)
SetUserID
(
v
int64
)
*
AnnouncementReadUpsertBulk
{
return
u
.
Update
(
func
(
s
*
AnnouncementReadUpsert
)
{
s
.
SetUserID
(
v
)
})
}
// UpdateUserID sets the "user_id" field to the value that was provided on create.
func
(
u
*
AnnouncementReadUpsertBulk
)
UpdateUserID
()
*
AnnouncementReadUpsertBulk
{
return
u
.
Update
(
func
(
s
*
AnnouncementReadUpsert
)
{
s
.
UpdateUserID
()
})
}
// SetReadAt sets the "read_at" field.
func
(
u
*
AnnouncementReadUpsertBulk
)
SetReadAt
(
v
time
.
Time
)
*
AnnouncementReadUpsertBulk
{
return
u
.
Update
(
func
(
s
*
AnnouncementReadUpsert
)
{
s
.
SetReadAt
(
v
)
})
}
// UpdateReadAt sets the "read_at" field to the value that was provided on create.
func
(
u
*
AnnouncementReadUpsertBulk
)
UpdateReadAt
()
*
AnnouncementReadUpsertBulk
{
return
u
.
Update
(
func
(
s
*
AnnouncementReadUpsert
)
{
s
.
UpdateReadAt
()
})
}
// Exec executes the query.
func
(
u
*
AnnouncementReadUpsertBulk
)
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 AnnouncementReadCreateBulk instead"
,
i
)
}
}
if
len
(
u
.
create
.
conflict
)
==
0
{
return
errors
.
New
(
"ent: missing options for AnnouncementReadCreateBulk.OnConflict"
)
}
return
u
.
create
.
Exec
(
ctx
)
}
// ExecX is like Exec, but panics if an error occurs.
func
(
u
*
AnnouncementReadUpsertBulk
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
u
.
create
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
backend/ent/announcementread_delete.go
0 → 100644
View file @
0170d19f
// 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/announcementread"
"github.com/Wei-Shaw/sub2api/ent/predicate"
)
// AnnouncementReadDelete is the builder for deleting a AnnouncementRead entity.
type
AnnouncementReadDelete
struct
{
config
hooks
[]
Hook
mutation
*
AnnouncementReadMutation
}
// Where appends a list predicates to the AnnouncementReadDelete builder.
func
(
_d
*
AnnouncementReadDelete
)
Where
(
ps
...
predicate
.
AnnouncementRead
)
*
AnnouncementReadDelete
{
_d
.
mutation
.
Where
(
ps
...
)
return
_d
}
// Exec executes the deletion query and returns how many vertices were deleted.
func
(
_d
*
AnnouncementReadDelete
)
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
*
AnnouncementReadDelete
)
ExecX
(
ctx
context
.
Context
)
int
{
n
,
err
:=
_d
.
Exec
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
n
}
func
(
_d
*
AnnouncementReadDelete
)
sqlExec
(
ctx
context
.
Context
)
(
int
,
error
)
{
_spec
:=
sqlgraph
.
NewDeleteSpec
(
announcementread
.
Table
,
sqlgraph
.
NewFieldSpec
(
announcementread
.
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
}
// AnnouncementReadDeleteOne is the builder for deleting a single AnnouncementRead entity.
type
AnnouncementReadDeleteOne
struct
{
_d
*
AnnouncementReadDelete
}
// Where appends a list predicates to the AnnouncementReadDelete builder.
func
(
_d
*
AnnouncementReadDeleteOne
)
Where
(
ps
...
predicate
.
AnnouncementRead
)
*
AnnouncementReadDeleteOne
{
_d
.
_d
.
mutation
.
Where
(
ps
...
)
return
_d
}
// Exec executes the deletion query.
func
(
_d
*
AnnouncementReadDeleteOne
)
Exec
(
ctx
context
.
Context
)
error
{
n
,
err
:=
_d
.
_d
.
Exec
(
ctx
)
switch
{
case
err
!=
nil
:
return
err
case
n
==
0
:
return
&
NotFoundError
{
announcementread
.
Label
}
default
:
return
nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_d
*
AnnouncementReadDeleteOne
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
_d
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
backend/ent/announcementread_query.go
0 → 100644
View file @
0170d19f
// 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/announcement"
"github.com/Wei-Shaw/sub2api/ent/announcementread"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/user"
)
// AnnouncementReadQuery is the builder for querying AnnouncementRead entities.
type
AnnouncementReadQuery
struct
{
config
ctx
*
QueryContext
order
[]
announcementread
.
OrderOption
inters
[]
Interceptor
predicates
[]
predicate
.
AnnouncementRead
withAnnouncement
*
AnnouncementQuery
withUser
*
UserQuery
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 AnnouncementReadQuery builder.
func
(
_q
*
AnnouncementReadQuery
)
Where
(
ps
...
predicate
.
AnnouncementRead
)
*
AnnouncementReadQuery
{
_q
.
predicates
=
append
(
_q
.
predicates
,
ps
...
)
return
_q
}
// Limit the number of records to be returned by this query.
func
(
_q
*
AnnouncementReadQuery
)
Limit
(
limit
int
)
*
AnnouncementReadQuery
{
_q
.
ctx
.
Limit
=
&
limit
return
_q
}
// Offset to start from.
func
(
_q
*
AnnouncementReadQuery
)
Offset
(
offset
int
)
*
AnnouncementReadQuery
{
_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
*
AnnouncementReadQuery
)
Unique
(
unique
bool
)
*
AnnouncementReadQuery
{
_q
.
ctx
.
Unique
=
&
unique
return
_q
}
// Order specifies how the records should be ordered.
func
(
_q
*
AnnouncementReadQuery
)
Order
(
o
...
announcementread
.
OrderOption
)
*
AnnouncementReadQuery
{
_q
.
order
=
append
(
_q
.
order
,
o
...
)
return
_q
}
// QueryAnnouncement chains the current query on the "announcement" edge.
func
(
_q
*
AnnouncementReadQuery
)
QueryAnnouncement
()
*
AnnouncementQuery
{
query
:=
(
&
AnnouncementClient
{
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
(
announcementread
.
Table
,
announcementread
.
FieldID
,
selector
),
sqlgraph
.
To
(
announcement
.
Table
,
announcement
.
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
M2O
,
true
,
announcementread
.
AnnouncementTable
,
announcementread
.
AnnouncementColumn
),
)
fromU
=
sqlgraph
.
SetNeighbors
(
_q
.
driver
.
Dialect
(),
step
)
return
fromU
,
nil
}
return
query
}
// QueryUser chains the current query on the "user" edge.
func
(
_q
*
AnnouncementReadQuery
)
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
(
announcementread
.
Table
,
announcementread
.
FieldID
,
selector
),
sqlgraph
.
To
(
user
.
Table
,
user
.
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
M2O
,
true
,
announcementread
.
UserTable
,
announcementread
.
UserColumn
),
)
fromU
=
sqlgraph
.
SetNeighbors
(
_q
.
driver
.
Dialect
(),
step
)
return
fromU
,
nil
}
return
query
}
// First returns the first AnnouncementRead entity from the query.
// Returns a *NotFoundError when no AnnouncementRead was found.
func
(
_q
*
AnnouncementReadQuery
)
First
(
ctx
context
.
Context
)
(
*
AnnouncementRead
,
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
{
announcementread
.
Label
}
}
return
nodes
[
0
],
nil
}
// FirstX is like First, but panics if an error occurs.
func
(
_q
*
AnnouncementReadQuery
)
FirstX
(
ctx
context
.
Context
)
*
AnnouncementRead
{
node
,
err
:=
_q
.
First
(
ctx
)
if
err
!=
nil
&&
!
IsNotFound
(
err
)
{
panic
(
err
)
}
return
node
}
// FirstID returns the first AnnouncementRead ID from the query.
// Returns a *NotFoundError when no AnnouncementRead ID was found.
func
(
_q
*
AnnouncementReadQuery
)
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
{
announcementread
.
Label
}
return
}
return
ids
[
0
],
nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func
(
_q
*
AnnouncementReadQuery
)
FirstIDX
(
ctx
context
.
Context
)
int64
{
id
,
err
:=
_q
.
FirstID
(
ctx
)
if
err
!=
nil
&&
!
IsNotFound
(
err
)
{
panic
(
err
)
}
return
id
}
// Only returns a single AnnouncementRead entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one AnnouncementRead entity is found.
// Returns a *NotFoundError when no AnnouncementRead entities are found.
func
(
_q
*
AnnouncementReadQuery
)
Only
(
ctx
context
.
Context
)
(
*
AnnouncementRead
,
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
{
announcementread
.
Label
}
default
:
return
nil
,
&
NotSingularError
{
announcementread
.
Label
}
}
}
// OnlyX is like Only, but panics if an error occurs.
func
(
_q
*
AnnouncementReadQuery
)
OnlyX
(
ctx
context
.
Context
)
*
AnnouncementRead
{
node
,
err
:=
_q
.
Only
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
node
}
// OnlyID is like Only, but returns the only AnnouncementRead ID in the query.
// Returns a *NotSingularError when more than one AnnouncementRead ID is found.
// Returns a *NotFoundError when no entities are found.
func
(
_q
*
AnnouncementReadQuery
)
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
{
announcementread
.
Label
}
default
:
err
=
&
NotSingularError
{
announcementread
.
Label
}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func
(
_q
*
AnnouncementReadQuery
)
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 AnnouncementReads.
func
(
_q
*
AnnouncementReadQuery
)
All
(
ctx
context
.
Context
)
([]
*
AnnouncementRead
,
error
)
{
ctx
=
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryAll
)
if
err
:=
_q
.
prepareQuery
(
ctx
);
err
!=
nil
{
return
nil
,
err
}
qr
:=
querierAll
[[]
*
AnnouncementRead
,
*
AnnouncementReadQuery
]()
return
withInterceptors
[[]
*
AnnouncementRead
](
ctx
,
_q
,
qr
,
_q
.
inters
)
}
// AllX is like All, but panics if an error occurs.
func
(
_q
*
AnnouncementReadQuery
)
AllX
(
ctx
context
.
Context
)
[]
*
AnnouncementRead
{
nodes
,
err
:=
_q
.
All
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
nodes
}
// IDs executes the query and returns a list of AnnouncementRead IDs.
func
(
_q
*
AnnouncementReadQuery
)
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
(
announcementread
.
FieldID
)
.
Scan
(
ctx
,
&
ids
);
err
!=
nil
{
return
nil
,
err
}
return
ids
,
nil
}
// IDsX is like IDs, but panics if an error occurs.
func
(
_q
*
AnnouncementReadQuery
)
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
*
AnnouncementReadQuery
)
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
[
*
AnnouncementReadQuery
](),
_q
.
inters
)
}
// CountX is like Count, but panics if an error occurs.
func
(
_q
*
AnnouncementReadQuery
)
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
*
AnnouncementReadQuery
)
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
*
AnnouncementReadQuery
)
ExistX
(
ctx
context
.
Context
)
bool
{
exist
,
err
:=
_q
.
Exist
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
exist
}
// Clone returns a duplicate of the AnnouncementReadQuery 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
*
AnnouncementReadQuery
)
Clone
()
*
AnnouncementReadQuery
{
if
_q
==
nil
{
return
nil
}
return
&
AnnouncementReadQuery
{
config
:
_q
.
config
,
ctx
:
_q
.
ctx
.
Clone
(),
order
:
append
([]
announcementread
.
OrderOption
{},
_q
.
order
...
),
inters
:
append
([]
Interceptor
{},
_q
.
inters
...
),
predicates
:
append
([]
predicate
.
AnnouncementRead
{},
_q
.
predicates
...
),
withAnnouncement
:
_q
.
withAnnouncement
.
Clone
(),
withUser
:
_q
.
withUser
.
Clone
(),
// clone intermediate query.
sql
:
_q
.
sql
.
Clone
(),
path
:
_q
.
path
,
}
}
// WithAnnouncement tells the query-builder to eager-load the nodes that are connected to
// the "announcement" edge. The optional arguments are used to configure the query builder of the edge.
func
(
_q
*
AnnouncementReadQuery
)
WithAnnouncement
(
opts
...
func
(
*
AnnouncementQuery
))
*
AnnouncementReadQuery
{
query
:=
(
&
AnnouncementClient
{
config
:
_q
.
config
})
.
Query
()
for
_
,
opt
:=
range
opts
{
opt
(
query
)
}
_q
.
withAnnouncement
=
query
return
_q
}
// 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
*
AnnouncementReadQuery
)
WithUser
(
opts
...
func
(
*
UserQuery
))
*
AnnouncementReadQuery
{
query
:=
(
&
UserClient
{
config
:
_q
.
config
})
.
Query
()
for
_
,
opt
:=
range
opts
{
opt
(
query
)
}
_q
.
withUser
=
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 {
// AnnouncementID int64 `json:"announcement_id,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.AnnouncementRead.Query().
// GroupBy(announcementread.FieldAnnouncementID).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func
(
_q
*
AnnouncementReadQuery
)
GroupBy
(
field
string
,
fields
...
string
)
*
AnnouncementReadGroupBy
{
_q
.
ctx
.
Fields
=
append
([]
string
{
field
},
fields
...
)
grbuild
:=
&
AnnouncementReadGroupBy
{
build
:
_q
}
grbuild
.
flds
=
&
_q
.
ctx
.
Fields
grbuild
.
label
=
announcementread
.
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 {
// AnnouncementID int64 `json:"announcement_id,omitempty"`
// }
//
// client.AnnouncementRead.Query().
// Select(announcementread.FieldAnnouncementID).
// Scan(ctx, &v)
func
(
_q
*
AnnouncementReadQuery
)
Select
(
fields
...
string
)
*
AnnouncementReadSelect
{
_q
.
ctx
.
Fields
=
append
(
_q
.
ctx
.
Fields
,
fields
...
)
sbuild
:=
&
AnnouncementReadSelect
{
AnnouncementReadQuery
:
_q
}
sbuild
.
label
=
announcementread
.
Label
sbuild
.
flds
,
sbuild
.
scan
=
&
_q
.
ctx
.
Fields
,
sbuild
.
Scan
return
sbuild
}
// Aggregate returns a AnnouncementReadSelect configured with the given aggregations.
func
(
_q
*
AnnouncementReadQuery
)
Aggregate
(
fns
...
AggregateFunc
)
*
AnnouncementReadSelect
{
return
_q
.
Select
()
.
Aggregate
(
fns
...
)
}
func
(
_q
*
AnnouncementReadQuery
)
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
!
announcementread
.
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
*
AnnouncementReadQuery
)
sqlAll
(
ctx
context
.
Context
,
hooks
...
queryHook
)
([]
*
AnnouncementRead
,
error
)
{
var
(
nodes
=
[]
*
AnnouncementRead
{}
_spec
=
_q
.
querySpec
()
loadedTypes
=
[
2
]
bool
{
_q
.
withAnnouncement
!=
nil
,
_q
.
withUser
!=
nil
,
}
)
_spec
.
ScanValues
=
func
(
columns
[]
string
)
([]
any
,
error
)
{
return
(
*
AnnouncementRead
)
.
scanValues
(
nil
,
columns
)
}
_spec
.
Assign
=
func
(
columns
[]
string
,
values
[]
any
)
error
{
node
:=
&
AnnouncementRead
{
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
.
withAnnouncement
;
query
!=
nil
{
if
err
:=
_q
.
loadAnnouncement
(
ctx
,
query
,
nodes
,
nil
,
func
(
n
*
AnnouncementRead
,
e
*
Announcement
)
{
n
.
Edges
.
Announcement
=
e
});
err
!=
nil
{
return
nil
,
err
}
}
if
query
:=
_q
.
withUser
;
query
!=
nil
{
if
err
:=
_q
.
loadUser
(
ctx
,
query
,
nodes
,
nil
,
func
(
n
*
AnnouncementRead
,
e
*
User
)
{
n
.
Edges
.
User
=
e
});
err
!=
nil
{
return
nil
,
err
}
}
return
nodes
,
nil
}
func
(
_q
*
AnnouncementReadQuery
)
loadAnnouncement
(
ctx
context
.
Context
,
query
*
AnnouncementQuery
,
nodes
[]
*
AnnouncementRead
,
init
func
(
*
AnnouncementRead
),
assign
func
(
*
AnnouncementRead
,
*
Announcement
))
error
{
ids
:=
make
([]
int64
,
0
,
len
(
nodes
))
nodeids
:=
make
(
map
[
int64
][]
*
AnnouncementRead
)
for
i
:=
range
nodes
{
fk
:=
nodes
[
i
]
.
AnnouncementID
if
_
,
ok
:=
nodeids
[
fk
];
!
ok
{
ids
=
append
(
ids
,
fk
)
}
nodeids
[
fk
]
=
append
(
nodeids
[
fk
],
nodes
[
i
])
}
if
len
(
ids
)
==
0
{
return
nil
}
query
.
Where
(
announcement
.
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 "announcement_id" returned %v`
,
n
.
ID
)
}
for
i
:=
range
nodes
{
assign
(
nodes
[
i
],
n
)
}
}
return
nil
}
func
(
_q
*
AnnouncementReadQuery
)
loadUser
(
ctx
context
.
Context
,
query
*
UserQuery
,
nodes
[]
*
AnnouncementRead
,
init
func
(
*
AnnouncementRead
),
assign
func
(
*
AnnouncementRead
,
*
User
))
error
{
ids
:=
make
([]
int64
,
0
,
len
(
nodes
))
nodeids
:=
make
(
map
[
int64
][]
*
AnnouncementRead
)
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
*
AnnouncementReadQuery
)
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
*
AnnouncementReadQuery
)
querySpec
()
*
sqlgraph
.
QuerySpec
{
_spec
:=
sqlgraph
.
NewQuerySpec
(
announcementread
.
Table
,
announcementread
.
Columns
,
sqlgraph
.
NewFieldSpec
(
announcementread
.
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
,
announcementread
.
FieldID
)
for
i
:=
range
fields
{
if
fields
[
i
]
!=
announcementread
.
FieldID
{
_spec
.
Node
.
Columns
=
append
(
_spec
.
Node
.
Columns
,
fields
[
i
])
}
}
if
_q
.
withAnnouncement
!=
nil
{
_spec
.
Node
.
AddColumnOnce
(
announcementread
.
FieldAnnouncementID
)
}
if
_q
.
withUser
!=
nil
{
_spec
.
Node
.
AddColumnOnce
(
announcementread
.
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
*
AnnouncementReadQuery
)
sqlQuery
(
ctx
context
.
Context
)
*
sql
.
Selector
{
builder
:=
sql
.
Dialect
(
_q
.
driver
.
Dialect
())
t1
:=
builder
.
Table
(
announcementread
.
Table
)
columns
:=
_q
.
ctx
.
Fields
if
len
(
columns
)
==
0
{
columns
=
announcementread
.
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
*
AnnouncementReadQuery
)
ForUpdate
(
opts
...
sql
.
LockOption
)
*
AnnouncementReadQuery
{
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
*
AnnouncementReadQuery
)
ForShare
(
opts
...
sql
.
LockOption
)
*
AnnouncementReadQuery
{
if
_q
.
driver
.
Dialect
()
==
dialect
.
Postgres
{
_q
.
Unique
(
false
)
}
_q
.
modifiers
=
append
(
_q
.
modifiers
,
func
(
s
*
sql
.
Selector
)
{
s
.
ForShare
(
opts
...
)
})
return
_q
}
// AnnouncementReadGroupBy is the group-by builder for AnnouncementRead entities.
type
AnnouncementReadGroupBy
struct
{
selector
build
*
AnnouncementReadQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func
(
_g
*
AnnouncementReadGroupBy
)
Aggregate
(
fns
...
AggregateFunc
)
*
AnnouncementReadGroupBy
{
_g
.
fns
=
append
(
_g
.
fns
,
fns
...
)
return
_g
}
// Scan applies the selector query and scans the result into the given value.
func
(
_g
*
AnnouncementReadGroupBy
)
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
[
*
AnnouncementReadQuery
,
*
AnnouncementReadGroupBy
](
ctx
,
_g
.
build
,
_g
,
_g
.
build
.
inters
,
v
)
}
func
(
_g
*
AnnouncementReadGroupBy
)
sqlScan
(
ctx
context
.
Context
,
root
*
AnnouncementReadQuery
,
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
)
}
// AnnouncementReadSelect is the builder for selecting fields of AnnouncementRead entities.
type
AnnouncementReadSelect
struct
{
*
AnnouncementReadQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func
(
_s
*
AnnouncementReadSelect
)
Aggregate
(
fns
...
AggregateFunc
)
*
AnnouncementReadSelect
{
_s
.
fns
=
append
(
_s
.
fns
,
fns
...
)
return
_s
}
// Scan applies the selector query and scans the result into the given value.
func
(
_s
*
AnnouncementReadSelect
)
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
[
*
AnnouncementReadQuery
,
*
AnnouncementReadSelect
](
ctx
,
_s
.
AnnouncementReadQuery
,
_s
,
_s
.
inters
,
v
)
}
func
(
_s
*
AnnouncementReadSelect
)
sqlScan
(
ctx
context
.
Context
,
root
*
AnnouncementReadQuery
,
v
any
)
error
{
selector
:=
root
.
sqlQuery
(
ctx
)
aggregation
:=
make
([]
string
,
0
,
len
(
_s
.
fns
))
for
_
,
fn
:=
range
_s
.
fns
{
aggregation
=
append
(
aggregation
,
fn
(
selector
))
}
switch
n
:=
len
(
*
_s
.
selector
.
flds
);
{
case
n
==
0
&&
len
(
aggregation
)
>
0
:
selector
.
Select
(
aggregation
...
)
case
n
!=
0
&&
len
(
aggregation
)
>
0
:
selector
.
AppendSelect
(
aggregation
...
)
}
rows
:=
&
sql
.
Rows
{}
query
,
args
:=
selector
.
Query
()
if
err
:=
_s
.
driver
.
Query
(
ctx
,
query
,
args
,
rows
);
err
!=
nil
{
return
err
}
defer
rows
.
Close
()
return
sql
.
ScanSlice
(
rows
,
v
)
}
backend/ent/announcementread_update.go
0 → 100644
View file @
0170d19f
// 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/announcement"
"github.com/Wei-Shaw/sub2api/ent/announcementread"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/user"
)
// AnnouncementReadUpdate is the builder for updating AnnouncementRead entities.
type
AnnouncementReadUpdate
struct
{
config
hooks
[]
Hook
mutation
*
AnnouncementReadMutation
}
// Where appends a list predicates to the AnnouncementReadUpdate builder.
func
(
_u
*
AnnouncementReadUpdate
)
Where
(
ps
...
predicate
.
AnnouncementRead
)
*
AnnouncementReadUpdate
{
_u
.
mutation
.
Where
(
ps
...
)
return
_u
}
// SetAnnouncementID sets the "announcement_id" field.
func
(
_u
*
AnnouncementReadUpdate
)
SetAnnouncementID
(
v
int64
)
*
AnnouncementReadUpdate
{
_u
.
mutation
.
SetAnnouncementID
(
v
)
return
_u
}
// SetNillableAnnouncementID sets the "announcement_id" field if the given value is not nil.
func
(
_u
*
AnnouncementReadUpdate
)
SetNillableAnnouncementID
(
v
*
int64
)
*
AnnouncementReadUpdate
{
if
v
!=
nil
{
_u
.
SetAnnouncementID
(
*
v
)
}
return
_u
}
// SetUserID sets the "user_id" field.
func
(
_u
*
AnnouncementReadUpdate
)
SetUserID
(
v
int64
)
*
AnnouncementReadUpdate
{
_u
.
mutation
.
SetUserID
(
v
)
return
_u
}
// SetNillableUserID sets the "user_id" field if the given value is not nil.
func
(
_u
*
AnnouncementReadUpdate
)
SetNillableUserID
(
v
*
int64
)
*
AnnouncementReadUpdate
{
if
v
!=
nil
{
_u
.
SetUserID
(
*
v
)
}
return
_u
}
// SetReadAt sets the "read_at" field.
func
(
_u
*
AnnouncementReadUpdate
)
SetReadAt
(
v
time
.
Time
)
*
AnnouncementReadUpdate
{
_u
.
mutation
.
SetReadAt
(
v
)
return
_u
}
// SetNillableReadAt sets the "read_at" field if the given value is not nil.
func
(
_u
*
AnnouncementReadUpdate
)
SetNillableReadAt
(
v
*
time
.
Time
)
*
AnnouncementReadUpdate
{
if
v
!=
nil
{
_u
.
SetReadAt
(
*
v
)
}
return
_u
}
// SetAnnouncement sets the "announcement" edge to the Announcement entity.
func
(
_u
*
AnnouncementReadUpdate
)
SetAnnouncement
(
v
*
Announcement
)
*
AnnouncementReadUpdate
{
return
_u
.
SetAnnouncementID
(
v
.
ID
)
}
// SetUser sets the "user" edge to the User entity.
func
(
_u
*
AnnouncementReadUpdate
)
SetUser
(
v
*
User
)
*
AnnouncementReadUpdate
{
return
_u
.
SetUserID
(
v
.
ID
)
}
// Mutation returns the AnnouncementReadMutation object of the builder.
func
(
_u
*
AnnouncementReadUpdate
)
Mutation
()
*
AnnouncementReadMutation
{
return
_u
.
mutation
}
// ClearAnnouncement clears the "announcement" edge to the Announcement entity.
func
(
_u
*
AnnouncementReadUpdate
)
ClearAnnouncement
()
*
AnnouncementReadUpdate
{
_u
.
mutation
.
ClearAnnouncement
()
return
_u
}
// ClearUser clears the "user" edge to the User entity.
func
(
_u
*
AnnouncementReadUpdate
)
ClearUser
()
*
AnnouncementReadUpdate
{
_u
.
mutation
.
ClearUser
()
return
_u
}
// Save executes the query and returns the number of nodes affected by the update operation.
func
(
_u
*
AnnouncementReadUpdate
)
Save
(
ctx
context
.
Context
)
(
int
,
error
)
{
return
withHooks
(
ctx
,
_u
.
sqlSave
,
_u
.
mutation
,
_u
.
hooks
)
}
// SaveX is like Save, but panics if an error occurs.
func
(
_u
*
AnnouncementReadUpdate
)
SaveX
(
ctx
context
.
Context
)
int
{
affected
,
err
:=
_u
.
Save
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
affected
}
// Exec executes the query.
func
(
_u
*
AnnouncementReadUpdate
)
Exec
(
ctx
context
.
Context
)
error
{
_
,
err
:=
_u
.
Save
(
ctx
)
return
err
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_u
*
AnnouncementReadUpdate
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
_u
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
// check runs all checks and user-defined validators on the builder.
func
(
_u
*
AnnouncementReadUpdate
)
check
()
error
{
if
_u
.
mutation
.
AnnouncementCleared
()
&&
len
(
_u
.
mutation
.
AnnouncementIDs
())
>
0
{
return
errors
.
New
(
`ent: clearing a required unique edge "AnnouncementRead.announcement"`
)
}
if
_u
.
mutation
.
UserCleared
()
&&
len
(
_u
.
mutation
.
UserIDs
())
>
0
{
return
errors
.
New
(
`ent: clearing a required unique edge "AnnouncementRead.user"`
)
}
return
nil
}
func
(
_u
*
AnnouncementReadUpdate
)
sqlSave
(
ctx
context
.
Context
)
(
_node
int
,
err
error
)
{
if
err
:=
_u
.
check
();
err
!=
nil
{
return
_node
,
err
}
_spec
:=
sqlgraph
.
NewUpdateSpec
(
announcementread
.
Table
,
announcementread
.
Columns
,
sqlgraph
.
NewFieldSpec
(
announcementread
.
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
.
ReadAt
();
ok
{
_spec
.
SetField
(
announcementread
.
FieldReadAt
,
field
.
TypeTime
,
value
)
}
if
_u
.
mutation
.
AnnouncementCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
M2O
,
Inverse
:
true
,
Table
:
announcementread
.
AnnouncementTable
,
Columns
:
[]
string
{
announcementread
.
AnnouncementColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
announcement
.
FieldID
,
field
.
TypeInt64
),
},
}
_spec
.
Edges
.
Clear
=
append
(
_spec
.
Edges
.
Clear
,
edge
)
}
if
nodes
:=
_u
.
mutation
.
AnnouncementIDs
();
len
(
nodes
)
>
0
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
M2O
,
Inverse
:
true
,
Table
:
announcementread
.
AnnouncementTable
,
Columns
:
[]
string
{
announcementread
.
AnnouncementColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
announcement
.
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
.
UserCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
M2O
,
Inverse
:
true
,
Table
:
announcementread
.
UserTable
,
Columns
:
[]
string
{
announcementread
.
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
:
announcementread
.
UserTable
,
Columns
:
[]
string
{
announcementread
.
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
_node
,
err
=
sqlgraph
.
UpdateNodes
(
ctx
,
_u
.
driver
,
_spec
);
err
!=
nil
{
if
_
,
ok
:=
err
.
(
*
sqlgraph
.
NotFoundError
);
ok
{
err
=
&
NotFoundError
{
announcementread
.
Label
}
}
else
if
sqlgraph
.
IsConstraintError
(
err
)
{
err
=
&
ConstraintError
{
msg
:
err
.
Error
(),
wrap
:
err
}
}
return
0
,
err
}
_u
.
mutation
.
done
=
true
return
_node
,
nil
}
// AnnouncementReadUpdateOne is the builder for updating a single AnnouncementRead entity.
type
AnnouncementReadUpdateOne
struct
{
config
fields
[]
string
hooks
[]
Hook
mutation
*
AnnouncementReadMutation
}
// SetAnnouncementID sets the "announcement_id" field.
func
(
_u
*
AnnouncementReadUpdateOne
)
SetAnnouncementID
(
v
int64
)
*
AnnouncementReadUpdateOne
{
_u
.
mutation
.
SetAnnouncementID
(
v
)
return
_u
}
// SetNillableAnnouncementID sets the "announcement_id" field if the given value is not nil.
func
(
_u
*
AnnouncementReadUpdateOne
)
SetNillableAnnouncementID
(
v
*
int64
)
*
AnnouncementReadUpdateOne
{
if
v
!=
nil
{
_u
.
SetAnnouncementID
(
*
v
)
}
return
_u
}
// SetUserID sets the "user_id" field.
func
(
_u
*
AnnouncementReadUpdateOne
)
SetUserID
(
v
int64
)
*
AnnouncementReadUpdateOne
{
_u
.
mutation
.
SetUserID
(
v
)
return
_u
}
// SetNillableUserID sets the "user_id" field if the given value is not nil.
func
(
_u
*
AnnouncementReadUpdateOne
)
SetNillableUserID
(
v
*
int64
)
*
AnnouncementReadUpdateOne
{
if
v
!=
nil
{
_u
.
SetUserID
(
*
v
)
}
return
_u
}
// SetReadAt sets the "read_at" field.
func
(
_u
*
AnnouncementReadUpdateOne
)
SetReadAt
(
v
time
.
Time
)
*
AnnouncementReadUpdateOne
{
_u
.
mutation
.
SetReadAt
(
v
)
return
_u
}
// SetNillableReadAt sets the "read_at" field if the given value is not nil.
func
(
_u
*
AnnouncementReadUpdateOne
)
SetNillableReadAt
(
v
*
time
.
Time
)
*
AnnouncementReadUpdateOne
{
if
v
!=
nil
{
_u
.
SetReadAt
(
*
v
)
}
return
_u
}
// SetAnnouncement sets the "announcement" edge to the Announcement entity.
func
(
_u
*
AnnouncementReadUpdateOne
)
SetAnnouncement
(
v
*
Announcement
)
*
AnnouncementReadUpdateOne
{
return
_u
.
SetAnnouncementID
(
v
.
ID
)
}
// SetUser sets the "user" edge to the User entity.
func
(
_u
*
AnnouncementReadUpdateOne
)
SetUser
(
v
*
User
)
*
AnnouncementReadUpdateOne
{
return
_u
.
SetUserID
(
v
.
ID
)
}
// Mutation returns the AnnouncementReadMutation object of the builder.
func
(
_u
*
AnnouncementReadUpdateOne
)
Mutation
()
*
AnnouncementReadMutation
{
return
_u
.
mutation
}
// ClearAnnouncement clears the "announcement" edge to the Announcement entity.
func
(
_u
*
AnnouncementReadUpdateOne
)
ClearAnnouncement
()
*
AnnouncementReadUpdateOne
{
_u
.
mutation
.
ClearAnnouncement
()
return
_u
}
// ClearUser clears the "user" edge to the User entity.
func
(
_u
*
AnnouncementReadUpdateOne
)
ClearUser
()
*
AnnouncementReadUpdateOne
{
_u
.
mutation
.
ClearUser
()
return
_u
}
// Where appends a list predicates to the AnnouncementReadUpdate builder.
func
(
_u
*
AnnouncementReadUpdateOne
)
Where
(
ps
...
predicate
.
AnnouncementRead
)
*
AnnouncementReadUpdateOne
{
_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
*
AnnouncementReadUpdateOne
)
Select
(
field
string
,
fields
...
string
)
*
AnnouncementReadUpdateOne
{
_u
.
fields
=
append
([]
string
{
field
},
fields
...
)
return
_u
}
// Save executes the query and returns the updated AnnouncementRead entity.
func
(
_u
*
AnnouncementReadUpdateOne
)
Save
(
ctx
context
.
Context
)
(
*
AnnouncementRead
,
error
)
{
return
withHooks
(
ctx
,
_u
.
sqlSave
,
_u
.
mutation
,
_u
.
hooks
)
}
// SaveX is like Save, but panics if an error occurs.
func
(
_u
*
AnnouncementReadUpdateOne
)
SaveX
(
ctx
context
.
Context
)
*
AnnouncementRead
{
node
,
err
:=
_u
.
Save
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
node
}
// Exec executes the query on the entity.
func
(
_u
*
AnnouncementReadUpdateOne
)
Exec
(
ctx
context
.
Context
)
error
{
_
,
err
:=
_u
.
Save
(
ctx
)
return
err
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_u
*
AnnouncementReadUpdateOne
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
_u
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
// check runs all checks and user-defined validators on the builder.
func
(
_u
*
AnnouncementReadUpdateOne
)
check
()
error
{
if
_u
.
mutation
.
AnnouncementCleared
()
&&
len
(
_u
.
mutation
.
AnnouncementIDs
())
>
0
{
return
errors
.
New
(
`ent: clearing a required unique edge "AnnouncementRead.announcement"`
)
}
if
_u
.
mutation
.
UserCleared
()
&&
len
(
_u
.
mutation
.
UserIDs
())
>
0
{
return
errors
.
New
(
`ent: clearing a required unique edge "AnnouncementRead.user"`
)
}
return
nil
}
func
(
_u
*
AnnouncementReadUpdateOne
)
sqlSave
(
ctx
context
.
Context
)
(
_node
*
AnnouncementRead
,
err
error
)
{
if
err
:=
_u
.
check
();
err
!=
nil
{
return
_node
,
err
}
_spec
:=
sqlgraph
.
NewUpdateSpec
(
announcementread
.
Table
,
announcementread
.
Columns
,
sqlgraph
.
NewFieldSpec
(
announcementread
.
FieldID
,
field
.
TypeInt64
))
id
,
ok
:=
_u
.
mutation
.
ID
()
if
!
ok
{
return
nil
,
&
ValidationError
{
Name
:
"id"
,
err
:
errors
.
New
(
`ent: missing "AnnouncementRead.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
,
announcementread
.
FieldID
)
for
_
,
f
:=
range
fields
{
if
!
announcementread
.
ValidColumn
(
f
)
{
return
nil
,
&
ValidationError
{
Name
:
f
,
err
:
fmt
.
Errorf
(
"ent: invalid field %q for query"
,
f
)}
}
if
f
!=
announcementread
.
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
.
ReadAt
();
ok
{
_spec
.
SetField
(
announcementread
.
FieldReadAt
,
field
.
TypeTime
,
value
)
}
if
_u
.
mutation
.
AnnouncementCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
M2O
,
Inverse
:
true
,
Table
:
announcementread
.
AnnouncementTable
,
Columns
:
[]
string
{
announcementread
.
AnnouncementColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
announcement
.
FieldID
,
field
.
TypeInt64
),
},
}
_spec
.
Edges
.
Clear
=
append
(
_spec
.
Edges
.
Clear
,
edge
)
}
if
nodes
:=
_u
.
mutation
.
AnnouncementIDs
();
len
(
nodes
)
>
0
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
M2O
,
Inverse
:
true
,
Table
:
announcementread
.
AnnouncementTable
,
Columns
:
[]
string
{
announcementread
.
AnnouncementColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
announcement
.
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
.
UserCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
M2O
,
Inverse
:
true
,
Table
:
announcementread
.
UserTable
,
Columns
:
[]
string
{
announcementread
.
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
:
announcementread
.
UserTable
,
Columns
:
[]
string
{
announcementread
.
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
)
}
_node
=
&
AnnouncementRead
{
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
{
announcementread
.
Label
}
}
else
if
sqlgraph
.
IsConstraintError
(
err
)
{
err
=
&
ConstraintError
{
msg
:
err
.
Error
(),
wrap
:
err
}
}
return
nil
,
err
}
_u
.
mutation
.
done
=
true
return
_node
,
nil
}
backend/ent/client.go
View file @
0170d19f
...
...
@@ -17,6 +17,8 @@ import (
"entgo.io/ent/dialect/sql/sqlgraph"
"github.com/Wei-Shaw/sub2api/ent/account"
"github.com/Wei-Shaw/sub2api/ent/accountgroup"
"github.com/Wei-Shaw/sub2api/ent/announcement"
"github.com/Wei-Shaw/sub2api/ent/announcementread"
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/promocode"
...
...
@@ -24,6 +26,7 @@ import (
"github.com/Wei-Shaw/sub2api/ent/proxy"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/setting"
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
"github.com/Wei-Shaw/sub2api/ent/usagelog"
"github.com/Wei-Shaw/sub2api/ent/user"
"github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
...
...
@@ -45,6 +48,10 @@ type Client struct {
Account
*
AccountClient
// AccountGroup is the client for interacting with the AccountGroup builders.
AccountGroup
*
AccountGroupClient
// Announcement is the client for interacting with the Announcement builders.
Announcement
*
AnnouncementClient
// AnnouncementRead is the client for interacting with the AnnouncementRead builders.
AnnouncementRead
*
AnnouncementReadClient
// Group is the client for interacting with the Group builders.
Group
*
GroupClient
// PromoCode is the client for interacting with the PromoCode builders.
...
...
@@ -57,6 +64,8 @@ type Client struct {
RedeemCode
*
RedeemCodeClient
// Setting is the client for interacting with the Setting builders.
Setting
*
SettingClient
// UsageCleanupTask is the client for interacting with the UsageCleanupTask builders.
UsageCleanupTask
*
UsageCleanupTaskClient
// UsageLog is the client for interacting with the UsageLog builders.
UsageLog
*
UsageLogClient
// User is the client for interacting with the User builders.
...
...
@@ -83,12 +92,15 @@ func (c *Client) init() {
c
.
APIKey
=
NewAPIKeyClient
(
c
.
config
)
c
.
Account
=
NewAccountClient
(
c
.
config
)
c
.
AccountGroup
=
NewAccountGroupClient
(
c
.
config
)
c
.
Announcement
=
NewAnnouncementClient
(
c
.
config
)
c
.
AnnouncementRead
=
NewAnnouncementReadClient
(
c
.
config
)
c
.
Group
=
NewGroupClient
(
c
.
config
)
c
.
PromoCode
=
NewPromoCodeClient
(
c
.
config
)
c
.
PromoCodeUsage
=
NewPromoCodeUsageClient
(
c
.
config
)
c
.
Proxy
=
NewProxyClient
(
c
.
config
)
c
.
RedeemCode
=
NewRedeemCodeClient
(
c
.
config
)
c
.
Setting
=
NewSettingClient
(
c
.
config
)
c
.
UsageCleanupTask
=
NewUsageCleanupTaskClient
(
c
.
config
)
c
.
UsageLog
=
NewUsageLogClient
(
c
.
config
)
c
.
User
=
NewUserClient
(
c
.
config
)
c
.
UserAllowedGroup
=
NewUserAllowedGroupClient
(
c
.
config
)
...
...
@@ -190,12 +202,15 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
APIKey
:
NewAPIKeyClient
(
cfg
),
Account
:
NewAccountClient
(
cfg
),
AccountGroup
:
NewAccountGroupClient
(
cfg
),
Announcement
:
NewAnnouncementClient
(
cfg
),
AnnouncementRead
:
NewAnnouncementReadClient
(
cfg
),
Group
:
NewGroupClient
(
cfg
),
PromoCode
:
NewPromoCodeClient
(
cfg
),
PromoCodeUsage
:
NewPromoCodeUsageClient
(
cfg
),
Proxy
:
NewProxyClient
(
cfg
),
RedeemCode
:
NewRedeemCodeClient
(
cfg
),
Setting
:
NewSettingClient
(
cfg
),
UsageCleanupTask
:
NewUsageCleanupTaskClient
(
cfg
),
UsageLog
:
NewUsageLogClient
(
cfg
),
User
:
NewUserClient
(
cfg
),
UserAllowedGroup
:
NewUserAllowedGroupClient
(
cfg
),
...
...
@@ -224,12 +239,15 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
APIKey
:
NewAPIKeyClient
(
cfg
),
Account
:
NewAccountClient
(
cfg
),
AccountGroup
:
NewAccountGroupClient
(
cfg
),
Announcement
:
NewAnnouncementClient
(
cfg
),
AnnouncementRead
:
NewAnnouncementReadClient
(
cfg
),
Group
:
NewGroupClient
(
cfg
),
PromoCode
:
NewPromoCodeClient
(
cfg
),
PromoCodeUsage
:
NewPromoCodeUsageClient
(
cfg
),
Proxy
:
NewProxyClient
(
cfg
),
RedeemCode
:
NewRedeemCodeClient
(
cfg
),
Setting
:
NewSettingClient
(
cfg
),
UsageCleanupTask
:
NewUsageCleanupTaskClient
(
cfg
),
UsageLog
:
NewUsageLogClient
(
cfg
),
User
:
NewUserClient
(
cfg
),
UserAllowedGroup
:
NewUserAllowedGroupClient
(
cfg
),
...
...
@@ -265,8 +283,9 @@ func (c *Client) Close() error {
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
func
(
c
*
Client
)
Use
(
hooks
...
Hook
)
{
for
_
,
n
:=
range
[]
interface
{
Use
(
...
Hook
)
}{
c
.
APIKey
,
c
.
Account
,
c
.
AccountGroup
,
c
.
Group
,
c
.
PromoCode
,
c
.
PromoCodeUsage
,
c
.
Proxy
,
c
.
RedeemCode
,
c
.
Setting
,
c
.
UsageLog
,
c
.
User
,
c
.
UserAllowedGroup
,
c
.
APIKey
,
c
.
Account
,
c
.
AccountGroup
,
c
.
Announcement
,
c
.
AnnouncementRead
,
c
.
Group
,
c
.
PromoCode
,
c
.
PromoCodeUsage
,
c
.
Proxy
,
c
.
RedeemCode
,
c
.
Setting
,
c
.
UsageCleanupTask
,
c
.
UsageLog
,
c
.
User
,
c
.
UserAllowedGroup
,
c
.
UserAttributeDefinition
,
c
.
UserAttributeValue
,
c
.
UserSubscription
,
}
{
n
.
Use
(
hooks
...
)
...
...
@@ -277,8 +296,9 @@ func (c *Client) Use(hooks ...Hook) {
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
func
(
c
*
Client
)
Intercept
(
interceptors
...
Interceptor
)
{
for
_
,
n
:=
range
[]
interface
{
Intercept
(
...
Interceptor
)
}{
c
.
APIKey
,
c
.
Account
,
c
.
AccountGroup
,
c
.
Group
,
c
.
PromoCode
,
c
.
PromoCodeUsage
,
c
.
Proxy
,
c
.
RedeemCode
,
c
.
Setting
,
c
.
UsageLog
,
c
.
User
,
c
.
UserAllowedGroup
,
c
.
APIKey
,
c
.
Account
,
c
.
AccountGroup
,
c
.
Announcement
,
c
.
AnnouncementRead
,
c
.
Group
,
c
.
PromoCode
,
c
.
PromoCodeUsage
,
c
.
Proxy
,
c
.
RedeemCode
,
c
.
Setting
,
c
.
UsageCleanupTask
,
c
.
UsageLog
,
c
.
User
,
c
.
UserAllowedGroup
,
c
.
UserAttributeDefinition
,
c
.
UserAttributeValue
,
c
.
UserSubscription
,
}
{
n
.
Intercept
(
interceptors
...
)
...
...
@@ -294,6 +314,10 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
return
c
.
Account
.
mutate
(
ctx
,
m
)
case
*
AccountGroupMutation
:
return
c
.
AccountGroup
.
mutate
(
ctx
,
m
)
case
*
AnnouncementMutation
:
return
c
.
Announcement
.
mutate
(
ctx
,
m
)
case
*
AnnouncementReadMutation
:
return
c
.
AnnouncementRead
.
mutate
(
ctx
,
m
)
case
*
GroupMutation
:
return
c
.
Group
.
mutate
(
ctx
,
m
)
case
*
PromoCodeMutation
:
...
...
@@ -306,6 +330,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
return
c
.
RedeemCode
.
mutate
(
ctx
,
m
)
case
*
SettingMutation
:
return
c
.
Setting
.
mutate
(
ctx
,
m
)
case
*
UsageCleanupTaskMutation
:
return
c
.
UsageCleanupTask
.
mutate
(
ctx
,
m
)
case
*
UsageLogMutation
:
return
c
.
UsageLog
.
mutate
(
ctx
,
m
)
case
*
UserMutation
:
...
...
@@ -821,6 +847,320 @@ func (c *AccountGroupClient) mutate(ctx context.Context, m *AccountGroupMutation
}
}
// AnnouncementClient is a client for the Announcement schema.
type
AnnouncementClient
struct
{
config
}
// NewAnnouncementClient returns a client for the Announcement from the given config.
func
NewAnnouncementClient
(
c
config
)
*
AnnouncementClient
{
return
&
AnnouncementClient
{
config
:
c
}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `announcement.Hooks(f(g(h())))`.
func
(
c
*
AnnouncementClient
)
Use
(
hooks
...
Hook
)
{
c
.
hooks
.
Announcement
=
append
(
c
.
hooks
.
Announcement
,
hooks
...
)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `announcement.Intercept(f(g(h())))`.
func
(
c
*
AnnouncementClient
)
Intercept
(
interceptors
...
Interceptor
)
{
c
.
inters
.
Announcement
=
append
(
c
.
inters
.
Announcement
,
interceptors
...
)
}
// Create returns a builder for creating a Announcement entity.
func
(
c
*
AnnouncementClient
)
Create
()
*
AnnouncementCreate
{
mutation
:=
newAnnouncementMutation
(
c
.
config
,
OpCreate
)
return
&
AnnouncementCreate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// CreateBulk returns a builder for creating a bulk of Announcement entities.
func
(
c
*
AnnouncementClient
)
CreateBulk
(
builders
...*
AnnouncementCreate
)
*
AnnouncementCreateBulk
{
return
&
AnnouncementCreateBulk
{
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
*
AnnouncementClient
)
MapCreateBulk
(
slice
any
,
setFunc
func
(
*
AnnouncementCreate
,
int
))
*
AnnouncementCreateBulk
{
rv
:=
reflect
.
ValueOf
(
slice
)
if
rv
.
Kind
()
!=
reflect
.
Slice
{
return
&
AnnouncementCreateBulk
{
err
:
fmt
.
Errorf
(
"calling to AnnouncementClient.MapCreateBulk with wrong type %T, need slice"
,
slice
)}
}
builders
:=
make
([]
*
AnnouncementCreate
,
rv
.
Len
())
for
i
:=
0
;
i
<
rv
.
Len
();
i
++
{
builders
[
i
]
=
c
.
Create
()
setFunc
(
builders
[
i
],
i
)
}
return
&
AnnouncementCreateBulk
{
config
:
c
.
config
,
builders
:
builders
}
}
// Update returns an update builder for Announcement.
func
(
c
*
AnnouncementClient
)
Update
()
*
AnnouncementUpdate
{
mutation
:=
newAnnouncementMutation
(
c
.
config
,
OpUpdate
)
return
&
AnnouncementUpdate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// UpdateOne returns an update builder for the given entity.
func
(
c
*
AnnouncementClient
)
UpdateOne
(
_m
*
Announcement
)
*
AnnouncementUpdateOne
{
mutation
:=
newAnnouncementMutation
(
c
.
config
,
OpUpdateOne
,
withAnnouncement
(
_m
))
return
&
AnnouncementUpdateOne
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// UpdateOneID returns an update builder for the given id.
func
(
c
*
AnnouncementClient
)
UpdateOneID
(
id
int64
)
*
AnnouncementUpdateOne
{
mutation
:=
newAnnouncementMutation
(
c
.
config
,
OpUpdateOne
,
withAnnouncementID
(
id
))
return
&
AnnouncementUpdateOne
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// Delete returns a delete builder for Announcement.
func
(
c
*
AnnouncementClient
)
Delete
()
*
AnnouncementDelete
{
mutation
:=
newAnnouncementMutation
(
c
.
config
,
OpDelete
)
return
&
AnnouncementDelete
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// DeleteOne returns a builder for deleting the given entity.
func
(
c
*
AnnouncementClient
)
DeleteOne
(
_m
*
Announcement
)
*
AnnouncementDeleteOne
{
return
c
.
DeleteOneID
(
_m
.
ID
)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func
(
c
*
AnnouncementClient
)
DeleteOneID
(
id
int64
)
*
AnnouncementDeleteOne
{
builder
:=
c
.
Delete
()
.
Where
(
announcement
.
ID
(
id
))
builder
.
mutation
.
id
=
&
id
builder
.
mutation
.
op
=
OpDeleteOne
return
&
AnnouncementDeleteOne
{
builder
}
}
// Query returns a query builder for Announcement.
func
(
c
*
AnnouncementClient
)
Query
()
*
AnnouncementQuery
{
return
&
AnnouncementQuery
{
config
:
c
.
config
,
ctx
:
&
QueryContext
{
Type
:
TypeAnnouncement
},
inters
:
c
.
Interceptors
(),
}
}
// Get returns a Announcement entity by its id.
func
(
c
*
AnnouncementClient
)
Get
(
ctx
context
.
Context
,
id
int64
)
(
*
Announcement
,
error
)
{
return
c
.
Query
()
.
Where
(
announcement
.
ID
(
id
))
.
Only
(
ctx
)
}
// GetX is like Get, but panics if an error occurs.
func
(
c
*
AnnouncementClient
)
GetX
(
ctx
context
.
Context
,
id
int64
)
*
Announcement
{
obj
,
err
:=
c
.
Get
(
ctx
,
id
)
if
err
!=
nil
{
panic
(
err
)
}
return
obj
}
// QueryReads queries the reads edge of a Announcement.
func
(
c
*
AnnouncementClient
)
QueryReads
(
_m
*
Announcement
)
*
AnnouncementReadQuery
{
query
:=
(
&
AnnouncementReadClient
{
config
:
c
.
config
})
.
Query
()
query
.
path
=
func
(
context
.
Context
)
(
fromV
*
sql
.
Selector
,
_
error
)
{
id
:=
_m
.
ID
step
:=
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
announcement
.
Table
,
announcement
.
FieldID
,
id
),
sqlgraph
.
To
(
announcementread
.
Table
,
announcementread
.
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
O2M
,
false
,
announcement
.
ReadsTable
,
announcement
.
ReadsColumn
),
)
fromV
=
sqlgraph
.
Neighbors
(
_m
.
driver
.
Dialect
(),
step
)
return
fromV
,
nil
}
return
query
}
// Hooks returns the client hooks.
func
(
c
*
AnnouncementClient
)
Hooks
()
[]
Hook
{
return
c
.
hooks
.
Announcement
}
// Interceptors returns the client interceptors.
func
(
c
*
AnnouncementClient
)
Interceptors
()
[]
Interceptor
{
return
c
.
inters
.
Announcement
}
func
(
c
*
AnnouncementClient
)
mutate
(
ctx
context
.
Context
,
m
*
AnnouncementMutation
)
(
Value
,
error
)
{
switch
m
.
Op
()
{
case
OpCreate
:
return
(
&
AnnouncementCreate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Save
(
ctx
)
case
OpUpdate
:
return
(
&
AnnouncementUpdate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Save
(
ctx
)
case
OpUpdateOne
:
return
(
&
AnnouncementUpdateOne
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Save
(
ctx
)
case
OpDelete
,
OpDeleteOne
:
return
(
&
AnnouncementDelete
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Exec
(
ctx
)
default
:
return
nil
,
fmt
.
Errorf
(
"ent: unknown Announcement mutation op: %q"
,
m
.
Op
())
}
}
// AnnouncementReadClient is a client for the AnnouncementRead schema.
type
AnnouncementReadClient
struct
{
config
}
// NewAnnouncementReadClient returns a client for the AnnouncementRead from the given config.
func
NewAnnouncementReadClient
(
c
config
)
*
AnnouncementReadClient
{
return
&
AnnouncementReadClient
{
config
:
c
}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `announcementread.Hooks(f(g(h())))`.
func
(
c
*
AnnouncementReadClient
)
Use
(
hooks
...
Hook
)
{
c
.
hooks
.
AnnouncementRead
=
append
(
c
.
hooks
.
AnnouncementRead
,
hooks
...
)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `announcementread.Intercept(f(g(h())))`.
func
(
c
*
AnnouncementReadClient
)
Intercept
(
interceptors
...
Interceptor
)
{
c
.
inters
.
AnnouncementRead
=
append
(
c
.
inters
.
AnnouncementRead
,
interceptors
...
)
}
// Create returns a builder for creating a AnnouncementRead entity.
func
(
c
*
AnnouncementReadClient
)
Create
()
*
AnnouncementReadCreate
{
mutation
:=
newAnnouncementReadMutation
(
c
.
config
,
OpCreate
)
return
&
AnnouncementReadCreate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// CreateBulk returns a builder for creating a bulk of AnnouncementRead entities.
func
(
c
*
AnnouncementReadClient
)
CreateBulk
(
builders
...*
AnnouncementReadCreate
)
*
AnnouncementReadCreateBulk
{
return
&
AnnouncementReadCreateBulk
{
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
*
AnnouncementReadClient
)
MapCreateBulk
(
slice
any
,
setFunc
func
(
*
AnnouncementReadCreate
,
int
))
*
AnnouncementReadCreateBulk
{
rv
:=
reflect
.
ValueOf
(
slice
)
if
rv
.
Kind
()
!=
reflect
.
Slice
{
return
&
AnnouncementReadCreateBulk
{
err
:
fmt
.
Errorf
(
"calling to AnnouncementReadClient.MapCreateBulk with wrong type %T, need slice"
,
slice
)}
}
builders
:=
make
([]
*
AnnouncementReadCreate
,
rv
.
Len
())
for
i
:=
0
;
i
<
rv
.
Len
();
i
++
{
builders
[
i
]
=
c
.
Create
()
setFunc
(
builders
[
i
],
i
)
}
return
&
AnnouncementReadCreateBulk
{
config
:
c
.
config
,
builders
:
builders
}
}
// Update returns an update builder for AnnouncementRead.
func
(
c
*
AnnouncementReadClient
)
Update
()
*
AnnouncementReadUpdate
{
mutation
:=
newAnnouncementReadMutation
(
c
.
config
,
OpUpdate
)
return
&
AnnouncementReadUpdate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// UpdateOne returns an update builder for the given entity.
func
(
c
*
AnnouncementReadClient
)
UpdateOne
(
_m
*
AnnouncementRead
)
*
AnnouncementReadUpdateOne
{
mutation
:=
newAnnouncementReadMutation
(
c
.
config
,
OpUpdateOne
,
withAnnouncementRead
(
_m
))
return
&
AnnouncementReadUpdateOne
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// UpdateOneID returns an update builder for the given id.
func
(
c
*
AnnouncementReadClient
)
UpdateOneID
(
id
int64
)
*
AnnouncementReadUpdateOne
{
mutation
:=
newAnnouncementReadMutation
(
c
.
config
,
OpUpdateOne
,
withAnnouncementReadID
(
id
))
return
&
AnnouncementReadUpdateOne
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// Delete returns a delete builder for AnnouncementRead.
func
(
c
*
AnnouncementReadClient
)
Delete
()
*
AnnouncementReadDelete
{
mutation
:=
newAnnouncementReadMutation
(
c
.
config
,
OpDelete
)
return
&
AnnouncementReadDelete
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// DeleteOne returns a builder for deleting the given entity.
func
(
c
*
AnnouncementReadClient
)
DeleteOne
(
_m
*
AnnouncementRead
)
*
AnnouncementReadDeleteOne
{
return
c
.
DeleteOneID
(
_m
.
ID
)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func
(
c
*
AnnouncementReadClient
)
DeleteOneID
(
id
int64
)
*
AnnouncementReadDeleteOne
{
builder
:=
c
.
Delete
()
.
Where
(
announcementread
.
ID
(
id
))
builder
.
mutation
.
id
=
&
id
builder
.
mutation
.
op
=
OpDeleteOne
return
&
AnnouncementReadDeleteOne
{
builder
}
}
// Query returns a query builder for AnnouncementRead.
func
(
c
*
AnnouncementReadClient
)
Query
()
*
AnnouncementReadQuery
{
return
&
AnnouncementReadQuery
{
config
:
c
.
config
,
ctx
:
&
QueryContext
{
Type
:
TypeAnnouncementRead
},
inters
:
c
.
Interceptors
(),
}
}
// Get returns a AnnouncementRead entity by its id.
func
(
c
*
AnnouncementReadClient
)
Get
(
ctx
context
.
Context
,
id
int64
)
(
*
AnnouncementRead
,
error
)
{
return
c
.
Query
()
.
Where
(
announcementread
.
ID
(
id
))
.
Only
(
ctx
)
}
// GetX is like Get, but panics if an error occurs.
func
(
c
*
AnnouncementReadClient
)
GetX
(
ctx
context
.
Context
,
id
int64
)
*
AnnouncementRead
{
obj
,
err
:=
c
.
Get
(
ctx
,
id
)
if
err
!=
nil
{
panic
(
err
)
}
return
obj
}
// QueryAnnouncement queries the announcement edge of a AnnouncementRead.
func
(
c
*
AnnouncementReadClient
)
QueryAnnouncement
(
_m
*
AnnouncementRead
)
*
AnnouncementQuery
{
query
:=
(
&
AnnouncementClient
{
config
:
c
.
config
})
.
Query
()
query
.
path
=
func
(
context
.
Context
)
(
fromV
*
sql
.
Selector
,
_
error
)
{
id
:=
_m
.
ID
step
:=
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
announcementread
.
Table
,
announcementread
.
FieldID
,
id
),
sqlgraph
.
To
(
announcement
.
Table
,
announcement
.
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
M2O
,
true
,
announcementread
.
AnnouncementTable
,
announcementread
.
AnnouncementColumn
),
)
fromV
=
sqlgraph
.
Neighbors
(
_m
.
driver
.
Dialect
(),
step
)
return
fromV
,
nil
}
return
query
}
// QueryUser queries the user edge of a AnnouncementRead.
func
(
c
*
AnnouncementReadClient
)
QueryUser
(
_m
*
AnnouncementRead
)
*
UserQuery
{
query
:=
(
&
UserClient
{
config
:
c
.
config
})
.
Query
()
query
.
path
=
func
(
context
.
Context
)
(
fromV
*
sql
.
Selector
,
_
error
)
{
id
:=
_m
.
ID
step
:=
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
announcementread
.
Table
,
announcementread
.
FieldID
,
id
),
sqlgraph
.
To
(
user
.
Table
,
user
.
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
M2O
,
true
,
announcementread
.
UserTable
,
announcementread
.
UserColumn
),
)
fromV
=
sqlgraph
.
Neighbors
(
_m
.
driver
.
Dialect
(),
step
)
return
fromV
,
nil
}
return
query
}
// Hooks returns the client hooks.
func
(
c
*
AnnouncementReadClient
)
Hooks
()
[]
Hook
{
return
c
.
hooks
.
AnnouncementRead
}
// Interceptors returns the client interceptors.
func
(
c
*
AnnouncementReadClient
)
Interceptors
()
[]
Interceptor
{
return
c
.
inters
.
AnnouncementRead
}
func
(
c
*
AnnouncementReadClient
)
mutate
(
ctx
context
.
Context
,
m
*
AnnouncementReadMutation
)
(
Value
,
error
)
{
switch
m
.
Op
()
{
case
OpCreate
:
return
(
&
AnnouncementReadCreate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Save
(
ctx
)
case
OpUpdate
:
return
(
&
AnnouncementReadUpdate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Save
(
ctx
)
case
OpUpdateOne
:
return
(
&
AnnouncementReadUpdateOne
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Save
(
ctx
)
case
OpDelete
,
OpDeleteOne
:
return
(
&
AnnouncementReadDelete
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Exec
(
ctx
)
default
:
return
nil
,
fmt
.
Errorf
(
"ent: unknown AnnouncementRead mutation op: %q"
,
m
.
Op
())
}
}
// GroupClient is a client for the Group schema.
type
GroupClient
struct
{
config
...
...
@@ -1847,6 +2187,139 @@ func (c *SettingClient) mutate(ctx context.Context, m *SettingMutation) (Value,
}
}
// UsageCleanupTaskClient is a client for the UsageCleanupTask schema.
type
UsageCleanupTaskClient
struct
{
config
}
// NewUsageCleanupTaskClient returns a client for the UsageCleanupTask from the given config.
func
NewUsageCleanupTaskClient
(
c
config
)
*
UsageCleanupTaskClient
{
return
&
UsageCleanupTaskClient
{
config
:
c
}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `usagecleanuptask.Hooks(f(g(h())))`.
func
(
c
*
UsageCleanupTaskClient
)
Use
(
hooks
...
Hook
)
{
c
.
hooks
.
UsageCleanupTask
=
append
(
c
.
hooks
.
UsageCleanupTask
,
hooks
...
)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `usagecleanuptask.Intercept(f(g(h())))`.
func
(
c
*
UsageCleanupTaskClient
)
Intercept
(
interceptors
...
Interceptor
)
{
c
.
inters
.
UsageCleanupTask
=
append
(
c
.
inters
.
UsageCleanupTask
,
interceptors
...
)
}
// Create returns a builder for creating a UsageCleanupTask entity.
func
(
c
*
UsageCleanupTaskClient
)
Create
()
*
UsageCleanupTaskCreate
{
mutation
:=
newUsageCleanupTaskMutation
(
c
.
config
,
OpCreate
)
return
&
UsageCleanupTaskCreate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// CreateBulk returns a builder for creating a bulk of UsageCleanupTask entities.
func
(
c
*
UsageCleanupTaskClient
)
CreateBulk
(
builders
...*
UsageCleanupTaskCreate
)
*
UsageCleanupTaskCreateBulk
{
return
&
UsageCleanupTaskCreateBulk
{
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
*
UsageCleanupTaskClient
)
MapCreateBulk
(
slice
any
,
setFunc
func
(
*
UsageCleanupTaskCreate
,
int
))
*
UsageCleanupTaskCreateBulk
{
rv
:=
reflect
.
ValueOf
(
slice
)
if
rv
.
Kind
()
!=
reflect
.
Slice
{
return
&
UsageCleanupTaskCreateBulk
{
err
:
fmt
.
Errorf
(
"calling to UsageCleanupTaskClient.MapCreateBulk with wrong type %T, need slice"
,
slice
)}
}
builders
:=
make
([]
*
UsageCleanupTaskCreate
,
rv
.
Len
())
for
i
:=
0
;
i
<
rv
.
Len
();
i
++
{
builders
[
i
]
=
c
.
Create
()
setFunc
(
builders
[
i
],
i
)
}
return
&
UsageCleanupTaskCreateBulk
{
config
:
c
.
config
,
builders
:
builders
}
}
// Update returns an update builder for UsageCleanupTask.
func
(
c
*
UsageCleanupTaskClient
)
Update
()
*
UsageCleanupTaskUpdate
{
mutation
:=
newUsageCleanupTaskMutation
(
c
.
config
,
OpUpdate
)
return
&
UsageCleanupTaskUpdate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// UpdateOne returns an update builder for the given entity.
func
(
c
*
UsageCleanupTaskClient
)
UpdateOne
(
_m
*
UsageCleanupTask
)
*
UsageCleanupTaskUpdateOne
{
mutation
:=
newUsageCleanupTaskMutation
(
c
.
config
,
OpUpdateOne
,
withUsageCleanupTask
(
_m
))
return
&
UsageCleanupTaskUpdateOne
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// UpdateOneID returns an update builder for the given id.
func
(
c
*
UsageCleanupTaskClient
)
UpdateOneID
(
id
int64
)
*
UsageCleanupTaskUpdateOne
{
mutation
:=
newUsageCleanupTaskMutation
(
c
.
config
,
OpUpdateOne
,
withUsageCleanupTaskID
(
id
))
return
&
UsageCleanupTaskUpdateOne
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// Delete returns a delete builder for UsageCleanupTask.
func
(
c
*
UsageCleanupTaskClient
)
Delete
()
*
UsageCleanupTaskDelete
{
mutation
:=
newUsageCleanupTaskMutation
(
c
.
config
,
OpDelete
)
return
&
UsageCleanupTaskDelete
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// DeleteOne returns a builder for deleting the given entity.
func
(
c
*
UsageCleanupTaskClient
)
DeleteOne
(
_m
*
UsageCleanupTask
)
*
UsageCleanupTaskDeleteOne
{
return
c
.
DeleteOneID
(
_m
.
ID
)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func
(
c
*
UsageCleanupTaskClient
)
DeleteOneID
(
id
int64
)
*
UsageCleanupTaskDeleteOne
{
builder
:=
c
.
Delete
()
.
Where
(
usagecleanuptask
.
ID
(
id
))
builder
.
mutation
.
id
=
&
id
builder
.
mutation
.
op
=
OpDeleteOne
return
&
UsageCleanupTaskDeleteOne
{
builder
}
}
// Query returns a query builder for UsageCleanupTask.
func
(
c
*
UsageCleanupTaskClient
)
Query
()
*
UsageCleanupTaskQuery
{
return
&
UsageCleanupTaskQuery
{
config
:
c
.
config
,
ctx
:
&
QueryContext
{
Type
:
TypeUsageCleanupTask
},
inters
:
c
.
Interceptors
(),
}
}
// Get returns a UsageCleanupTask entity by its id.
func
(
c
*
UsageCleanupTaskClient
)
Get
(
ctx
context
.
Context
,
id
int64
)
(
*
UsageCleanupTask
,
error
)
{
return
c
.
Query
()
.
Where
(
usagecleanuptask
.
ID
(
id
))
.
Only
(
ctx
)
}
// GetX is like Get, but panics if an error occurs.
func
(
c
*
UsageCleanupTaskClient
)
GetX
(
ctx
context
.
Context
,
id
int64
)
*
UsageCleanupTask
{
obj
,
err
:=
c
.
Get
(
ctx
,
id
)
if
err
!=
nil
{
panic
(
err
)
}
return
obj
}
// Hooks returns the client hooks.
func
(
c
*
UsageCleanupTaskClient
)
Hooks
()
[]
Hook
{
return
c
.
hooks
.
UsageCleanupTask
}
// Interceptors returns the client interceptors.
func
(
c
*
UsageCleanupTaskClient
)
Interceptors
()
[]
Interceptor
{
return
c
.
inters
.
UsageCleanupTask
}
func
(
c
*
UsageCleanupTaskClient
)
mutate
(
ctx
context
.
Context
,
m
*
UsageCleanupTaskMutation
)
(
Value
,
error
)
{
switch
m
.
Op
()
{
case
OpCreate
:
return
(
&
UsageCleanupTaskCreate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Save
(
ctx
)
case
OpUpdate
:
return
(
&
UsageCleanupTaskUpdate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Save
(
ctx
)
case
OpUpdateOne
:
return
(
&
UsageCleanupTaskUpdateOne
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Save
(
ctx
)
case
OpDelete
,
OpDeleteOne
:
return
(
&
UsageCleanupTaskDelete
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Exec
(
ctx
)
default
:
return
nil
,
fmt
.
Errorf
(
"ent: unknown UsageCleanupTask mutation op: %q"
,
m
.
Op
())
}
}
// UsageLogClient is a client for the UsageLog schema.
type
UsageLogClient
struct
{
config
...
...
@@ -2232,6 +2705,22 @@ func (c *UserClient) QueryAssignedSubscriptions(_m *User) *UserSubscriptionQuery
return
query
}
// QueryAnnouncementReads queries the announcement_reads edge of a User.
func
(
c
*
UserClient
)
QueryAnnouncementReads
(
_m
*
User
)
*
AnnouncementReadQuery
{
query
:=
(
&
AnnouncementReadClient
{
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
(
announcementread
.
Table
,
announcementread
.
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
O2M
,
false
,
user
.
AnnouncementReadsTable
,
user
.
AnnouncementReadsColumn
),
)
fromV
=
sqlgraph
.
Neighbors
(
_m
.
driver
.
Dialect
(),
step
)
return
fromV
,
nil
}
return
query
}
// QueryAllowedGroups queries the allowed_groups edge of a User.
func
(
c
*
UserClient
)
QueryAllowedGroups
(
_m
*
User
)
*
GroupQuery
{
query
:=
(
&
GroupClient
{
config
:
c
.
config
})
.
Query
()
...
...
@@ -2973,14 +3462,16 @@ func (c *UserSubscriptionClient) mutate(ctx context.Context, m *UserSubscription
// hooks and interceptors per client, for fast access.
type
(
hooks
struct
{
APIKey
,
Account
,
AccountGroup
,
Group
,
PromoCode
,
PromoCodeUsage
,
Proxy
,
RedeemCode
,
Setting
,
UsageLog
,
User
,
UserAllowedGroup
,
UserAttributeDefinition
,
UserAttributeValue
,
UserSubscription
[]
ent
.
Hook
APIKey
,
Account
,
AccountGroup
,
Announcement
,
AnnouncementRead
,
Group
,
PromoCode
,
PromoCodeUsage
,
Proxy
,
RedeemCode
,
Setting
,
UsageCleanupTask
,
UsageLog
,
User
,
UserAllowedGroup
,
UserAttributeDefinition
,
UserAttributeValue
,
UserSubscription
[]
ent
.
Hook
}
inters
struct
{
APIKey
,
Account
,
AccountGroup
,
Group
,
PromoCode
,
PromoCodeUsage
,
Proxy
,
RedeemCode
,
Setting
,
UsageLog
,
User
,
UserAllowedGroup
,
UserAttributeDefinition
,
UserAttributeValue
,
UserSubscription
[]
ent
.
Interceptor
APIKey
,
Account
,
AccountGroup
,
Announcement
,
AnnouncementRead
,
Group
,
PromoCode
,
PromoCodeUsage
,
Proxy
,
RedeemCode
,
Setting
,
UsageCleanupTask
,
UsageLog
,
User
,
UserAllowedGroup
,
UserAttributeDefinition
,
UserAttributeValue
,
UserSubscription
[]
ent
.
Interceptor
}
)
...
...
backend/ent/ent.go
View file @
0170d19f
...
...
@@ -14,6 +14,8 @@ import (
"entgo.io/ent/dialect/sql/sqlgraph"
"github.com/Wei-Shaw/sub2api/ent/account"
"github.com/Wei-Shaw/sub2api/ent/accountgroup"
"github.com/Wei-Shaw/sub2api/ent/announcement"
"github.com/Wei-Shaw/sub2api/ent/announcementread"
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/promocode"
...
...
@@ -21,6 +23,7 @@ import (
"github.com/Wei-Shaw/sub2api/ent/proxy"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/setting"
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
"github.com/Wei-Shaw/sub2api/ent/usagelog"
"github.com/Wei-Shaw/sub2api/ent/user"
"github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
...
...
@@ -90,12 +93,15 @@ func checkColumn(t, c string) error {
apikey
.
Table
:
apikey
.
ValidColumn
,
account
.
Table
:
account
.
ValidColumn
,
accountgroup
.
Table
:
accountgroup
.
ValidColumn
,
announcement
.
Table
:
announcement
.
ValidColumn
,
announcementread
.
Table
:
announcementread
.
ValidColumn
,
group
.
Table
:
group
.
ValidColumn
,
promocode
.
Table
:
promocode
.
ValidColumn
,
promocodeusage
.
Table
:
promocodeusage
.
ValidColumn
,
proxy
.
Table
:
proxy
.
ValidColumn
,
redeemcode
.
Table
:
redeemcode
.
ValidColumn
,
setting
.
Table
:
setting
.
ValidColumn
,
usagecleanuptask
.
Table
:
usagecleanuptask
.
ValidColumn
,
usagelog
.
Table
:
usagelog
.
ValidColumn
,
user
.
Table
:
user
.
ValidColumn
,
userallowedgroup
.
Table
:
userallowedgroup
.
ValidColumn
,
...
...
backend/ent/hook/hook.go
View file @
0170d19f
...
...
@@ -45,6 +45,30 @@ func (f AccountGroupFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value
return
nil
,
fmt
.
Errorf
(
"unexpected mutation type %T. expect *ent.AccountGroupMutation"
,
m
)
}
// The AnnouncementFunc type is an adapter to allow the use of ordinary
// function as Announcement mutator.
type
AnnouncementFunc
func
(
context
.
Context
,
*
ent
.
AnnouncementMutation
)
(
ent
.
Value
,
error
)
// Mutate calls f(ctx, m).
func
(
f
AnnouncementFunc
)
Mutate
(
ctx
context
.
Context
,
m
ent
.
Mutation
)
(
ent
.
Value
,
error
)
{
if
mv
,
ok
:=
m
.
(
*
ent
.
AnnouncementMutation
);
ok
{
return
f
(
ctx
,
mv
)
}
return
nil
,
fmt
.
Errorf
(
"unexpected mutation type %T. expect *ent.AnnouncementMutation"
,
m
)
}
// The AnnouncementReadFunc type is an adapter to allow the use of ordinary
// function as AnnouncementRead mutator.
type
AnnouncementReadFunc
func
(
context
.
Context
,
*
ent
.
AnnouncementReadMutation
)
(
ent
.
Value
,
error
)
// Mutate calls f(ctx, m).
func
(
f
AnnouncementReadFunc
)
Mutate
(
ctx
context
.
Context
,
m
ent
.
Mutation
)
(
ent
.
Value
,
error
)
{
if
mv
,
ok
:=
m
.
(
*
ent
.
AnnouncementReadMutation
);
ok
{
return
f
(
ctx
,
mv
)
}
return
nil
,
fmt
.
Errorf
(
"unexpected mutation type %T. expect *ent.AnnouncementReadMutation"
,
m
)
}
// The GroupFunc type is an adapter to allow the use of ordinary
// function as Group mutator.
type
GroupFunc
func
(
context
.
Context
,
*
ent
.
GroupMutation
)
(
ent
.
Value
,
error
)
...
...
@@ -117,6 +141,18 @@ func (f SettingFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, err
return
nil
,
fmt
.
Errorf
(
"unexpected mutation type %T. expect *ent.SettingMutation"
,
m
)
}
// The UsageCleanupTaskFunc type is an adapter to allow the use of ordinary
// function as UsageCleanupTask mutator.
type
UsageCleanupTaskFunc
func
(
context
.
Context
,
*
ent
.
UsageCleanupTaskMutation
)
(
ent
.
Value
,
error
)
// Mutate calls f(ctx, m).
func
(
f
UsageCleanupTaskFunc
)
Mutate
(
ctx
context
.
Context
,
m
ent
.
Mutation
)
(
ent
.
Value
,
error
)
{
if
mv
,
ok
:=
m
.
(
*
ent
.
UsageCleanupTaskMutation
);
ok
{
return
f
(
ctx
,
mv
)
}
return
nil
,
fmt
.
Errorf
(
"unexpected mutation type %T. expect *ent.UsageCleanupTaskMutation"
,
m
)
}
// The UsageLogFunc type is an adapter to allow the use of ordinary
// function as UsageLog mutator.
type
UsageLogFunc
func
(
context
.
Context
,
*
ent
.
UsageLogMutation
)
(
ent
.
Value
,
error
)
...
...
backend/ent/intercept/intercept.go
View file @
0170d19f
...
...
@@ -10,6 +10,8 @@ import (
"github.com/Wei-Shaw/sub2api/ent"
"github.com/Wei-Shaw/sub2api/ent/account"
"github.com/Wei-Shaw/sub2api/ent/accountgroup"
"github.com/Wei-Shaw/sub2api/ent/announcement"
"github.com/Wei-Shaw/sub2api/ent/announcementread"
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/predicate"
...
...
@@ -18,6 +20,7 @@ import (
"github.com/Wei-Shaw/sub2api/ent/proxy"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/setting"
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
"github.com/Wei-Shaw/sub2api/ent/usagelog"
"github.com/Wei-Shaw/sub2api/ent/user"
"github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
...
...
@@ -163,6 +166,60 @@ func (f TraverseAccountGroup) Traverse(ctx context.Context, q ent.Query) error {
return
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.AccountGroupQuery"
,
q
)
}
// The AnnouncementFunc type is an adapter to allow the use of ordinary function as a Querier.
type
AnnouncementFunc
func
(
context
.
Context
,
*
ent
.
AnnouncementQuery
)
(
ent
.
Value
,
error
)
// Query calls f(ctx, q).
func
(
f
AnnouncementFunc
)
Query
(
ctx
context
.
Context
,
q
ent
.
Query
)
(
ent
.
Value
,
error
)
{
if
q
,
ok
:=
q
.
(
*
ent
.
AnnouncementQuery
);
ok
{
return
f
(
ctx
,
q
)
}
return
nil
,
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.AnnouncementQuery"
,
q
)
}
// The TraverseAnnouncement type is an adapter to allow the use of ordinary function as Traverser.
type
TraverseAnnouncement
func
(
context
.
Context
,
*
ent
.
AnnouncementQuery
)
error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func
(
f
TraverseAnnouncement
)
Intercept
(
next
ent
.
Querier
)
ent
.
Querier
{
return
next
}
// Traverse calls f(ctx, q).
func
(
f
TraverseAnnouncement
)
Traverse
(
ctx
context
.
Context
,
q
ent
.
Query
)
error
{
if
q
,
ok
:=
q
.
(
*
ent
.
AnnouncementQuery
);
ok
{
return
f
(
ctx
,
q
)
}
return
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.AnnouncementQuery"
,
q
)
}
// The AnnouncementReadFunc type is an adapter to allow the use of ordinary function as a Querier.
type
AnnouncementReadFunc
func
(
context
.
Context
,
*
ent
.
AnnouncementReadQuery
)
(
ent
.
Value
,
error
)
// Query calls f(ctx, q).
func
(
f
AnnouncementReadFunc
)
Query
(
ctx
context
.
Context
,
q
ent
.
Query
)
(
ent
.
Value
,
error
)
{
if
q
,
ok
:=
q
.
(
*
ent
.
AnnouncementReadQuery
);
ok
{
return
f
(
ctx
,
q
)
}
return
nil
,
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.AnnouncementReadQuery"
,
q
)
}
// The TraverseAnnouncementRead type is an adapter to allow the use of ordinary function as Traverser.
type
TraverseAnnouncementRead
func
(
context
.
Context
,
*
ent
.
AnnouncementReadQuery
)
error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func
(
f
TraverseAnnouncementRead
)
Intercept
(
next
ent
.
Querier
)
ent
.
Querier
{
return
next
}
// Traverse calls f(ctx, q).
func
(
f
TraverseAnnouncementRead
)
Traverse
(
ctx
context
.
Context
,
q
ent
.
Query
)
error
{
if
q
,
ok
:=
q
.
(
*
ent
.
AnnouncementReadQuery
);
ok
{
return
f
(
ctx
,
q
)
}
return
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.AnnouncementReadQuery"
,
q
)
}
// The GroupFunc type is an adapter to allow the use of ordinary function as a Querier.
type
GroupFunc
func
(
context
.
Context
,
*
ent
.
GroupQuery
)
(
ent
.
Value
,
error
)
...
...
@@ -325,6 +382,33 @@ func (f TraverseSetting) Traverse(ctx context.Context, q ent.Query) error {
return
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.SettingQuery"
,
q
)
}
// The UsageCleanupTaskFunc type is an adapter to allow the use of ordinary function as a Querier.
type
UsageCleanupTaskFunc
func
(
context
.
Context
,
*
ent
.
UsageCleanupTaskQuery
)
(
ent
.
Value
,
error
)
// Query calls f(ctx, q).
func
(
f
UsageCleanupTaskFunc
)
Query
(
ctx
context
.
Context
,
q
ent
.
Query
)
(
ent
.
Value
,
error
)
{
if
q
,
ok
:=
q
.
(
*
ent
.
UsageCleanupTaskQuery
);
ok
{
return
f
(
ctx
,
q
)
}
return
nil
,
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.UsageCleanupTaskQuery"
,
q
)
}
// The TraverseUsageCleanupTask type is an adapter to allow the use of ordinary function as Traverser.
type
TraverseUsageCleanupTask
func
(
context
.
Context
,
*
ent
.
UsageCleanupTaskQuery
)
error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func
(
f
TraverseUsageCleanupTask
)
Intercept
(
next
ent
.
Querier
)
ent
.
Querier
{
return
next
}
// Traverse calls f(ctx, q).
func
(
f
TraverseUsageCleanupTask
)
Traverse
(
ctx
context
.
Context
,
q
ent
.
Query
)
error
{
if
q
,
ok
:=
q
.
(
*
ent
.
UsageCleanupTaskQuery
);
ok
{
return
f
(
ctx
,
q
)
}
return
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.UsageCleanupTaskQuery"
,
q
)
}
// The UsageLogFunc type is an adapter to allow the use of ordinary function as a Querier.
type
UsageLogFunc
func
(
context
.
Context
,
*
ent
.
UsageLogQuery
)
(
ent
.
Value
,
error
)
...
...
@@ -496,6 +580,10 @@ func NewQuery(q ent.Query) (Query, error) {
return
&
query
[
*
ent
.
AccountQuery
,
predicate
.
Account
,
account
.
OrderOption
]{
typ
:
ent
.
TypeAccount
,
tq
:
q
},
nil
case
*
ent
.
AccountGroupQuery
:
return
&
query
[
*
ent
.
AccountGroupQuery
,
predicate
.
AccountGroup
,
accountgroup
.
OrderOption
]{
typ
:
ent
.
TypeAccountGroup
,
tq
:
q
},
nil
case
*
ent
.
AnnouncementQuery
:
return
&
query
[
*
ent
.
AnnouncementQuery
,
predicate
.
Announcement
,
announcement
.
OrderOption
]{
typ
:
ent
.
TypeAnnouncement
,
tq
:
q
},
nil
case
*
ent
.
AnnouncementReadQuery
:
return
&
query
[
*
ent
.
AnnouncementReadQuery
,
predicate
.
AnnouncementRead
,
announcementread
.
OrderOption
]{
typ
:
ent
.
TypeAnnouncementRead
,
tq
:
q
},
nil
case
*
ent
.
GroupQuery
:
return
&
query
[
*
ent
.
GroupQuery
,
predicate
.
Group
,
group
.
OrderOption
]{
typ
:
ent
.
TypeGroup
,
tq
:
q
},
nil
case
*
ent
.
PromoCodeQuery
:
...
...
@@ -508,6 +596,8 @@ func NewQuery(q ent.Query) (Query, error) {
return
&
query
[
*
ent
.
RedeemCodeQuery
,
predicate
.
RedeemCode
,
redeemcode
.
OrderOption
]{
typ
:
ent
.
TypeRedeemCode
,
tq
:
q
},
nil
case
*
ent
.
SettingQuery
:
return
&
query
[
*
ent
.
SettingQuery
,
predicate
.
Setting
,
setting
.
OrderOption
]{
typ
:
ent
.
TypeSetting
,
tq
:
q
},
nil
case
*
ent
.
UsageCleanupTaskQuery
:
return
&
query
[
*
ent
.
UsageCleanupTaskQuery
,
predicate
.
UsageCleanupTask
,
usagecleanuptask
.
OrderOption
]{
typ
:
ent
.
TypeUsageCleanupTask
,
tq
:
q
},
nil
case
*
ent
.
UsageLogQuery
:
return
&
query
[
*
ent
.
UsageLogQuery
,
predicate
.
UsageLog
,
usagelog
.
OrderOption
]{
typ
:
ent
.
TypeUsageLog
,
tq
:
q
},
nil
case
*
ent
.
UserQuery
:
...
...
backend/ent/migrate/schema.go
View file @
0170d19f
...
...
@@ -204,6 +204,98 @@ var (
},
},
}
// AnnouncementsColumns holds the columns for the "announcements" table.
AnnouncementsColumns
=
[]
*
schema
.
Column
{
{
Name
:
"id"
,
Type
:
field
.
TypeInt64
,
Increment
:
true
},
{
Name
:
"title"
,
Type
:
field
.
TypeString
,
Size
:
200
},
{
Name
:
"content"
,
Type
:
field
.
TypeString
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"text"
}},
{
Name
:
"status"
,
Type
:
field
.
TypeString
,
Size
:
20
,
Default
:
"draft"
},
{
Name
:
"targeting"
,
Type
:
field
.
TypeJSON
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"jsonb"
}},
{
Name
:
"starts_at"
,
Type
:
field
.
TypeTime
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"ends_at"
,
Type
:
field
.
TypeTime
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"created_by"
,
Type
:
field
.
TypeInt64
,
Nullable
:
true
},
{
Name
:
"updated_by"
,
Type
:
field
.
TypeInt64
,
Nullable
:
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"
}},
}
// AnnouncementsTable holds the schema information for the "announcements" table.
AnnouncementsTable
=
&
schema
.
Table
{
Name
:
"announcements"
,
Columns
:
AnnouncementsColumns
,
PrimaryKey
:
[]
*
schema
.
Column
{
AnnouncementsColumns
[
0
]},
Indexes
:
[]
*
schema
.
Index
{
{
Name
:
"announcement_status"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
AnnouncementsColumns
[
3
]},
},
{
Name
:
"announcement_created_at"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
AnnouncementsColumns
[
9
]},
},
{
Name
:
"announcement_starts_at"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
AnnouncementsColumns
[
5
]},
},
{
Name
:
"announcement_ends_at"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
AnnouncementsColumns
[
6
]},
},
},
}
// AnnouncementReadsColumns holds the columns for the "announcement_reads" table.
AnnouncementReadsColumns
=
[]
*
schema
.
Column
{
{
Name
:
"id"
,
Type
:
field
.
TypeInt64
,
Increment
:
true
},
{
Name
:
"read_at"
,
Type
:
field
.
TypeTime
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"created_at"
,
Type
:
field
.
TypeTime
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"announcement_id"
,
Type
:
field
.
TypeInt64
},
{
Name
:
"user_id"
,
Type
:
field
.
TypeInt64
},
}
// AnnouncementReadsTable holds the schema information for the "announcement_reads" table.
AnnouncementReadsTable
=
&
schema
.
Table
{
Name
:
"announcement_reads"
,
Columns
:
AnnouncementReadsColumns
,
PrimaryKey
:
[]
*
schema
.
Column
{
AnnouncementReadsColumns
[
0
]},
ForeignKeys
:
[]
*
schema
.
ForeignKey
{
{
Symbol
:
"announcement_reads_announcements_reads"
,
Columns
:
[]
*
schema
.
Column
{
AnnouncementReadsColumns
[
3
]},
RefColumns
:
[]
*
schema
.
Column
{
AnnouncementsColumns
[
0
]},
OnDelete
:
schema
.
NoAction
,
},
{
Symbol
:
"announcement_reads_users_announcement_reads"
,
Columns
:
[]
*
schema
.
Column
{
AnnouncementReadsColumns
[
4
]},
RefColumns
:
[]
*
schema
.
Column
{
UsersColumns
[
0
]},
OnDelete
:
schema
.
NoAction
,
},
},
Indexes
:
[]
*
schema
.
Index
{
{
Name
:
"announcementread_announcement_id"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
AnnouncementReadsColumns
[
3
]},
},
{
Name
:
"announcementread_user_id"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
AnnouncementReadsColumns
[
4
]},
},
{
Name
:
"announcementread_read_at"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
AnnouncementReadsColumns
[
1
]},
},
{
Name
:
"announcementread_announcement_id_user_id"
,
Unique
:
true
,
Columns
:
[]
*
schema
.
Column
{
AnnouncementReadsColumns
[
3
],
AnnouncementReadsColumns
[
4
]},
},
},
}
// GroupsColumns holds the columns for the "groups" table.
GroupsColumns
=
[]
*
schema
.
Column
{
{
Name
:
"id"
,
Type
:
field
.
TypeInt64
,
Increment
:
true
},
...
...
@@ -436,6 +528,44 @@ var (
Columns
:
SettingsColumns
,
PrimaryKey
:
[]
*
schema
.
Column
{
SettingsColumns
[
0
]},
}
// UsageCleanupTasksColumns holds the columns for the "usage_cleanup_tasks" table.
UsageCleanupTasksColumns
=
[]
*
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
:
"status"
,
Type
:
field
.
TypeString
,
Size
:
20
},
{
Name
:
"filters"
,
Type
:
field
.
TypeJSON
},
{
Name
:
"created_by"
,
Type
:
field
.
TypeInt64
},
{
Name
:
"deleted_rows"
,
Type
:
field
.
TypeInt64
,
Default
:
0
},
{
Name
:
"error_message"
,
Type
:
field
.
TypeString
,
Nullable
:
true
},
{
Name
:
"canceled_by"
,
Type
:
field
.
TypeInt64
,
Nullable
:
true
},
{
Name
:
"canceled_at"
,
Type
:
field
.
TypeTime
,
Nullable
:
true
},
{
Name
:
"started_at"
,
Type
:
field
.
TypeTime
,
Nullable
:
true
},
{
Name
:
"finished_at"
,
Type
:
field
.
TypeTime
,
Nullable
:
true
},
}
// UsageCleanupTasksTable holds the schema information for the "usage_cleanup_tasks" table.
UsageCleanupTasksTable
=
&
schema
.
Table
{
Name
:
"usage_cleanup_tasks"
,
Columns
:
UsageCleanupTasksColumns
,
PrimaryKey
:
[]
*
schema
.
Column
{
UsageCleanupTasksColumns
[
0
]},
Indexes
:
[]
*
schema
.
Index
{
{
Name
:
"usagecleanuptask_status_created_at"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UsageCleanupTasksColumns
[
3
],
UsageCleanupTasksColumns
[
1
]},
},
{
Name
:
"usagecleanuptask_created_at"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UsageCleanupTasksColumns
[
1
]},
},
{
Name
:
"usagecleanuptask_canceled_at"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UsageCleanupTasksColumns
[
9
]},
},
},
}
// UsageLogsColumns holds the columns for the "usage_logs" table.
UsageLogsColumns
=
[]
*
schema
.
Column
{
{
Name
:
"id"
,
Type
:
field
.
TypeInt64
,
Increment
:
true
},
...
...
@@ -574,6 +704,9 @@ var (
{
Name
:
"status"
,
Type
:
field
.
TypeString
,
Size
:
20
,
Default
:
"active"
},
{
Name
:
"username"
,
Type
:
field
.
TypeString
,
Size
:
100
,
Default
:
""
},
{
Name
:
"notes"
,
Type
:
field
.
TypeString
,
Default
:
""
,
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_at"
,
Type
:
field
.
TypeTime
,
Nullable
:
true
},
}
// UsersTable holds the schema information for the "users" table.
UsersTable
=
&
schema
.
Table
{
...
...
@@ -801,12 +934,15 @@ var (
APIKeysTable
,
AccountsTable
,
AccountGroupsTable
,
AnnouncementsTable
,
AnnouncementReadsTable
,
GroupsTable
,
PromoCodesTable
,
PromoCodeUsagesTable
,
ProxiesTable
,
RedeemCodesTable
,
SettingsTable
,
UsageCleanupTasksTable
,
UsageLogsTable
,
UsersTable
,
UserAllowedGroupsTable
,
...
...
@@ -831,6 +967,14 @@ func init() {
AccountGroupsTable
.
Annotation
=
&
entsql
.
Annotation
{
Table
:
"account_groups"
,
}
AnnouncementsTable
.
Annotation
=
&
entsql
.
Annotation
{
Table
:
"announcements"
,
}
AnnouncementReadsTable
.
ForeignKeys
[
0
]
.
RefTable
=
AnnouncementsTable
AnnouncementReadsTable
.
ForeignKeys
[
1
]
.
RefTable
=
UsersTable
AnnouncementReadsTable
.
Annotation
=
&
entsql
.
Annotation
{
Table
:
"announcement_reads"
,
}
GroupsTable
.
Annotation
=
&
entsql
.
Annotation
{
Table
:
"groups"
,
}
...
...
@@ -853,6 +997,9 @@ func init() {
SettingsTable
.
Annotation
=
&
entsql
.
Annotation
{
Table
:
"settings"
,
}
UsageCleanupTasksTable
.
Annotation
=
&
entsql
.
Annotation
{
Table
:
"usage_cleanup_tasks"
,
}
UsageLogsTable
.
ForeignKeys
[
0
]
.
RefTable
=
APIKeysTable
UsageLogsTable
.
ForeignKeys
[
1
]
.
RefTable
=
AccountsTable
UsageLogsTable
.
ForeignKeys
[
2
]
.
RefTable
=
GroupsTable
...
...
backend/ent/mutation.go
View file @
0170d19f
This source diff could not be displayed because it is too large. You can
view the blob
instead.
backend/ent/predicate/predicate.go
View file @
0170d19f
...
...
@@ -15,6 +15,12 @@ type Account func(*sql.Selector)
// AccountGroup is the predicate function for accountgroup builders.
type
AccountGroup
func
(
*
sql
.
Selector
)
// Announcement is the predicate function for announcement builders.
type
Announcement
func
(
*
sql
.
Selector
)
// AnnouncementRead is the predicate function for announcementread builders.
type
AnnouncementRead
func
(
*
sql
.
Selector
)
// Group is the predicate function for group builders.
type
Group
func
(
*
sql
.
Selector
)
...
...
@@ -33,6 +39,9 @@ type RedeemCode func(*sql.Selector)
// Setting is the predicate function for setting builders.
type
Setting
func
(
*
sql
.
Selector
)
// UsageCleanupTask is the predicate function for usagecleanuptask builders.
type
UsageCleanupTask
func
(
*
sql
.
Selector
)
// UsageLog is the predicate function for usagelog builders.
type
UsageLog
func
(
*
sql
.
Selector
)
...
...
backend/ent/runtime/runtime.go
View file @
0170d19f
...
...
@@ -7,6 +7,8 @@ import (
"github.com/Wei-Shaw/sub2api/ent/account"
"github.com/Wei-Shaw/sub2api/ent/accountgroup"
"github.com/Wei-Shaw/sub2api/ent/announcement"
"github.com/Wei-Shaw/sub2api/ent/announcementread"
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/promocode"
...
...
@@ -15,6 +17,7 @@ import (
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/schema"
"github.com/Wei-Shaw/sub2api/ent/setting"
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
"github.com/Wei-Shaw/sub2api/ent/usagelog"
"github.com/Wei-Shaw/sub2api/ent/user"
"github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
...
...
@@ -209,6 +212,56 @@ func init() {
accountgroupDescCreatedAt
:=
accountgroupFields
[
3
]
.
Descriptor
()
// accountgroup.DefaultCreatedAt holds the default value on creation for the created_at field.
accountgroup
.
DefaultCreatedAt
=
accountgroupDescCreatedAt
.
Default
.
(
func
()
time
.
Time
)
announcementFields
:=
schema
.
Announcement
{}
.
Fields
()
_
=
announcementFields
// announcementDescTitle is the schema descriptor for title field.
announcementDescTitle
:=
announcementFields
[
0
]
.
Descriptor
()
// announcement.TitleValidator is a validator for the "title" field. It is called by the builders before save.
announcement
.
TitleValidator
=
func
()
func
(
string
)
error
{
validators
:=
announcementDescTitle
.
Validators
fns
:=
[
...
]
func
(
string
)
error
{
validators
[
0
]
.
(
func
(
string
)
error
),
validators
[
1
]
.
(
func
(
string
)
error
),
}
return
func
(
title
string
)
error
{
for
_
,
fn
:=
range
fns
{
if
err
:=
fn
(
title
);
err
!=
nil
{
return
err
}
}
return
nil
}
}()
// announcementDescContent is the schema descriptor for content field.
announcementDescContent
:=
announcementFields
[
1
]
.
Descriptor
()
// announcement.ContentValidator is a validator for the "content" field. It is called by the builders before save.
announcement
.
ContentValidator
=
announcementDescContent
.
Validators
[
0
]
.
(
func
(
string
)
error
)
// announcementDescStatus is the schema descriptor for status field.
announcementDescStatus
:=
announcementFields
[
2
]
.
Descriptor
()
// announcement.DefaultStatus holds the default value on creation for the status field.
announcement
.
DefaultStatus
=
announcementDescStatus
.
Default
.
(
string
)
// announcement.StatusValidator is a validator for the "status" field. It is called by the builders before save.
announcement
.
StatusValidator
=
announcementDescStatus
.
Validators
[
0
]
.
(
func
(
string
)
error
)
// announcementDescCreatedAt is the schema descriptor for created_at field.
announcementDescCreatedAt
:=
announcementFields
[
8
]
.
Descriptor
()
// announcement.DefaultCreatedAt holds the default value on creation for the created_at field.
announcement
.
DefaultCreatedAt
=
announcementDescCreatedAt
.
Default
.
(
func
()
time
.
Time
)
// announcementDescUpdatedAt is the schema descriptor for updated_at field.
announcementDescUpdatedAt
:=
announcementFields
[
9
]
.
Descriptor
()
// announcement.DefaultUpdatedAt holds the default value on creation for the updated_at field.
announcement
.
DefaultUpdatedAt
=
announcementDescUpdatedAt
.
Default
.
(
func
()
time
.
Time
)
// announcement.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
announcement
.
UpdateDefaultUpdatedAt
=
announcementDescUpdatedAt
.
UpdateDefault
.
(
func
()
time
.
Time
)
announcementreadFields
:=
schema
.
AnnouncementRead
{}
.
Fields
()
_
=
announcementreadFields
// announcementreadDescReadAt is the schema descriptor for read_at field.
announcementreadDescReadAt
:=
announcementreadFields
[
2
]
.
Descriptor
()
// announcementread.DefaultReadAt holds the default value on creation for the read_at field.
announcementread
.
DefaultReadAt
=
announcementreadDescReadAt
.
Default
.
(
func
()
time
.
Time
)
// announcementreadDescCreatedAt is the schema descriptor for created_at field.
announcementreadDescCreatedAt
:=
announcementreadFields
[
3
]
.
Descriptor
()
// announcementread.DefaultCreatedAt holds the default value on creation for the created_at field.
announcementread
.
DefaultCreatedAt
=
announcementreadDescCreatedAt
.
Default
.
(
func
()
time
.
Time
)
groupMixin
:=
schema
.
Group
{}
.
Mixin
()
groupMixinHooks1
:=
groupMixin
[
1
]
.
Hooks
()
group
.
Hooks
[
0
]
=
groupMixinHooks1
[
0
]
...
...
@@ -499,6 +552,43 @@ func init() {
setting
.
DefaultUpdatedAt
=
settingDescUpdatedAt
.
Default
.
(
func
()
time
.
Time
)
// setting.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
setting
.
UpdateDefaultUpdatedAt
=
settingDescUpdatedAt
.
UpdateDefault
.
(
func
()
time
.
Time
)
usagecleanuptaskMixin
:=
schema
.
UsageCleanupTask
{}
.
Mixin
()
usagecleanuptaskMixinFields0
:=
usagecleanuptaskMixin
[
0
]
.
Fields
()
_
=
usagecleanuptaskMixinFields0
usagecleanuptaskFields
:=
schema
.
UsageCleanupTask
{}
.
Fields
()
_
=
usagecleanuptaskFields
// usagecleanuptaskDescCreatedAt is the schema descriptor for created_at field.
usagecleanuptaskDescCreatedAt
:=
usagecleanuptaskMixinFields0
[
0
]
.
Descriptor
()
// usagecleanuptask.DefaultCreatedAt holds the default value on creation for the created_at field.
usagecleanuptask
.
DefaultCreatedAt
=
usagecleanuptaskDescCreatedAt
.
Default
.
(
func
()
time
.
Time
)
// usagecleanuptaskDescUpdatedAt is the schema descriptor for updated_at field.
usagecleanuptaskDescUpdatedAt
:=
usagecleanuptaskMixinFields0
[
1
]
.
Descriptor
()
// usagecleanuptask.DefaultUpdatedAt holds the default value on creation for the updated_at field.
usagecleanuptask
.
DefaultUpdatedAt
=
usagecleanuptaskDescUpdatedAt
.
Default
.
(
func
()
time
.
Time
)
// usagecleanuptask.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
usagecleanuptask
.
UpdateDefaultUpdatedAt
=
usagecleanuptaskDescUpdatedAt
.
UpdateDefault
.
(
func
()
time
.
Time
)
// usagecleanuptaskDescStatus is the schema descriptor for status field.
usagecleanuptaskDescStatus
:=
usagecleanuptaskFields
[
0
]
.
Descriptor
()
// usagecleanuptask.StatusValidator is a validator for the "status" field. It is called by the builders before save.
usagecleanuptask
.
StatusValidator
=
func
()
func
(
string
)
error
{
validators
:=
usagecleanuptaskDescStatus
.
Validators
fns
:=
[
...
]
func
(
string
)
error
{
validators
[
0
]
.
(
func
(
string
)
error
),
validators
[
1
]
.
(
func
(
string
)
error
),
}
return
func
(
status
string
)
error
{
for
_
,
fn
:=
range
fns
{
if
err
:=
fn
(
status
);
err
!=
nil
{
return
err
}
}
return
nil
}
}()
// usagecleanuptaskDescDeletedRows is the schema descriptor for deleted_rows field.
usagecleanuptaskDescDeletedRows
:=
usagecleanuptaskFields
[
3
]
.
Descriptor
()
// usagecleanuptask.DefaultDeletedRows holds the default value on creation for the deleted_rows field.
usagecleanuptask
.
DefaultDeletedRows
=
usagecleanuptaskDescDeletedRows
.
Default
.
(
int64
)
usagelogFields
:=
schema
.
UsageLog
{}
.
Fields
()
_
=
usagelogFields
// usagelogDescRequestID is the schema descriptor for request_id field.
...
...
@@ -702,6 +792,10 @@ func init() {
userDescNotes
:=
userFields
[
7
]
.
Descriptor
()
// user.DefaultNotes holds the default value on creation for the notes field.
user
.
DefaultNotes
=
userDescNotes
.
Default
.
(
string
)
// userDescTotpEnabled is the schema descriptor for totp_enabled field.
userDescTotpEnabled
:=
userFields
[
9
]
.
Descriptor
()
// user.DefaultTotpEnabled holds the default value on creation for the totp_enabled field.
user
.
DefaultTotpEnabled
=
userDescTotpEnabled
.
Default
.
(
bool
)
userallowedgroupFields
:=
schema
.
UserAllowedGroup
{}
.
Fields
()
_
=
userallowedgroupFields
// userallowedgroupDescCreatedAt is the schema descriptor for created_at field.
...
...
backend/ent/schema/account.go
View file @
0170d19f
...
...
@@ -4,7 +4,7 @@ package schema
import
(
"github.com/Wei-Shaw/sub2api/ent/schema/mixins"
"github.com/Wei-Shaw/sub2api/internal/
service
"
"github.com/Wei-Shaw/sub2api/internal/
domain
"
"entgo.io/ent"
"entgo.io/ent/dialect"
...
...
@@ -111,7 +111,7 @@ func (Account) Fields() []ent.Field {
// status: 账户状态,如 "active", "error", "disabled"
field
.
String
(
"status"
)
.
MaxLen
(
20
)
.
Default
(
service
.
StatusActive
),
Default
(
domain
.
StatusActive
),
// error_message: 错误信息,记录账户异常时的详细信息
field
.
String
(
"error_message"
)
.
...
...
backend/ent/schema/announcement.go
0 → 100644
View file @
0170d19f
package
schema
import
(
"time"
"github.com/Wei-Shaw/sub2api/internal/domain"
"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"
)
// Announcement holds the schema definition for the Announcement entity.
//
// 删除策略:硬删除(已读记录通过外键级联删除)
type
Announcement
struct
{
ent
.
Schema
}
func
(
Announcement
)
Annotations
()
[]
schema
.
Annotation
{
return
[]
schema
.
Annotation
{
entsql
.
Annotation
{
Table
:
"announcements"
},
}
}
func
(
Announcement
)
Fields
()
[]
ent
.
Field
{
return
[]
ent
.
Field
{
field
.
String
(
"title"
)
.
MaxLen
(
200
)
.
NotEmpty
()
.
Comment
(
"公告标题"
),
field
.
String
(
"content"
)
.
SchemaType
(
map
[
string
]
string
{
dialect
.
Postgres
:
"text"
})
.
NotEmpty
()
.
Comment
(
"公告内容(支持 Markdown)"
),
field
.
String
(
"status"
)
.
MaxLen
(
20
)
.
Default
(
domain
.
AnnouncementStatusDraft
)
.
Comment
(
"状态: draft, active, archived"
),
field
.
JSON
(
"targeting"
,
domain
.
AnnouncementTargeting
{})
.
Optional
()
.
SchemaType
(
map
[
string
]
string
{
dialect
.
Postgres
:
"jsonb"
})
.
Comment
(
"展示条件(JSON 规则)"
),
field
.
Time
(
"starts_at"
)
.
Optional
()
.
Nillable
()
.
SchemaType
(
map
[
string
]
string
{
dialect
.
Postgres
:
"timestamptz"
})
.
Comment
(
"开始展示时间(为空表示立即生效)"
),
field
.
Time
(
"ends_at"
)
.
Optional
()
.
Nillable
()
.
SchemaType
(
map
[
string
]
string
{
dialect
.
Postgres
:
"timestamptz"
})
.
Comment
(
"结束展示时间(为空表示永久生效)"
),
field
.
Int64
(
"created_by"
)
.
Optional
()
.
Nillable
()
.
Comment
(
"创建人用户ID(管理员)"
),
field
.
Int64
(
"updated_by"
)
.
Optional
()
.
Nillable
()
.
Comment
(
"更新人用户ID(管理员)"
),
field
.
Time
(
"created_at"
)
.
Immutable
()
.
Default
(
time
.
Now
)
.
SchemaType
(
map
[
string
]
string
{
dialect
.
Postgres
:
"timestamptz"
}),
field
.
Time
(
"updated_at"
)
.
Default
(
time
.
Now
)
.
UpdateDefault
(
time
.
Now
)
.
SchemaType
(
map
[
string
]
string
{
dialect
.
Postgres
:
"timestamptz"
}),
}
}
func
(
Announcement
)
Edges
()
[]
ent
.
Edge
{
return
[]
ent
.
Edge
{
edge
.
To
(
"reads"
,
AnnouncementRead
.
Type
),
}
}
func
(
Announcement
)
Indexes
()
[]
ent
.
Index
{
return
[]
ent
.
Index
{
index
.
Fields
(
"status"
),
index
.
Fields
(
"created_at"
),
index
.
Fields
(
"starts_at"
),
index
.
Fields
(
"ends_at"
),
}
}
backend/ent/schema/announcement_read.go
0 → 100644
View file @
0170d19f
package
schema
import
(
"time"
"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"
)
// AnnouncementRead holds the schema definition for the AnnouncementRead entity.
//
// 记录用户对公告的已读状态(首次已读时间)。
type
AnnouncementRead
struct
{
ent
.
Schema
}
func
(
AnnouncementRead
)
Annotations
()
[]
schema
.
Annotation
{
return
[]
schema
.
Annotation
{
entsql
.
Annotation
{
Table
:
"announcement_reads"
},
}
}
func
(
AnnouncementRead
)
Fields
()
[]
ent
.
Field
{
return
[]
ent
.
Field
{
field
.
Int64
(
"announcement_id"
),
field
.
Int64
(
"user_id"
),
field
.
Time
(
"read_at"
)
.
Default
(
time
.
Now
)
.
SchemaType
(
map
[
string
]
string
{
dialect
.
Postgres
:
"timestamptz"
})
.
Comment
(
"用户首次已读时间"
),
field
.
Time
(
"created_at"
)
.
Immutable
()
.
Default
(
time
.
Now
)
.
SchemaType
(
map
[
string
]
string
{
dialect
.
Postgres
:
"timestamptz"
}),
}
}
func
(
AnnouncementRead
)
Edges
()
[]
ent
.
Edge
{
return
[]
ent
.
Edge
{
edge
.
From
(
"announcement"
,
Announcement
.
Type
)
.
Ref
(
"reads"
)
.
Field
(
"announcement_id"
)
.
Unique
()
.
Required
(),
edge
.
From
(
"user"
,
User
.
Type
)
.
Ref
(
"announcement_reads"
)
.
Field
(
"user_id"
)
.
Unique
()
.
Required
(),
}
}
func
(
AnnouncementRead
)
Indexes
()
[]
ent
.
Index
{
return
[]
ent
.
Index
{
index
.
Fields
(
"announcement_id"
),
index
.
Fields
(
"user_id"
),
index
.
Fields
(
"read_at"
),
index
.
Fields
(
"announcement_id"
,
"user_id"
)
.
Unique
(),
}
}
backend/ent/schema/api_key.go
View file @
0170d19f
...
...
@@ -2,7 +2,7 @@ package schema
import
(
"github.com/Wei-Shaw/sub2api/ent/schema/mixins"
"github.com/Wei-Shaw/sub2api/internal/
service
"
"github.com/Wei-Shaw/sub2api/internal/
domain
"
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
...
...
@@ -45,7 +45,7 @@ func (APIKey) Fields() []ent.Field {
Nillable
(),
field
.
String
(
"status"
)
.
MaxLen
(
20
)
.
Default
(
service
.
StatusActive
),
Default
(
domain
.
StatusActive
),
field
.
JSON
(
"ip_whitelist"
,
[]
string
{})
.
Optional
()
.
Comment
(
"Allowed IPs/CIDRs, e.g. [
\"
192.168.1.100
\"
,
\"
10.0.0.0/8
\"
]"
),
...
...
backend/ent/schema/group.go
View file @
0170d19f
...
...
@@ -2,7 +2,7 @@ package schema
import
(
"github.com/Wei-Shaw/sub2api/ent/schema/mixins"
"github.com/Wei-Shaw/sub2api/internal/
service
"
"github.com/Wei-Shaw/sub2api/internal/
domain
"
"entgo.io/ent"
"entgo.io/ent/dialect"
...
...
@@ -49,15 +49,15 @@ func (Group) Fields() []ent.Field {
Default
(
false
),
field
.
String
(
"status"
)
.
MaxLen
(
20
)
.
Default
(
service
.
StatusActive
),
Default
(
domain
.
StatusActive
),
// Subscription-related fields (added by migration 003)
field
.
String
(
"platform"
)
.
MaxLen
(
50
)
.
Default
(
service
.
PlatformAnthropic
),
Default
(
domain
.
PlatformAnthropic
),
field
.
String
(
"subscription_type"
)
.
MaxLen
(
20
)
.
Default
(
service
.
SubscriptionTypeStandard
),
Default
(
domain
.
SubscriptionTypeStandard
),
field
.
Float
(
"daily_limit_usd"
)
.
Optional
()
.
Nillable
()
.
...
...
backend/ent/schema/mixins/soft_delete.go
View file @
0170d19f
...
...
@@ -5,6 +5,7 @@ package mixins
import
(
"context"
"fmt"
"reflect"
"time"
"entgo.io/ent"
...
...
@@ -12,7 +13,6 @@ import (
"entgo.io/ent/dialect/sql"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/mixin"
dbent
"github.com/Wei-Shaw/sub2api/ent"
"github.com/Wei-Shaw/sub2api/ent/intercept"
)
...
...
@@ -113,7 +113,6 @@ func (d SoftDeleteMixin) Hooks() []ent.Hook {
SetOp
(
ent
.
Op
)
SetDeletedAt
(
time
.
Time
)
WhereP
(
...
func
(
*
sql
.
Selector
))
Client
()
*
dbent
.
Client
})
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"unexpected mutation type %T"
,
m
)
...
...
@@ -124,7 +123,7 @@ func (d SoftDeleteMixin) Hooks() []ent.Hook {
mx
.
SetOp
(
ent
.
OpUpdate
)
// 设置删除时间为当前时间
mx
.
SetDeletedAt
(
time
.
Now
())
return
m
x
.
Client
()
.
Mutate
(
ctx
,
m
)
return
m
utateWithClient
(
ctx
,
m
,
next
)
})
},
}
...
...
@@ -137,3 +136,41 @@ func (d SoftDeleteMixin) applyPredicate(w interface{ WhereP(...func(*sql.Selecto
sql
.
FieldIsNull
(
d
.
Fields
()[
0
]
.
Descriptor
()
.
Name
),
)
}
func
mutateWithClient
(
ctx
context
.
Context
,
m
ent
.
Mutation
,
fallback
ent
.
Mutator
)
(
ent
.
Value
,
error
)
{
clientMethod
:=
reflect
.
ValueOf
(
m
)
.
MethodByName
(
"Client"
)
if
!
clientMethod
.
IsValid
()
||
clientMethod
.
Type
()
.
NumIn
()
!=
0
||
clientMethod
.
Type
()
.
NumOut
()
!=
1
{
return
nil
,
fmt
.
Errorf
(
"soft delete: mutation client method not found for %T"
,
m
)
}
client
:=
clientMethod
.
Call
(
nil
)[
0
]
mutateMethod
:=
client
.
MethodByName
(
"Mutate"
)
if
!
mutateMethod
.
IsValid
()
{
return
nil
,
fmt
.
Errorf
(
"soft delete: mutation client missing Mutate for %T"
,
m
)
}
if
mutateMethod
.
Type
()
.
NumIn
()
!=
2
||
mutateMethod
.
Type
()
.
NumOut
()
!=
2
{
return
nil
,
fmt
.
Errorf
(
"soft delete: mutation client signature mismatch for %T"
,
m
)
}
results
:=
mutateMethod
.
Call
([]
reflect
.
Value
{
reflect
.
ValueOf
(
ctx
),
reflect
.
ValueOf
(
m
)})
value
:=
results
[
0
]
.
Interface
()
var
err
error
if
!
results
[
1
]
.
IsNil
()
{
errValue
:=
results
[
1
]
.
Interface
()
typedErr
,
ok
:=
errValue
.
(
error
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"soft delete: unexpected error type %T for %T"
,
errValue
,
m
)
}
err
=
typedErr
}
if
err
!=
nil
{
return
nil
,
err
}
if
value
==
nil
{
return
nil
,
fmt
.
Errorf
(
"soft delete: mutation client returned nil for %T"
,
m
)
}
v
,
ok
:=
value
.
(
ent
.
Value
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"soft delete: unexpected value type %T for %T"
,
value
,
m
)
}
return
v
,
nil
}
backend/ent/schema/promo_code.go
View file @
0170d19f
...
...
@@ -3,7 +3,7 @@ package schema
import
(
"time"
"github.com/Wei-Shaw/sub2api/internal/
service
"
"github.com/Wei-Shaw/sub2api/internal/
domain
"
"entgo.io/ent"
"entgo.io/ent/dialect"
...
...
@@ -49,7 +49,7 @@ func (PromoCode) Fields() []ent.Field {
Comment
(
"已使用次数"
),
field
.
String
(
"status"
)
.
MaxLen
(
20
)
.
Default
(
service
.
PromoCodeStatusActive
)
.
Default
(
domain
.
PromoCodeStatusActive
)
.
Comment
(
"状态: active, disabled"
),
field
.
Time
(
"expires_at"
)
.
Optional
()
.
...
...
backend/ent/schema/redeem_code.go
View file @
0170d19f
...
...
@@ -3,7 +3,7 @@ package schema
import
(
"time"
"github.com/Wei-Shaw/sub2api/internal/
service
"
"github.com/Wei-Shaw/sub2api/internal/
domain
"
"entgo.io/ent"
"entgo.io/ent/dialect"
...
...
@@ -41,13 +41,13 @@ func (RedeemCode) Fields() []ent.Field {
Unique
(),
field
.
String
(
"type"
)
.
MaxLen
(
20
)
.
Default
(
service
.
RedeemTypeBalance
),
Default
(
domain
.
RedeemTypeBalance
),
field
.
Float
(
"value"
)
.
SchemaType
(
map
[
string
]
string
{
dialect
.
Postgres
:
"decimal(20,8)"
})
.
Default
(
0
),
field
.
String
(
"status"
)
.
MaxLen
(
20
)
.
Default
(
service
.
StatusUnused
),
Default
(
domain
.
StatusUnused
),
field
.
Int64
(
"used_by"
)
.
Optional
()
.
Nillable
(),
...
...
Prev
1
2
3
4
5
6
…
16
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