12345678910111213141516171819202122232425262728293031323334353637 |
- package service
- import (
- "net/http"
- "sghgogs.com/micro/common/errorcode"
- req "sghgogs.com/micro/shopping-service/domain/model/request"
- pb "sghgogs.com/micro/shopping-service/proto"
- "time"
- )
- func (svc *Service) CreateShoppingCart(add *pb.CreateShoppingCartRequest) error {
- if err := svc.Repository.CreateShoppingCart(&req.ShoppingCart{
- UserID: add.UserId,
- Quantity: add.Quantity,
- }); err != nil {
- return errorcode.New(svc.Namespace, err.Error(), http.StatusBadRequest)
- }
- return nil
- }
- func (svc *Service) CreateMultipleShoppingCartItem(cartItems *pb.CreateShoppingCartItemRequest) error {
- items := make([]*req.ShoppingCartItem, 0)
- for _, item := range cartItems.Items {
- items = append(items, &req.ShoppingCartItem{
- ShoppingCartID: item.ShoppingCartId,
- ProductID: item.ProductId,
- Quantity: item.Quantity,
- TotalPrice: item.TotalPrice,
- CreatedAt: time.Now(),
- UpdatedAt: nil,
- })
- }
- if err := svc.Repository.CreateMultipleShoppingCartItem(items); err != nil {
- return errorcode.New(svc.Namespace, err.Error(), http.StatusBadRequest)
- }
- return nil
- }
|