Skip to content

Commit

Permalink
feat: fix api get account list
Browse files Browse the repository at this point in the history
  • Loading branch information
scorpiotzh committed Nov 15, 2024
1 parent 6b3e83c commit 58dd41c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
27 changes: 24 additions & 3 deletions dao/t_account_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,32 @@ func (d *DbDao) FindAccountListByAddress(chainType common.ChainType, address str
return
}

func (d *DbDao) FindAccountNameListByAddress(chainType common.ChainType, address, role string) (list []tables.TableAccountInfo, err error) {
func (d *DbDao) FindAccountNameListByAddress(chainType common.ChainType, address, role string, limit, offset int) (list []tables.TableAccountInfo, err error) {
if role == "" || role == "owner" {
err = d.db.Select("account,registered_at,expired_at").Where(" owner_chain_type=? AND owner=? AND `status`!=? and expired_at >= ?", chainType, address, tables.AccountStatusOnLock, time.Now().Unix()-90*86400).Find(&list).Error
err = d.db.Select("account,registered_at,expired_at").
Where(" owner_chain_type=? AND owner=? AND `status`!=? and expired_at >= ?",
chainType, address, tables.AccountStatusOnLock, time.Now().Unix()-90*86400).
Order("account").Limit(limit).Offset(offset).Find(&list).Error
} else if role == "manager" {
err = d.db.Select("account,registered_at,expired_at").Where(" manager_chain_type=? AND manager=? AND `status`!=? and expired_at >= ?", chainType, address, tables.AccountStatusOnLock, time.Now().Unix()-90*86400).Find(&list).Error
err = d.db.Select("account,registered_at,expired_at").
Where(" manager_chain_type=? AND manager=? AND `status`!=? and expired_at >= ?",
chainType, address, tables.AccountStatusOnLock, time.Now().Unix()-90*86400).
Order("account").Limit(limit).Offset(offset).Find(&list).Error
}
return
}

func (d *DbDao) FindTotalAccountNameListByAddress(chainType common.ChainType, address, role string) (count int64, err error) {
if role == "" || role == "owner" {
err = d.db.Model(tables.TableAccountInfo{}).
Where(" owner_chain_type=? AND owner=? AND `status`!=? and expired_at >= ?",
chainType, address, tables.AccountStatusOnLock, time.Now().Unix()-90*86400).
Count(&count).Error
} else if role == "manager" {
err = d.db.Model(tables.TableAccountInfo{}).
Where(" manager_chain_type=? AND manager=? AND `status`!=? and expired_at >= ?",
chainType, address, tables.AccountStatusOnLock, time.Now().Unix()-90*86400).
Count(&count).Error
}
return
}
Expand Down
8 changes: 7 additions & 1 deletion http_server/handle/account_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (h *HttpHandle) doAccountList(ctx context.Context, req *ReqAccountList, api
}
resp.Total = total
} else {
list, err := h.DbDao.FindAccountNameListByAddress(addrHex.ChainType, addrHex.AddressHex, req.Role)
list, err := h.DbDao.FindAccountNameListByAddress(addrHex.ChainType, addrHex.AddressHex, req.Role, req.GetLimit(), req.GetOffset())
if err != nil {
log.Error(ctx, "FindAccountListByAddress err:", err.Error(), req.KeyInfo)
apiResp.ApiRespErr(http_api.ApiCodeDbError, "find account list err")
Expand All @@ -147,6 +147,12 @@ func (h *HttpHandle) doAccountList(ctx context.Context, req *ReqAccountList, api
}
resp.AccountList = append(resp.AccountList, tmp)
}
total, err := h.DbDao.FindTotalAccountNameListByAddress(addrHex.ChainType, addrHex.AddressHex, req.Role)
if err != nil {
apiResp.ApiRespErr(http_api.ApiCodeDbError, "search account total err")
return fmt.Errorf("FindTotalAccountNameListByAddress err: %s", err.Error())
}
resp.Total = total
}

apiResp.ApiRespOK(resp)
Expand Down

0 comments on commit 58dd41c

Please sign in to comment.