go-urlsh/internal/app/routes.go

57 lines
1.6 KiB
Go

package app
import (
"code.lila.network/adoralaura/go-urlsh/internal/api"
"code.lila.network/adoralaura/go-urlsh/internal/config"
"code.lila.network/adoralaura/go-urlsh/internal/web"
"github.com/gofiber/fiber/v2"
"github.com/rs/zerolog"
"github.com/uptrace/bun"
)
func addWebRoutes(
f *fiber.App) {
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)
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)
f.Static("/admin/", "./web")
f.Get("/", web.HandleIndexGet)
f.Get("/:id", web.HandleIndexGet)
}
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)
r.Get("/apikeys", am.HandleApiKeysGetAll)
r.Post("/apikeys", am.HandleApiKeysPost)
r.Delete("/apikeys/:id<guid>", am.HandleApiKeysPost)
r.Post("/users", am.HandleUserPost)
}