-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
application.go
59 lines (53 loc) · 2.09 KB
/
application.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
47
48
49
50
51
52
53
54
55
56
57
58
59
package application
import (
"context"
"github.com/LordMoMA/Intelli-Mall/depot/internal/application/commands"
"github.com/LordMoMA/Intelli-Mall/depot/internal/application/queries"
"github.com/LordMoMA/Intelli-Mall/depot/internal/domain"
"github.com/LordMoMA/Intelli-Mall/internal/ddd"
)
type (
App interface {
Commands
Queries
}
Commands interface {
CreateShoppingList(ctx context.Context, cmd commands.CreateShoppingList) error
CancelShoppingList(ctx context.Context, cmd commands.CancelShoppingList) error
InitiateShopping(ctx context.Context, cmd commands.InitiateShopping) error
AssignShoppingList(ctx context.Context, cmd commands.AssignShoppingList) error
CompleteShoppingList(ctx context.Context, cmd commands.CompleteShoppingList) error
}
Queries interface {
GetShoppingList(ctx context.Context, query queries.GetShoppingList) (*domain.ShoppingList, error)
}
Application struct {
appCommands
appQueries
}
appCommands struct {
commands.CreateShoppingListHandler
commands.CancelShoppingListHandler
commands.InitiateShoppingHandler
commands.AssignShoppingListHandler
commands.CompleteShoppingListHandler
}
appQueries struct {
queries.GetShoppingListHandler
}
)
var _ App = (*Application)(nil)
func New(shoppingLists domain.ShoppingListRepository, stores domain.StoreRepository, products domain.ProductRepository, domainPublisher ddd.EventPublisher[ddd.AggregateEvent]) *Application {
return &Application{
appCommands: appCommands{
CreateShoppingListHandler: commands.NewCreateShoppingListHandler(shoppingLists, stores, products, domainPublisher),
CancelShoppingListHandler: commands.NewCancelShoppingListHandler(shoppingLists, domainPublisher),
InitiateShoppingHandler: commands.NewInitiateShoppingHandler(shoppingLists, domainPublisher),
AssignShoppingListHandler: commands.NewAssignShoppingListHandler(shoppingLists, domainPublisher),
CompleteShoppingListHandler: commands.NewCompleteShoppingListHandler(shoppingLists, domainPublisher),
},
appQueries: appQueries{
GetShoppingListHandler: queries.NewGetShoppingListHandler(shoppingLists),
},
}
}