-
Notifications
You must be signed in to change notification settings - Fork 81
/
module.go
96 lines (81 loc) · 2.84 KB
/
module.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package category
import (
"flamingo.me/dingo"
"flamingo.me/flamingo/v3/framework/config"
"flamingo.me/flamingo/v3/framework/web"
flamingographql "flamingo.me/graphql"
"flamingo.me/flamingo-commerce/v3/category/application"
"flamingo.me/flamingo-commerce/v3/category/domain"
"flamingo.me/flamingo-commerce/v3/category/infrastructure"
"flamingo.me/flamingo-commerce/v3/category/interfaces/controller"
categoryGraphql "flamingo.me/flamingo-commerce/v3/category/interfaces/graphql"
"flamingo.me/flamingo-commerce/v3/product"
productApplication "flamingo.me/flamingo-commerce/v3/product/application"
"flamingo.me/flamingo-commerce/v3/search"
)
// Module registers our profiler
type Module struct {
useCategoryFixedAdapter bool
}
// URL to category
func URL(code string) (string, map[string]string) {
return application.URL(code)
}
// URLWithName to category
func URLWithName(code, name string) (string, map[string]string) {
return application.URLWithName(code, web.URLTitle(name))
}
// Inject dependencies
func (m *Module) Inject(
routerRegistry *web.RouterRegistry,
config *struct {
UseCategoryFixedAdapter bool `inject:"config:commerce.category.useCategoryFixedAdapter,optional"`
},
) {
if config != nil {
m.useCategoryFixedAdapter = config.UseCategoryFixedAdapter
}
}
// Configure the product URL
func (m *Module) Configure(injector *dingo.Injector) {
injector.Bind(new(controller.QueryHandler)).To(controller.QueryHandlerImpl{})
injector.Bind(new(controller.ProductSearchService)).To(productApplication.ProductSearchService{})
if m.useCategoryFixedAdapter {
injector.Bind((*domain.CategoryService)(nil)).To(infrastructure.CategoryServiceFixed{})
}
web.BindRoutes(injector, new(routes))
injector.Bind(new(application.RouterRouter)).To(new(web.Router))
injector.BindMulti(new(flamingographql.Service)).To(categoryGraphql.Service{})
}
// DefaultConfig for this module
func (m *Module) DefaultConfig() config.Map {
return config.Map{
"commerce.category.view.template": "category/category",
"commerce.category.view.teaserTemplate": "category/teaser",
}
}
// Depends on other modules
func (m *Module) Depends() []dingo.Module {
return []dingo.Module{
new(product.Module),
new(search.Module),
}
}
type routes struct {
view *controller.ViewController
entity *controller.Entity
tree *controller.Tree
}
func (r *routes) Inject(view *controller.ViewController, entity *controller.Entity, tree *controller.Tree) {
r.view = view
r.entity = entity
r.tree = tree
}
func (r *routes) Routes(registry *web.RouterRegistry) {
registry.HandleGet("category.view", r.view.Get)
handler, _ := registry.Route("/category/:code/:name.html", "category.view(code, name, *)")
handler.Normalize("name")
registry.Route("/category/:code", "category.view(code, *)")
registry.HandleData("category.tree", r.tree.Data)
registry.HandleData("category", r.entity.Data)
}