-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
132 lines (109 loc) · 4.29 KB
/
main.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
package main
import (
"net/url"
"os"
"time"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"github.com/truc9/racket/internal/di"
"github.com/truc9/racket/internal/handler"
jwtmiddleware "github.com/auth0/go-jwt-middleware/v2"
"github.com/auth0/go-jwt-middleware/v2/jwks"
"github.com/auth0/go-jwt-middleware/v2/validator"
adapter "github.com/gwatts/gin-adapter"
)
func main() {
godotenv.Load()
container := di.Register()
app := gin.Default()
app.Use(cors.New(cors.Config{
AllowOrigins: []string{
"http://localhost:5173",
"https://getracket.vercel.app",
},
AllowMethods: []string{"PUT", "POST", "GET", "DELETE", "PATCH"},
AllowHeaders: []string{"*"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
MaxAge: 12 * time.Hour,
}))
app.GET("/health", func(ctx *gin.Context) {
ctx.JSON(200, gin.H{
"message": "ok",
})
})
public := app.Group("/api/v1/public")
container.Invoke(func(handler *handler.ReportingHandler) {
public.GET("/reports/unpaid", handler.GetUnpaidReportForPublic)
})
issuerURL, _ := url.Parse(os.Getenv("AUTH0_ISSUER_URL"))
audience := os.Getenv("AUTH0_AUDIENCE")
provider := jwks.NewCachingProvider(issuerURL, time.Duration(5*time.Minute))
jwtValidator, _ := validator.New(provider.KeyFunc,
validator.RS256,
issuerURL.String(),
[]string{audience},
)
jwtMiddleware := jwtmiddleware.New(jwtValidator.ValidateToken)
app.Use(adapter.Wrap(jwtMiddleware.CheckJWT))
app.GET("/health/origins", func(ctx *gin.Context) {
ctx.JSON(200, ctx.Request.Header.Get("Origin"))
})
v1 := app.Group("/api/v1")
container.Invoke(func(handler *handler.MatchHandler) {
v1.POST("/matches", handler.Create)
v1.GET("/matches", handler.GetAll)
v1.GET("/matches/archived", handler.GetArchivedMatches)
v1.GET("/matches/future", handler.GetFutureMatches)
v1.GET("/matches/today", handler.GetTodayMatches)
v1.GET("/upcoming-matches", handler.GetUpcomingMatches)
v1.GET("/matches/:matchId/registrations", handler.GetRegistrationsByMatch)
v1.GET("/matches/:matchId/cost", handler.GetCost)
v1.POST("/matches/:matchId/clone", handler.Clone)
v1.GET("/matches/:matchId/additional-costs", handler.GetAdditionalCost)
v1.PUT("/matches/:matchId", handler.UpdateMatch)
v1.PUT("/matches/:matchId/costs", handler.UpdateCost)
v1.PUT("/matches/:matchId/additional-costs", handler.CreateAdditionalCost)
v1.DELETE("/matches/:matchId", handler.Delete)
})
container.Invoke(func(handler *handler.PlayerHandler) {
v1.GET("/players", handler.GetAll)
v1.GET("/players/external-users/:externalUserId/attendant-requests", handler.GetExternalUserAttendantRequests)
v1.POST("/players", handler.Create)
v1.DELETE("/players/:playerId", handler.Delete)
v1.PUT("/players/:playerId", handler.Update)
v1.PUT("/players/:playerId/outstanding-payments/paid", handler.MarkOutstandingPaymentsAsPaid)
v1.POST("/players/:playerId/accounts", handler.OpenAccount)
})
container.Invoke(func(handler *handler.RegistrationHandler) {
v1.GET("/registrations", handler.GetAll)
v1.POST("/registrations", handler.Register)
v1.POST("/registrations/attendant-requests", handler.AttendantRequest)
v1.PUT("/registrations/:registrationId/paid", handler.MarkPaid)
v1.PUT("/registrations/:registrationId/unpaid", handler.MarkUnPaid)
v1.DELETE("/registrations/:registrationId", handler.Unregister)
})
container.Invoke(func(handler *handler.SportCenterHandler) {
v1.GET("/sportcenters", handler.GetAll)
v1.GET("/sportcenters/options", handler.GetOptions)
v1.POST("/sportcenters", handler.Create)
v1.PUT("/sportcenters/:sportCenterId", handler.Update)
})
container.Invoke(func(handler *handler.SettingsHandler) {
v1.GET("/settings/message-template", handler.GetMessageTemplate)
v1.POST("/settings/message-template", handler.CreateMessageTemplate)
})
container.Invoke(func(handler *handler.ReportingHandler) {
v1.GET("/reports/unpaid", handler.GetUnpaidReport)
})
container.Invoke(func(handler *handler.ActivityHandler) {
v1.GET("/activities", handler.GetAll)
})
container.Invoke(func(handler *handler.ShareCodeHandler) {
v1.GET("/share-codes/urls", handler.GetShareUrls)
v1.POST("/share-codes/urls", handler.CreateShareUrl)
v1.DELETE("/share-codes/urls/:shareCodeId", handler.DeleteShareCodeUrl)
})
app.Run()
}