go-urlsh/internal/app/routes.go

58 lines
1.6 KiB
Go
Raw Permalink Normal View History

2024-05-04 17:06:01 +02:00
package app
import (
"code.lila.network/adoralaura/go-urlsh/internal/api"
2024-09-30 13:19:01 +02:00
"code.lila.network/adoralaura/go-urlsh/internal/config"
2024-05-04 17:06:01 +02:00
"code.lila.network/adoralaura/go-urlsh/internal/web"
"github.com/gofiber/fiber/v2"
2024-09-30 13:19:01 +02:00
"github.com/rs/zerolog"
"github.com/uptrace/bun"
2024-05-04 17:06:01 +02:00
)
2024-09-30 13:19:01 +02:00
func addWebRoutes(
f *fiber.App) {
2024-05-04 17:06:01 +02:00
f.Get("/admin/", web.HandleAdminLinkIndexGet)
f.Get("/admin/account/", web.HandleAdminAccountGet)
f.Get("/admin/account/setup-multifactor", web.HandleAdminAccountMFASetupGet)
f.Post("/admin/account/mfa/confirm", web.HandleAdminAccountMFASetupPost)
f.Delete("/admin/account/mfa", web.HandleAdminAccountMFARemove)
2024-05-04 17:06:01 +02:00
f.Get("/admin/login", web.HandleAdminLoginGet)
f.Post("/admin/login", web.HandleAdminLoginPost)
f.Get("/admin/login/multifactor", web.HandleAdminLoginMFAGet)
f.Post("/admin/login/multifactor", web.HandleAdminLoginMFAPost)
f.Get("/admin/", web.HandleAdminLinkIndexGet)
f.Get("/admin/links/new", web.HandleAdminLinkNewGet)
f.Get("/admin/links/edit/:id", web.HandleAdminLinkEditGet)
2024-09-30 13:19:01 +02:00
f.Static("/admin/", "./web")
f.Get("/", web.HandleIndexGet)
f.Get("/:id", web.HandleIndexGet)
2024-05-04 17:06:01 +02:00
}
2024-09-30 13:19:01 +02:00
func addApiRoutes(
r fiber.Router,
db *bun.DB,
logger *zerolog.Logger,
config *config.Config) {
am := api.NewAPIRouteManager(db, logger, config)
r.Get("/links", am.HandleLinkGetAll)
r.Get("/links/:id", am.HandleLinkGet)
r.Put("/links/:id", am.HandleLinkPut)
r.Post("/links", am.HandleLinkPost)
r.Delete("/links/:id", am.HandleLinkDelete)
2024-05-04 17:06:01 +02:00
2024-09-30 13:19:01 +02:00
r.Get("/apikeys", am.HandleApiKeysGetAll)
r.Post("/apikeys", am.HandleApiKeysPost)
r.Delete("/apikeys/:id<guid>", am.HandleApiKeysPost)
2024-05-04 17:06:01 +02:00
2024-09-30 13:19:01 +02:00
r.Post("/users", am.HandleUserPost)
2024-05-04 17:06:01 +02:00
}