From 7aca5a54dc23121f81d563586cea5b91fce1ab8d Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Fri, 26 Nov 2021 14:56:01 +0000 Subject: [PATCH] Add more to reviews API response --- app/blueprints/api/endpoints.py | 8 ++++++-- app/flatpages/help/api.md | 12 +++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/blueprints/api/endpoints.py b/app/blueprints/api/endpoints.py index d195184..ae9a059 100644 --- a/app/blueprints/api/endpoints.py +++ b/app/blueprints/api/endpoints.py @@ -13,6 +13,7 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import math from typing import List import flask_sqlalchemy @@ -396,9 +397,12 @@ def list_all_reviews(): pagination: flask_sqlalchemy.Pagination = query.paginate(page, num, True) return jsonify({ "page": pagination.page, + "per_page": pagination.per_page, + "page_count": math.ceil(pagination.total / pagination.per_page), + "total": pagination.total, "urls": { - "previous": abs_url(url_set_query(page=page - 1)) if page > 1 else None, - "next": abs_url(url_set_query(page=page + 1)) if pagination.next_num else None, + "previous": abs_url(url_set_query(page=page - 1)) if pagination.has_prev else None, + "next": abs_url(url_set_query(page=page + 1)) if pagination.has_next else None, }, "items": [review.getAsDictionary(True) for review in pagination.items], }) diff --git a/app/flatpages/help/api.md b/app/flatpages/help/api.md index 2171747..a9b7da0 100644 --- a/app/flatpages/help/api.md +++ b/app/flatpages/help/api.md @@ -239,13 +239,19 @@ curl -X POST https://content.minetest.net/api/packages/username/name/screenshots * GET `/api/reviews/` (List) * Returns a paginated response. This is a dictionary with `page`, `url`, and `items`. * `page`: page number, integer from 1 to max - * `url`: dictionary containing `next` and `previous` - * `items`: array of review dictionaries, like above. - * Each review also has a `package` dictionary with `type`, `author` and `name` + * `per_page`: number of items per page, same as `n` + * `page_count`: number of pages + * `total`: total number of results + * `urls`: dictionary containing + * `next`: url to next page + * `previous`: url to previous page + * `items`: array of review dictionaries, like above + * Each review also has a `package` dictionary with `type`, `author` and `name` * Query arguments: * `page`: page number, integer from 1 to max * `n`: number of results per page, max 100 * `author`: filter by review author username + * `is_positive`: true or false. Default: null * `q`: filter by title (case insensitive, no fulltext search) Example: