fix: some api bug
This commit is contained in:
@@ -35,9 +35,7 @@ type WalletMutation struct {
|
||||
config
|
||||
op Op
|
||||
typ string
|
||||
id *int
|
||||
user_id *int64
|
||||
adduser_id *int64
|
||||
id *int64
|
||||
balance *decimal.Decimal
|
||||
frozen_balance *decimal.Decimal
|
||||
version *int
|
||||
@@ -69,7 +67,7 @@ func newWalletMutation(c config, op Op, opts ...walletOption) *WalletMutation {
|
||||
}
|
||||
|
||||
// withWalletID sets the ID field of the mutation.
|
||||
func withWalletID(id int) walletOption {
|
||||
func withWalletID(id int64) walletOption {
|
||||
return func(m *WalletMutation) {
|
||||
var (
|
||||
err error
|
||||
@@ -119,9 +117,15 @@ func (m WalletMutation) Tx() (*Tx, error) {
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
// SetID sets the value of the id field. Note that this
|
||||
// operation is only accepted on creation of Wallet entities.
|
||||
func (m *WalletMutation) SetID(id int64) {
|
||||
m.id = &id
|
||||
}
|
||||
|
||||
// ID returns the ID value in the mutation. Note that the ID is only available
|
||||
// if it was provided to the builder or after it was returned from the database.
|
||||
func (m *WalletMutation) ID() (id int, exists bool) {
|
||||
func (m *WalletMutation) ID() (id int64, exists bool) {
|
||||
if m.id == nil {
|
||||
return
|
||||
}
|
||||
@@ -132,12 +136,12 @@ func (m *WalletMutation) ID() (id int, exists bool) {
|
||||
// That means, if the mutation is applied within a transaction with an isolation level such
|
||||
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
|
||||
// or updated by the mutation.
|
||||
func (m *WalletMutation) IDs(ctx context.Context) ([]int, error) {
|
||||
func (m *WalletMutation) IDs(ctx context.Context) ([]int64, error) {
|
||||
switch {
|
||||
case m.op.Is(OpUpdateOne | OpDeleteOne):
|
||||
id, exists := m.ID()
|
||||
if exists {
|
||||
return []int{id}, nil
|
||||
return []int64{id}, nil
|
||||
}
|
||||
fallthrough
|
||||
case m.op.Is(OpUpdate | OpDelete):
|
||||
@@ -147,62 +151,6 @@ func (m *WalletMutation) IDs(ctx context.Context) ([]int, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (m *WalletMutation) SetUserID(i int64) {
|
||||
m.user_id = &i
|
||||
m.adduser_id = nil
|
||||
}
|
||||
|
||||
// UserID returns the value of the "user_id" field in the mutation.
|
||||
func (m *WalletMutation) UserID() (r int64, exists bool) {
|
||||
v := m.user_id
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldUserID returns the old "user_id" field's value of the Wallet entity.
|
||||
// If the Wallet object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *WalletMutation) OldUserID(ctx context.Context) (v int64, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldUserID is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldUserID requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldUserID: %w", err)
|
||||
}
|
||||
return oldValue.UserID, nil
|
||||
}
|
||||
|
||||
// AddUserID adds i to the "user_id" field.
|
||||
func (m *WalletMutation) AddUserID(i int64) {
|
||||
if m.adduser_id != nil {
|
||||
*m.adduser_id += i
|
||||
} else {
|
||||
m.adduser_id = &i
|
||||
}
|
||||
}
|
||||
|
||||
// AddedUserID returns the value that was added to the "user_id" field in this mutation.
|
||||
func (m *WalletMutation) AddedUserID() (r int64, exists bool) {
|
||||
v := m.adduser_id
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ResetUserID resets all changes to the "user_id" field.
|
||||
func (m *WalletMutation) ResetUserID() {
|
||||
m.user_id = nil
|
||||
m.adduser_id = nil
|
||||
}
|
||||
|
||||
// SetBalance sets the "balance" field.
|
||||
func (m *WalletMutation) SetBalance(d decimal.Decimal) {
|
||||
m.balance = &d
|
||||
@@ -401,10 +349,7 @@ func (m *WalletMutation) Type() string {
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *WalletMutation) Fields() []string {
|
||||
fields := make([]string, 0, 5)
|
||||
if m.user_id != nil {
|
||||
fields = append(fields, wallet.FieldUserID)
|
||||
}
|
||||
fields := make([]string, 0, 4)
|
||||
if m.balance != nil {
|
||||
fields = append(fields, wallet.FieldBalance)
|
||||
}
|
||||
@@ -425,8 +370,6 @@ func (m *WalletMutation) Fields() []string {
|
||||
// schema.
|
||||
func (m *WalletMutation) Field(name string) (ent.Value, bool) {
|
||||
switch name {
|
||||
case wallet.FieldUserID:
|
||||
return m.UserID()
|
||||
case wallet.FieldBalance:
|
||||
return m.Balance()
|
||||
case wallet.FieldFrozenBalance:
|
||||
@@ -444,8 +387,6 @@ func (m *WalletMutation) Field(name string) (ent.Value, bool) {
|
||||
// database failed.
|
||||
func (m *WalletMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
||||
switch name {
|
||||
case wallet.FieldUserID:
|
||||
return m.OldUserID(ctx)
|
||||
case wallet.FieldBalance:
|
||||
return m.OldBalance(ctx)
|
||||
case wallet.FieldFrozenBalance:
|
||||
@@ -463,13 +404,6 @@ func (m *WalletMutation) OldField(ctx context.Context, name string) (ent.Value,
|
||||
// type.
|
||||
func (m *WalletMutation) SetField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
case wallet.FieldUserID:
|
||||
v, ok := value.(int64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetUserID(v)
|
||||
return nil
|
||||
case wallet.FieldBalance:
|
||||
v, ok := value.(decimal.Decimal)
|
||||
if !ok {
|
||||
@@ -506,9 +440,6 @@ func (m *WalletMutation) SetField(name string, value ent.Value) error {
|
||||
// this mutation.
|
||||
func (m *WalletMutation) AddedFields() []string {
|
||||
var fields []string
|
||||
if m.adduser_id != nil {
|
||||
fields = append(fields, wallet.FieldUserID)
|
||||
}
|
||||
if m.addversion != nil {
|
||||
fields = append(fields, wallet.FieldVersion)
|
||||
}
|
||||
@@ -520,8 +451,6 @@ func (m *WalletMutation) AddedFields() []string {
|
||||
// was not set, or was not defined in the schema.
|
||||
func (m *WalletMutation) AddedField(name string) (ent.Value, bool) {
|
||||
switch name {
|
||||
case wallet.FieldUserID:
|
||||
return m.AddedUserID()
|
||||
case wallet.FieldVersion:
|
||||
return m.AddedVersion()
|
||||
}
|
||||
@@ -533,13 +462,6 @@ func (m *WalletMutation) AddedField(name string) (ent.Value, bool) {
|
||||
// type.
|
||||
func (m *WalletMutation) AddField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
case wallet.FieldUserID:
|
||||
v, ok := value.(int64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.AddUserID(v)
|
||||
return nil
|
||||
case wallet.FieldVersion:
|
||||
v, ok := value.(int)
|
||||
if !ok {
|
||||
@@ -574,9 +496,6 @@ func (m *WalletMutation) ClearField(name string) error {
|
||||
// It returns an error if the field is not defined in the schema.
|
||||
func (m *WalletMutation) ResetField(name string) error {
|
||||
switch name {
|
||||
case wallet.FieldUserID:
|
||||
m.ResetUserID()
|
||||
return nil
|
||||
case wallet.FieldBalance:
|
||||
m.ResetBalance()
|
||||
return nil
|
||||
@@ -1106,9 +1025,22 @@ func (m *WalletTransactionsMutation) OldSearchText(ctx context.Context) (v strin
|
||||
return oldValue.SearchText, nil
|
||||
}
|
||||
|
||||
// ClearSearchText clears the value of the "search_text" field.
|
||||
func (m *WalletTransactionsMutation) ClearSearchText() {
|
||||
m.search_text = nil
|
||||
m.clearedFields[wallettransactions.FieldSearchText] = struct{}{}
|
||||
}
|
||||
|
||||
// SearchTextCleared returns if the "search_text" field was cleared in this mutation.
|
||||
func (m *WalletTransactionsMutation) SearchTextCleared() bool {
|
||||
_, ok := m.clearedFields[wallettransactions.FieldSearchText]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetSearchText resets all changes to the "search_text" field.
|
||||
func (m *WalletTransactionsMutation) ResetSearchText() {
|
||||
m.search_text = nil
|
||||
delete(m.clearedFields, wallettransactions.FieldSearchText)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the WalletTransactionsMutation builder.
|
||||
@@ -1340,7 +1272,11 @@ func (m *WalletTransactionsMutation) AddField(name string, value ent.Value) erro
|
||||
// ClearedFields returns all nullable fields that were cleared during this
|
||||
// mutation.
|
||||
func (m *WalletTransactionsMutation) ClearedFields() []string {
|
||||
return nil
|
||||
var fields []string
|
||||
if m.FieldCleared(wallettransactions.FieldSearchText) {
|
||||
fields = append(fields, wallettransactions.FieldSearchText)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
// FieldCleared returns a boolean indicating if a field with the given name was
|
||||
@@ -1353,6 +1289,11 @@ func (m *WalletTransactionsMutation) FieldCleared(name string) bool {
|
||||
// ClearField clears the value of the field with the given name. It returns an
|
||||
// error if the field is not defined in the schema.
|
||||
func (m *WalletTransactionsMutation) ClearField(name string) error {
|
||||
switch name {
|
||||
case wallettransactions.FieldSearchText:
|
||||
m.ClearSearchText()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown WalletTransactions nullable field %s", name)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user