package logic import ( "context" "strconv" "lone-services/pkg/modelbase" "lone-services/pkg/utils" "lone-services/pkg/validate" product "lone-services/rpc/product/pb" "lone-services/services/product/internal/dao" "lone-services/services/product/internal/model" "lone-services/services/product/internal/svc" "lone-services/services/product/validator" "github.com/zeromicro/go-zero/core/logx" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) type InfoByIdLogic struct { ctx context.Context svcCtx *svc.ServiceContext logx.Logger } func NewInfoByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoByIdLogic { return &InfoByIdLogic{ ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx), } } func (l *InfoByIdLogic) InfoById(in *product.InfoByIdReq) (*product.Item, error) { var req validator.ProductInfoValidator if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty { return nil, status.Error(codes.InvalidArgument, msg) } var info dao.Info err := model.ProductModel{}.Init().GetOne(modelbase.Params{ Eq: map[string]string{"id": strconv.FormatInt(req.Id, 10)}, }, &info) if err != nil { l.Errorf("product InfoById: %v", err) return nil, status.Error(codes.Internal, utils.Fail.Msg) } if info.Id < 1 { return nil, status.Error(codes.NotFound, utils.ErrorNotFund.Msg) } return toProductItem(info), nil }