getTopic, getAuthor

This commit is contained in:
tonyrewin 2022-11-10 09:51:40 +03:00
parent 503d6daa93
commit 1720f00839
3 changed files with 16 additions and 1 deletions

View File

@ -34,7 +34,6 @@ async def get_author_stat(slug):
return {
"followers": session.query(AuthorFollower).where(AuthorFollower.author == slug).count(),
"rating": session.query(func.sum(UserRating.value)).where(UserRating.user == slug).first()
# TODO: debug
}
@ -210,3 +209,10 @@ async def get_authors_all(_, _info):
@query.field("topAuthors")
def get_top_authors(_, _info, offset, limit):
return list(UserStorage.get_top_users())[offset : offset + limit] # type: ignore
@query.field("getAuthor")
async def get_author(_, _info, slug):
a = await UserStorage.users[slug]
a.stat = get_author_stat(slug)
return a

View File

@ -53,6 +53,13 @@ async def topics_by_author(_, _info, author):
return list(author_topics)
@query.field("getTopic")
async def get_topic(_, _info, slug):
t = await TopicStorage.topics[slug]
t.stat = get_topic_stat(slug)
return t
@mutation.field("createTopic")
@login_required
async def create_topic(_, _info, inp):

View File

@ -214,6 +214,7 @@ type Query {
userReactedShouts(slug: String!): [Shout]! # test
getUserRoles(slug: String!): [Role]!
authorsAll: [User]!
getAuthor(slug: String!): User!
# shouts
getShoutBySlug(slug: String!): Shout!
@ -244,6 +245,7 @@ type Query {
markdownBody(body: String!): String!
# topics
getTopic(slug: String!): Topic!
topicsAll: [Topic]!
topicsRandom(amount: Int): [Topic]!
topicsByCommunity(community: String!): [Topic]!