order.go 987 B

123456789101112131415161718192021222324252627282930313233343536
  1. package service
  2. import (
  3. "net/http"
  4. "sghgogs.com/micro/common/errorcode"
  5. req "sghgogs.com/micro/shopping-service/domain/model/request"
  6. pb "sghgogs.com/micro/shopping-service/proto"
  7. "time"
  8. )
  9. func (svc *Service) CreateOrder(add *pb.CreateOrderRequest) error {
  10. if err := svc.Repository.CreateOrder(&req.Order{
  11. UserID: add.UserId,
  12. AddressID: add.AddressId,
  13. TotalAmount: add.TotalAmount,
  14. Status: add.Status,
  15. PaymentMethod: add.PaymentMethod,
  16. CreatedAt: time.Now(),
  17. UpdatedAt: nil,
  18. }); err != nil {
  19. return errorcode.New(svc.Namespace, err.Error(), http.StatusBadRequest)
  20. }
  21. return nil
  22. }
  23. func (svc *Service) CreateOrderItem(add *pb.CreateOrderItemRequest) error {
  24. if err := svc.Repository.CreateOrderItem(&req.OrderItem{
  25. OrderID: add.OrderId,
  26. ProductID: add.ProductId,
  27. Quantity: add.Quantity,
  28. Subtotal: add.Subtotal,
  29. }); err != nil {
  30. return errorcode.New(svc.Namespace, err.Error(), http.StatusBadRequest)
  31. }
  32. return nil
  33. }