mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-02-11 19:23:56 +08:00
fix(invite): 邀请码增加使用情况和过期时间
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/chaitin/MonkeyCode/backend/consts"
|
||||
"github.com/chaitin/MonkeyCode/backend/db/invitecode"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
@@ -36,6 +37,20 @@ func (icc *InviteCodeCreate) SetCode(s string) *InviteCodeCreate {
|
||||
return icc
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (icc *InviteCodeCreate) SetStatus(ccs consts.InviteCodeStatus) *InviteCodeCreate {
|
||||
icc.mutation.SetStatus(ccs)
|
||||
return icc
|
||||
}
|
||||
|
||||
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||
func (icc *InviteCodeCreate) SetNillableStatus(ccs *consts.InviteCodeStatus) *InviteCodeCreate {
|
||||
if ccs != nil {
|
||||
icc.SetStatus(*ccs)
|
||||
}
|
||||
return icc
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (icc *InviteCodeCreate) SetCreatedAt(t time.Time) *InviteCodeCreate {
|
||||
icc.mutation.SetCreatedAt(t)
|
||||
@@ -64,6 +79,12 @@ func (icc *InviteCodeCreate) SetNillableUpdatedAt(t *time.Time) *InviteCodeCreat
|
||||
return icc
|
||||
}
|
||||
|
||||
// SetExpiredAt sets the "expired_at" field.
|
||||
func (icc *InviteCodeCreate) SetExpiredAt(t time.Time) *InviteCodeCreate {
|
||||
icc.mutation.SetExpiredAt(t)
|
||||
return icc
|
||||
}
|
||||
|
||||
// SetID sets the "id" field.
|
||||
func (icc *InviteCodeCreate) SetID(u uuid.UUID) *InviteCodeCreate {
|
||||
icc.mutation.SetID(u)
|
||||
@@ -105,6 +126,10 @@ func (icc *InviteCodeCreate) ExecX(ctx context.Context) {
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (icc *InviteCodeCreate) defaults() {
|
||||
if _, ok := icc.mutation.Status(); !ok {
|
||||
v := invitecode.DefaultStatus
|
||||
icc.mutation.SetStatus(v)
|
||||
}
|
||||
if _, ok := icc.mutation.CreatedAt(); !ok {
|
||||
v := invitecode.DefaultCreatedAt()
|
||||
icc.mutation.SetCreatedAt(v)
|
||||
@@ -123,12 +148,18 @@ func (icc *InviteCodeCreate) check() error {
|
||||
if _, ok := icc.mutation.Code(); !ok {
|
||||
return &ValidationError{Name: "code", err: errors.New(`db: missing required field "InviteCode.code"`)}
|
||||
}
|
||||
if _, ok := icc.mutation.Status(); !ok {
|
||||
return &ValidationError{Name: "status", err: errors.New(`db: missing required field "InviteCode.status"`)}
|
||||
}
|
||||
if _, ok := icc.mutation.CreatedAt(); !ok {
|
||||
return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "InviteCode.created_at"`)}
|
||||
}
|
||||
if _, ok := icc.mutation.UpdatedAt(); !ok {
|
||||
return &ValidationError{Name: "updated_at", err: errors.New(`db: missing required field "InviteCode.updated_at"`)}
|
||||
}
|
||||
if _, ok := icc.mutation.ExpiredAt(); !ok {
|
||||
return &ValidationError{Name: "expired_at", err: errors.New(`db: missing required field "InviteCode.expired_at"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -173,6 +204,10 @@ func (icc *InviteCodeCreate) createSpec() (*InviteCode, *sqlgraph.CreateSpec) {
|
||||
_spec.SetField(invitecode.FieldCode, field.TypeString, value)
|
||||
_node.Code = value
|
||||
}
|
||||
if value, ok := icc.mutation.Status(); ok {
|
||||
_spec.SetField(invitecode.FieldStatus, field.TypeString, value)
|
||||
_node.Status = value
|
||||
}
|
||||
if value, ok := icc.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(invitecode.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
@@ -181,6 +216,10 @@ func (icc *InviteCodeCreate) createSpec() (*InviteCode, *sqlgraph.CreateSpec) {
|
||||
_spec.SetField(invitecode.FieldUpdatedAt, field.TypeTime, value)
|
||||
_node.UpdatedAt = value
|
||||
}
|
||||
if value, ok := icc.mutation.ExpiredAt(); ok {
|
||||
_spec.SetField(invitecode.FieldExpiredAt, field.TypeTime, value)
|
||||
_node.ExpiredAt = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
@@ -257,6 +296,18 @@ func (u *InviteCodeUpsert) UpdateCode() *InviteCodeUpsert {
|
||||
return u
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (u *InviteCodeUpsert) SetStatus(v consts.InviteCodeStatus) *InviteCodeUpsert {
|
||||
u.Set(invitecode.FieldStatus, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateStatus sets the "status" field to the value that was provided on create.
|
||||
func (u *InviteCodeUpsert) UpdateStatus() *InviteCodeUpsert {
|
||||
u.SetExcluded(invitecode.FieldStatus)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (u *InviteCodeUpsert) SetCreatedAt(v time.Time) *InviteCodeUpsert {
|
||||
u.Set(invitecode.FieldCreatedAt, v)
|
||||
@@ -281,6 +332,18 @@ func (u *InviteCodeUpsert) UpdateUpdatedAt() *InviteCodeUpsert {
|
||||
return u
|
||||
}
|
||||
|
||||
// SetExpiredAt sets the "expired_at" field.
|
||||
func (u *InviteCodeUpsert) SetExpiredAt(v time.Time) *InviteCodeUpsert {
|
||||
u.Set(invitecode.FieldExpiredAt, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateExpiredAt sets the "expired_at" field to the value that was provided on create.
|
||||
func (u *InviteCodeUpsert) UpdateExpiredAt() *InviteCodeUpsert {
|
||||
u.SetExcluded(invitecode.FieldExpiredAt)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
@@ -357,6 +420,20 @@ func (u *InviteCodeUpsertOne) UpdateCode() *InviteCodeUpsertOne {
|
||||
})
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (u *InviteCodeUpsertOne) SetStatus(v consts.InviteCodeStatus) *InviteCodeUpsertOne {
|
||||
return u.Update(func(s *InviteCodeUpsert) {
|
||||
s.SetStatus(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateStatus sets the "status" field to the value that was provided on create.
|
||||
func (u *InviteCodeUpsertOne) UpdateStatus() *InviteCodeUpsertOne {
|
||||
return u.Update(func(s *InviteCodeUpsert) {
|
||||
s.UpdateStatus()
|
||||
})
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (u *InviteCodeUpsertOne) SetCreatedAt(v time.Time) *InviteCodeUpsertOne {
|
||||
return u.Update(func(s *InviteCodeUpsert) {
|
||||
@@ -385,6 +462,20 @@ func (u *InviteCodeUpsertOne) UpdateUpdatedAt() *InviteCodeUpsertOne {
|
||||
})
|
||||
}
|
||||
|
||||
// SetExpiredAt sets the "expired_at" field.
|
||||
func (u *InviteCodeUpsertOne) SetExpiredAt(v time.Time) *InviteCodeUpsertOne {
|
||||
return u.Update(func(s *InviteCodeUpsert) {
|
||||
s.SetExpiredAt(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateExpiredAt sets the "expired_at" field to the value that was provided on create.
|
||||
func (u *InviteCodeUpsertOne) UpdateExpiredAt() *InviteCodeUpsertOne {
|
||||
return u.Update(func(s *InviteCodeUpsert) {
|
||||
s.UpdateExpiredAt()
|
||||
})
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (u *InviteCodeUpsertOne) Exec(ctx context.Context) error {
|
||||
if len(u.create.conflict) == 0 {
|
||||
@@ -628,6 +719,20 @@ func (u *InviteCodeUpsertBulk) UpdateCode() *InviteCodeUpsertBulk {
|
||||
})
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (u *InviteCodeUpsertBulk) SetStatus(v consts.InviteCodeStatus) *InviteCodeUpsertBulk {
|
||||
return u.Update(func(s *InviteCodeUpsert) {
|
||||
s.SetStatus(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateStatus sets the "status" field to the value that was provided on create.
|
||||
func (u *InviteCodeUpsertBulk) UpdateStatus() *InviteCodeUpsertBulk {
|
||||
return u.Update(func(s *InviteCodeUpsert) {
|
||||
s.UpdateStatus()
|
||||
})
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (u *InviteCodeUpsertBulk) SetCreatedAt(v time.Time) *InviteCodeUpsertBulk {
|
||||
return u.Update(func(s *InviteCodeUpsert) {
|
||||
@@ -656,6 +761,20 @@ func (u *InviteCodeUpsertBulk) UpdateUpdatedAt() *InviteCodeUpsertBulk {
|
||||
})
|
||||
}
|
||||
|
||||
// SetExpiredAt sets the "expired_at" field.
|
||||
func (u *InviteCodeUpsertBulk) SetExpiredAt(v time.Time) *InviteCodeUpsertBulk {
|
||||
return u.Update(func(s *InviteCodeUpsert) {
|
||||
s.SetExpiredAt(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateExpiredAt sets the "expired_at" field to the value that was provided on create.
|
||||
func (u *InviteCodeUpsertBulk) UpdateExpiredAt() *InviteCodeUpsertBulk {
|
||||
return u.Update(func(s *InviteCodeUpsert) {
|
||||
s.UpdateExpiredAt()
|
||||
})
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (u *InviteCodeUpsertBulk) Exec(ctx context.Context) error {
|
||||
if u.create.err != nil {
|
||||
|
||||
Reference in New Issue
Block a user