Added admin bool field and middleware.

This commit is contained in:
mikestefanello 2025-04-19 16:13:12 -04:00
parent dae9ea3ae1
commit 2c9cf2a21a
13 changed files with 183 additions and 5 deletions

View file

@ -23,6 +23,8 @@ const (
FieldPassword = "password"
// FieldVerified holds the string denoting the verified field in the database.
FieldVerified = "verified"
// FieldAdmin holds the string denoting the admin field in the database.
FieldAdmin = "admin"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at"
// EdgeOwner holds the string denoting the owner edge name in mutations.
@ -45,6 +47,7 @@ var Columns = []string{
FieldEmail,
FieldPassword,
FieldVerified,
FieldAdmin,
FieldCreatedAt,
}
@ -73,6 +76,8 @@ var (
PasswordValidator func(string) error
// DefaultVerified holds the default value on creation for the "verified" field.
DefaultVerified bool
// DefaultAdmin holds the default value on creation for the "admin" field.
DefaultAdmin bool
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() time.Time
)
@ -105,6 +110,11 @@ func ByVerified(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldVerified, opts...).ToFunc()
}
// ByAdmin orders the results by the admin field.
func ByAdmin(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldAdmin, opts...).ToFunc()
}
// ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()

View file

@ -75,6 +75,11 @@ func Verified(v bool) predicate.User {
return predicate.User(sql.FieldEQ(FieldVerified, v))
}
// Admin applies equality check predicate on the "admin" field. It's identical to AdminEQ.
func Admin(v bool) predicate.User {
return predicate.User(sql.FieldEQ(FieldAdmin, v))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func CreatedAt(v time.Time) predicate.User {
return predicate.User(sql.FieldEQ(FieldCreatedAt, v))
@ -285,6 +290,16 @@ func VerifiedNEQ(v bool) predicate.User {
return predicate.User(sql.FieldNEQ(FieldVerified, v))
}
// AdminEQ applies the EQ predicate on the "admin" field.
func AdminEQ(v bool) predicate.User {
return predicate.User(sql.FieldEQ(FieldAdmin, v))
}
// AdminNEQ applies the NEQ predicate on the "admin" field.
func AdminNEQ(v bool) predicate.User {
return predicate.User(sql.FieldNEQ(FieldAdmin, v))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v time.Time) predicate.User {
return predicate.User(sql.FieldEQ(FieldCreatedAt, v))