get account list api supports only requesting visible accounts
This commit is contained in:
+14
-2
@@ -22,6 +22,14 @@ var (
|
||||
)
|
||||
|
||||
func (a *AccountsApi) AccountListHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var accountListReq models.AccountListRequest
|
||||
err := c.ShouldBindQuery(&accountListReq)
|
||||
|
||||
if err != nil {
|
||||
log.WarnfWithRequestId(c, "[accounts.AccountListHandler] parse request failed, because %s", err.Error())
|
||||
return nil, errs.NewIncompleteOrIncorrectSubmissionError(err)
|
||||
}
|
||||
|
||||
uid := c.GetCurrentUid()
|
||||
accounts, err := a.accounts.GetAllAccountsByUid(uid)
|
||||
|
||||
@@ -41,6 +49,10 @@ func (a *AccountsApi) AccountListHandler(c *core.Context) (interface{}, *errs.Er
|
||||
for i := 0; i < len(userAllAccountResps); i++ {
|
||||
userAccountResp := userAllAccountResps[i]
|
||||
|
||||
if accountListReq.VisibleOnly && userAccountResp.Hidden {
|
||||
continue
|
||||
}
|
||||
|
||||
if userAccountResp.ParentId <= models.ACCOUNT_PARENT_ID_LEVEL_ONE {
|
||||
continue
|
||||
}
|
||||
@@ -54,10 +66,10 @@ func (a *AccountsApi) AccountListHandler(c *core.Context) (interface{}, *errs.Er
|
||||
parentAccount.SubAccounts = append(parentAccount.SubAccounts, userAccountResp)
|
||||
}
|
||||
|
||||
userFinalAccountResps := make(models.AccountInfoResponseSlice, 0)
|
||||
userFinalAccountResps := make(models.AccountInfoResponseSlice, 0, len(userAllAccountResps))
|
||||
|
||||
for i := 0; i < len(userAllAccountResps); i++ {
|
||||
if userAllAccountResps[i].ParentId == models.ACCOUNT_PARENT_ID_LEVEL_ONE {
|
||||
if userAllAccountResps[i].ParentId == models.ACCOUNT_PARENT_ID_LEVEL_ONE && (!accountListReq.VisibleOnly || !userAllAccountResps[i].Hidden) {
|
||||
sort.Sort(userAllAccountResps[i].SubAccounts)
|
||||
userFinalAccountResps = append(userFinalAccountResps, userAllAccountResps[i])
|
||||
}
|
||||
|
||||
@@ -62,10 +62,6 @@ type Account struct {
|
||||
DeletedUnixTime int64
|
||||
}
|
||||
|
||||
type AccountGetRequest struct {
|
||||
Id int64 `form:"id,string" binding:"required,min=1"`
|
||||
}
|
||||
|
||||
type AccountCreateRequest struct {
|
||||
Name string `json:"name" binding:"required,notBlank,max=32"`
|
||||
Category AccountCategory `json:"category" binding:"required"`
|
||||
@@ -89,6 +85,14 @@ type AccountModifyRequest struct {
|
||||
SubAccounts []*AccountModifyRequest `json:"subAccounts" binding:"omitempty"`
|
||||
}
|
||||
|
||||
type AccountListRequest struct {
|
||||
VisibleOnly bool `form:"visible_only"`
|
||||
}
|
||||
|
||||
type AccountGetRequest struct {
|
||||
Id int64 `form:"id,string" binding:"required,min=1"`
|
||||
}
|
||||
|
||||
type AccountHideRequest struct {
|
||||
Id int64 `json:"id,string" binding:"required,min=1"`
|
||||
Hidden bool `json:"hidden"`
|
||||
|
||||
+2
-2
@@ -166,8 +166,8 @@ export default {
|
||||
password
|
||||
});
|
||||
},
|
||||
getAllAccounts: () => {
|
||||
return axios.get('v1/accounts/list.json');
|
||||
getAllAccounts: ({ visibleOnly }) => {
|
||||
return axios.get('v1/accounts/list.json?visible_only=' + !!visibleOnly);
|
||||
},
|
||||
getAccount: ({ id }) => {
|
||||
return axios.get('v1/accounts/get.json?id=' + id);
|
||||
|
||||
@@ -318,7 +318,7 @@ export default {
|
||||
|
||||
self.loading = true;
|
||||
|
||||
self.$services.getAllAccounts().then(response => {
|
||||
self.$services.getAllAccounts({ visibleOnly: false }).then(response => {
|
||||
const data = response.data;
|
||||
|
||||
if (!data || !data.success || !data.result) {
|
||||
@@ -358,7 +358,7 @@ export default {
|
||||
|
||||
const self = this;
|
||||
|
||||
self.$services.getAllAccounts().then(response => {
|
||||
self.$services.getAllAccounts({ visibleOnly: false }).then(response => {
|
||||
if (done) {
|
||||
done();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user