mirror of
https://github.com/minetest/contentdb.git
synced 2024-11-10 01:23:48 +01:00
Add review count to scores API
This commit is contained in:
parent
37bff46f33
commit
1fad818f05
@ -572,7 +572,7 @@ def all_package_stats():
|
|||||||
|
|
||||||
@bp.route("/api/scores/")
|
@bp.route("/api/scores/")
|
||||||
@cors_allowed
|
@cors_allowed
|
||||||
@cached(300)
|
@cached(900)
|
||||||
def package_scores():
|
def package_scores():
|
||||||
qb = QueryBuilder(request.args)
|
qb = QueryBuilder(request.args)
|
||||||
query = qb.build_package_query()
|
query = qb.build_package_query()
|
||||||
|
@ -522,6 +522,10 @@ Supported query parameters:
|
|||||||
* `score`: total package score.
|
* `score`: total package score.
|
||||||
* `score_reviews`: score from reviews.
|
* `score_reviews`: score from reviews.
|
||||||
* `score_downloads`: score from downloads.
|
* `score_downloads`: score from downloads.
|
||||||
|
* `reviews`: a dictionary of
|
||||||
|
* `positive`: int, number of positive reviews.
|
||||||
|
* `neutral`: int, number of neutral reviews.
|
||||||
|
* `negative`: int, number of negative reviews.
|
||||||
* GET `/api/homepage/` ([View](/api/homepage/)) - get contents of homepage.
|
* GET `/api/homepage/` ([View](/api/homepage/)) - get contents of homepage.
|
||||||
* `count`: number of packages
|
* `count`: number of packages
|
||||||
* `downloads`: get number of downloads
|
* `downloads`: get number of downloads
|
||||||
|
@ -759,13 +759,19 @@ class Package(db.Model):
|
|||||||
return states
|
return states
|
||||||
|
|
||||||
def as_score_dict(self):
|
def as_score_dict(self):
|
||||||
|
reviews = self.get_review_summary()
|
||||||
return {
|
return {
|
||||||
"author": self.author.username,
|
"author": self.author.username,
|
||||||
"name": self.name,
|
"name": self.name,
|
||||||
"score": self.score,
|
"score": self.score,
|
||||||
"score_downloads": self.score_downloads,
|
"score_downloads": self.score_downloads,
|
||||||
"score_reviews": self.score - self.score_downloads,
|
"score_reviews": self.score - self.score_downloads,
|
||||||
"downloads": self.downloads
|
"downloads": self.downloads,
|
||||||
|
"reviews": {
|
||||||
|
"positive": reviews[0],
|
||||||
|
"neutral": reviews[1],
|
||||||
|
"negative": reviews[2],
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
def recalculate_score(self):
|
def recalculate_score(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user