diff --git a/handler/read_all.go b/handler/read_all.go index 7f0e736..001b60f 100644 --- a/handler/read_all.go +++ b/handler/read_all.go @@ -17,6 +17,7 @@ package handler import ( "github.com/labstack/echo/v4" + "math" "net/http" "strconv" ) @@ -82,7 +83,9 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error { } // Calculate the number of pages from the number of items - var numberOfPages = numberOfItems / int64(perPageNumber) + // We always round up, because if we don't have a number of items which is exactly dividable by the number of items per page, + // we would get a result that is one page off. + var numberOfPages = math.Ceil(float64(numberOfItems) / float64(perPageNumber)) // If we return all results, we only have one page if pageNumber < 0 { numberOfPages = 1 @@ -92,7 +95,7 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error { numberOfPages = 0 } - ctx.Response().Header().Set("x-pagination-total-pages", strconv.FormatInt(numberOfPages, 10)) + ctx.Response().Header().Set("x-pagination-total-pages", strconv.FormatFloat(numberOfPages, 'f', 0, 64)) 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")