Chever John 71a2d912e2 feat: initial commit for muyu-apiserver
Go service with gateway, RPC, model layers and k8s deploy configs.

Made-with: Cursor
2026-02-28 15:29:16 +08:00

56 lines
1.3 KiB
Go

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
}
return &types.ProductInfo{
ProductId: rpcResp.ProductId,
ProductName: rpcResp.ProductName,
ImageUrl: rpcResp.ImageUrl,
Spec: rpcResp.Spec,
Color: rpcResp.Color,
UnitPieces: rpcResp.UnitPieces,
UnitRolls: rpcResp.UnitRolls,
StockQuantity: rpcResp.StockQuantity,
Location: rpcResp.Location,
CostPrice: rpcResp.CostPrice,
SalesPrice: rpcResp.SalesPrice,
Remark: rpcResp.Remark,
Status: rpcResp.Status,
CreatedAt: rpcResp.CreatedAt,
UpdatedAt: rpcResp.UpdatedAt,
}, nil
}