This repository has been archived by the owner on Jun 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
routes.go
135 lines (109 loc) · 4.15 KB
/
routes.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package action
import (
"fmt"
"net/http"
"github.com/factly/mande-server/model"
"github.com/factly/x/healthx"
"github.com/factly/x/middlewarex"
"github.com/factly/mande-server/util"
"github.com/factly/mande-server/action/cart"
"github.com/factly/mande-server/action/catalog"
"github.com/factly/mande-server/action/currency"
"github.com/factly/mande-server/action/dataset"
"github.com/factly/mande-server/action/format"
"github.com/factly/mande-server/action/medium"
"github.com/factly/mande-server/action/member"
"github.com/factly/mande-server/action/membership"
"github.com/factly/mande-server/action/membership/user"
"github.com/factly/mande-server/action/order"
"github.com/factly/mande-server/action/organisation"
"github.com/factly/mande-server/action/payment"
"github.com/factly/mande-server/action/plan"
"github.com/factly/mande-server/action/product"
"github.com/factly/mande-server/action/search"
"github.com/factly/mande-server/action/tag"
userList "github.com/factly/mande-server/action/user"
"github.com/factly/mande-server/action/webhook"
_ "github.com/factly/mande-server/docs" // docs is generated by Swag CLI, you have to import it.
"github.com/factly/x/loggerx"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/spf13/viper"
httpSwagger "github.com/swaggo/http-swagger"
)
// GetCommonRouter returns router with common middleware and settings
func GetCommonRouter() chi.Router {
r := chi.NewRouter()
r.Use(middleware.RequestID)
r.Use(loggerx.Init())
r.Use(middleware.RealIP)
r.Use(middleware.Recoverer)
r.Use(middleware.Heartbeat("/ping"))
sqlDB, _ := model.DB.DB()
healthx.RegisterRoutes(r, healthx.ReadyCheckers{
"database": sqlDB.Ping,
"keto": util.KetoChecker,
"kavach": util.KavachChecker,
"kratos": util.KratosChecker,
"meilisearch": util.MeiliChecker,
})
return r
}
// RegisterUserRoutes - register user routes
func RegisterUserRoutes() http.Handler {
r := GetCommonRouter()
r.Mount("/products", product.PublicRouter())
r.Mount("/catalogs", catalog.PublicRouter())
r.Mount("/datasets", dataset.PublicRouter())
r.Mount("/plans", plan.UserRouter())
r.With(middlewarex.CheckUser).Group(func(r chi.Router) {
r.Mount("/organisations", organisation.UserRouter())
})
r.With(middlewarex.CheckUser, util.CheckOrganisation).Group(func(r chi.Router) {
r.Mount("/currencies", currency.UserRouter())
r.Mount("/memberships/{membership_id}/users", user.UserRouter())
r.Mount("/memberships", membership.UserRouter())
r.Mount("/payments", payment.UserRouter())
r.Mount("/tags", tag.UserRouter())
r.Mount("/formats", format.UserRouter())
r.Mount("/cartitems", cart.UserRouter())
r.Mount("/orders", order.UserRouter())
r.Mount("/media", medium.UserRouter())
r.Mount("/search", search.Router())
r.Mount("/users", userList.UserListRouter())
r.Mount("/members", member.Router())
})
return r
}
// RegisterAdminRoutes - register admin routes
func RegisterAdminRoutes() http.Handler {
r := GetCommonRouter()
r.With(middlewarex.CheckUser).Group(func(r chi.Router) {
r.Mount("/organisations", organisation.AdminRouter())
})
r.With(middlewarex.CheckUser, util.CheckOrganisation, middlewarex.CheckAccess("mande", 0, util.GetOrganisation), util.CheckSuperOrganisation).Group(func(r chi.Router) {
r.Mount("/currencies", currency.AdminRouter())
r.Mount("/plans", plan.AdminRouter())
r.Mount("/memberships", membership.AdminRouter())
r.Mount("/payments", payment.AdminRouter())
r.Mount("/products", product.AdminRouter())
r.Mount("/tags", tag.AdminRouter())
r.Mount("/formats", format.AdminRouter())
r.Mount("/catalogs", catalog.AdminRouter())
r.Mount("/cartitems", cart.AdminRouter())
r.Mount("/orders", order.AdminRouter())
r.Mount("/datasets", dataset.AdminRouter())
r.Mount("/media", medium.AdminRouter())
r.Mount("/search", search.Router())
})
if viper.IsSet("mode") && viper.GetString("mode") == "development" {
r.Get("/swagger/*", httpSwagger.WrapHandler)
fmt.Println("Admin Swagger @ http://localhost:7721/swagger/index.html")
}
return r
}
func RegisterWebHookRoutes() http.Handler {
r := GetCommonRouter()
r.Mount("/webhooks", webhook.Router())
return r
}