Updated web handler

This commit is contained in:
kolaente 2019-10-22 21:51:47 +02:00
parent 44b3ced845
commit df6c4f064e
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
7 changed files with 11 additions and 9 deletions

2
go.mod
View File

@ -18,7 +18,7 @@ module code.vikunja.io/api
require (
cloud.google.com/go v0.34.0 // indirect
code.vikunja.io/web v0.0.0-20191021211916-f7834b02a174
code.vikunja.io/web v0.0.0-20191022193355-23a3d145177a
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a
github.com/beevik/etree v1.1.0 // indirect

2
go.sum
View File

@ -9,6 +9,8 @@ code.vikunja.io/web v0.0.0-20190628075253-b457b5a1a332 h1:gXxyLkjhgN+vqrLvPyqySc
code.vikunja.io/web v0.0.0-20190628075253-b457b5a1a332/go.mod h1:cuP1/ieGWAZzgQGw+QPt6Y5F0fVb/8Ol5NV4QSezGdo=
code.vikunja.io/web v0.0.0-20191021211916-f7834b02a174 h1:hBY+r6bzGEfHxolaXbiVoz2LBNNnyHZK7d7Ga4Jowu8=
code.vikunja.io/web v0.0.0-20191021211916-f7834b02a174/go.mod h1:cuP1/ieGWAZzgQGw+QPt6Y5F0fVb/8Ol5NV4QSezGdo=
code.vikunja.io/web v0.0.0-20191022193355-23a3d145177a h1:exDC9eZ+SK0GT3zB/5f3OBahWzbTZlvX9OfZWgqlbeI=
code.vikunja.io/web v0.0.0-20191022193355-23a3d145177a/go.mod h1:cuP1/ieGWAZzgQGw+QPt6Y5F0fVb/8Ol5NV4QSezGdo=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=

View File

@ -147,7 +147,7 @@ handler.SetLoggingProvider(&log.Log)
The `ReadAll`-method has a number of parameters:
```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.

View File

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

View File

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

2
vendor/code.vikunja.io/web/web.go generated vendored
View File

@ -31,7 +31,7 @@ type Rights interface {
type CRUDable interface {
Create(Auth) 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
Delete() error
}

2
vendor/modules.txt vendored
View File

@ -1,4 +1,4 @@
# code.vikunja.io/web v0.0.0-20191021211916-f7834b02a174
# code.vikunja.io/web v0.0.0-20191022193355-23a3d145177a
code.vikunja.io/web
code.vikunja.io/web/handler
# github.com/BurntSushi/toml v0.3.1