订单服务新增订单 事务处理

master
shenzhuan 2 years ago
parent 12b95a1fa8
commit ab85aec437

@ -216,12 +216,12 @@ func main() {
c.JSON(http.StatusOK, gin.H{"addCart": "SUCCESS", "Message": "新增购物车成功!"}) c.JSON(http.StatusOK, gin.H{"addCart": "SUCCESS", "Message": "新增购物车成功!"})
}) })
router.POST("/addCart-compensate", func(c *gin.Context) { router.POST("/addCart-compensate", func(c *gin.Context) {
req := &proto.AddCartReq{} req := &proto.UpdateCartReq{}
if err := c.BindJSON(req); err != nil { if err := c.BindJSON(req); err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
req.Id = CartId req.Id = CartId
resp, err = UpdateCartClient.UpdateCart(context.TODO(), req) resp, err := UpdateCartClient.UpdateCart(context.TODO(), req)
CartId = resp.ID CartId = resp.ID
if err != nil { if err != nil {
log.Println("/addCart-compensate err ", err) log.Println("/addCart-compensate err ", err)
@ -264,6 +264,7 @@ func main() {
ProductId: int32(productId), ProductId: int32(productId),
ProductSkuId: int32(productSkuId), ProductSkuId: int32(productSkuId),
UserId: int32(sum), UserId: int32(sum),
CreateUser: int32(sum),
} }
resp := &proto.AddCartResp{} resp := &proto.AddCartResp{}
//商品详情 //商品详情

@ -18,7 +18,7 @@ import (
//接口 //接口
type ICartRepository interface { type ICartRepository interface {
AddCart(*proto.AddCartReq) (*model.ShoppingCart, error) AddCart(*proto.AddCartReq) (*model.ShoppingCart, error)
UpdateCart(*proto.AddCartReq) (*model.ShoppingCart, error) UpdateCart(req *proto.UpdateCartReq) (*model.ShoppingCart, error)
} }
// 创建实例 // 创建实例
@ -39,6 +39,7 @@ func (u *CartRepository) AddCart(req *proto.AddCartReq) (obj *model.ShoppingCart
ProductName: req.ProductName, ProductName: req.ProductName,
ProductMainPicture: req.ProductMainPicture, ProductMainPicture: req.ProductMainPicture,
UserId: req.UserId, UserId: req.UserId,
CreateUser: req.CreateUser,
} }
cart.CreateTime = time.Now() // cart.CreateTime = time.Now() //
tb := u.mysqlDB.Create(&cart) tb := u.mysqlDB.Create(&cart)
@ -47,7 +48,7 @@ func (u *CartRepository) AddCart(req *proto.AddCartReq) (obj *model.ShoppingCart
return &cart, tb.Error //err return &cart, tb.Error //err
} }
func (u *CartRepository) UpdateCart(req *proto.AddCartReq) (obj *model.ShoppingCart, err error) { func (u *CartRepository) UpdateCart(req *proto.UpdateCartReq) (obj *model.ShoppingCart, err error) {
cart := model.ShoppingCart{ cart := model.ShoppingCart{
Number: req.Number, Number: req.Number,
ProductId: req.ProductId, ProductId: req.ProductId,
@ -56,9 +57,14 @@ func (u *CartRepository) UpdateCart(req *proto.AddCartReq) (obj *model.ShoppingC
ProductMainPicture: req.ProductMainPicture, ProductMainPicture: req.ProductMainPicture,
UserId: req.UserId, UserId: req.UserId,
ID: req.Id, ID: req.Id,
IsDeleted: req.IsDeleted,
UpdateUser: req.UpdateUser,
} }
cart.UpdateTime = time.Now() // cart.UpdateTime = time.Now() // &cart
tb := u.mysqlDB.Model(&model.ShoppingCart{}).Where("id = ?", cart.ID).Update("is_deleted", 1) tb := u.mysqlDB.Model(&model.ShoppingCart{}).
Where("id = ?", cart.ID).
Updates(&cart)
//Update("is_deleted", 1)
//err = errors.New("400", "测试异常", 400) //err = errors.New("400", "测试异常", 400)
fmt.Println("repository UpdateCart >>>> ", cart) fmt.Println("repository UpdateCart >>>> ", cart)
return &cart, tb.Error //err return &cart, tb.Error //err

@ -8,7 +8,7 @@ import (
type ICartService interface { type ICartService interface {
AddCart(*proto.AddCartReq) (obj *model.ShoppingCart, err error) AddCart(*proto.AddCartReq) (obj *model.ShoppingCart, err error)
UpdateCart(*proto.AddCartReq) (obj *model.ShoppingCart, err error) UpdateCart(*proto.UpdateCartReq) (obj *model.ShoppingCart, err error)
} }
type CartService struct { type CartService struct {
cartRepository repository.ICartRepository cartRepository repository.ICartRepository
@ -27,6 +27,6 @@ func NewCartService(cartRepository repository.ICartRepository) ICartService {
func (u *CartService) AddCart(req *proto.AddCartReq) (obj *model.ShoppingCart, err error) { func (u *CartService) AddCart(req *proto.AddCartReq) (obj *model.ShoppingCart, err error) {
return u.cartRepository.AddCart(req) return u.cartRepository.AddCart(req)
} }
func (u *CartService) UpdateCart(req *proto.AddCartReq) (obj *model.ShoppingCart, err error) { func (u *CartService) UpdateCart(req *proto.UpdateCartReq) (obj *model.ShoppingCart, err error) {
return u.cartRepository.UpdateCart(req) return u.cartRepository.UpdateCart(req)
} }

@ -28,7 +28,7 @@ func (u *CartHandler) AddCart(ctx context.Context, req *proto.AddCartReq, resp *
//修改购物车 //修改购物车
func (u *CartHandler) UpdateCart(ctx context.Context, req *proto.AddCartReq, resp *proto.AddCartResp) error { func (u *CartHandler) UpdateCart(ctx context.Context, req *proto.UpdateCartReq, resp *proto.UpdateCartResp) error {
obj, err := u.CartService.UpdateCart(req) obj, err := u.CartService.UpdateCart(req)
if err != nil { if err != nil {
println(" UpdateCart err :", err) println(" UpdateCart err :", err)

File diff suppressed because it is too large Load Diff

@ -98,7 +98,7 @@ func NewUpdateCartEndpoints() []*api.Endpoint {
type UpdateCartService interface { type UpdateCartService interface {
// rpc 服务 // rpc 服务
UpdateCart(ctx context.Context, in *AddCartReq, opts ...client.CallOption) (*AddCartResp, error) UpdateCart(ctx context.Context, in *UpdateCartReq, opts ...client.CallOption) (*UpdateCartResp, error)
} }
type updateCartService struct { type updateCartService struct {
@ -113,9 +113,9 @@ func NewUpdateCartService(name string, c client.Client) UpdateCartService {
} }
} }
func (c *updateCartService) UpdateCart(ctx context.Context, in *AddCartReq, opts ...client.CallOption) (*AddCartResp, error) { func (c *updateCartService) UpdateCart(ctx context.Context, in *UpdateCartReq, opts ...client.CallOption) (*UpdateCartResp, error) {
req := c.c.NewRequest(c.name, "UpdateCart.UpdateCart", in) req := c.c.NewRequest(c.name, "UpdateCart.UpdateCart", in)
out := new(AddCartResp) out := new(UpdateCartResp)
err := c.c.Call(ctx, req, out, opts...) err := c.c.Call(ctx, req, out, opts...)
if err != nil { if err != nil {
return nil, err return nil, err
@ -127,12 +127,12 @@ func (c *updateCartService) UpdateCart(ctx context.Context, in *AddCartReq, opts
type UpdateCartHandler interface { type UpdateCartHandler interface {
// rpc 服务 // rpc 服务
UpdateCart(context.Context, *AddCartReq, *AddCartResp) error UpdateCart(context.Context, *UpdateCartReq, *UpdateCartResp) error
} }
func RegisterUpdateCartHandler(s server.Server, hdlr UpdateCartHandler, opts ...server.HandlerOption) error { func RegisterUpdateCartHandler(s server.Server, hdlr UpdateCartHandler, opts ...server.HandlerOption) error {
type updateCart interface { type updateCart interface {
UpdateCart(ctx context.Context, in *AddCartReq, out *AddCartResp) error UpdateCart(ctx context.Context, in *UpdateCartReq, out *UpdateCartResp) error
} }
type UpdateCart struct { type UpdateCart struct {
updateCart updateCart
@ -145,10 +145,69 @@ type updateCartHandler struct {
UpdateCartHandler UpdateCartHandler
} }
func (h *updateCartHandler) UpdateCart(ctx context.Context, in *AddCartReq, out *AddCartResp) error { func (h *updateCartHandler) UpdateCart(ctx context.Context, in *UpdateCartReq, out *UpdateCartResp) error {
return h.UpdateCartHandler.UpdateCart(ctx, in, out) return h.UpdateCartHandler.UpdateCart(ctx, in, out)
} }
// Api Endpoints for FindCart service
func NewFindCartEndpoints() []*api.Endpoint {
return []*api.Endpoint{}
}
// Client API for FindCart service
type FindCartService interface {
FindCart(ctx context.Context, in *FindCartReq, opts ...client.CallOption) (*FindCartResp, error)
}
type findCartService struct {
c client.Client
name string
}
func NewFindCartService(name string, c client.Client) FindCartService {
return &findCartService{
c: c,
name: name,
}
}
func (c *findCartService) FindCart(ctx context.Context, in *FindCartReq, opts ...client.CallOption) (*FindCartResp, error) {
req := c.c.NewRequest(c.name, "FindCart.FindCart", in)
out := new(FindCartResp)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for FindCart service
type FindCartHandler interface {
FindCart(context.Context, *FindCartReq, *FindCartResp) error
}
func RegisterFindCartHandler(s server.Server, hdlr FindCartHandler, opts ...server.HandlerOption) error {
type findCart interface {
FindCart(ctx context.Context, in *FindCartReq, out *FindCartResp) error
}
type FindCart struct {
findCart
}
h := &findCartHandler{hdlr}
return s.Handle(s.NewHandler(&FindCart{h}, opts...))
}
type findCartHandler struct {
FindCartHandler
}
func (h *findCartHandler) FindCart(ctx context.Context, in *FindCartReq, out *FindCartResp) error {
return h.FindCartHandler.FindCart(ctx, in, out)
}
// Api Endpoints for Page service // Api Endpoints for Page service
func NewPageEndpoints() []*api.Endpoint { func NewPageEndpoints() []*api.Endpoint {

@ -30,6 +30,12 @@ message ShoppingCart {
string productName = 5; string productName = 5;
string productMainPicture = 6; string productMainPicture = 6;
int32 number = 7; int32 number = 7;
//
string updateTime =8;
string crateTime = 9;
int32 createUser = 10;
int32 updateUser = 11;
bool isDeleted = 12;
} }
/** /**
@ -48,6 +54,7 @@ message AddCartReq {
string productMainPicture = 5; string productMainPicture = 5;
int32 userId =6; int32 userId =6;
int32 id = 7; int32 id = 7;
int32 createUser = 8;
} }
// resp struct // resp struct
/** /**
@ -85,12 +92,44 @@ service AddCart {
//rpc //rpc
rpc AddCart (AddCartReq) returns (AddCartResp){} rpc AddCart (AddCartReq) returns (AddCartResp){}
} }
message UpdateCartReq {
int32 id = 1;
int32 userId = 2;
int32 productId =3;
int32 productSkuId = 4;
string productName = 5;
string productMainPicture = 6;
int32 number = 7;
//
string updateTime =8;
string crateTime = 9;
int32 createUser = 10;
int32 updateUser = 11;
bool isDeleted = 12;
}
message UpdateCartResp {
int64 shoppingCartNumber = 3;
int64 canSetShoppingCartNumber = 4;
bool isBeyondMaxLimit = 5;
int32 ID = 6;
}
service UpdateCart { service UpdateCart {
//rpc //rpc
rpc UpdateCart (AddCartReq) returns (AddCartResp){} rpc UpdateCart (UpdateCartReq) returns (UpdateCartResp){}
} }
message FindCartReq {
int32 id = 1;
int32 userId = 2;
bool isDeleted = 3;
}
message FindCartResp {
repeated ShoppingCart shoppingCarts = 1;
}
//
service FindCart {
rpc FindCart (FindCartReq) returns (FindCartResp){}
}
message Product { message Product {
int32 id = 1; int32 id = 1;

@ -5,8 +5,10 @@ import (
"fmt" "fmt"
"github.com/afex/hystrix-go/hystrix" "github.com/afex/hystrix-go/hystrix"
consul "github.com/asim/go-micro/plugins/registry/consul/v4" consul "github.com/asim/go-micro/plugins/registry/consul/v4"
"github.com/dtm-labs/dtm/client/dtmcli"
"github.com/go-micro/plugins/v4/wrapper/select/roundrobin" "github.com/go-micro/plugins/v4/wrapper/select/roundrobin"
opentracing2 "github.com/go-micro/plugins/v4/wrapper/trace/opentracing" opentracing2 "github.com/go-micro/plugins/v4/wrapper/trace/opentracing"
"github.com/lithammer/shortuuid/v3"
"github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go"
"go-micro.dev/v4/client" "go-micro.dev/v4/client"
"go-micro.dev/v4/web" "go-micro.dev/v4/web"
@ -70,43 +72,74 @@ func main() {
micro.WrapClient(roundrobin.NewClientWrapper()), micro.WrapClient(roundrobin.NewClientWrapper()),
) )
//AddCartClient := proto.NewAddCartService("shop-cart", rpcServer.Client()) //AddCartClient := proto.NewAddCartService("shop-cart", rpcServer.Client())
//UpdateCartClient := proto.NewUpdateCartService("shop-cart", rpcServer.Client()) UpdateCartClient := proto.NewUpdateCartService("shop-cart", rpcServer.Client())
//ShowProductDetailClient := proto.NewShowProductDetailService("shop-product", rpcServer.Client()) //ShowProductDetailClient := proto.NewShowProductDetailService("shop-product", rpcServer.Client())
//ShowDetailSkuClient := proto.NewShowDetailSkuService("shop-product", rpcServer.Client()) //ShowDetailSkuClient := proto.NewShowDetailSkuService("shop-product", rpcServer.Client())
GetUserTokenClient := proto.NewGetUserTokenService("shop-user", rpcServer.Client()) GetUserTokenClient := proto.NewGetUserTokenService("shop-user", rpcServer.Client())
//UpdateSkuClient := proto.NewUpdateSkuService("shop-product", rpcServer.Client()) //UpdateSkuClient := proto.NewUpdateSkuService("shop-product", rpcServer.Client())
AddTraderClient := proto.NewAddTradeOrderService("trade-order", rpcServer.Client()) AddTraderClient := proto.NewAddTradeOrderService("trade-order", rpcServer.Client())
//UpdateTraderClient := proto.NewUpdateTradeOrderService("trade-order", rpcServer.Client()) UpdateTraderClient := proto.NewUpdateTradeOrderService("trade-order", rpcServer.Client())
//开始拆分 DTM服务 //开始拆分 DTM服务
//
//router.POST("/updateSku", func(c *gin.Context) { router.POST("/updateCart", func(c *gin.Context) {
// req := &proto.UpdateSkuReq{} req := &proto.UpdateCartReq{}
// if err := c.BindJSON(req); err != nil { if err := c.BindJSON(req); err != nil {
// log.Fatalln(err) log.Fatalln(err)
// } }
// _, err := UpdateSkuClient.UpdateSku(context.TODO(), req) req.IsDeleted = true
// if err != nil { _, err := UpdateCartClient.UpdateCart(context.TODO(), req)
// log.Println("/updateSku err ", err) if err != nil {
// c.JSON(http.StatusOK, gin.H{"dtm_reslut": "FAILURE", "Message": "修改库存失败!"}) log.Println("/updateCart err ", err)
// return c.JSON(http.StatusOK, gin.H{"dtm_reslut": "FAILURE", "Message": "删除购物车失败!"})
// } return
// c.JSON(http.StatusOK, gin.H{"updateSku": "SUCCESS", "Message": "修改库存成功!"}) }
//}) c.JSON(http.StatusOK, gin.H{"updateCart": "SUCCESS", "Message": "删除购物车成功!"})
//router.POST("/updateSku-compensate", func(c *gin.Context) { })
// req := &proto.UpdateSkuReq{} router.POST("/updateCart-compensate", func(c *gin.Context) {
// if err := c.BindJSON(req); err != nil { req := &proto.UpdateCartReq{}
// log.Fatalln(err) if err := c.BindJSON(req); err != nil {
// } log.Fatalln(err)
// req.ProductSku.Stock += Number }
// _, err := UpdateSkuClient.UpdateSku(context.TODO(), req) req.IsDeleted = false
// if err != nil { _, err := UpdateCartClient.UpdateCart(context.TODO(), req)
// log.Println("/updateSku err ", err) if err != nil {
// c.JSON(http.StatusOK, gin.H{"dtm_reslut": "FAILURE", "Message": "回滚库存失败!"}) log.Println("/updateCart err ", err)
// return c.JSON(http.StatusOK, gin.H{"dtm_reslut": "FAILURE", "Message": "回滚购物车失败!"})
// } return
// c.JSON(http.StatusOK, gin.H{"updateSku-compensate": "SUCCESS", "Message": "回滚库存成功!"}) }
//}) c.JSON(http.StatusOK, gin.H{"updateCart-compensate": "SUCCESS", "Message": "回滚购物车成功!"})
})
router.POST("/addTrade", func(c *gin.Context) {
req := &proto.AddTradeOrderReq{}
if err := c.BindJSON(req); err != nil {
log.Fatalln(err)
}
_, err := AddTraderClient.AddTradeOrder(context.TODO(), req)
if err != nil {
log.Println("/addTrade err ", err)
c.JSON(http.StatusOK, gin.H{"dtm_reslut": "FAILURE", "Message": "新增订单失败!"})
return
}
c.JSON(http.StatusOK, gin.H{"addTrade": "SUCCESS", "Message": "新增订单成功!"})
})
router.POST("/addTrade-compensate", func(c *gin.Context) {
req := &proto.AddTradeOrderReq{}
if err := c.BindJSON(req); err != nil {
log.Fatalln(err)
}
req.TradeOrder.IsDeleted = true
_, err := UpdateTraderClient.UpdateTradeOrder(context.TODO(), req)
if err != nil {
log.Println("/addTrade err ", err)
c.JSON(http.StatusOK, gin.H{"dtm_reslut": "FAILURE", "Message": "回滚订单失败!"})
return
}
c.JSON(http.StatusOK, gin.H{"addTrade-compensate": "SUCCESS", "Message": "回滚订单成功!"})
})
//新增订单API
router.GET("/cartAdvanceOrder", func(c *gin.Context) { router.GET("/cartAdvanceOrder", func(c *gin.Context) {
//开始检验登录 //开始检验登录
uuid := c.Request.Header["Uuid"][0] uuid := c.Request.Header["Uuid"][0]
@ -149,18 +182,24 @@ func main() {
RecipientAddressId: int32(recipientAddressId), RecipientAddressId: int32(recipientAddressId),
TradeOrder: tradeOrder, TradeOrder: tradeOrder,
} }
resp, err = AddTraderClient.AddTradeOrder(context.TODO(), req) updateCartReq := &proto.UpdateCartReq{
fmt.Println(resp) Id: cartIds[0],
//CartId = resp.ID }
//测试异常
//err = errors.New("400", "测试异常", 400) //全局事务
gid := shortuuid.New()
saga := dtmcli.NewSaga(DtmServer, gid).
Add(QSBusi+"/updateCart", QSBusi+"/updateCart-compensate", updateCartReq).
Add(QSBusi+"/addTrade", QSBusi+"/addTrade-compensate", req)
err = saga.Submit()
if err != nil { if err != nil {
log.Println("/addCart err ", err) log.Println("saga submit err :", err)
c.JSON(http.StatusOK, gin.H{"dtm_reslut": "FAILURE", "Message": "新增购物车失败!"}) common.RespFail(c.Writer, resp, "添加失败")
return
} }
log.Println(" /saga submit submit :", gid)
////writer data message row total field
common.RespOK(c.Writer, resp, "请求成功")
c.JSON(http.StatusOK, gin.H{"addCart": "SUCCESS", "Message": "新增购物车成功!"})
}) })
//router.POST("/addCart-compensate", func(c *gin.Context) { //router.POST("/addCart-compensate", func(c *gin.Context) {
// req := &proto.AddCartReq{} // req := &proto.AddCartReq{}

@ -68,7 +68,10 @@ func (u *TradeRepository) AddTradeOrder(req *proto.AddTradeOrderReq) (obj *model
func (u *TradeRepository) UpdateTradeOrder(req *proto.AddTradeOrderReq) (obj *model.TraderOrder, err error) { func (u *TradeRepository) UpdateTradeOrder(req *proto.AddTradeOrderReq) (obj *model.TraderOrder, err error) {
trade := model.TraderOrder{} trade := model.TraderOrder{}
trade.UpdateTime = time.Now() // trade.UpdateTime = time.Now() //
tb := u.mysqlDB.Model(&model.TraderOrder{}).Where("id = ?", trade.ID).Update("order_status", trade.OrderStatus) tb := u.mysqlDB.Model(&model.TraderOrder{}).
Where("id = ?", trade.ID).
Updates(&trade)
//Update("order_status", trade.OrderStatus)
//err = errors.New("400", "测试异常", 400) //err = errors.New("400", "测试异常", 400)
fmt.Println("repository UpdateTradeOrder >>>> ", trade) fmt.Println("repository UpdateTradeOrder >>>> ", trade)
return &trade, tb.Error //err return &trade, tb.Error //err

File diff suppressed because it is too large Load Diff

@ -149,6 +149,126 @@ func (h *updateTradeOrderHandler) UpdateTradeOrder(ctx context.Context, in *AddT
return h.UpdateTradeOrderHandler.UpdateTradeOrder(ctx, in, out) return h.UpdateTradeOrderHandler.UpdateTradeOrder(ctx, in, out)
} }
// Api Endpoints for UpdateCart service
func NewUpdateCartEndpoints() []*api.Endpoint {
return []*api.Endpoint{}
}
// Client API for UpdateCart service
type UpdateCartService interface {
// rpc 服务
UpdateCart(ctx context.Context, in *UpdateCartReq, opts ...client.CallOption) (*UpdateCartResp, error)
}
type updateCartService struct {
c client.Client
name string
}
func NewUpdateCartService(name string, c client.Client) UpdateCartService {
return &updateCartService{
c: c,
name: name,
}
}
func (c *updateCartService) UpdateCart(ctx context.Context, in *UpdateCartReq, opts ...client.CallOption) (*UpdateCartResp, error) {
req := c.c.NewRequest(c.name, "UpdateCart.UpdateCart", in)
out := new(UpdateCartResp)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for UpdateCart service
type UpdateCartHandler interface {
// rpc 服务
UpdateCart(context.Context, *UpdateCartReq, *UpdateCartResp) error
}
func RegisterUpdateCartHandler(s server.Server, hdlr UpdateCartHandler, opts ...server.HandlerOption) error {
type updateCart interface {
UpdateCart(ctx context.Context, in *UpdateCartReq, out *UpdateCartResp) error
}
type UpdateCart struct {
updateCart
}
h := &updateCartHandler{hdlr}
return s.Handle(s.NewHandler(&UpdateCart{h}, opts...))
}
type updateCartHandler struct {
UpdateCartHandler
}
func (h *updateCartHandler) UpdateCart(ctx context.Context, in *UpdateCartReq, out *UpdateCartResp) error {
return h.UpdateCartHandler.UpdateCart(ctx, in, out)
}
// Api Endpoints for FindCart service
func NewFindCartEndpoints() []*api.Endpoint {
return []*api.Endpoint{}
}
// Client API for FindCart service
type FindCartService interface {
FindCart(ctx context.Context, in *FindCartReq, opts ...client.CallOption) (*FindCartResp, error)
}
type findCartService struct {
c client.Client
name string
}
func NewFindCartService(name string, c client.Client) FindCartService {
return &findCartService{
c: c,
name: name,
}
}
func (c *findCartService) FindCart(ctx context.Context, in *FindCartReq, opts ...client.CallOption) (*FindCartResp, error) {
req := c.c.NewRequest(c.name, "FindCart.FindCart", in)
out := new(FindCartResp)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for FindCart service
type FindCartHandler interface {
FindCart(context.Context, *FindCartReq, *FindCartResp) error
}
func RegisterFindCartHandler(s server.Server, hdlr FindCartHandler, opts ...server.HandlerOption) error {
type findCart interface {
FindCart(ctx context.Context, in *FindCartReq, out *FindCartResp) error
}
type FindCart struct {
findCart
}
h := &findCartHandler{hdlr}
return s.Handle(s.NewHandler(&FindCart{h}, opts...))
}
type findCartHandler struct {
FindCartHandler
}
func (h *findCartHandler) FindCart(ctx context.Context, in *FindCartReq, out *FindCartResp) error {
return h.FindCartHandler.FindCart(ctx, in, out)
}
// Api Endpoints for Page service // Api Endpoints for Page service
func NewPageEndpoints() []*api.Endpoint { func NewPageEndpoints() []*api.Endpoint {

@ -88,13 +88,64 @@ service AddTradeOrder {
//rpc //rpc
rpc AddTradeOrder (AddTradeOrderReq) returns (AddTradeOrderResp){} rpc AddTradeOrder (AddTradeOrderReq) returns (AddTradeOrderResp){}
} }
service UpdateTradeOrder { service UpdateTradeOrder {
//rpc //rpc
rpc UpdateTradeOrder (AddTradeOrderReq) returns (AddTradeOrderResp){} rpc UpdateTradeOrder (AddTradeOrderReq) returns (AddTradeOrderResp){}
} }
message ShoppingCart {
int32 id = 1;
int32 userId = 2;
int32 productId =3;
int32 productSkuId = 4;
string productName = 5;
string productMainPicture = 6;
int32 number = 7;
//
string updateTime =8;
string crateTime = 9;
int32 createUser = 10;
int32 updateUser = 11;
bool isDeleted = 12;
}
message UpdateCartReq {
int32 number = 1;
int32 productId = 2;
int32 productSkuId =3;
string productName = 4;
string productMainPicture = 5;
int32 userId =6;
int32 id = 7;
string updateTime =8;
string crateTime = 9;
int32 createUser = 10;
int32 updateUser = 11;
bool isDeleted = 12;
}
message UpdateCartResp {
int64 shoppingCartNumber = 3;
int64 canSetShoppingCartNumber = 4;
bool isBeyondMaxLimit = 5;
int32 ID = 6;
}
service UpdateCart {
//rpc
rpc UpdateCart (UpdateCartReq) returns (UpdateCartResp){}
}
message FindCartReq {
int32 id = 1;
int32 userId = 2;
bool isDeleted = 3;
}
message FindCartResp {
repeated ShoppingCart shoppingCarts = 1;
}
//
service FindCart {
rpc FindCart (FindCartReq) returns (FindCartResp){}
}
message Product { message Product {
int32 id = 1; int32 id = 1;
string name = 2; string name = 2;

Loading…
Cancel
Save