This commit is contained in:
parent
da3e7e55fd
commit
6207f7d3ed
|
@ -179,6 +179,12 @@ async def get_author(_, _info, slug="", author_id=None):
|
||||||
)
|
)
|
||||||
.count()
|
.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
|
author.stat["commented"] = comments_count
|
||||||
else:
|
else:
|
||||||
return {"error": "cant find author"}
|
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)
|
author_id_query = select(Author.id).where(Author.slug == slug)
|
||||||
elif user:
|
elif user:
|
||||||
author_id_query = select(Author.id).where(Author.user == 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:
|
with local_session() as session:
|
||||||
author_id = session.execute(author_id_query).scalar()
|
author_id = session.execute(author_id_query).scalar()
|
||||||
|
|
||||||
|
|
|
@ -197,5 +197,7 @@ def get_random_topic():
|
||||||
q = q.order_by(func.random()).limit(1)
|
q = q.order_by(func.random()).limit(1)
|
||||||
|
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
[topic] = session.execute(q).first()
|
r = session.execute(q).first()
|
||||||
return topic
|
if r:
|
||||||
|
[topic] = r
|
||||||
|
return topic
|
||||||
|
|
Loading…
Reference in New Issue
Block a user