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

67 lines
1.5 KiB
Go

package stock
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 ListStockLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewListStockLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListStockLogic {
return &ListStockLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ListStockLogic) ListStock(req *types.ListProductReq) (resp *types.ListProductResp, err error) {
rpcResp, err := l.svcCtx.InventoryRpc.ListProduct(l.ctx, &pb.ListProductReq{
Page: req.Page,
PageSize: req.PageSize,
ProductName: req.ProductName,
Spec: req.Spec,
Color: req.Color,
Location: req.Location,
Status: req.Status,
})
if err != nil {
return nil, err
}
list := make([]types.ProductInfo, 0, len(rpcResp.List))
for _, p := range rpcResp.List {
list = append(list, types.ProductInfo{
ProductId: p.ProductId,
ProductName: p.ProductName,
ImageUrl: p.ImageUrl,
Spec: p.Spec,
Color: p.Color,
UnitPieces: p.UnitPieces,
UnitRolls: p.UnitRolls,
StockQuantity: p.StockQuantity,
Location: p.Location,
CostPrice: p.CostPrice,
SalesPrice: p.SalesPrice,
Remark: p.Remark,
Status: p.Status,
CreatedAt: p.CreatedAt,
UpdatedAt: p.UpdatedAt,
})
}
return &types.ListProductResp{
Total: rpcResp.Total,
List: list,
}, nil
}