Skip to content

Commit 9ceeeff

Browse files
committed
place the account at the end of the account category after changing account category
1 parent 7123837 commit 9ceeeff

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

pkg/api/accounts.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,17 @@ func (a *AccountsApi) AccountModifyHandler(c *core.WebContext) (any, *errs.Error
437437
toUpdateAccount := a.getToUpdateAccount(uid, &accountModifyReq, mainAccount, false)
438438

439439
if toUpdateAccount != nil {
440+
if toUpdateAccount.Category != mainAccount.Category {
441+
maxOrderId, err := a.accounts.GetMaxDisplayOrder(c, uid, toUpdateAccount.Category)
442+
443+
if err != nil {
444+
log.Errorf(c, "[accounts.AccountModifyHandler] failed to get max display order for user \"uid:%d\", because %s", uid, err.Error())
445+
return nil, errs.Or(err, errs.ErrOperationFailed)
446+
}
447+
448+
toUpdateAccount.DisplayOrder = maxOrderId + 1
449+
}
450+
440451
anythingUpdate = true
441452
toUpdateAccounts = append(toUpdateAccounts, toUpdateAccount)
442453
}
@@ -762,15 +773,16 @@ func (a *AccountsApi) getToUpdateAccount(uid int64, accountModifyReq *models.Acc
762773
}
763774

764775
newAccount := &models.Account{
765-
AccountId: oldAccount.AccountId,
766-
Uid: uid,
767-
Name: accountModifyReq.Name,
768-
Category: accountModifyReq.Category,
769-
Icon: accountModifyReq.Icon,
770-
Color: accountModifyReq.Color,
771-
Comment: accountModifyReq.Comment,
772-
Extend: newAccountExtend,
773-
Hidden: accountModifyReq.Hidden,
776+
AccountId: oldAccount.AccountId,
777+
Uid: uid,
778+
Name: accountModifyReq.Name,
779+
DisplayOrder: oldAccount.DisplayOrder,
780+
Category: accountModifyReq.Category,
781+
Icon: accountModifyReq.Icon,
782+
Color: accountModifyReq.Color,
783+
Comment: accountModifyReq.Comment,
784+
Extend: newAccountExtend,
785+
Hidden: accountModifyReq.Hidden,
774786
}
775787

776788
if newAccount.Name != oldAccount.Name ||

pkg/services/accounts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ func (s *AccountService) ModifyAccounts(c core.Context, mainAccount *models.Acco
445445
// update accounts
446446
for i := 0; i < len(updateAccounts); i++ {
447447
account := updateAccounts[i]
448-
updatedRows, err := sess.ID(account.AccountId).Cols("name", "category", "icon", "color", "comment", "extend", "hidden", "updated_unix_time").Where("uid=? AND deleted=?", account.Uid, false).Update(account)
448+
updatedRows, err := sess.ID(account.AccountId).Cols("name", "display_order", "category", "icon", "color", "comment", "extend", "hidden", "updated_unix_time").Where("uid=? AND deleted=?", account.Uid, false).Update(account)
449449

450450
if err != nil {
451451
return err

0 commit comments

Comments
 (0)