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
// Package product holds the repository and the implementations for a ProductRepository | |
package product | |
import ( | |
"errors" | |
"github.com/google/uuid" | |
"github.com/percybolmer/ddd-go/aggregate" | |
) |
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
// Package memory is a in memory implementation of the ProductRepository interface. | |
package memory | |
import ( | |
"sync" | |
"github.com/google/uuid" | |
"github.com/percybolmer/ddd-go/aggregate" | |
"github.com/percybolmer/ddd-go/domain/product" | |
) |
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
package memory | |
import ( | |
"testing" | |
"github.com/google/uuid" | |
"github.com/percybolmer/ddd-go/aggregate" | |
"github.com/percybolmer/ddd-go/domain/product" | |
) |
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
package aggregate_test | |
import ( | |
"testing" | |
"github.com/percybolmer/ddd-go/aggregate" | |
) | |
func TestProduct_NewProduct(t *testing.T) { | |
type testCase struct { |
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
// Package aggregate | |
// File: product.go | |
// Product is an aggregate that represents a product. | |
package aggregate | |
import ( | |
"errors" | |
"github.com/google/uuid" | |
"github.com/percybolmer/ddd-go/entity" |
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 | |
func (o *OrderService) CreateOrder(customerID uuid.UUID, productIDs []uuid.UUID) error { | |
// Get the customer | |
c, err := o.customers.Get(customerID) | |
if err != nil { | |
return err | |
} | |
// Get each Product, Ouchie, We need a ProductRepository |
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
// WithCustomerRepository applies a given customer repository to the OrderService | |
func WithCustomerRepository(cr customer.CustomerRepository) OrderConfiguration { | |
// return a function that matches the OrderConfiguration alias, | |
// You need to return this so that the parent function can take in all the needed parameters | |
return func(os *OrderService) error { | |
os.customers = cr | |
return nil | |
} | |
} |
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
// Package services holds all the services that connects repositories into a business flow | |
package services | |
import ( | |
"github.com/percybolmer/ddd-go/domain/customer" | |
) | |
// OrderConfiguration is an alias for a function that will take in a pointer to an OrderService and modify it | |
type OrderConfiguration func(os *OrderService) error |
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
package memory | |
import ( | |
"testing" | |
"github.com/google/uuid" | |
"github.com/percybolmer/ddd-go/aggregate" | |
"github.com/percybolmer/ddd-go/domain/customer" | |
) |
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
// Package memory is a in-memory implementation of the customer repository | |
package memory | |
import ( | |
"fmt" | |
"sync" | |
"github.com/google/uuid" | |
"github.com/percybolmer/ddd-go/aggregate" | |
"github.com/percybolmer/ddd-go/domain/customer" |