This commit is contained in:
parent
0ba38ac700
commit
aa9ffd3053
|
@ -111,16 +111,6 @@ async def get_authors_all(_, _info):
|
|||
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:
|
||||
replied_alias = aliased(Reaction)
|
||||
replies_likes = (
|
||||
|
@ -159,14 +149,8 @@ def count_author_shouts_rating(session, author_id) -> int:
|
|||
return shouts_likes - shouts_dislikes
|
||||
|
||||
|
||||
@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)
|
||||
elif author_id:
|
||||
q = select(Author).where(Author.id == author_id)
|
||||
|
||||
def load_author_with_stats(q):
|
||||
q = add_author_stat_columns(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["commented"] = comments_count
|
||||
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")
|
||||
|
|
Loading…
Reference in New Issue
Block a user