45 lines
1.0 KiB
Go
45 lines
1.0 KiB
Go
|
|
package panbolt
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
|
||
|
|
"muyu-apiserver/gateway/internal/svc"
|
||
|
|
"muyu-apiserver/gateway/internal/types"
|
||
|
|
"muyu-apiserver/pkg/ctxdata"
|
||
|
|
"muyu-apiserver/rpc/inventory/pb"
|
||
|
|
|
||
|
|
"github.com/zeromicro/go-zero/core/logx"
|
||
|
|
)
|
||
|
|
|
||
|
|
type ListBoltsLogic struct {
|
||
|
|
logx.Logger
|
||
|
|
ctx context.Context
|
||
|
|
svcCtx *svc.ServiceContext
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewListBoltsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListBoltsLogic {
|
||
|
|
return &ListBoltsLogic{
|
||
|
|
Logger: logx.WithContext(ctx),
|
||
|
|
ctx: ctx,
|
||
|
|
svcCtx: svcCtx,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (l *ListBoltsLogic) ListBolts() (resp *types.ListBoltResp, err error) {
|
||
|
|
panId := ctxdata.GetPathId(l.ctx)
|
||
|
|
rpcResp, err := l.svcCtx.InventoryRpc.ListBolts(l.ctx, &pb.ListBoltReq{PanId: panId})
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
list := make([]types.BoltInfo, 0, len(rpcResp.List))
|
||
|
|
for _, b := range rpcResp.List {
|
||
|
|
list = append(list, types.BoltInfo{
|
||
|
|
BoltId: b.BoltId,
|
||
|
|
PanId: b.PanId,
|
||
|
|
LengthM: b.LengthM,
|
||
|
|
SortOrder: b.SortOrder,
|
||
|
|
})
|
||
|
|
}
|
||
|
|
return &types.ListBoltResp{List: list}, nil
|
||
|
|
}
|