From f93b17cead813936c0fb0c91d5454861dd4e0448 Mon Sep 17 00:00:00 2001 From: knst-kotov Date: Thu, 23 Jun 2022 11:39:00 +0300 Subject: [PATCH] remove CommentSubscription; fix subscribe/unsibscribe method --- orm/__init__.py | 2 +- orm/shout.py | 8 -------- resolvers/collab.py | 4 ++-- resolvers/comments.py | 16 ---------------- resolvers/editor.py | 4 +--- resolvers/zine.py | 25 ++++++++++--------------- 6 files changed, 14 insertions(+), 45 deletions(-) diff --git a/orm/__init__.py b/orm/__init__.py index 0f37ca12..958a9310 100644 --- a/orm/__init__.py +++ b/orm/__init__.py @@ -4,7 +4,7 @@ from orm.user import User, UserRating, UserRole, UserStorage from orm.topic import Topic, TopicSubscription, TopicStorage from orm.notification import Notification from orm.shout import Shout, ShoutAuthor, ShoutTopic, ShoutRating, ShoutViewByDay,\ - ShoutRatingStorage, ShoutViewStorage, ShoutCommentsSubscription + ShoutRatingStorage, ShoutViewStorage from orm.base import Base, engine, local_session from orm.comment import Comment, CommentRating #, CommentRatingStorage from orm.proposal import Proposal, ProposalRating #, ProposalRatingStorage diff --git a/orm/shout.py b/orm/shout.py index de6f1d6b..0631c7bc 100644 --- a/orm/shout.py +++ b/orm/shout.py @@ -11,14 +11,6 @@ from functools import reduce import asyncio -class ShoutCommentsSubscription(Base): - __tablename__ = "shout_comments_subscription" - - id = None - subscriber = Column(ForeignKey('user.slug'), primary_key = True) - shout = Column(ForeignKey('shout.slug'), primary_key = True) - createdAt: str = Column(DateTime, nullable=False, default = datetime.now, comment="Created at") - class ShoutAuthor(Base): __tablename__ = "shout_author" diff --git a/resolvers/collab.py b/resolvers/collab.py index 8131cc51..ecfc14ef 100644 --- a/resolvers/collab.py +++ b/resolvers/collab.py @@ -219,7 +219,7 @@ async def invite_author(_, author_slug, shout): @mutation.field("removeAuthor") @login_required -async def invite_author(_, author_slug, shout): +async def remove_author(_, author_slug, shout): auth = info.context["request"].auth user_id = auth.user_id @@ -241,4 +241,4 @@ async def invite_author(_, author_slug, shout): # TODO: email notify - return {} \ No newline at end of file + return {} diff --git a/resolvers/comments.py b/resolvers/comments.py index 29a4163c..ee41a814 100644 --- a/resolvers/comments.py +++ b/resolvers/comments.py @@ -1,6 +1,5 @@ from orm import Comment, CommentRating from orm.base import local_session -from orm.shout import ShoutCommentsSubscription from resolvers.base import mutation, query, subscription from auth.authenticate import login_required import asyncio @@ -41,21 +40,6 @@ class ShoutCommentsStorage: if comment_result.comment.shout == subs.shout_slug: subs.queue.put_nowait(comment_result) -def comments_subscribe(user, slug): - ShoutCommentsSubscription.create( - subscriber = user.slug, - shout = slug) - -def comments_unsubscribe(user, slug): - with local_session() as session: - sub = session.query(ShoutCommentsSubscription).\ - filter(and_(ShoutCommentsSubscription.subscriber == user.slug, ShoutCommentsSubscription.shout == slug)).\ - first() - if not sub: - raise Exception("subscription not exist") - session.delete(sub) - session.commit() - @mutation.field("createComment") @login_required async def create_comment(_, info, body, shout, replyTo = None): diff --git a/resolvers/editor.py b/resolvers/editor.py index 86e7654c..670cd4e1 100644 --- a/resolvers/editor.py +++ b/resolvers/editor.py @@ -35,8 +35,6 @@ async def create_shout(_, info, input): user.email, "new shout %s" % (new_shout.slug) ) - - await ShoutCommentsStorage.send_shout(new_shout) return { "shout" : new_shout @@ -106,4 +104,4 @@ async def delete_shout(_, info, slug): shout.deletedAt = datetime.now() session.commit() - return {} \ No newline at end of file + return {} diff --git a/resolvers/zine.py b/resolvers/zine.py index 9a94872c..27916de5 100644 --- a/resolvers/zine.py +++ b/resolvers/zine.py @@ -1,13 +1,12 @@ from orm import Shout, ShoutAuthor, ShoutTopic, ShoutRating, ShoutViewByDay, \ User, Community, Resource, ShoutRatingStorage, ShoutViewStorage, \ - Comment, CommentRating, Topic, ShoutCommentsSubscription + Comment, CommentRating, Topic from orm.community import CommunitySubscription from orm.base import local_session from orm.user import UserStorage, AuthorSubscription from orm.topic import TopicSubscription from resolvers.base import mutation, query -from resolvers.comments import comments_subscribe, comments_unsubscribe from auth.authenticate import login_required from settings import SHOUTS_REPO @@ -315,18 +314,16 @@ async def shouts_by_communities(_, info, slugs, page, size): @mutation.field("subscribe") @login_required -async def subscribe(_, info, subscription, slug): +async def subscribe(_, info, what, slug): user = info.context["request"].user try: - if subscription == "AUTHOR": + if what == "AUTHOR": author_subscribe(user, slug) - elif subscription == "TOPIC": + elif what == "TOPIC": topic_subscribe(user, slug) - elif subscription == "COMMUNITY": + elif what == "COMMUNITY": community_subscribe(user, slug) - elif comments_subscription == "COMMENTS": - comments_subscribe(user, slug) except Exception as e: return {"error" : e} @@ -334,18 +331,16 @@ async def subscribe(_, info, subscription, slug): @mutation.field("unsubscribe") @login_required -async def unsubscribe(_, info, subscription, slug): +async def unsubscribe(_, info, what, slug): user = info.context["request"].user try: - if subscription == "AUTHOR": + if what == "AUTHOR": author_unsubscribe(user, slug) - elif subscription == "TOPIC": + elif what == "TOPIC": topic_unsubscribe(user, slug) - elif subscription == "COMMUNITY": + elif what == "COMMUNITY": community_unsubscribe(user, slug) - elif subscription == "COMMENTS": - comments_unsubscribe(user, slug) except Exception as e: return {"error" : e} @@ -374,4 +369,4 @@ async def rate_shout(_, info, slug, value): await ShoutRatingStorage.update_rating(rating) - return {"error" : ""} \ No newline at end of file + return {"error" : ""}