This commit is contained in:
tonyrewin 2022-07-13 18:53:06 +03:00
parent 910f8f59e6
commit 82fe60f764
4 changed files with 42 additions and 23 deletions

View File

@ -129,3 +129,7 @@ def get_subscribed_shout_comments(slug):
all()
slugs = [row.shout for row in rows]
return slugs
def get_top10_comments():
with local_session() as session:
rows = session.query(Comment).limit(10).all()

View File

@ -98,17 +98,18 @@ async def user_comments(_, info, slug, page, size):
return comments
@query.field("userSubscriptions")
@query.field("userSubscribedAuthors")
async def user_subscriptions(_, info, slug):
return _get_user_subscribed_authors(slug)
slugs = _get_user_subscribed_authors(slug)
return slugs
@query.field("userSubscribers")
async def user_subscribers(_, info, slug):
with local_session() as session:
users = session.query(User).\
slugs = session.query(User.slug).\
join(AuthorSubscription, User.slug == AuthorSubscription.subscriber).\
where(AuthorSubscription.author == slug)
return users
return slugs
@query.field("userSubscribedTopics")
async def user_subscribed_topics(_, info, slug):

View File

@ -13,16 +13,21 @@ async def topics_by_slugs(_, info, slugs = None):
with local_session() as session:
topics = await TopicStorage.get_topics(slugs)
all_fields = [node.name.value for node in info.field_nodes[0].selection_set.selections]
if "topicStat" in all_fields:
if "stat" in all_fields:
for topic in topics:
topic.topicStat = await TopicStat.get_stat(topic.slug)
topic.stat = await TopicStat.get_stat(topic.slug)
return topics
@query.field("topicsByCommunity")
async def topics_by_community(_, info, community):
with local_session() as session:
return await TopicStorage.get_topics_by_community(community)
topics = await TopicStorage.get_topics_by_community(community)
all_fields = [node.name.value for node in info.field_nodes[0].selection_set.selections]
if "stat" in all_fields:
for topic in topics:
topic.stat = await TopicStat.get_stat(topic.slug)
return topics
@query.field("topicsByAuthor")
async def topics_by_author(_, info, author):
slugs = set()

View File

@ -159,33 +159,46 @@ type Mutation {
################################### Query
type Query {
# auth
isEmailUsed(email: String!): Boolean!
signIn(email: String!, password: String): AuthResult!
signOut: Result!
forget(email: String!): Result!
requestPasswordReset(email: String!): Result!
updatePassword(password: String!, token: String!): Result!
# profile
userSubscribers(slug: String!): [String]!
userSubscribedAuthors(slug: String!): [String]!
userSubscribedTopics(slug: String!): [String]!
getCurrentUser: UserResult!
getUsersBySlugs(slugs: [String]!): [User]!
getUserRoles(slug: String!): [Role]!
userComments(slug: String!, page: Int!, size: Int!): [Comment]!
userSubscriptions(slug: String!): [User]!
userSubscribers(slug: String!): [User]!
userSubscribedTopics(slug: String!): [String]!
shoutsRatedByUser(page: Int!, size: Int!): ShoutsResult!
shoutsCommentedByUser(slug: String!, page: Int!, size: Int!): [Shout]!
userUnpublishedShouts(page: Int!, size: Int!): ShoutsResult!
# shouts
getShoutBySlug(slug: String!): Shout!
shoutsByTopics(slugs: [String]!, page: Int!, size: Int!): [Shout]!
shoutsByAuthors(slugs: [String]!, page: Int!, size: Int!): [Shout]!
shoutsByCommunities(slugs: [String]!, page: Int!, size: Int!): [Shout]!
shoutsRatedByUser(page: Int!, size: Int!): ShoutsResult!
shoutsReviewed(page: Int!, size: Int!): [Shout]!
userUnpublishedShouts(page: Int!, size: Int!): ShoutsResult!
shoutsCommentedByUser(page: Int!, size: Int!): ShoutsResult!
recentCommented(page: Int!, size: Int!): [Shout]!
# comments
getShoutComments(slug: String!): [Comment]!
getAllComments: [Comment]! # top10
userComments(slug: String!, page: Int!, size: Int!): [Comment]!
# collab
getShoutProposals(slug: String!): [Proposal]!
createProposal(body: String!, range: String): Proposal!
updateProposal(body: String!, range: String): Proposal!
destroyProposal(id: Int!): Result!
inviteAuthor(slug: String!, author: String!): Result!
removeAuthor(slug: String!, author: String!): Result!
# mainpage
topViewed(page: Int!, size: Int!): [Shout]!
@ -197,18 +210,14 @@ type Query {
recentAll(page: Int!, size: Int!): [Shout]!
# topics
topicsAll(slugs: [String]): [Topic]!
topicsAll(page: Int!, size: Int!): [Topic]!
topicsByCommunity(community: String!): [Topic]!
topicsByAuthor(author: String!): [Topic]!
# getOnlineUsers: [User!]!
# communities
getCommunity(slug: String): Community!
getCommunities: [Community]!
shoutsReviewed(page: Int!, size: Int!): [Shout]!
recentCommented(page: Int!, size: Int!): [Shout]!
# TODO: getCommunityMembers(slug: String!): [User]!
}
############################################ Subscription
@ -365,7 +374,7 @@ type Topic {
parents: [String] # NOTE: topic can have parent topics
children: [String] # and children
community: String!
topicStat: TopicStat
stat: TopicStat
oid: String
}