You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package district
|
|
|
|
import (
|
|
"context"
|
|
"git.noahlan.cn/n-admin/n-admin-server/api/internal/svc"
|
|
"git.noahlan.cn/n-admin/n-admin-server/api/internal/types"
|
|
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core"
|
|
|
|
"net/http"
|
|
)
|
|
|
|
type GetDistrictChildrenLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
r *http.Request
|
|
}
|
|
|
|
func NewGetDistrictChildrenLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *GetDistrictChildrenLogic {
|
|
return &GetDistrictChildrenLogic{
|
|
r: r,
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *GetDistrictChildrenLogic) GetDistrictChildren(req *types.GetDistrictChildrenReq) (resp []*types.DistrictInfo, err error) {
|
|
rpcReq := &core.DistrictReq{ParentCode: req.ParentCode, QueryType: core.DistrictQueryType_Children}
|
|
if req.ParentCode == "" {
|
|
rpcReq.Level = 1
|
|
}
|
|
rpcResp, err := l.svcCtx.CoreRpc.GetDistrictList(l.ctx, rpcReq)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
resp = make([]*types.DistrictInfo, len(rpcResp.Data))
|
|
|
|
for i, item := range rpcResp.Data {
|
|
resp[i] = l.svcCtx.Convert.ConvertDistrict(l.ctx, item)
|
|
}
|
|
return
|
|
}
|