You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.8 KiB

2 years ago
package handler
import (
"context"
"fmt"
2 years ago
"shoppingCart/domain/service"
"shoppingCart/proto"
2 years ago
)
type CartHandler struct {
CartService service.ICartService
}
// 新增购物车
2 years ago
func (u *CartHandler) AddCart(ctx context.Context, req *proto.AddCartReq, resp *proto.AddCartResp) error {
obj, err := u.CartService.AddCart(req)
if err != nil {
println(" AddCart err :", err)
} else {
resp.CanSetShoppingCartNumber = int64(obj.Number)
resp.ShoppingCartNumber = int64(obj.Number)
resp.IsBeyondMaxLimit = false // 查询sku
resp.ID = obj.ID //增加新增cart的ID
fmt.Println(" AddCart handler >>>>>> ", resp)
}
return err
}
//修改购物车
func (u *CartHandler) UpdateCart(ctx context.Context, req *proto.UpdateCartReq, resp *proto.UpdateCartResp) error {
obj, err := u.CartService.UpdateCart(req)
if err != nil {
println(" UpdateCart err :", err)
} else {
resp.CanSetShoppingCartNumber = int64(obj.Number)
resp.ShoppingCartNumber = int64(obj.Number)
resp.IsBeyondMaxLimit = false // 查询sku
resp.ID = obj.ID //增加新增cart的ID
fmt.Println(" UpdateCart handler >>>>>> ", resp)
2 years ago
}
return err
2 years ago
}
func (u *CartHandler) FindCart(ctx context.Context, req *proto.FindCartReq, obj *proto.FindCartResp) error {
//int32List := SplitToInt32List(req.GetCartIds(), ",")
cart, err := u.CartService.FindCart(req)
obj.ShoppingCart = &proto.ShoppingCart{}
obj.ShoppingCart.Id = cart.ID
obj.ShoppingCart.UserId = cart.UserId
obj.ShoppingCart.IsDeleted = cart.IsDeleted
//其他需要再加
return err
}
// (int32List []int32) (obj *float32, err error)
func (u *CartHandler) GetOrderTotal(ctx context.Context, req *proto.OrderTotalReq, obj *proto.OrderTotalResp) error {
//int32List := SplitToInt32List(req.GetCartIds(), ",")
obj.TotalPrice, _ = u.CartService.GetOrderTotal(req.GetCartIds())
return nil
}