1
0

Added pagination (#16)

This commit is contained in:
konrad
2018-11-09 10:30:17 +00:00
committed by Gitea
parent 0e7e1b7e38
commit d232836423
22 changed files with 71 additions and 31 deletions

View File

@ -39,7 +39,7 @@ func Caldav(c echo.Context) error {
}
// Get all tasks for that user
tasks, err := models.GetTasksByUser(&u)
tasks, err := models.GetTasksByUser(&u, -1)
if err != nil {
return crud.HandleHTTPError(err)
}

View File

@ -1,9 +1,11 @@
package crud
import (
"code.vikunja.io/api/pkg/log"
"code.vikunja.io/api/pkg/models"
"github.com/labstack/echo"
"net/http"
"strconv"
)
// ReadAllWeb is the webhandler to get all objects of a type
@ -21,7 +23,21 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest, "No or invalid model provided.")
}
lists, err := currentStruct.ReadAll(&currentUser)
// Pagination
page := ctx.QueryParam("page")
if page == "" {
page = "1"
}
pageNumber, err := strconv.Atoi(page)
if err != nil {
log.Log.Error(err.Error())
return echo.NewHTTPError(http.StatusBadRequest, "Bad page requested.")
}
if pageNumber < 0 {
return echo.NewHTTPError(http.StatusBadRequest, "Bad page requested.")
}
lists, err := currentStruct.ReadAll(&currentUser, pageNumber)
if err != nil {
return HandleHTTPError(err)
}