-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
135 lines (100 loc) · 3.42 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
133
134
135
package main
import (
"phrasmotica/bore-score-api/auth"
"phrasmotica/bore-score-api/routes"
"github.com/gin-gonic/gin"
)
func main() {
router := gin.Default()
router.Use(auth.CORSMiddleware())
approvals := router.Group("/approvals", auth.TokenAuth(false))
{
approvals.GET("/:resultId", routes.GetApprovals)
approvals.POST("", routes.PostApproval)
}
games := router.Group("/games")
{
games.GET("", routes.GetGames)
games.POST("", routes.PostGame)
gameByName := games.Group("/:gameId")
{
gameByName.GET("", routes.GetGame)
gameByName.DELETE("", auth.TokenAuth(false), auth.CheckPermission("superuser"), routes.DeleteGame)
}
}
groups := router.Group("/groups")
{
groups.GET("", auth.TokenAuth(true), routes.GetGroups)
groups.POST("", auth.TokenAuth(false), routes.PostGroup)
groupById := groups.Group("/:groupId")
{
groupById.GET("", auth.TokenAuth(true), routes.GetGroup)
groupById.GET("/invitations", auth.TokenAuth(false), routes.GetGroupInvitationsForGroup)
groupById.GET("/players", auth.TokenAuth(false), routes.GetPlayersInGroup)
groupById.GET("/results", auth.TokenAuth(false), routes.GetResultsForGroup)
groupById.DELETE("", auth.TokenAuth(false), auth.CheckPermission("superuser"), routes.DeleteGroup)
groupLeaderboards := groupById.Group("/leaderboard")
{
groupLeaderboards.GET("/:gameId", auth.TokenAuth(false), routes.GetLeaderboard)
}
}
}
groupInvitations := router.Group("/invitations", auth.TokenAuth(false))
{
groupInvitations.POST("", routes.AddGroupInvitation)
groupInvitationById := groupInvitations.Group("/:invitationId")
{
groupInvitationById.GET("", routes.GetGroupInvitation)
groupInvitationById.POST("/accept", routes.AcceptGroupInvitation)
groupInvitationById.POST("/decline", routes.DeclineGroupInvitation)
}
}
groupMemberships := router.Group("/memberships", auth.TokenAuth(false))
{
groupMemberships.GET("/:username", routes.GetGroupMemberships)
groupMemberships.POST("", routes.AddGroupMembership)
}
linkTypes := router.Group("/linkTypes")
{
linkTypes.GET("", routes.GetLinkTypes)
}
// TODO: move Player columns into User entity
players := router.Group("/players")
{
players.GET("", routes.GetPlayers)
players.POST("", routes.PostPlayer)
playerByUsername := players.Group("/:username")
{
playerByUsername.GET("", routes.GetPlayer)
playerByUsername.PUT("", auth.TokenAuth(false), routes.UpdatePlayer)
playerByUsername.DELETE("", auth.TokenAuth(false), auth.CheckPermission("superuser"), routes.DeletePlayer)
}
}
router.GET("/summary", routes.GetSummary)
results := router.Group("/results")
{
results.GET("", auth.TokenAuth(true), routes.GetResults)
results.POST("", routes.PostResult)
}
winMethods := router.Group("/winMethods")
{
winMethods.GET("", routes.GetWinMethods)
}
token := router.Group("/token")
{
token.POST("", routes.GenerateToken)
token.POST("/refresh", auth.TokenAuth(false), routes.RefreshToken)
}
users := router.Group("/users")
{
users.POST("", routes.RegisterUser)
userByUsername := users.Group("/:username")
{
userByUsername.GET("", auth.TokenAuth(true), routes.GetUser)
userByUsername.GET("/invitations", auth.TokenAuth(false), routes.GetGroupInvitationsForUser)
userByUsername.GET("/results", auth.TokenAuth(false), routes.GetResultsForUser)
userByUsername.PUT("/password", auth.TokenAuth(false), routes.UpdatePassword)
}
}
router.Run(":8000")
}