2026-02-28 15:29:16 +08:00
|
|
|
package logic
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
"muyu-apiserver/rpc/inventory/internal/svc"
|
|
|
|
|
"muyu-apiserver/rpc/inventory/pb"
|
|
|
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
|
"google.golang.org/grpc/status"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type GetProductLogic struct {
|
|
|
|
|
ctx context.Context
|
|
|
|
|
svcCtx *svc.ServiceContext
|
|
|
|
|
logx.Logger
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewGetProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductLogic {
|
|
|
|
|
return &GetProductLogic{
|
|
|
|
|
ctx: ctx,
|
|
|
|
|
svcCtx: svcCtx,
|
|
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (l *GetProductLogic) GetProduct(in *pb.GetProductReq) (*pb.ProductInfo, error) {
|
|
|
|
|
product, err := l.svcCtx.ProductModel.FindOneByProductId(l.ctx, in.ProductId)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, status.Error(codes.NotFound, "product not found")
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-05 08:06:28 +09:00
|
|
|
return productToPb(product), nil
|
2026-02-28 15:29:16 +08:00
|
|
|
}
|