51 lines
1.2 KiB
Go
51 lines
1.2 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 UpdateProductLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewUpdateProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateProductLogic {
|
|
return &UpdateProductLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *UpdateProductLogic) UpdateProduct(req *types.UpdateProductReq) (resp *types.IdResp, err error) {
|
|
id := ctxdata.GetPathId(l.ctx)
|
|
|
|
_, err = l.svcCtx.InventoryRpc.UpdateProduct(l.ctx, &pb.UpdateProductReq{
|
|
ProductId: id,
|
|
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: id}, nil
|
|
}
|