add getTopicAuthors

This commit is contained in:
knst-kotov
2021-12-13 21:05:00 +03:00
parent ab9990a616
commit 64a728de41
4 changed files with 59 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
from orm import Topic, TopicSubscription, TopicStorage, Shout, User
from orm.shout import TopicStat
from orm.shout import TopicStat, ShoutAuthorStorage
from orm.user import UserStorage
from orm.base import local_session
from resolvers.base import mutation, query, subscription
from resolvers.zine import ShoutSubscriptions
@@ -31,6 +32,17 @@ async def topics_by_author(_, info, author):
slugs.update([topic.slug for topic in shout.topics])
return await TopicStorage.get_topics(slugs)
@query.field("getTopicAuthors")
async def topics_by_author(_, info, slug, count, page):
shouts = await TopicStat.get_shouts(slug)
authors = set()
for shout in shouts:
authors.update(await ShoutAuthorStorage.get_authors(shout))
authors = list(authors)
authors.sort() #TODO sort by username
authors = authors[count * page : count * (page + 1) ]
return [await UserStorage.get_user(author) for author in authors]
@mutation.field("createTopic")
@login_required
async def create_topic(_, info, input):