code refactor
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user