mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-19 09:14:27 +08:00
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) {
|
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()
|
uid := c.GetCurrentUid()
|
||||||
accounts, err := a.accounts.GetAllAccountsByUid(uid)
|
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++ {
|
for i := 0; i < len(userAllAccountResps); i++ {
|
||||||
userAccountResp := userAllAccountResps[i]
|
userAccountResp := userAllAccountResps[i]
|
||||||
|
|
||||||
|
if accountListReq.VisibleOnly && userAccountResp.Hidden {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if userAccountResp.ParentId <= models.ACCOUNT_PARENT_ID_LEVEL_ONE {
|
if userAccountResp.ParentId <= models.ACCOUNT_PARENT_ID_LEVEL_ONE {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -54,10 +66,10 @@ func (a *AccountsApi) AccountListHandler(c *core.Context) (interface{}, *errs.Er
|
|||||||
parentAccount.SubAccounts = append(parentAccount.SubAccounts, userAccountResp)
|
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++ {
|
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)
|
sort.Sort(userAllAccountResps[i].SubAccounts)
|
||||||
userFinalAccountResps = append(userFinalAccountResps, userAllAccountResps[i])
|
userFinalAccountResps = append(userFinalAccountResps, userAllAccountResps[i])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,10 +62,6 @@ type Account struct {
|
|||||||
DeletedUnixTime int64
|
DeletedUnixTime int64
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccountGetRequest struct {
|
|
||||||
Id int64 `form:"id,string" binding:"required,min=1"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AccountCreateRequest struct {
|
type AccountCreateRequest struct {
|
||||||
Name string `json:"name" binding:"required,notBlank,max=32"`
|
Name string `json:"name" binding:"required,notBlank,max=32"`
|
||||||
Category AccountCategory `json:"category" binding:"required"`
|
Category AccountCategory `json:"category" binding:"required"`
|
||||||
@@ -89,6 +85,14 @@ type AccountModifyRequest struct {
|
|||||||
SubAccounts []*AccountModifyRequest `json:"subAccounts" binding:"omitempty"`
|
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 {
|
type AccountHideRequest struct {
|
||||||
Id int64 `json:"id,string" binding:"required,min=1"`
|
Id int64 `json:"id,string" binding:"required,min=1"`
|
||||||
Hidden bool `json:"hidden"`
|
Hidden bool `json:"hidden"`
|
||||||
|
|||||||
+2
-2
@@ -166,8 +166,8 @@ export default {
|
|||||||
password
|
password
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getAllAccounts: () => {
|
getAllAccounts: ({ visibleOnly }) => {
|
||||||
return axios.get('v1/accounts/list.json');
|
return axios.get('v1/accounts/list.json?visible_only=' + !!visibleOnly);
|
||||||
},
|
},
|
||||||
getAccount: ({ id }) => {
|
getAccount: ({ id }) => {
|
||||||
return axios.get('v1/accounts/get.json?id=' + id);
|
return axios.get('v1/accounts/get.json?id=' + id);
|
||||||
|
|||||||
@@ -318,7 +318,7 @@ export default {
|
|||||||
|
|
||||||
self.loading = true;
|
self.loading = true;
|
||||||
|
|
||||||
self.$services.getAllAccounts().then(response => {
|
self.$services.getAllAccounts({ visibleOnly: false }).then(response => {
|
||||||
const data = response.data;
|
const data = response.data;
|
||||||
|
|
||||||
if (!data || !data.success || !data.result) {
|
if (!data || !data.success || !data.result) {
|
||||||
@@ -358,7 +358,7 @@ export default {
|
|||||||
|
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
self.$services.getAllAccounts().then(response => {
|
self.$services.getAllAccounts({ visibleOnly: false }).then(response => {
|
||||||
if (done) {
|
if (done) {
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user