ratings-update
All checks were successful
deploy / deploy (push) Successful in 1m30s

This commit is contained in:
Untone 2023-12-28 01:37:54 +03:00
parent 0ba38ac700
commit aa9ffd3053

View File

@ -111,16 +111,6 @@ async def get_authors_all(_, _info):
return session.query(Author).all() return session.query(Author).all()
@query.field("get_author_id")
async def get_author_id(_, _info, user: str):
with local_session() as session:
print(f"[resolvers.author] getting author id for {user}")
a = session.query(Author).filter(Author.user == user).first()
if a:
print(f"[resolvers.author] got @{a.slug}")
return a
def count_author_comments_rating(session, author_id) -> int: def count_author_comments_rating(session, author_id) -> int:
replied_alias = aliased(Reaction) replied_alias = aliased(Reaction)
replies_likes = ( replies_likes = (
@ -159,14 +149,8 @@ def count_author_shouts_rating(session, author_id) -> int:
return shouts_likes - shouts_dislikes return shouts_likes - shouts_dislikes
@query.field("get_author")
async def get_author(_, _info, slug="", author_id=None): def load_author_with_stats(q):
q = None
if slug or author_id:
if bool(slug):
q = select(Author).where(Author.slug == slug)
elif author_id:
q = select(Author).where(Author.id == author_id)
q = add_author_stat_columns(q) q = add_author_stat_columns(q)
[author] = get_authors_from_query(q) [author] = get_authors_from_query(q)
@ -199,8 +183,26 @@ async def get_author(_, _info, slug="", author_id=None):
author.stat["rating_comments"] = count_author_comments_rating(session, author.id) author.stat["rating_comments"] = count_author_comments_rating(session, author.id)
author.stat["commented"] = comments_count author.stat["commented"] = comments_count
return author return author
else:
return {"error": "cant find author"}
@query.field("get_author")
async def get_author(_, _info, slug="", author_id=None):
q = None
if slug or author_id:
if bool(slug):
q = select(Author).where(Author.slug == slug)
if author_id:
q = select(Author).where(Author.id == author_id)
return load_author_with_stats(q)
@query.field("get_author_id")
async def get_author_id(_, _info, user: str):
with local_session() as session:
print(f"[resolvers.author] getting author id for {user}")
q = select(Author).filter(Author.user == user)
return load_author_with_stats(q)
@query.field("load_authors_by") @query.field("load_authors_by")