From 8e3dcb8370f70dc41a598e80199977c8f34c925d Mon Sep 17 00:00:00 2001 From: MaysWind Date: Sun, 6 Dec 2020 22:14:40 +0800 Subject: [PATCH] code refactor --- pkg/services/accounts.go | 4 ++-- pkg/services/transaction_categories.go | 6 +++--- pkg/services/transaction_tags.go | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/services/accounts.go b/pkg/services/accounts.go index 6ba84dd8..284478c4 100644 --- a/pkg/services/accounts.go +++ b/pkg/services/accounts.go @@ -151,7 +151,7 @@ func (s *AccountService) ModifyAccounts(uid int64, accounts []*models.Account) e return s.UserDataDB(uid).DoTransaction(func(sess *xorm.Session) error { for i := 0; i < len(accounts); i++ { account := accounts[i] - updatedRows, err := sess.Cols("name", "category", "icon", "color", "comment", "hidden", "updated_unix_time").Where("account_id=? AND uid=? AND deleted=?", account.AccountId, uid, false).Update(account) + updatedRows, err := sess.ID(account.AccountId).Cols("name", "category", "icon", "color", "comment", "hidden", "updated_unix_time").Where("uid=? AND deleted=?", uid, false).Update(account) if err != nil { return err @@ -201,7 +201,7 @@ func (s *AccountService) ModifyAccountDisplayOrders(uid int64, accounts []*model return s.UserDataDB(uid).DoTransaction(func(sess *xorm.Session) error { for i := 0; i < len(accounts); i++ { account := accounts[i] - updatedRows, err := sess.Cols("display_order", "updated_unix_time").Where("account_id=? AND uid=? AND deleted=?", account.AccountId, uid, false).Update(account) + updatedRows, err := sess.ID(account.AccountId).Cols("display_order", "updated_unix_time").Where("uid=? AND deleted=?", uid, false).Update(account) if err != nil { return err diff --git a/pkg/services/transaction_categories.go b/pkg/services/transaction_categories.go index 8dce86b0..6e047a86 100644 --- a/pkg/services/transaction_categories.go +++ b/pkg/services/transaction_categories.go @@ -63,7 +63,7 @@ func (s *TransactionCategoryService) GetCategoryByCategoryId(uid int64, category } category := &models.TransactionCategory{} - has, err := s.UserDataDB(uid).Where("uid=? AND deleted=? AND category_id=?", uid, false, categoryId).Get(category) + has, err := s.UserDataDB(uid).ID(categoryId).Where("uid=? AND deleted=?", uid, false).Get(category) if err != nil { return nil, err @@ -209,7 +209,7 @@ func (s *TransactionCategoryService) ModifyCategory(category *models.Transaction category.UpdatedUnixTime = time.Now().Unix() return s.UserDataDB(category.Uid).DoTransaction(func(sess *xorm.Session) error { - updatedRows, err := sess.Cols("name", "icon", "color", "comment", "hidden", "updated_unix_time").Where("category_id=? AND uid=? AND deleted=?", category.CategoryId, category.Uid, false).Update(category) + updatedRows, err := sess.ID(category.CategoryId).Cols("name", "icon", "color", "comment", "hidden", "updated_unix_time").Where("uid=? AND deleted=?", category.Uid, false).Update(category) if err != nil { return err @@ -258,7 +258,7 @@ func (s *TransactionCategoryService) ModifyCategoryDisplayOrders(uid int64, cate return s.UserDataDB(uid).DoTransaction(func(sess *xorm.Session) error { for i := 0; i < len(categories); i++ { category := categories[i] - updatedRows, err := sess.Cols("display_order", "updated_unix_time").Where("category_id=? AND uid=? AND deleted=?", category.CategoryId, uid, false).Update(category) + updatedRows, err := sess.ID(category.CategoryId).Cols("display_order", "updated_unix_time").Where("uid=? AND deleted=?", uid, false).Update(category) if err != nil { return err diff --git a/pkg/services/transaction_tags.go b/pkg/services/transaction_tags.go index 5222a5b5..091d1931 100644 --- a/pkg/services/transaction_tags.go +++ b/pkg/services/transaction_tags.go @@ -48,7 +48,7 @@ func (s *TransactionTagService) GetTagByTagId(uid int64, tagId int64) (*models.T } tag := &models.TransactionTag{} - has, err := s.UserDataDB(uid).Where("uid=? AND tag_id=?", uid, tagId).Get(tag) + has, err := s.UserDataDB(uid).ID(tagId).Where("uid=?", uid).Get(tag) if err != nil { return nil, err @@ -118,7 +118,7 @@ func (s *TransactionTagService) ModifyTag(tag *models.TransactionTag) error { tag.UpdatedUnixTime = time.Now().Unix() return s.UserDataDB(tag.Uid).DoTransaction(func(sess *xorm.Session) error { - updatedRows, err := sess.Cols("name", "updated_unix_time").Where("tag_id=? AND uid=?", tag.TagId, tag.Uid).Update(tag) + updatedRows, err := sess.ID(tag.TagId).Cols("name", "updated_unix_time").Where("uid=?", tag.Uid).Update(tag) if err != nil { return err @@ -167,7 +167,7 @@ func (s *TransactionTagService) ModifyTagDisplayOrders(uid int64, tags []*models return s.UserDataDB(uid).DoTransaction(func(sess *xorm.Session) error { for i := 0; i < len(tags); i++ { tag := tags[i] - updatedRows, err := sess.Cols("display_order", "updated_unix_time").Where("tag_id=? AND uid=?", tag.TagId, uid).Update(tag) + updatedRows, err := sess.ID(tag.TagId).Cols("display_order", "updated_unix_time").Where("uid=?", uid).Update(tag) if err != nil { return err