modification api returns updated model object instead of processing result

This commit is contained in:
MaysWind
2021-01-03 21:37:32 +08:00
parent a947b1ae8c
commit 0d4be75b22
3 changed files with 48 additions and 3 deletions
+38 -1
View File
@@ -274,7 +274,44 @@ func (a *AccountsApi) AccountModifyHandler(c *core.Context) (interface{}, *errs.
log.InfofWithRequestId(c, "[accounts.AccountModifyHandler] user \"uid:%d\" has updated account \"id:%d\" successfully", uid, accountModifyReq.Id)
return true, nil
accountRespMap := make(map[int64]*models.AccountInfoResponse)
for i := 0; i < len(toUpdateAccounts); i++ {
account := toUpdateAccounts[i]
oldAccount := accountMap[account.AccountId]
account.Type = oldAccount.Type
account.ParentAccountId = oldAccount.ParentAccountId
account.DisplayOrder = oldAccount.DisplayOrder
account.Currency = oldAccount.Currency
account.Balance = oldAccount.Balance
accountResp := account.ToAccountInfoResponse()
accountRespMap[accountResp.Id] = accountResp
}
for i := 0; i < len(accountAndSubAccounts); i++ {
oldAccount := accountAndSubAccounts[i]
_, exists := accountRespMap[oldAccount.AccountId]
if !exists {
oldAccountResp := oldAccount.ToAccountInfoResponse()
accountRespMap[oldAccountResp.Id] = oldAccountResp
}
}
accountResp := accountRespMap[accountModifyReq.Id]
for i := 0; i < len(accountAndSubAccounts); i++ {
if accountAndSubAccounts[i].ParentAccountId == accountResp.Id {
subAccountResp := accountRespMap[accountAndSubAccounts[i].AccountId]
accountResp.SubAccounts = append(accountResp.SubAccounts, subAccountResp)
}
}
sort.Sort(accountResp.SubAccounts)
return accountResp, nil
}
// AccountHideHandler hides an existed account by request parameters for current user
+6 -1
View File
@@ -238,7 +238,12 @@ func (a *TransactionCategoriesApi) CategoryModifyHandler(c *core.Context) (inter
log.InfofWithRequestId(c, "[transaction_categories.CategoryModifyHandler] user \"uid:%d\" has updated category \"id:%d\" successfully", uid, categoryModifyReq.Id)
return true, nil
newCategory.Type = category.Type
newCategory.ParentCategoryId = category.ParentCategoryId
newCategory.DisplayOrder = category.DisplayOrder
categoryResp := newCategory.ToTransactionCategoryInfoResponse()
return categoryResp, nil
}
// CategoryHideHandler hides an existed transaction category by request parameters for current user
+4 -1
View File
@@ -295,7 +295,10 @@ func (a *TransactionsApi) TransactionModifyHandler(c *core.Context) (interface{}
log.InfofWithRequestId(c, "[transactions.TransactionModifyHandler] user \"uid:%d\" has updated transaction \"id:%d\" successfully", uid, transactionModifyReq.Id)
return true, nil
newTransaction.Type = transaction.Type
newTransactionResp := newTransaction.ToTransactionInfoResponse(tagIds)
return newTransactionResp, nil
}
// TransactionDeleteHandler deletes an existed transaction by request parameters for current user