add_author_stat-fix+fmt

This commit is contained in:
2024-03-06 12:25:55 +03:00
parent 70589a35da
commit 9f881c0641
15 changed files with 241 additions and 138 deletions

View File

@@ -16,7 +16,11 @@ from resolvers.topic import topic_unfollow
from resolvers.stat import get_with_stat, author_follows_topics, author_follows_authors
from services.auth import login_required
from services.db import local_session
from services.cache import DEFAULT_FOLLOWS, update_follows_for_author, update_followers_for_author
from services.cache import (
DEFAULT_FOLLOWS,
update_follows_for_author,
update_followers_for_author,
)
from services.notify import notify_follower
from services.schema import mutation, query
from services.logger import root_logger as logger
@@ -29,22 +33,30 @@ async def follow(_, info, what, slug):
follows = None
try:
user_id = info.context['user_id']
follower_query = select(Author).select_from(Author).filter(Author.user == user_id)
follower_query = (
select(Author).select_from(Author).filter(Author.user == user_id)
)
[follower] = get_with_stat(follower_query)
if follower:
if what == 'AUTHOR':
if author_unfollow(follower.id, slug):
author_query = select(Author).select_from(Author).where(Author.slug == slug)
author_query = (
select(Author).select_from(Author).where(Author.slug == slug)
)
[author] = get_with_stat(author_query)
if author:
follows = await update_follows_for_author(follower, 'author', author, True)
follows = await update_follows_for_author(
follower, 'author', author, True
)
await update_followers_for_author(follower, author, True)
await notify_follower(follower.dict(), author.id, 'unfollow')
elif what == 'TOPIC':
topic_query = select(Topic).where(Topic.slug == slug)
[topic] = get_with_stat(topic_query)
if topic:
follows = await update_follows_for_author(follower, 'topic', topic, True)
follows = await update_follows_for_author(
follower, 'topic', topic, True
)
topic_unfollow(follower.id, slug)
elif what == 'COMMUNITY':
community_follow(follower.id, slug)
@@ -72,14 +84,20 @@ async def unfollow(_, info, what, slug):
author_query = select(Author).where(Author.slug == slug)
[author] = get_with_stat(author_query)
if author:
await update_follows_for_author(follower, 'author', author, False)
follows = await update_followers_for_author(follower, author, False)
await update_follows_for_author(
follower, 'author', author, False
)
follows = await update_followers_for_author(
follower, author, False
)
await notify_follower(follower.dict(), author.id, 'unfollow')
elif what == 'TOPIC':
topic_query = select(Topic).where(Topic.slug == slug)
[topic] = get_with_stat(topic_query)
if topic:
follows = await update_follows_for_author(follower, 'topic', topic, False)
follows = await update_follows_for_author(
follower, 'topic', topic, False
)
topic_unfollow(follower.id, slug)
elif what == 'COMMUNITY':
community_unfollow(follower.id, slug)