support sub account

This commit is contained in:
MaysWind
2020-11-15 01:16:17 +08:00
parent afd6996c69
commit af809a098e
10 changed files with 243 additions and 46 deletions
+21
View File
@@ -8,6 +8,7 @@ import (
"github.com/mayswind/lab/pkg/log"
"github.com/mayswind/lab/pkg/models"
"github.com/mayswind/lab/pkg/services"
"github.com/mayswind/lab/pkg/validators"
)
type AccountsApi struct {
@@ -86,6 +87,25 @@ func (a *AccountsApi) AccountCreateHandler(c *core.Context) (interface{}, *errs.
log.WarnfWithRequestId(c, "[accounts.AccountCreateHandler] account does not have any sub accounts")
return nil, errs.ErrAccountHaveNoSubAccount
}
if accountCreateReq.Currency != validators.PARENT_ACCOUNT_CURRENCY_PLACEHODLER {
log.WarnfWithRequestId(c, "[accounts.AccountCreateHandler] parent account cannot set currency")
return nil, errs.ErrParentAccountCannotSetCurrency
}
for i := 0; i < len(accountCreateReq.SubAccounts); i++ {
subAccount := accountCreateReq.SubAccounts[i]
if subAccount.Category != accountCreateReq.Category {
log.WarnfWithRequestId(c, "[accounts.AccountCreateHandler] category of sub account not equals to parent")
return nil, errs.ErrSubAccountCategoryNotEqualsToParent
}
if subAccount.Type != models.ACCOUNT_TYPE_SINGLE_ACCOUNT {
log.WarnfWithRequestId(c, "[accounts.AccountCreateHandler] sub account type invalid")
return nil, errs.ErrSubAccountTypeInvalid
}
}
} else {
log.WarnfWithRequestId(c, "[accounts.AccountCreateHandler] account type invalid, type is %d", accountCreateReq.Type)
return nil, errs.ErrAccountTypeInvalid
@@ -206,6 +226,7 @@ func (a *AccountsApi) createNewAccount(uid int64, accountCreateReq *models.Accou
Name: accountCreateReq.Name,
DisplayOrder: order,
Category: accountCreateReq.Category,
Type: accountCreateReq.Type,
Icon: accountCreateReq.Icon,
Currency: accountCreateReq.Currency,
Comment: accountCreateReq.Comment,