add createTopic and updateTopic; fix create/update Shout
This commit is contained in:
parent
04f2ceb629
commit
1c0e977a60
|
@ -22,7 +22,7 @@ class Topic(Base):
|
||||||
title: str = Column(String, nullable=False, comment="Title")
|
title: str = Column(String, nullable=False, comment="Title")
|
||||||
body: str = Column(String, nullable=True, comment="Body")
|
body: str = Column(String, nullable=True, comment="Body")
|
||||||
pic: str = Column(String, nullable=True, comment="Picture")
|
pic: str = Column(String, nullable=True, comment="Picture")
|
||||||
children = Column(JSONType, nullable=True, comment="list of children topics")
|
children = Column(JSONType, nullable=True, default = [], comment="list of children topics")
|
||||||
community = Column(ForeignKey("community.slug"), nullable=False, comment="Community")
|
community = Column(ForeignKey("community.slug"), nullable=False, comment="Community")
|
||||||
|
|
||||||
class TopicStorage:
|
class TopicStorage:
|
||||||
|
|
|
@ -25,6 +25,33 @@ async def topics_by_author(_, info, author):
|
||||||
slugs.update([topic.slug for topic in shout.topics])
|
slugs.update([topic.slug for topic in shout.topics])
|
||||||
return await TopicStorage.get_topics(slugs)
|
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")
|
@mutation.field("topicSubscribe")
|
||||||
@login_required
|
@login_required
|
||||||
async def topic_subscribe(_, info, slug):
|
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)
|
await ShoutSubscriptions.register_subscription(shouts_queue)
|
||||||
while True:
|
while True:
|
||||||
shout = await shouts_queue.get()
|
shout = await shouts_queue.get()
|
||||||
if topics.intersection(set(shout.topic_ids)):
|
if topics.intersection(set(shout.topic_slugs)):
|
||||||
yield shout
|
yield shout
|
||||||
finally:
|
finally:
|
||||||
await ShoutSubscriptions.del_subscription(shouts_queue)
|
await ShoutSubscriptions.del_subscription(shouts_queue)
|
||||||
|
|
|
@ -249,19 +249,19 @@ async def create_shout(_, info, input):
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
user = session.query(User).filter(User.id == user_id).first()
|
user = session.query(User).filter(User.id == user_id).first()
|
||||||
|
|
||||||
topic_ids = input.get("topic_ids")
|
topic_slugs = input.get("topic_slugs")
|
||||||
del input["topic_ids"]
|
del input["topic_slugs"]
|
||||||
|
|
||||||
new_shout = Shout.create(**input)
|
new_shout = Shout.create(**input)
|
||||||
ShoutAuthor.create(
|
ShoutAuthor.create(
|
||||||
shout = new_shout.id,
|
shout = new_shout.id,
|
||||||
user = user_id)
|
user = user_id)
|
||||||
|
|
||||||
for id in topic_ids:
|
for slug in topic_slugs:
|
||||||
topic = ShoutTopic.create(
|
topic = ShoutTopic.create(
|
||||||
shout = new_shout.id,
|
shout = new_shout.id,
|
||||||
topic = id)
|
topic = slug)
|
||||||
new_shout.topic_ids = topic_ids
|
new_shout.topic_slugs = topic_slugs
|
||||||
|
|
||||||
task = GitTask(
|
task = GitTask(
|
||||||
input,
|
input,
|
||||||
|
@ -305,7 +305,7 @@ async def update_shout(_, info, id, input):
|
||||||
session.commit()
|
session.commit()
|
||||||
session.close()
|
session.close()
|
||||||
|
|
||||||
for topic in input.get("topics"):
|
for topic in input.get("topic_slugs"):
|
||||||
ShoutTopic.create(
|
ShoutTopic.create(
|
||||||
shout = shout.id,
|
shout = shout.id,
|
||||||
topic = topic)
|
topic = topic)
|
||||||
|
|
|
@ -27,7 +27,7 @@ input ShoutInput {
|
||||||
body: String!
|
body: String!
|
||||||
# replyTo: String # another shout
|
# replyTo: String # another shout
|
||||||
# tags: [String] # actual values
|
# tags: [String] # actual values
|
||||||
topic_ids: [Int]
|
topic_slugs: [String]
|
||||||
title: String
|
title: String
|
||||||
subtitle: String
|
subtitle: String
|
||||||
versionOf: String
|
versionOf: String
|
||||||
|
@ -74,6 +74,20 @@ type ChatRoomResult {
|
||||||
room: ChatRoom!
|
room: ChatRoom!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input TopicInput {
|
||||||
|
slug: String!
|
||||||
|
title: String
|
||||||
|
body: String
|
||||||
|
pic: String
|
||||||
|
children: [String]
|
||||||
|
community: String!
|
||||||
|
}
|
||||||
|
|
||||||
|
type TopicResult {
|
||||||
|
error: String
|
||||||
|
topic: Topic
|
||||||
|
}
|
||||||
|
|
||||||
################################### Mutation
|
################################### Mutation
|
||||||
|
|
||||||
type Mutation {
|
type Mutation {
|
||||||
|
@ -106,6 +120,8 @@ type Mutation {
|
||||||
updateProfile(profile: ProfileInput!): Result!
|
updateProfile(profile: ProfileInput!): Result!
|
||||||
|
|
||||||
# topics
|
# topics
|
||||||
|
createTopic(input: TopicInput!): TopicResult!
|
||||||
|
updateTopic(input: TopicInput!): TopicResult!
|
||||||
topicSubscribe(slug: String!): Result!
|
topicSubscribe(slug: String!): Result!
|
||||||
topicUnsubscribe(slug: String!): Result!
|
topicUnsubscribe(slug: String!): Result!
|
||||||
|
|
||||||
|
@ -324,8 +340,7 @@ type Topic {
|
||||||
pic: String
|
pic: String
|
||||||
parents: [String] # NOTE: topic can have parent topics
|
parents: [String] # NOTE: topic can have parent topics
|
||||||
children: [String] # and children
|
children: [String] # and children
|
||||||
cat_id: String
|
community: String!
|
||||||
community: String
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# TODO: resolvers to add/remove topics from publication
|
# TODO: resolvers to add/remove topics from publication
|
||||||
|
|
Loading…
Reference in New Issue
Block a user