41 lines
817 B
Go
Raw Normal View History

package product
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 GetProductLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductLogic {
return &GetProductLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetProductLogic) GetProduct() (resp *types.ProductInfo, err error) {
id := ctxdata.GetPathId(l.ctx)
rpcResp, err := l.svcCtx.InventoryRpc.GetProduct(l.ctx, &pb.GetProductReq{
ProductId: id,
})
if err != nil {
return nil, err
}
pi := productInfoFromPB(rpcResp)
return &pi, nil
}