Changed page int64 to int since its all limit can handle

This commit is contained in:
kolaente 2019-10-22 21:33:55 +02:00
parent f7834b02a1
commit 23a3d14517
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
4 changed files with 7 additions and 7 deletions

View File

@ -147,7 +147,7 @@ handler.SetLoggingProvider(&log.Log)
The `ReadAll`-method has a number of parameters: The `ReadAll`-method has a number of parameters:
```go ```go
ReadAll(auth Auth, search string, page int64, perPage int64) (result interface{}, resultCount int64, numberOfPages int64, err error) ReadAll(auth Auth, search string, page int, perPage int) (result interface{}, resultCount int, numberOfPages int, err error)
``` ```
The third parameter contains the requested page, the fourth parameter contains the number of items per page. The third parameter contains the requested page, the fourth parameter contains the number of items per page.

View File

@ -25,7 +25,7 @@ import (
type Config struct { type Config struct {
AuthProvider *web.Auths AuthProvider *web.Auths
LoggingProvider *logging.Logger LoggingProvider *logging.Logger
MaxItemsPerPage int64 MaxItemsPerPage int
} }
var config *Config var config *Config

View File

@ -41,7 +41,7 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error {
if page == "" { if page == "" {
page = "1" page = "1"
} }
pageNumber, err := strconv.ParseInt(page, 10, 64) pageNumber, err := strconv.Atoi(page)
if err != nil { if err != nil {
config.LoggingProvider.Error(err.Error()) config.LoggingProvider.Error(err.Error())
return echo.NewHTTPError(http.StatusBadRequest, "Bad page requested.") return echo.NewHTTPError(http.StatusBadRequest, "Bad page requested.")
@ -52,7 +52,7 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error {
// Items per page // Items per page
perPage := ctx.QueryParam("per_page") perPage := ctx.QueryParam("per_page")
perPageNumber, err := strconv.ParseInt(perPage, 10, 64) perPageNumber, err := strconv.Atoi(perPage)
if err != nil { if err != nil {
config.LoggingProvider.Error(err.Error()) config.LoggingProvider.Error(err.Error())
return echo.NewHTTPError(http.StatusBadRequest, "Bad per page amount requested.") return echo.NewHTTPError(http.StatusBadRequest, "Bad per page amount requested.")
@ -76,8 +76,8 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error {
return HandleHTTPError(err, ctx) return HandleHTTPError(err, ctx)
} }
ctx.Response().Header().Set("x-pagination-total-pages", strconv.FormatInt(numberOfPages, 10)) ctx.Response().Header().Set("x-pagination-total-pages", strconv.FormatInt(int64(numberOfPages), 10))
ctx.Response().Header().Set("x-pagination-result-count", strconv.FormatInt(resultCount, 10)) ctx.Response().Header().Set("x-pagination-result-count", strconv.FormatInt(int64(resultCount), 10))
ctx.Response().Header().Set("Access-Control-Expose-Headers", "x-pagination-total-pages, x-pagination-result-count") ctx.Response().Header().Set("Access-Control-Expose-Headers", "x-pagination-total-pages, x-pagination-result-count")
return ctx.JSON(http.StatusOK, result) return ctx.JSON(http.StatusOK, result)

2
web.go
View File

@ -31,7 +31,7 @@ type Rights interface {
type CRUDable interface { type CRUDable interface {
Create(Auth) error Create(Auth) error
ReadOne() error ReadOne() error
ReadAll(auth Auth, search string, page int64, perPage int64) (result interface{}, resultCount int64, numberOfPages int64, err error) ReadAll(auth Auth, search string, page int, perPage int) (result interface{}, resultCount int, numberOfPages int, err error)
Update() error Update() error
Delete() error Delete() error
} }