fix(invite): 邀请码增加使用情况和过期时间

This commit is contained in:
yokowu
2025-07-09 18:47:44 +08:00
parent 51fbfae0d2
commit d3202c777d
13 changed files with 528 additions and 7 deletions

View File

@@ -6,6 +6,7 @@ import (
"time"
"entgo.io/ent/dialect/sql"
"github.com/chaitin/MonkeyCode/backend/consts"
)
const (
@@ -17,10 +18,14 @@ const (
FieldAdminID = "admin_id"
// FieldCode holds the string denoting the code field in the database.
FieldCode = "code"
// FieldStatus holds the string denoting the status field in the database.
FieldStatus = "status"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at"
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
FieldUpdatedAt = "updated_at"
// FieldExpiredAt holds the string denoting the expired_at field in the database.
FieldExpiredAt = "expired_at"
// Table holds the table name of the invitecode in the database.
Table = "invite_codes"
)
@@ -30,8 +35,10 @@ var Columns = []string{
FieldID,
FieldAdminID,
FieldCode,
FieldStatus,
FieldCreatedAt,
FieldUpdatedAt,
FieldExpiredAt,
}
// ValidColumn reports if the column name is valid (part of the table columns).
@@ -45,6 +52,8 @@ func ValidColumn(column string) bool {
}
var (
// DefaultStatus holds the default value on creation for the "status" field.
DefaultStatus consts.InviteCodeStatus
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() time.Time
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
@@ -71,6 +80,11 @@ func ByCode(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCode, opts...).ToFunc()
}
// ByStatus orders the results by the status field.
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldStatus, opts...).ToFunc()
}
// ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
@@ -80,3 +94,8 @@ func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
}
// ByExpiredAt orders the results by the expired_at field.
func ByExpiredAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldExpiredAt, opts...).ToFunc()
}

View File

