47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
|
package product
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"tianyuan-api/apps/sentinel/client/product"
|
||
|
|
||
|
"tianyuan-api/apps/index/internal/svc"
|
||
|
"tianyuan-api/apps/index/internal/types"
|
||
|
|
||
|
"github.com/zeromicro/go-zero/core/logx"
|
||
|
)
|
||
|
|
||
|
type GetProductByIdLogic struct {
|
||
|
logx.Logger
|
||
|
ctx context.Context
|
||
|
svcCtx *svc.ServiceContext
|
||
|
}
|
||
|
|
||
|
func NewGetProductByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductByIdLogic {
|
||
|
return &GetProductByIdLogic{
|
||
|
Logger: logx.WithContext(ctx),
|
||
|
ctx: ctx,
|
||
|
svcCtx: svcCtx,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (l *GetProductByIdLogic) GetProductById(req *types.GetProductByIdReq) (resp *types.GetProductByIdResp, err error) {
|
||
|
productResp, err := l.svcCtx.ProductRpc.GetProductById(l.ctx, &product.GetRecordByIdRequest{
|
||
|
Id: req.ProductId,
|
||
|
})
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
return &types.GetProductByIdResp{
|
||
|
ProductItem: types.ProductItem{
|
||
|
ProductId: productResp.Id,
|
||
|
ProductName: productResp.ProductName,
|
||
|
ProductCode: productResp.ProductCode,
|
||
|
ProductDescription: productResp.ProductDescription,
|
||
|
ProductContent: productResp.ProductContent,
|
||
|
ProductGroup: productResp.ProductGroup,
|
||
|
ProductPrice: productResp.ProductPrice,
|
||
|
},
|
||
|
}, nil
|
||
|
}
|