Last active
September 4, 2021 18:04
-
-
Save percybolmer/ae5a5a85b7f5c34c5963194df8eacf5f to your computer and use it in GitHub Desktop.
#ddd-tavern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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