indiescrobble/server/router.go

59 lines
1.4 KiB
Go
Raw Permalink Normal View History

package server
import (
"git.jamesravey.me/ravenscroftj/indiescrobble/config"
"git.jamesravey.me/ravenscroftj/indiescrobble/controllers"
"git.jamesravey.me/ravenscroftj/indiescrobble/middlewares"
"github.com/gin-gonic/gin"
2022-02-13 15:49:22 +00:00
"gorm.io/gorm"
)
2022-02-13 15:49:22 +00:00
func NewRouter(db *gorm.DB) *gin.Engine {
router := gin.New()
router.Use(gin.Logger())
router.Use(gin.Recovery())
config := config.GetConfig()
health := new(controllers.HealthController)
2022-02-13 15:49:22 +00:00
iam := controllers.NewIndieAuthManager(db)
2022-02-05 16:24:07 +00:00
router.GET("/health", health.Status)
2022-02-13 15:49:22 +00:00
router.Use(middlewares.AuthMiddleware(false, iam))
2022-02-05 16:24:07 +00:00
router.GET("/", controllers.Index)
router.GET("/faqs", controllers.FAQ)
router.Static("/static", config.GetString("server.static_path"))
// add auth endpoints
2022-02-05 16:24:07 +00:00
router.POST("/indieauth", iam.IndieAuthLoginPost)
router.GET("/auth", iam.LoginCallbackGet)
router.GET("/logout", iam.Logout)
2022-02-13 15:49:22 +00:00
authed := router.Use(middlewares.AuthMiddleware(true, iam))
// add scrobble endpoints
2022-02-19 15:47:25 +00:00
scrobbleController := controllers.NewScrobbleController(db)
authed.GET("/scrobble", scrobbleController.ScrobbleForm)
authed.POST("/scrobble/preview", scrobbleController.PreviewScrobble)
2022-02-05 16:24:07 +00:00
2022-02-19 22:00:56 +00:00
authed.POST("/scrobble/do", scrobbleController.DoScrobble)
// v1 := router.Group("v1")
// {
// userGroup := v1.Group("user")
// {
// user := new(controllers.UserController)
// userGroup.GET("/:id", user.Retrieve)
// }
// }
return router
}