From 9c804bc8733142f64504a8f5840811e737e32e0e Mon Sep 17 00:00:00 2001 From: Untone Date: Sat, 13 Jan 2024 11:01:59 +0300 Subject: [PATCH] get-my-followed-fix --- resolvers/follower.py | 19 ++++++++++++------- resolvers/reaction.py | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/resolvers/follower.py b/resolvers/follower.py index 8eaf75af..5c190dc3 100644 --- a/resolvers/follower.py +++ b/resolvers/follower.py @@ -92,6 +92,9 @@ async def unfollow(_, info, what, slug): @login_required async def get_my_followed(_, info): user_id = info.context["user_id"] + topics = [] + authors = [] + communities = [] with local_session() as session: author = session.query(Author).filter(Author.user == user_id).first() if author: @@ -101,19 +104,21 @@ async def get_my_followed(_, info): .filter(AuthorFollower.follower == author.id) ) - topics_query = select(Topic).join(TopicFollower).filter(TopicFollower.follower == author.id) + topics_query = select(Topic).join(TopicFollower, TopicFollower.follower == Author.id) - # communities_query = select(Community).join(CommunityAuthor).filter(CommunityAuthor.author == author.id) + for [author] in session.execute(authors_query): + authors.append(author) + + for [topic] in session.execute(topics_query): + topics.append(topic) - topics = session.execute(topics_query).all() - authors = session.execute(authors_query).all() communities = session.query(Community).all() - return {"topics": topics, "authors": authors, "communities": communities} + return {"topics": topics, "authors": authors, "communities": communities} @query.field("get_shout_followers") -def get_shout_followers(_, _info, slug: str = "", shout_id: int = None) -> List[Author]: +def get_shout_followers(_, _info, slug: str = "", shout_id: int | None = None) -> List[Author]: followers = [] with local_session() as session: shout = None @@ -126,4 +131,4 @@ def get_shout_followers(_, _info, slug: str = "", shout_id: int = None) -> List[ for r in reactions: followers.append(r.created_by) - return followers + return followers diff --git a/resolvers/reaction.py b/resolvers/reaction.py index 39ad9a7e..92ac6087 100644 --- a/resolvers/reaction.py +++ b/resolvers/reaction.py @@ -62,7 +62,7 @@ def reactions_follow(author_id, shout_id, auto=False): return False -def reactions_unfollow(author_id: int, shout_id: int): +def reactions_unfollow(author_id, shout_id: int): try: with local_session() as session: shout = session.query(Shout).where(Shout.id == shout_id).one()