123456789101112131415161718192021222324252627282930313233343536 |
- 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) CreateOrder(add *pb.CreateOrderRequest) error {
- if err := svc.Repository.CreateOrder(&req.Order{
- UserID: add.UserId,
- AddressID: add.AddressId,
- TotalAmount: add.TotalAmount,
- Status: add.Status,
- PaymentMethod: add.PaymentMethod,
- CreatedAt: time.Now(),
- UpdatedAt: nil,
- }); err != nil {
- return errorcode.New(svc.Namespace, err.Error(), http.StatusBadRequest)
- }
- return nil
- }
- func (svc *Service) CreateOrderItem(add *pb.CreateOrderItemRequest) error {
- if err := svc.Repository.CreateOrderItem(&req.OrderItem{
- OrderID: add.OrderId,
- ProductID: add.ProductId,
- Quantity: add.Quantity,
- Subtotal: add.Subtotal,
- }); err != nil {
- return errorcode.New(svc.Namespace, err.Error(), http.StatusBadRequest)
- }
- return nil
- }
|