update topics logix
This commit is contained in:
@@ -2,6 +2,7 @@ from resolvers.auth import login, sign_out, is_email_free, register, confirm
|
||||
from resolvers.inbox import create_message, delete_message, update_message, get_messages
|
||||
from resolvers.zine import create_shout, get_shout_by_slug
|
||||
from resolvers.profile import get_user_by_slug, get_current_user
|
||||
from resolvers.topics import topic_subscribe, topic_unsubscribe, topics_by_author, topics_by_community, topics_by_slugs
|
||||
|
||||
__all__ = [
|
||||
"login",
|
||||
@@ -17,5 +18,10 @@ __all__ = [
|
||||
"create_shout",
|
||||
"get_current_user",
|
||||
"get_user_by_slug",
|
||||
"get_shout_by_slug"
|
||||
"get_shout_by_slug",
|
||||
"topics_by_slugs",
|
||||
"topics_by_community",
|
||||
"topics_by_author",
|
||||
"topic_subscribe",
|
||||
"topic_unsubscribe"
|
||||
]
|
||||
|
45
resolvers/topics.py
Normal file
45
resolvers/topics.py
Normal file
@@ -0,0 +1,45 @@
|
||||
from orm import Topic, TopicSubscription
|
||||
from orm.base import local_session
|
||||
from resolvers.base import mutation, query, subscription
|
||||
from auth.authenticate import login_required
|
||||
import asyncio
|
||||
|
||||
@query.field("topicsBySlugs")
|
||||
async def topics_by_slugs(_, info, slugs):
|
||||
topics = []
|
||||
with local_session() as session:
|
||||
topics = session.query(Topic).filter(Topic.slug in slugs)
|
||||
return topics
|
||||
|
||||
@query.field("topicsByCommunity")
|
||||
async def topics_by_community(_, info, community):
|
||||
topics = []
|
||||
with local_session() as session:
|
||||
topics = session.query(Topic).filter(Topic.community == community)
|
||||
return topics
|
||||
|
||||
@query.field("topicsByAuthor")
|
||||
async def topics_by_author(_, info, author):
|
||||
topics = []
|
||||
with local_session() as session:
|
||||
topics = session.query(Topic).filter(Topic.community == community)
|
||||
return topics
|
||||
|
||||
@mutation.field("topicSubscribe")
|
||||
@login_required
|
||||
async def topic_subscribe(_, info, slug):
|
||||
auth = info.context["request"].auth
|
||||
user_id = auth.user_id
|
||||
sub = TopicSubscription.create({ user: user_id, topic: slug })
|
||||
return {} # type Result
|
||||
|
||||
@mutation.field("topicUnsubscribe")
|
||||
@login_required
|
||||
async def topic_unsubscribe(_, info, slug):
|
||||
auth = info.context["request"].auth
|
||||
user_id = auth.user_id
|
||||
sub = session.query(TopicSubscription).filter(TopicSubscription.user == user_id and TopicSubscription.topic == slug).first()
|
||||
with local_session() as session:
|
||||
session.delete(sub)
|
||||
return {} # type Result
|
||||
return { "error": "session error" }
|
Reference in New Issue
Block a user