Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Last active September 4, 2021 18:04
Show Gist options
  • Save percybolmer/ae5a5a85b7f5c34c5963194df8eacf5f to your computer and use it in GitHub Desktop.
Save percybolmer/ae5a5a85b7f5c34c5963194df8eacf5f to your computer and use it in GitHub Desktop.
#ddd-tavern
// CreateOrder will chaintogether all repositories to create a order for a customer
// will return the collected price of all Products
func (o *OrderService) CreateOrder(customerID uuid.UUID, productIDs []uuid.UUID) (float64, error) {
// Get the customer
c, err := o.customers.Get(customerID)
if err != nil {
return 0, err
}
// Get each Product, Ouchie, We need a ProductRepository
var products []aggregate.Product
var price float64
for _, id := range productIDs {
p, err := o.products.GetByID(id)
if err != nil {
return 0, err
}
products = append(products, p)
price += p.GetPrice()
}
// All Products exists in store, now we can create the order
log.Printf("Customer: %s has ordered %d products", c.GetID(), len(products))
return price, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment