shiori/internal/http/routes/api/v1/api.go
Felipe Martin cc7c75116d
refactor: migrate bookmark static pages to new http server (#775)
* migrate bookmark content route to new http server

* new archive page

* remove unused go generate comment

* database mock

* utils cleanup

* unused var

* domains refactor and tests

* fixed secret key type

* redirect to login on ui errors

* fixed archive folder with storage domain

* webroot documentation

* some bookmark route tests

* fixed error in bookmark domain for non existant bookmarks

* centralice errors

* add coverage data to unittests

* added tests, refactor storage to use afero

* removed mock to avoid increasing complexity

* using deps to copy files around

* remove config usage (to deps)

* remove handler-ui file
2023-12-28 18:18:32 +01:00

40 lines
1.1 KiB
Go

package api_v1
import (
"github.com/gin-gonic/gin"
"github.com/go-shiori/shiori/internal/dependencies"
"github.com/go-shiori/shiori/internal/http/middleware"
"github.com/go-shiori/shiori/internal/model"
"github.com/sirupsen/logrus"
)
type APIRoutes struct {
logger *logrus.Logger
deps *dependencies.Dependencies
loginHandler model.LegacyLoginHandler
}
func (r *APIRoutes) Setup(g *gin.RouterGroup) model.Routes {
// Account API handles authentication in each route
r.handle(g, "/auth", NewAuthAPIRoutes(r.logger, r.deps, r.loginHandler))
// From here on, all routes require authentication
g.Use(middleware.AuthenticationRequired())
r.handle(g, "/bookmarks", NewBookmarksPIRoutes(r.logger, r.deps))
r.handle(g, "/tags", NewTagsPIRoutes(r.logger, r.deps))
return r
}
func (s *APIRoutes) handle(g *gin.RouterGroup, path string, routes model.Routes) {
group := g.Group(path)
routes.Setup(group)
}
func NewAPIRoutes(logger *logrus.Logger, deps *dependencies.Dependencies, loginHandler model.LegacyLoginHandler) *APIRoutes {
return &APIRoutes{
logger: logger,
deps: deps,
loginHandler: loginHandler,
}
}