Skip to content

Instantly share code, notes, and snippets.

View percybolmer's full-sized avatar

ProgrammingPercy percybolmer

View GitHub Profile
// 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"
)
// 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"
)
package memory
import (
"testing"
"github.com/google/uuid"
"github.com/percybolmer/ddd-go/aggregate"
"github.com/percybolmer/ddd-go/domain/product"
)
package aggregate_test
import (
"testing"
"github.com/percybolmer/ddd-go/aggregate"
)
func TestProduct_NewProduct(t *testing.T) {
type testCase struct {
// 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"
// 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
// 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
}
}
// 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
package memory
import (
"testing"
"github.com/google/uuid"
"github.com/percybolmer/ddd-go/aggregate"
"github.com/percybolmer/ddd-go/domain/customer"
)
// 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"