mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-09 22:47:36 +01:00
API: Add option to filter reviews by package author
This commit is contained in:
parent
e446e9011a
commit
43e9641feb
@ -445,15 +445,18 @@ def list_reviews(package):
|
|||||||
@cors_allowed
|
@cors_allowed
|
||||||
def list_all_reviews():
|
def list_all_reviews():
|
||||||
page = get_int_or_abort(request.args.get("page"), 1)
|
page = get_int_or_abort(request.args.get("page"), 1)
|
||||||
num = min(get_int_or_abort(request.args.get("n"), 100), 100)
|
num = min(get_int_or_abort(request.args.get("n"), 100), 200)
|
||||||
|
|
||||||
query = PackageReview.query
|
query = PackageReview.query
|
||||||
query = query.options(joinedload(PackageReview.author), joinedload(PackageReview.package))
|
query = query.options(joinedload(PackageReview.author), joinedload(PackageReview.package))
|
||||||
|
|
||||||
if request.args.get("author"):
|
if "for_user" in request.args:
|
||||||
|
query = query.filter(PackageReview.package.has(Package.author.has(username=request.args["for_user"])))
|
||||||
|
|
||||||
|
if "author" in request.args:
|
||||||
query = query.filter(PackageReview.author.has(User.username == request.args.get("author")))
|
query = query.filter(PackageReview.author.has(User.username == request.args.get("author")))
|
||||||
|
|
||||||
if request.args.get("is_positive"):
|
if "is_positive" in request.args:
|
||||||
if is_yes(request.args.get("is_positive")):
|
if is_yes(request.args.get("is_positive")):
|
||||||
query = query.filter(PackageReview.rating > 3)
|
query = query.filter(PackageReview.rating > 3)
|
||||||
else:
|
else:
|
||||||
@ -463,6 +466,8 @@ def list_all_reviews():
|
|||||||
if q:
|
if q:
|
||||||
query = query.filter(PackageReview.thread.has(Thread.title.ilike(f"%{q}%")))
|
query = query.filter(PackageReview.thread.has(Thread.title.ilike(f"%{q}%")))
|
||||||
|
|
||||||
|
query = query.order_by(db.desc(PackageReview.created_at))
|
||||||
|
|
||||||
pagination: flask_sqlalchemy.Pagination = query.paginate(page=page, per_page=num)
|
pagination: flask_sqlalchemy.Pagination = query.paginate(page=page, per_page=num)
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"page": pagination.page,
|
"page": pagination.page,
|
||||||
|
@ -328,10 +328,12 @@ curl -X POST https://content.minetest.net/api/packages/username/name/screenshots
|
|||||||
* [Paginated result](#paginated-results)
|
* [Paginated result](#paginated-results)
|
||||||
* `items`: array of review dictionaries, like above
|
* `items`: array of review dictionaries, like above
|
||||||
* Each review also has a `package` dictionary with `type`, `author` and `name`
|
* Each review also has a `package` dictionary with `type`, `author` and `name`
|
||||||
|
* Ordered by created at, newest to oldest.
|
||||||
* 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 200
|
||||||
* `author`: filter by review author username
|
* `author`: filter by review author username
|
||||||
|
* `for_user`: filter by package author
|
||||||
* `rating`: 1 for negative, 3 for neutral, 5 for positive
|
* `rating`: 1 for negative, 3 for neutral, 5 for positive
|
||||||
* `is_positive`: true or false. Default: null
|
* `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)
|
||||||
|
Loading…
Reference in New Issue
Block a user