mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-08 22:17:34 +01:00
Add more to reviews API response
This commit is contained in:
parent
e1cd2ceb1d
commit
7aca5a54dc
@ -13,6 +13,7 @@
|
|||||||
#
|
#
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
import math
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
import flask_sqlalchemy
|
import flask_sqlalchemy
|
||||||
@ -396,9 +397,12 @@ def list_all_reviews():
|
|||||||
pagination: flask_sqlalchemy.Pagination = query.paginate(page, num, True)
|
pagination: flask_sqlalchemy.Pagination = query.paginate(page, num, True)
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"page": pagination.page,
|
"page": pagination.page,
|
||||||
|
"per_page": pagination.per_page,
|
||||||
|
"page_count": math.ceil(pagination.total / pagination.per_page),
|
||||||
|
"total": pagination.total,
|
||||||
"urls": {
|
"urls": {
|
||||||
"previous": abs_url(url_set_query(page=page - 1)) if page > 1 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.next_num 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],
|
"items": [review.getAsDictionary(True) for review in pagination.items],
|
||||||
})
|
})
|
||||||
|
@ -239,13 +239,19 @@ curl -X POST https://content.minetest.net/api/packages/username/name/screenshots
|
|||||||
* GET `/api/reviews/` (List)
|
* GET `/api/reviews/` (List)
|
||||||
* Returns a paginated response. This is a dictionary with `page`, `url`, and `items`.
|
* Returns a paginated response. This is a dictionary with `page`, `url`, and `items`.
|
||||||
* `page`: page number, integer from 1 to max
|
* `page`: page number, integer from 1 to max
|
||||||
* `url`: dictionary containing `next` and `previous`
|
* `per_page`: number of items per page, same as `n`
|
||||||
* `items`: array of review dictionaries, like above.
|
* `page_count`: number of pages
|
||||||
* Each review also has a `package` dictionary with `type`, `author` and `name`
|
* `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:
|
* Query arguments:
|
||||||
* `page`: page number, integer from 1 to max
|
* `page`: page number, integer from 1 to max
|
||||||
* `n`: number of results per page, max 100
|
* `n`: number of results per page, max 100
|
||||||
* `author`: filter by review author username
|
* `author`: filter by review author username
|
||||||
|
* `is_positive`: true or false. Default: null
|
||||||
* `q`: filter by title (case insensitive, no fulltext search)
|
* `q`: filter by title (case insensitive, no fulltext search)
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
Loading…
Reference in New Issue
Block a user