1
|
|
|
package v1 |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"net/http" |
5
|
|
|
|
6
|
|
|
"github.com/gofiber/fiber/v2" |
7
|
|
|
"github.com/memnix/memnix-rest/domain" |
8
|
|
|
"github.com/memnix/memnix-rest/services" |
9
|
|
|
) |
10
|
|
|
|
11
|
|
|
func registerRoutes(router *fiber.Router) { |
12
|
|
|
serviceContainer := services.DefaultServiceContainer() |
13
|
|
|
userController := serviceContainer.User() |
14
|
|
|
authController := serviceContainer.Auth() |
15
|
|
|
jwtController := serviceContainer.Jwt() |
16
|
|
|
oauthController := serviceContainer.OAuth() |
17
|
|
|
deckController := serviceContainer.Deck() |
18
|
|
|
|
19
|
|
|
(*router).Get("/health", func(c *fiber.Ctx) error { return c.Status(http.StatusOK).SendString("ok") }) |
20
|
|
|
|
21
|
|
|
(*router).Get("/user/me", |
22
|
|
|
jwtController.IsConnectedMiddleware(domain.PermissionUser), userController.GetMe) |
23
|
|
|
|
24
|
|
|
(*router).Get("/user/:uuid", |
25
|
|
|
userController.GetName) |
26
|
|
|
|
27
|
|
|
(*router).Post("/security/login", |
28
|
|
|
jwtController.IsConnectedMiddleware(domain.PermissionNone), authController.Login) |
29
|
|
|
|
30
|
|
|
(*router).Post("/security/register", |
31
|
|
|
jwtController.IsConnectedMiddleware(domain.PermissionNone), authController.Register) |
32
|
|
|
|
33
|
|
|
(*router).Post("/security/logout", |
34
|
|
|
jwtController.IsConnectedMiddleware(domain.PermissionUser), authController.Logout) |
35
|
|
|
|
36
|
|
|
(*router).Post("/security/refresh", |
37
|
|
|
jwtController.IsConnectedMiddleware(domain.PermissionUser), authController.RefreshToken) |
38
|
|
|
|
39
|
|
|
(*router).Get("/security/github", |
40
|
|
|
oauthController.GithubLogin) |
41
|
|
|
|
42
|
|
|
(*router).Get("/security/github_callback", |
43
|
|
|
oauthController.GithubCallback) |
44
|
|
|
|
45
|
|
|
(*router).Get("/security/discord", |
46
|
|
|
oauthController.DiscordLogin) |
47
|
|
|
|
48
|
|
|
(*router).Get("/security/discord_callback", |
49
|
|
|
oauthController.DiscordCallback) |
50
|
|
|
|
51
|
|
|
(*router).Get("/deck/owned", |
52
|
|
|
jwtController.IsConnectedMiddleware(domain.PermissionUser), deckController.GetOwned) |
53
|
|
|
|
54
|
|
|
(*router).Get("/deck/public", |
55
|
|
|
jwtController.IsConnectedMiddleware(domain.PermissionUser), deckController.GetPublic) |
56
|
|
|
|
57
|
|
|
(*router).Get("/deck/learning", |
58
|
|
|
jwtController.IsConnectedMiddleware(domain.PermissionUser), deckController.GetLearning) |
59
|
|
|
|
60
|
|
|
(*router).Get("/deck/:id", |
61
|
|
|
jwtController.IsConnectedMiddleware(domain.PermissionUser), deckController.GetByID) |
62
|
|
|
|
63
|
|
|
(*router).Post("/deck", |
64
|
|
|
jwtController.IsConnectedMiddleware(domain.PermissionUser), deckController.Create) |
65
|
|
|
} |
66
|
|
|
|