tianyuan-api-server/apps/gateway/internal/logic/product/getproductbyidlogic.go

47 lines
1.2 KiB
Go
Raw Permalink Normal View History

2024-10-02 00:57:17 +08:00
package product
import (
"context"
"tianyuan-api/apps/sentinel/client/product"
"tianyuan-api/apps/gateway/internal/svc"
"tianyuan-api/apps/gateway/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
}