support modify account

This commit is contained in:
MaysWind
2020-11-15 23:11:14 +08:00
parent f74ea31c6d
commit 84317975c8
11 changed files with 408 additions and 34 deletions
+40
View File
@@ -38,6 +38,21 @@ func (s *AccountService) GetAllAccountsByUid(uid int64) ([]*models.Account, erro
return accounts, err
}
func (s *AccountService) GetAccountByAccountId(uid int64, accountId int64) ([]*models.Account, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
if accountId <= 0 {
return nil, errs.ErrAccountIdInvalid
}
var accounts []*models.Account
err := s.UserDataDB(uid).Where("uid=? AND deleted=? AND (account_id=? OR parent_account_id=?)", uid, false, accountId, accountId).OrderBy("parent_account_id asc, display_order asc").Find(&accounts)
return accounts, err
}
func (s *AccountService) GetMaxDisplayOrder(uid int64, category models.AccountCategory) (int, error) {
if uid <= 0 {
return 0, errs.ErrUserIdInvalid
@@ -122,6 +137,31 @@ func (s *AccountService) CreateAccounts(mainAccount *models.Account, childrenAcc
})
}
func (s *AccountService) ModifyAccounts(uid int64, accounts []*models.Account) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
now := time.Now().Unix()
for i := 0; i < len(accounts); i++ {
accounts[i].UpdatedUnixTime = now
}
return s.UserDataDB(uid).DoTransaction(func(sess *xorm.Session) error {
for i := 0; i < len(accounts); i++ {
account := accounts[i]
_, err := sess.Cols("name", "category", "icon", "comment", "hidden", "updated_unix_time").Where("account_id=? AND uid=? AND deleted=?", account.AccountId, uid, false).Update(account)
if err != nil {
return err
}
}
return nil
})
}
func (s *AccountService) HideAccount(uid int64, ids []int64, hidden bool) error {
if uid <= 0 {
return errs.ErrUserIdInvalid