-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.go
151 lines (127 loc) · 6.4 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package main
import (
"net/http"
"time"
"github.com/go-chi/chi/middleware"
"github.com/go-chi/chi/v5"
"github.com/go-chi/cors"
)
func InitRoutes() http.Handler {
r := chi.NewRouter()
r.Use(middleware.Logger)
r.Use(middleware.Recoverer)
r.Use(middleware.Timeout(60 * time.Second))
// allow cors
r.Use(cors.Handler(cors.Options{
AllowedOrigins: []string{"http://localhost:3000"},
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token", "Session-ID"},
AllowCredentials: true,
}))
// Add API Key middleware
r.Use(APIKeyMiddleware)
r.Get("/", HandleHome)
r.Post("/register", userHandler.Register)
r.Post("/login", userHandler.Login)
r.Post("/logout", userHandler.Logout)
r.Get("/l/{id}", paymentLinkHandler.PublicLinkHandler)
r.Get("/c/{id}", checkoutHandler.PublicLinkHandler)
r.Get("/c/{id}/poll", checkoutHandler.PollInvoice)
r.Group(func(r chi.Router) {
r.Use(CombinedAuthMiddleware)
r.Get("/dashboard", userHandler.Dashboard)
r.Post("/account", accountHandler.Create)
r.Put("/account/{id}", accountHandler.Update)
r.Get("/account", accountHandler.GetAll)
r.Get("/account/{id}", accountHandler.Get)
r.Delete("/account/{id}", accountHandler.Delete)
r.Get("/dashboard/{accountID}/sales/daily/{date}", dashboardHandler.GetDailySales)
r.Get("/dashboard/{accountID}/sales/7-days/{date}", dashboardHandler.GetLast7DaysSales)
r.Get("/dashboard/{accountID}/sales/30-days/{date}", dashboardHandler.GetLast30DaysSales)
r.Get("/dashboard/{accountID}/sales/6-months/{date}", dashboardHandler.GetLast6MonthsSales)
r.Get("/dashboard/{accountID}/sales/12-months/{date}", dashboardHandler.GetLast12MonthsSales)
// New customer metrics endpoints
r.Get("/dashboard/{accountID}/customers/daily/{date}", dashboardHandler.GetDailyCustomers)
r.Get("/dashboard/{accountID}/customers/7-days/{date}", dashboardHandler.GetLast7DaysNewCustomers)
r.Get("/dashboard/{accountID}/customers/30-days/{date}", dashboardHandler.GetLast30DaysNewCustomers)
r.Get("/dashboard/{accountID}/customers/6-months/{date}", dashboardHandler.GetLast6MonthsNewCustomers)
r.Get("/dashboard/{accountID}/customers/12-months/{date}", dashboardHandler.GetLast12MonthsNewCustomers)
r.Get("/dashboard/{accountID}/subscribers/daily/{date}", dashboardHandler.GetDailyActiveSubscribers)
r.Get("/dashboard/{accountID}/subscribers/7-days/{date}", dashboardHandler.GetLast7DaysActiveSubscribers)
r.Get("/dashboard/{accountID}/subscribers/30-days/{date}", dashboardHandler.GetLast30DaysActiveSubscribers)
r.Get("/dashboard/{accountID}/subscribers/6-months/{date}", dashboardHandler.GetLast6MonthsActiveSubscribers)
r.Get("/dashboard/{accountID}/subscribers/12-months/{date}", dashboardHandler.GetLast12MonthsActiveSubscribers)
r.Route("/api-key", func(r chi.Router) {
r.Post("/", apiKeyHandler.Create)
r.Get("/", apiKeyHandler.GetAll)
r.Get("/{id}", apiKeyHandler.Get)
r.Put("/{id}", apiKeyHandler.Update)
r.Delete("/{id}", apiKeyHandler.Delete)
r.Post("/{id}/lock", apiKeyHandler.Lock)
r.Get("/account/{accountId}", apiKeyHandler.GetByAccount)
})
r.Route("/webhook", func(r chi.Router) {
r.Post("/", webhookHandler.Create)
r.Get("/{id}", webhookHandler.Get)
r.Put("/{id}", webhookHandler.Update)
r.Delete("/{id}", webhookHandler.Delete)
r.Post("/{id}/regenerate-secret", webhookHandler.RegenerateSecret)
r.Get("/account/{accountId}", webhookHandler.GetByAccount)
r.Get("/{id}/deliveries", webhookHandler.GetDeliveries)
r.Post("/{id}/deliveries/{deliveryId}/retry", webhookHandler.RetryDelivery)
})
r.Post("/product", productHandler.Create)
r.Put("/product/{id}", productHandler.Update)
r.Get("/product", productHandler.GetAll)
r.Get("/product/{id}", productHandler.Get)
r.Get("/product/account/{accountId}", productHandler.GetByAccount)
r.Delete("/product/{id}", productHandler.Delete)
r.Post("/customer", customerHandler.Create)
r.Put("/customer/{id}", customerHandler.Update)
r.Get("/customer", customerHandler.GetAll)
r.Get("/customer/{id}", customerHandler.Get)
r.Get("/customer/account/{accountId}", customerHandler.GetByAccount)
r.Delete("/customer/{id}", customerHandler.Delete)
r.Post("/subscription", subscriptionHandler.Create)
r.Put("/subscription/{id}", subscriptionHandler.Update)
r.Get("/subscription", subscriptionHandler.GetAll)
r.Get("/subscription/{id}", subscriptionHandler.Get)
r.Get("/subscription/account/{accountId}", subscriptionHandler.GetByAccount)
r.Get("/subscription/customer/{customerId}", subscriptionHandler.GetByCustomer)
r.Get("/subscription/product/{productId}", subscriptionHandler.GetByProduct)
r.Delete("/subscription/{id}", subscriptionHandler.Delete)
r.Post("/wallet", walletHandler.Create)
r.Get("/wallet", walletHandler.GetAll)
r.Get("/wallet/{id}", walletHandler.Get)
r.Get("/wallet/account/{accountId}", walletHandler.GetByAccount)
r.Delete("/wallet/{id}", walletHandler.Delete)
r.Post("/invoice", walletHandler.MakeInvoice)
r.Post("/checkout", checkoutHandler.Create)
r.Get("/checkout/{id}", checkoutHandler.Get)
r.Post("/checkout/{id}/subscribe", checkoutHandler.ConnectWallet)
r.Get("/checkout/account/{accountId}", checkoutHandler.GetAllByAccount)
r.Route("/payment-link", func(r chi.Router) {
r.Get("/", paymentLinkHandler.List)
r.Post("/", paymentLinkHandler.Create)
r.Get("/{id}", paymentLinkHandler.Get)
r.Put("/{id}", paymentLinkHandler.Update)
r.Delete("/{id}", paymentLinkHandler.Delete)
r.Get("/account/{accountID}", paymentLinkHandler.ListByAccount)
})
r.Route("/notification-settings", func(r chi.Router) {
r.Get("/account/{accountId}", notificationHandler.GetSettings)
r.Post("/", notificationHandler.UpdateSettings)
})
r.Route("/fiat", func(r chi.Router) {
r.Get("/rates", fiatHandler.GetRates)
r.Get("/convert/to-fiat/{currency}", fiatHandler.ConvertSatoshisToFiat)
r.Get("/convert/to-sats/{currency}", fiatHandler.ConvertFiatToSatoshis)
})
r.Get("/dashboard/{accountID}/mrr/7-days/{date}", dashboardHandler.GetLast7DaysMRR)
r.Get("/dashboard/{accountID}/mrr/30-days/{date}", dashboardHandler.GetLast30DaysMRR)
r.Get("/dashboard/{accountID}/mrr/6-months/{date}", dashboardHandler.GetLast6MonthsMRR)
r.Get("/dashboard/{accountID}/mrr/12-months/{date}", dashboardHandler.GetLast12MonthsMRR)
r.Get("/dashboard/{accountID}/mrr/daily/{date}", dashboardHandler.GetDailyMRR)
})
return r
}