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

47 lines
1.1 KiB
Go

package product
import (
"context"
"muyu-apiserver/gateway/internal/svc"
"muyu-apiserver/gateway/internal/types"
"muyu-apiserver/rpc/inventory/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type CreateProductLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewCreateProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateProductLogic {
return &CreateProductLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *CreateProductLogic) CreateProduct(req *types.CreateProductReq) (resp *types.IdResp, err error) {
rpcResp, err := l.svcCtx.InventoryRpc.CreateProduct(l.ctx, &pb.CreateProductReq{
ProductName: req.ProductName,
ImageUrl: req.ImageUrl,
Spec: req.Spec,
Color: req.Color,
UnitPieces: req.UnitPieces,
UnitRolls: req.UnitRolls,
StockQuantity: req.StockQuantity,
Location: req.Location,
CostPrice: req.CostPrice,
SalesPrice: req.SalesPrice,
Remark: req.Remark,
})
if err != nil {
return nil, err
}
return &types.IdResp{Id: rpcResp.Id}, nil
}