1
0

chore(web): use config directly

(cherry picked from commit bcfd72c64545241b53fc8a69197cfc6a3f316d92)
This commit is contained in:
kolaente 2024-08-29 18:41:20 +02:00
parent d885b43328
commit 5fba4ed6ef
No known key found for this signature in database
GPG Key ID: F40E70337AB24C9B
3 changed files with 4 additions and 11 deletions

View File

@ -58,7 +58,6 @@ import (
"time" "time"
"code.vikunja.io/api/pkg/config" "code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/log" "code.vikunja.io/api/pkg/log"
"code.vikunja.io/api/pkg/models" "code.vikunja.io/api/pkg/models"
"code.vikunja.io/api/pkg/modules/auth" "code.vikunja.io/api/pkg/modules/auth"
@ -124,7 +123,6 @@ func NewEcho() *echo.Echo {
AuthObject: auth.GetAuthFromClaims, AuthObject: auth.GetAuthFromClaims,
}) })
handler.SetLoggingProvider(log.GetLogger()) handler.SetLoggingProvider(log.GetLogger())
handler.SetMaxItemsPerPage(config.ServiceMaxItemsPerPage.GetInt())
return e return e
} }

View File

@ -25,7 +25,6 @@ import (
type Config struct { type Config struct {
AuthProvider *web.Auths AuthProvider *web.Auths
LoggingProvider *logging.Logger LoggingProvider *logging.Logger
MaxItemsPerPage int
} }
var config *Config var config *Config
@ -43,8 +42,3 @@ func SetAuthProvider(provider *web.Auths) {
func SetLoggingProvider(logger *logging.Logger) { func SetLoggingProvider(logger *logging.Logger) {
config.LoggingProvider = logger config.LoggingProvider = logger
} }
// SetMaxItemsPerPage sets the max number of items per page in the config
func SetMaxItemsPerPage(maxItemsPerPage int) {
config.MaxItemsPerPage = maxItemsPerPage
}

View File

@ -23,6 +23,7 @@ import (
"net/http" "net/http"
"strconv" "strconv"
vconfig "code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/db" "code.vikunja.io/api/pkg/db"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
@ -76,13 +77,13 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error {
} }
// Set default page count // Set default page count
if perPageNumber == 0 { if perPageNumber == 0 {
perPageNumber = config.MaxItemsPerPage perPageNumber = vconfig.ServiceMaxItemsPerPage.GetInt()
} }
if perPageNumber < 1 { if perPageNumber < 1 {
return echo.NewHTTPError(http.StatusBadRequest, "Per page amount cannot be negative.") return echo.NewHTTPError(http.StatusBadRequest, "Per page amount cannot be negative.")
} }
if perPageNumber > config.MaxItemsPerPage { if perPageNumber > vconfig.ServiceMaxItemsPerPage.GetInt() {
perPageNumber = config.MaxItemsPerPage perPageNumber = vconfig.ServiceMaxItemsPerPage.GetInt()
} }
// Create the db session // Create the db session