-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathcreate_order.go
46 lines (39 loc) · 1.11 KB
/
create_order.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package commands
import (
"context"
"time"
"github.com/stackus/ftgogo/customer-web/internal/adapters"
"github.com/stackus/ftgogo/serviceapis/commonapi"
)
type CreateOrder struct {
ConsumerID string
RestaurantID string
AddressID string
LineItems commonapi.MenuItemQuantities
}
type CreateOrderHandler struct {
orderRepo adapters.OrderRepository
consumerRepo adapters.ConsumerRepository
}
func NewCreateOrderHandler(orderRepo adapters.OrderRepository, consumerRepo adapters.ConsumerRepository) CreateOrderHandler {
return CreateOrderHandler{
orderRepo: orderRepo,
consumerRepo: consumerRepo,
}
}
func (h CreateOrderHandler) Handle(ctx context.Context, cmd CreateOrder) (string, error) {
address, err := h.consumerRepo.FindAddress(ctx, adapters.FindConsumerAddress{
ConsumerID: cmd.ConsumerID,
AddressID: cmd.AddressID,
})
if err != nil {
return "", err
}
return h.orderRepo.Create(ctx, adapters.CreateOrder{
ConsumerID: cmd.ConsumerID,
RestaurantID: cmd.RestaurantID,
DeliverAt: time.Now().Add(30 * time.Minute),
DeliverTo: address,
LineItems: cmd.LineItems,
})
}