author-rating-fix
All checks were successful
deploy / deploy (push) Successful in 1m33s

This commit is contained in:
Untone 2023-12-28 00:30:18 +03:00
parent da3e7e55fd
commit 6207f7d3ed
2 changed files with 11 additions and 3 deletions

View File

@ -179,6 +179,12 @@ async def get_author(_, _info, slug="", author_id=None):
)
.count()
)
rating_sum = (
session.query(func.sum(AuthorRating.value))
.filter(AuthorRating.author == author.id)
.scalar()
)
author.stat["rating"] = rating_sum
author.stat["commented"] = comments_count
else:
return {"error": "cant find author"}
@ -213,7 +219,7 @@ async def get_author_followed(_, _info, slug="", user=None, author_id=None) -> L
author_id_query = select(Author.id).where(Author.slug == slug)
elif user:
author_id_query = select(Author.id).where(Author.user == user)
if not author_id:
if author_id_query is not None and not author_id:
with local_session() as session:
author_id = session.execute(author_id_query).scalar()

View File

@ -197,5 +197,7 @@ def get_random_topic():
q = q.order_by(func.random()).limit(1)
with local_session() as session:
[topic] = session.execute(q).first()
return topic
r = session.execute(q).first()
if r:
[topic] = r
return topic