add createTopic and updateTopic; fix create/update Shout
This commit is contained in:
@@ -25,6 +25,33 @@ async def topics_by_author(_, info, author):
|
||||
slugs.update([topic.slug for topic in shout.topics])
|
||||
return await TopicStorage.get_topics(slugs)
|
||||
|
||||
@mutation.field("createTopic")
|
||||
@login_required
|
||||
async def create_topic(_, info, input):
|
||||
new_topic = Topic.create(**input)
|
||||
await TopicStorage.add_topic(new_topic)
|
||||
|
||||
return { "topic" : new_topic }
|
||||
|
||||
@mutation.field("updateTopic")
|
||||
@login_required
|
||||
async def update_topic(_, info, input):
|
||||
slug = input["slug"]
|
||||
|
||||
session = local_session()
|
||||
topic = session.query(Topic).filter(Topic.slug == slug).first()
|
||||
|
||||
if not topic:
|
||||
return { "error" : "topic not found" }
|
||||
|
||||
topic.update(input)
|
||||
session.commit()
|
||||
session.close()
|
||||
|
||||
await TopicStorage.add_topic(topic)
|
||||
|
||||
return { "topic" : topic }
|
||||
|
||||
@mutation.field("topicSubscribe")
|
||||
@login_required
|
||||
async def topic_subscribe(_, info, slug):
|
||||
@@ -54,7 +81,7 @@ async def new_shout_generator(obj, info, user_id):
|
||||
await ShoutSubscriptions.register_subscription(shouts_queue)
|
||||
while True:
|
||||
shout = await shouts_queue.get()
|
||||
if topics.intersection(set(shout.topic_ids)):
|
||||
if topics.intersection(set(shout.topic_slugs)):
|
||||
yield shout
|
||||
finally:
|
||||
await ShoutSubscriptions.del_subscription(shouts_queue)
|
||||
|
@@ -249,19 +249,19 @@ async def create_shout(_, info, input):
|
||||
with local_session() as session:
|
||||
user = session.query(User).filter(User.id == user_id).first()
|
||||
|
||||
topic_ids = input.get("topic_ids")
|
||||
del input["topic_ids"]
|
||||
topic_slugs = input.get("topic_slugs")
|
||||
del input["topic_slugs"]
|
||||
|
||||
new_shout = Shout.create(**input)
|
||||
ShoutAuthor.create(
|
||||
shout = new_shout.id,
|
||||
user = user_id)
|
||||
|
||||
for id in topic_ids:
|
||||
for slug in topic_slugs:
|
||||
topic = ShoutTopic.create(
|
||||
shout = new_shout.id,
|
||||
topic = id)
|
||||
new_shout.topic_ids = topic_ids
|
||||
topic = slug)
|
||||
new_shout.topic_slugs = topic_slugs
|
||||
|
||||
task = GitTask(
|
||||
input,
|
||||
@@ -305,7 +305,7 @@ async def update_shout(_, info, id, input):
|
||||
session.commit()
|
||||
session.close()
|
||||
|
||||
for topic in input.get("topics"):
|
||||
for topic in input.get("topic_slugs"):
|
||||
ShoutTopic.create(
|
||||
shout = shout.id,
|
||||
topic = topic)
|
||||
|
Reference in New Issue
Block a user