🚧 Refactor basic services

This commit is contained in:
2025-12-14 02:19:50 +08:00
parent d16905c0a3
commit cc4c2189dc
126 changed files with 18164 additions and 4247 deletions

View File

@@ -0,0 +1,477 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"voidraft/internal/models/ent/keybinding"
"voidraft/internal/models/ent/predicate"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// KeyBindingUpdate is the builder for updating KeyBinding entities.
type KeyBindingUpdate struct {
config
hooks []Hook
mutation *KeyBindingMutation
modifiers []func(*sql.UpdateBuilder)
}
// Where appends a list predicates to the KeyBindingUpdate builder.
func (_u *KeyBindingUpdate) Where(ps ...predicate.KeyBinding) *KeyBindingUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *KeyBindingUpdate) SetUpdatedAt(v string) *KeyBindingUpdate {
_u.mutation.SetUpdatedAt(v)
return _u
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (_u *KeyBindingUpdate) SetNillableUpdatedAt(v *string) *KeyBindingUpdate {
if v != nil {
_u.SetUpdatedAt(*v)
}
return _u
}
// SetDeletedAt sets the "deleted_at" field.
func (_u *KeyBindingUpdate) SetDeletedAt(v string) *KeyBindingUpdate {
_u.mutation.SetDeletedAt(v)
return _u
}
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (_u *KeyBindingUpdate) SetNillableDeletedAt(v *string) *KeyBindingUpdate {
if v != nil {
_u.SetDeletedAt(*v)
}
return _u
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (_u *KeyBindingUpdate) ClearDeletedAt() *KeyBindingUpdate {
_u.mutation.ClearDeletedAt()
return _u
}
// SetKey sets the "key" field.
func (_u *KeyBindingUpdate) SetKey(v string) *KeyBindingUpdate {
_u.mutation.SetKey(v)
return _u
}
// SetNillableKey sets the "key" field if the given value is not nil.
func (_u *KeyBindingUpdate) SetNillableKey(v *string) *KeyBindingUpdate {
if v != nil {
_u.SetKey(*v)
}
return _u
}
// SetCommand sets the "command" field.
func (_u *KeyBindingUpdate) SetCommand(v string) *KeyBindingUpdate {
_u.mutation.SetCommand(v)
return _u
}
// SetNillableCommand sets the "command" field if the given value is not nil.
func (_u *KeyBindingUpdate) SetNillableCommand(v *string) *KeyBindingUpdate {
if v != nil {
_u.SetCommand(*v)
}
return _u
}
// SetExtension sets the "extension" field.
func (_u *KeyBindingUpdate) SetExtension(v string) *KeyBindingUpdate {
_u.mutation.SetExtension(v)
return _u
}
// SetNillableExtension sets the "extension" field if the given value is not nil.
func (_u *KeyBindingUpdate) SetNillableExtension(v *string) *KeyBindingUpdate {
if v != nil {
_u.SetExtension(*v)
}
return _u
}
// ClearExtension clears the value of the "extension" field.
func (_u *KeyBindingUpdate) ClearExtension() *KeyBindingUpdate {
_u.mutation.ClearExtension()
return _u
}
// SetEnabled sets the "enabled" field.
func (_u *KeyBindingUpdate) SetEnabled(v bool) *KeyBindingUpdate {
_u.mutation.SetEnabled(v)
return _u
}
// SetNillableEnabled sets the "enabled" field if the given value is not nil.
func (_u *KeyBindingUpdate) SetNillableEnabled(v *bool) *KeyBindingUpdate {
if v != nil {
_u.SetEnabled(*v)
}
return _u
}
// Mutation returns the KeyBindingMutation object of the builder.
func (_u *KeyBindingUpdate) Mutation() *KeyBindingMutation {
return _u.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *KeyBindingUpdate) 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 *KeyBindingUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *KeyBindingUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *KeyBindingUpdate) 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 *KeyBindingUpdate) check() error {
if v, ok := _u.mutation.Key(); ok {
if err := keybinding.KeyValidator(v); err != nil {
return &ValidationError{Name: "key", err: fmt.Errorf(`ent: validator failed for field "KeyBinding.key": %w`, err)}
}
}
if v, ok := _u.mutation.Command(); ok {
if err := keybinding.CommandValidator(v); err != nil {
return &ValidationError{Name: "command", err: fmt.Errorf(`ent: validator failed for field "KeyBinding.command": %w`, err)}
}
}
if v, ok := _u.mutation.Extension(); ok {
if err := keybinding.ExtensionValidator(v); err != nil {
return &ValidationError{Name: "extension", err: fmt.Errorf(`ent: validator failed for field "KeyBinding.extension": %w`, err)}
}
}
return nil
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *KeyBindingUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *KeyBindingUpdate {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *KeyBindingUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(keybinding.Table, keybinding.Columns, sqlgraph.NewFieldSpec(keybinding.FieldID, field.TypeInt))
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.UpdatedAt(); ok {
_spec.SetField(keybinding.FieldUpdatedAt, field.TypeString, value)
}
if value, ok := _u.mutation.DeletedAt(); ok {
_spec.SetField(keybinding.FieldDeletedAt, field.TypeString, value)
}
if _u.mutation.DeletedAtCleared() {
_spec.ClearField(keybinding.FieldDeletedAt, field.TypeString)
}
if value, ok := _u.mutation.Key(); ok {
_spec.SetField(keybinding.FieldKey, field.TypeString, value)
}
if value, ok := _u.mutation.Command(); ok {
_spec.SetField(keybinding.FieldCommand, field.TypeString, value)
}
if value, ok := _u.mutation.Extension(); ok {
_spec.SetField(keybinding.FieldExtension, field.TypeString, value)
}
if _u.mutation.ExtensionCleared() {
_spec.ClearField(keybinding.FieldExtension, field.TypeString)
}
if value, ok := _u.mutation.Enabled(); ok {
_spec.SetField(keybinding.FieldEnabled, field.TypeBool, value)
}
_spec.AddModifiers(_u.modifiers...)
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{keybinding.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// KeyBindingUpdateOne is the builder for updating a single KeyBinding entity.
type KeyBindingUpdateOne struct {
config
fields []string
hooks []Hook
mutation *KeyBindingMutation
modifiers []func(*sql.UpdateBuilder)
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *KeyBindingUpdateOne) SetUpdatedAt(v string) *KeyBindingUpdateOne {
_u.mutation.SetUpdatedAt(v)
return _u
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (_u *KeyBindingUpdateOne) SetNillableUpdatedAt(v *string) *KeyBindingUpdateOne {
if v != nil {
_u.SetUpdatedAt(*v)
}
return _u
}
// SetDeletedAt sets the "deleted_at" field.
func (_u *KeyBindingUpdateOne) SetDeletedAt(v string) *KeyBindingUpdateOne {
_u.mutation.SetDeletedAt(v)
return _u
}
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (_u *KeyBindingUpdateOne) SetNillableDeletedAt(v *string) *KeyBindingUpdateOne {
if v != nil {
_u.SetDeletedAt(*v)
}
return _u
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (_u *KeyBindingUpdateOne) ClearDeletedAt() *KeyBindingUpdateOne {
_u.mutation.ClearDeletedAt()
return _u
}
// SetKey sets the "key" field.
func (_u *KeyBindingUpdateOne) SetKey(v string) *KeyBindingUpdateOne {
_u.mutation.SetKey(v)
return _u
}
// SetNillableKey sets the "key" field if the given value is not nil.
func (_u *KeyBindingUpdateOne) SetNillableKey(v *string) *KeyBindingUpdateOne {
if v != nil {
_u.SetKey(*v)
}
return _u
}
// SetCommand sets the "command" field.
func (_u *KeyBindingUpdateOne) SetCommand(v string) *KeyBindingUpdateOne {
_u.mutation.SetCommand(v)
return _u
}
// SetNillableCommand sets the "command" field if the given value is not nil.
func (_u *KeyBindingUpdateOne) SetNillableCommand(v *string) *KeyBindingUpdateOne {
if v != nil {
_u.SetCommand(*v)
}
return _u
}
// SetExtension sets the "extension" field.
func (_u *KeyBindingUpdateOne) SetExtension(v string) *KeyBindingUpdateOne {
_u.mutation.SetExtension(v)
return _u
}
// SetNillableExtension sets the "extension" field if the given value is not nil.
func (_u *KeyBindingUpdateOne) SetNillableExtension(v *string) *KeyBindingUpdateOne {
if v != nil {
_u.SetExtension(*v)
}
return _u
}
// ClearExtension clears the value of the "extension" field.
func (_u *KeyBindingUpdateOne) ClearExtension() *KeyBindingUpdateOne {
_u.mutation.ClearExtension()
return _u
}
// SetEnabled sets the "enabled" field.
func (_u *KeyBindingUpdateOne) SetEnabled(v bool) *KeyBindingUpdateOne {
_u.mutation.SetEnabled(v)
return _u
}
// SetNillableEnabled sets the "enabled" field if the given value is not nil.
func (_u *KeyBindingUpdateOne) SetNillableEnabled(v *bool) *KeyBindingUpdateOne {
if v != nil {
_u.SetEnabled(*v)
}
return _u
}
// Mutation returns the KeyBindingMutation object of the builder.
func (_u *KeyBindingUpdateOne) Mutation() *KeyBindingMutation {
return _u.mutation
}
// Where appends a list predicates to the KeyBindingUpdate builder.
func (_u *KeyBindingUpdateOne) Where(ps ...predicate.KeyBinding) *KeyBindingUpdateOne {
_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 *KeyBindingUpdateOne) Select(field string, fields ...string) *KeyBindingUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated KeyBinding entity.
func (_u *KeyBindingUpdateOne) Save(ctx context.Context) (*KeyBinding, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *KeyBindingUpdateOne) SaveX(ctx context.Context) *KeyBinding {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *KeyBindingUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *KeyBindingUpdateOne) 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 *KeyBindingUpdateOne) check() error {
if v, ok := _u.mutation.Key(); ok {
if err := keybinding.KeyValidator(v); err != nil {
return &ValidationError{Name: "key", err: fmt.Errorf(`ent: validator failed for field "KeyBinding.key": %w`, err)}
}
}
if v, ok := _u.mutation.Command(); ok {
if err := keybinding.CommandValidator(v); err != nil {
return &ValidationError{Name: "command", err: fmt.Errorf(`ent: validator failed for field "KeyBinding.command": %w`, err)}
}
}
if v, ok := _u.mutation.Extension(); ok {
if err := keybinding.ExtensionValidator(v); err != nil {
return &ValidationError{Name: "extension", err: fmt.Errorf(`ent: validator failed for field "KeyBinding.extension": %w`, err)}
}
}
return nil
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *KeyBindingUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *KeyBindingUpdateOne {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *KeyBindingUpdateOne) sqlSave(ctx context.Context) (_node *KeyBinding, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(keybinding.Table, keybinding.Columns, sqlgraph.NewFieldSpec(keybinding.FieldID, field.TypeInt))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "KeyBinding.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, keybinding.FieldID)
for _, f := range fields {
if !keybinding.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != keybinding.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.UpdatedAt(); ok {
_spec.SetField(keybinding.FieldUpdatedAt, field.TypeString, value)
}
if value, ok := _u.mutation.DeletedAt(); ok {
_spec.SetField(keybinding.FieldDeletedAt, field.TypeString, value)
}
if _u.mutation.DeletedAtCleared() {
_spec.ClearField(keybinding.FieldDeletedAt, field.TypeString)
}
if value, ok := _u.mutation.Key(); ok {
_spec.SetField(keybinding.FieldKey, field.TypeString, value)
}
if value, ok := _u.mutation.Command(); ok {
_spec.SetField(keybinding.FieldCommand, field.TypeString, value)
}
if value, ok := _u.mutation.Extension(); ok {
_spec.SetField(keybinding.FieldExtension, field.TypeString, value)
}
if _u.mutation.ExtensionCleared() {
_spec.ClearField(keybinding.FieldExtension, field.TypeString)
}
if value, ok := _u.mutation.Enabled(); ok {
_spec.SetField(keybinding.FieldEnabled, field.TypeBool, value)
}
_spec.AddModifiers(_u.modifiers...)
_node = &KeyBinding{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{keybinding.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}