feat(admin): add drag-and-drop group sort order
- Add `sort_order` field to groups table with migration - Add `PUT /api/v1/admin/groups/sort-order` API for batch update - Implement drag-and-drop UI using vue-draggable-plus - All queries now order groups by sort_order - Add i18n support (en/zh) for sort-related UI text - Update test stubs to satisfy new interface methods
This commit is contained in:
@@ -340,6 +340,20 @@ func (_c *GroupCreate) SetSupportedModelScopes(v []string) *GroupCreate {
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetSortOrder sets the "sort_order" field.
|
||||
func (_c *GroupCreate) SetSortOrder(v int) *GroupCreate {
|
||||
_c.mutation.SetSortOrder(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableSortOrder sets the "sort_order" field if the given value is not nil.
|
||||
func (_c *GroupCreate) SetNillableSortOrder(v *int) *GroupCreate {
|
||||
if v != nil {
|
||||
_c.SetSortOrder(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
|
||||
func (_c *GroupCreate) AddAPIKeyIDs(ids ...int64) *GroupCreate {
|
||||
_c.mutation.AddAPIKeyIDs(ids...)
|
||||
@@ -521,6 +535,10 @@ func (_c *GroupCreate) defaults() error {
|
||||
v := group.DefaultSupportedModelScopes
|
||||
_c.mutation.SetSupportedModelScopes(v)
|
||||
}
|
||||
if _, ok := _c.mutation.SortOrder(); !ok {
|
||||
v := group.DefaultSortOrder
|
||||
_c.mutation.SetSortOrder(v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -585,6 +603,9 @@ func (_c *GroupCreate) check() error {
|
||||
if _, ok := _c.mutation.SupportedModelScopes(); !ok {
|
||||
return &ValidationError{Name: "supported_model_scopes", err: errors.New(`ent: missing required field "Group.supported_model_scopes"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.SortOrder(); !ok {
|
||||
return &ValidationError{Name: "sort_order", err: errors.New(`ent: missing required field "Group.sort_order"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -708,6 +729,10 @@ func (_c *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) {
|
||||
_spec.SetField(group.FieldSupportedModelScopes, field.TypeJSON, value)
|
||||
_node.SupportedModelScopes = value
|
||||
}
|
||||
if value, ok := _c.mutation.SortOrder(); ok {
|
||||
_spec.SetField(group.FieldSortOrder, field.TypeInt, value)
|
||||
_node.SortOrder = value
|
||||
}
|
||||
if nodes := _c.mutation.APIKeysIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
@@ -1266,6 +1291,24 @@ func (u *GroupUpsert) UpdateSupportedModelScopes() *GroupUpsert {
|
||||
return u
|
||||
}
|
||||
|
||||
// SetSortOrder sets the "sort_order" field.
|
||||
func (u *GroupUpsert) SetSortOrder(v int) *GroupUpsert {
|
||||
u.Set(group.FieldSortOrder, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateSortOrder sets the "sort_order" field to the value that was provided on create.
|
||||
func (u *GroupUpsert) UpdateSortOrder() *GroupUpsert {
|
||||
u.SetExcluded(group.FieldSortOrder)
|
||||
return u
|
||||
}
|
||||
|
||||
// AddSortOrder adds v to the "sort_order" field.
|
||||
func (u *GroupUpsert) AddSortOrder(v int) *GroupUpsert {
|
||||
u.Add(group.FieldSortOrder, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
@@ -1780,6 +1823,27 @@ func (u *GroupUpsertOne) UpdateSupportedModelScopes() *GroupUpsertOne {
|
||||
})
|
||||
}
|
||||
|
||||
// SetSortOrder sets the "sort_order" field.
|
||||
func (u *GroupUpsertOne) SetSortOrder(v int) *GroupUpsertOne {
|
||||
return u.Update(func(s *GroupUpsert) {
|
||||
s.SetSortOrder(v)
|
||||
})
|
||||
}
|
||||
|
||||
// AddSortOrder adds v to the "sort_order" field.
|
||||
func (u *GroupUpsertOne) AddSortOrder(v int) *GroupUpsertOne {
|
||||
return u.Update(func(s *GroupUpsert) {
|
||||
s.AddSortOrder(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateSortOrder sets the "sort_order" field to the value that was provided on create.
|
||||
func (u *GroupUpsertOne) UpdateSortOrder() *GroupUpsertOne {
|
||||
return u.Update(func(s *GroupUpsert) {
|
||||
s.UpdateSortOrder()
|
||||
})
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (u *GroupUpsertOne) Exec(ctx context.Context) error {
|
||||
if len(u.create.conflict) == 0 {
|
||||
@@ -2460,6 +2524,27 @@ func (u *GroupUpsertBulk) UpdateSupportedModelScopes() *GroupUpsertBulk {
|
||||
})
|
||||
}
|
||||
|
||||
// SetSortOrder sets the "sort_order" field.
|
||||
func (u *GroupUpsertBulk) SetSortOrder(v int) *GroupUpsertBulk {
|
||||
return u.Update(func(s *GroupUpsert) {
|
||||
s.SetSortOrder(v)
|
||||
})
|
||||
}
|
||||
|
||||
// AddSortOrder adds v to the "sort_order" field.
|
||||
func (u *GroupUpsertBulk) AddSortOrder(v int) *GroupUpsertBulk {
|
||||
return u.Update(func(s *GroupUpsert) {
|
||||
s.AddSortOrder(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateSortOrder sets the "sort_order" field to the value that was provided on create.
|
||||
func (u *GroupUpsertBulk) UpdateSortOrder() *GroupUpsertBulk {
|
||||
return u.Update(func(s *GroupUpsert) {
|
||||
s.UpdateSortOrder()
|
||||
})
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (u *GroupUpsertBulk) Exec(ctx context.Context) error {
|
||||
if u.create.err != nil {
|
||||
|
||||
Reference in New Issue
Block a user