@@ -6,6 +6,7 @@ import (
"time"
"entgo.io/ent/dialect/sql"
"github.com/chaitin/MonkeyCode/backend/consts"
"github.com/chaitin/MonkeyCode/backend/db/predicate"
"github.com/google/uuid"
)
@@ -65,6 +66,12 @@ func Code(v string) predicate.InviteCode {
return predicate.InviteCode(sql.FieldEQ(FieldCode, v))
}
// Status applies equality check predicate on the "status" field. It's identical to StatusEQ.
func Status(v consts.InviteCodeStatus) predicate.InviteCode {
vc := string(v)
return predicate.InviteCode(sql.FieldEQ(FieldStatus, vc))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func CreatedAt(v time.Time) predicate.InviteCode {
return predicate.InviteCode(sql.FieldEQ(FieldCreatedAt, v))
@@ -75,6 +82,11 @@ func UpdatedAt(v time.Time) predicate.InviteCode {
return predicate.InviteCode(sql.FieldEQ(FieldUpdatedAt, v))
}
// ExpiredAt applies equality check predicate on the "expired_at" field. It's identical to ExpiredAtEQ.
func ExpiredAt(v time.Time) predicate.InviteCode {
return predicate.InviteCode(sql.FieldEQ(FieldExpiredAt, v))
}
// AdminIDEQ applies the EQ predicate on the "admin_id" field.
func AdminIDEQ(v uuid.UUID) predicate.InviteCode {
return predicate.InviteCode(sql.FieldEQ(FieldAdminID, v))
@@ -180,6 +192,90 @@ func CodeContainsFold(v string) predicate.InviteCode {
return predicate.InviteCode(sql.FieldContainsFold(FieldCode, v))
}
// StatusEQ applies the EQ predicate on the "status" field.
func StatusEQ(v consts.InviteCodeStatus) predicate.InviteCode {
vc := string(v)
return predicate.InviteCode(sql.FieldEQ(FieldStatus, vc))
}
// StatusNEQ applies the NEQ predicate on the "status" field.
func StatusNEQ(v consts.InviteCodeStatus) predicate.InviteCode {
vc := string(v)
return predicate.InviteCode(sql.FieldNEQ(FieldStatus, vc))
}
// StatusIn applies the In predicate on the "status" field.
func StatusIn(vs ...consts.InviteCodeStatus) predicate.InviteCode {
v := make([]any, len(vs))
for i := range v {
v[i] = string(vs[i])
}
return predicate.InviteCode(sql.FieldIn(FieldStatus, v...))
}
// StatusNotIn applies the NotIn predicate on the "status" field.
func StatusNotIn(vs ...consts.InviteCodeStatus) predicate.InviteCode {
v := make([]any, len(vs))
for i := range v {
v[i] = string(vs[i])
}
return predicate.InviteCode(sql.FieldNotIn(FieldStatus, v...))
}
// StatusGT applies the GT predicate on the "status" field.
func StatusGT(v consts.InviteCodeStatus) predicate.InviteCode {
vc := string(v)
return predicate.InviteCode(sql.FieldGT(FieldStatus, vc))
}
// StatusGTE applies the GTE predicate on the "status" field.
func StatusGTE(v consts.InviteCodeStatus) predicate.InviteCode {
vc := string(v)
return predicate.InviteCode(sql.FieldGTE(FieldStatus, vc))
}
// StatusLT applies the LT predicate on the "status" field.
func StatusLT(v consts.InviteCodeStatus) predicate.InviteCode {
vc := string(v)
return predicate.InviteCode(sql.FieldLT(FieldStatus, vc))
}
// StatusLTE applies the LTE predicate on the "status" field.
func StatusLTE(v consts.InviteCodeStatus) predicate.InviteCode {
vc := string(v)
return predicate.InviteCode(sql.FieldLTE(FieldStatus, vc))
}
// StatusContains applies the Contains predicate on the "status" field.
func StatusContains(v consts.InviteCodeStatus) predicate.InviteCode {
vc := string(v)
return predicate.InviteCode(sql.FieldContains(FieldStatus, vc))
}
// StatusHasPrefix applies the HasPrefix predicate on the "status" field.
func StatusHasPrefix(v consts.InviteCodeStatus) predicate.InviteCode {
vc := string(v)
return predicate.InviteCode(sql.FieldHasPrefix(FieldStatus, vc))
}
// StatusHasSuffix applies the HasSuffix predicate on the "status" field.
func StatusHasSuffix(v consts.InviteCodeStatus) predicate.InviteCode {
vc := string(v)
return predicate.InviteCode(sql.FieldHasSuffix(FieldStatus, vc))
}
// StatusEqualFold applies the EqualFold predicate on the "status" field.
func StatusEqualFold(v consts.InviteCodeStatus) predicate.InviteCode {
vc := string(v)
return predicate.InviteCode(sql.FieldEqualFold(FieldStatus, vc))
}
// StatusContainsFold applies the ContainsFold predicate on the "status" field.
func StatusContainsFold(v consts.InviteCodeStatus) predicate.InviteCode {
vc := string(v)
return predicate.InviteCode(sql.FieldContainsFold(FieldStatus, vc))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v time.Time) predicate.InviteCode {
return predicate.InviteCode(sql.FieldEQ(FieldCreatedAt, v))
@@ -260,6 +356,46 @@ func UpdatedAtLTE(v time.Time) predicate.InviteCode {
return predicate.InviteCode(sql.FieldLTE(FieldUpdatedAt, v))
}
// ExpiredAtEQ applies the EQ predicate on the "expired_at" field.
func ExpiredAtEQ(v time.Time) predicate.InviteCode {
return predicate.InviteCode(sql.FieldEQ(FieldExpiredAt, v))
}
// ExpiredAtNEQ applies the NEQ predicate on the "expired_at" field.
func ExpiredAtNEQ(v time.Time) predicate.InviteCode {
return predicate.InviteCode(sql.FieldNEQ(FieldExpiredAt, v))
}
// ExpiredAtIn applies the In predicate on the "expired_at" field.
func ExpiredAtIn(vs ...time.Time) predicate.InviteCode {
return predicate.InviteCode(sql.FieldIn(FieldExpiredAt, vs...))
}
// ExpiredAtNotIn applies the NotIn predicate on the "expired_at" field.
func ExpiredAtNotIn(vs ...time.Time) predicate.InviteCode {
return predicate.InviteCode(sql.FieldNotIn(FieldExpiredAt, vs...))
}
// ExpiredAtGT applies the GT predicate on the "expired_at" field.
func ExpiredAtGT(v time.Time) predicate.InviteCode {
return predicate.InviteCode(sql.FieldGT(FieldExpiredAt, v))
}
// ExpiredAtGTE applies the GTE predicate on the "expired_at" field.
func ExpiredAtGTE(v time.Time) predicate.InviteCode {
return predicate.InviteCode(sql.FieldGTE(FieldExpiredAt, v))
}
// ExpiredAtLT applies the LT predicate on the "expired_at" field.
func ExpiredAtLT(v time.Time) predicate.InviteCode {
return predicate.InviteCode(sql.FieldLT(FieldExpiredAt, v))
}
// ExpiredAtLTE applies the LTE predicate on the "expired_at" field.
func ExpiredAtLTE(v time.Time) predicate.InviteCode {
return predicate.InviteCode(sql.FieldLTE(FieldExpiredAt, v))
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.InviteCode) predicate.InviteCode {
return predicate.InviteCode(sql.AndPredicates(predicates...))