topicsBySlugs and topicsByAuthor
This commit is contained in:
parent
a43055ddd9
commit
705731aa0e
|
@ -1,4 +1,4 @@
|
||||||
from orm import Topic, TopicSubscription
|
from orm import Topic, TopicSubscription, Shout, User
|
||||||
from orm.base import local_session
|
from orm.base import local_session
|
||||||
from resolvers.base import mutation, query, subscription
|
from resolvers.base import mutation, query, subscription
|
||||||
from resolvers.zine import ShoutSubscriptions
|
from resolvers.zine import ShoutSubscriptions
|
||||||
|
@ -17,7 +17,7 @@ async def topics_all(_, info):
|
||||||
async def topics_by_slugs(_, info, slugs):
|
async def topics_by_slugs(_, info, slugs):
|
||||||
topics = []
|
topics = []
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
topics = session.query(Topic).filter(Topic.slug in slugs)
|
topics = session.query(Topic).filter(Topic.slug.in_(slugs))
|
||||||
return topics
|
return topics
|
||||||
|
|
||||||
@query.field("topicsByCommunity")
|
@query.field("topicsByCommunity")
|
||||||
|
@ -29,12 +29,13 @@ async def topics_by_community(_, info, community):
|
||||||
|
|
||||||
@query.field("topicsByAuthor")
|
@query.field("topicsByAuthor")
|
||||||
async def topics_by_author(_, info, author):
|
async def topics_by_author(_, info, author):
|
||||||
topics = []
|
topics = {}
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
author_shouts = session.query(Shout).filter(author in Shout.authors)
|
shouts = session.query(Shout).\
|
||||||
# TODO: all the topics from author_shouts
|
filter(Shout.authors.any(User.slug == author))
|
||||||
topics = []
|
for shout in shouts:
|
||||||
return topics
|
topics.update(dict([(topic.slug, topic) for topic in shout.topics]))
|
||||||
|
return topics.values()
|
||||||
|
|
||||||
@mutation.field("topicSubscribe")
|
@mutation.field("topicSubscribe")
|
||||||
@login_required
|
@login_required
|
||||||
|
|
Loading…
Reference in New Issue
Block a user