following manager works

This commit is contained in:
2023-02-20 20:38:20 +03:00
parent a8ad52caba
commit 80030f21b7
6 changed files with 114 additions and 95 deletions

View File

@@ -198,11 +198,15 @@ async def rate_user(_, info, rated_userslug, value):
# for mutation.field("follow")
def author_follow(user_id, slug):
with local_session() as session:
author = session.query(User).where(User.slug == slug).one()
af = AuthorFollower.create(follower=user_id, author=author.id)
session.add(af)
session.commit()
try:
with local_session() as session:
author = session.query(User).where(User.slug == slug).one()
af = AuthorFollower.create(follower=user_id, author=author.id)
session.add(af)
session.commit()
return True
except:
return False
# for mutation.field("unfollow")
@@ -217,14 +221,11 @@ def author_unfollow(user_id, slug):
)
).first()
)
if not flw:
return {
"error": "Follower is not exist, cant unfollow"
}
else:
if flw:
session.delete(flw)
session.commit()
return {}
return True
return False
@query.field("authorsAll")