diff --git a/resolvers/author.py b/resolvers/author.py index 970eb39d..82ea8136 100644 --- a/resolvers/author.py +++ b/resolvers/author.py @@ -299,19 +299,19 @@ def get_author_followers(_, _info, slug): q = ( select(author_alias) - .join(alias_author_authors, alias_author_authors.follower_id == author_alias.id) + .join(alias_author_authors, alias_author_authors.follower == author_alias.id) .join( - alias_author_followers, alias_author_followers.author_id == author_alias.id + alias_author_followers, alias_author_followers.author == author_alias.id ) .filter(author_alias.slug == slug) .add_columns( func.count(distinct(alias_shout_author.shout)).label('shouts_stat'), - func.count(distinct(alias_author_authors.author_id)).label('authors_stat'), - func.count(distinct(alias_author_follower_followers.follower_id)).label( + func.count(distinct(alias_author_authors.author)).label('authors_stat'), + func.count(distinct(alias_author_follower_followers.follower)).label( 'followers_stat' ), ) - .outerjoin(alias_shout_author, author_alias.id == alias_shout_author.author_id) + .outerjoin(alias_shout_author, author_alias.id == alias_shout_author.author) .group_by(author_alias.id) ) diff --git a/resolvers/collab.py b/resolvers/collab.py index 90db98c2..f998d09c 100644 --- a/resolvers/collab.py +++ b/resolvers/collab.py @@ -19,7 +19,7 @@ async def accept_invite(_, info, invite_id: int): invite = session.query(Invite).filter(Invite.id == invite_id).first() if ( invite - and invite.author_id is author.id + and invite.author_d is author.id and invite.status is InviteStatus.PENDING.value ): # Add the user to the shout authors diff --git a/resolvers/stat.py b/resolvers/stat.py index e83ce514..6ca7ca04 100644 --- a/resolvers/stat.py +++ b/resolvers/stat.py @@ -191,11 +191,11 @@ def author_follows_topics(author_id: int): subquery_topic_followers = ( select( [ - TopicFollower.topic_id, + TopicFollower.topic, func.count(distinct(TopicFollower.follower)).label('followers_stat'), ] ) - .group_by(TopicFollower.topic_id) + .group_by(TopicFollower.topic) .alias() ) diff --git a/tests/query_follows_test.py b/tests/query_follows_test.py index 2701888f..c30034c2 100644 --- a/tests/query_follows_test.py +++ b/tests/query_follows_test.py @@ -48,27 +48,27 @@ def test_query_follows(): expected_queries = [ mock_session.query( mock_Author.id, - mock_ShoutAuthor.author_id, - mock_AuthorFollower.author_id, - mock_AuthorFollower.follower_id, + mock_ShoutAuthor.author, + mock_AuthorFollower.author, + mock_AuthorFollower.follower, ) .select_from(mock_Author) - .outerjoin(mock_ShoutAuthor, mock_Author.id == mock_ShoutAuthor.author_id) - .outerjoin(mock_AuthorFollower, mock_Author.id == mock_AuthorFollower.author_id) + .outerjoin(mock_ShoutAuthor, mock_Author.id == mock_ShoutAuthor.author) + .outerjoin(mock_AuthorFollower, mock_Author.id == mock_AuthorFollower.author) .outerjoin( - mock_AuthorFollower, mock_Author.id == mock_AuthorFollower.follower_id + mock_AuthorFollower, mock_Author.id == mock_AuthorFollower.follower ) .all, mock_session.query( mock_Topic.id, - mock_ShoutTopic.topic_id, - mock_ShoutTopic.topic_id, - mock_TopicFollower.topic_id, + mock_ShoutTopic.topic, + mock_ShoutTopic.topic, + mock_TopicFollower.topic, ) .select_from(mock_Topic) - .outerjoin(mock_ShoutTopic, mock_Topic.id == mock_ShoutTopic.topic_id) - .outerjoin(mock_ShoutTopic, mock_Topic.id == mock_ShoutTopic.topic_id) - .outerjoin(mock_TopicFollower, mock_Topic.id == mock_TopicFollower.topic_id) + .outerjoin(mock_ShoutTopic, mock_Topic.id == mock_ShoutTopic.topic) + .outerjoin(mock_ShoutTopic, mock_Topic.id == mock_ShoutTopic.topic) + .outerjoin(mock_TopicFollower, mock_Topic.id == mock_TopicFollower.topic) .all, ] mock_session.query.assert_has_calls(expected_queries)