my-subs-fix
All checks were successful
deploy / deploy (push) Successful in 2m6s

This commit is contained in:
Untone 2023-11-24 04:13:55 +03:00
parent 7257f52aeb
commit 167eed436d
3 changed files with 33 additions and 5 deletions

View File

@ -20,7 +20,7 @@ from resolvers.topic import (
) )
from resolvers.follower import follow, unfollow from resolvers.follower import follow, unfollow
from resolvers.reader import load_shout, load_shouts_by, search from resolvers.reader import load_shout, load_shouts_by, search, load_my_subscriptions
from resolvers.community import get_community, get_communities_all from resolvers.community import get_community, get_communities_all
__all__ = [ __all__ = [
@ -33,6 +33,8 @@ __all__ = [
"load_shout", "load_shout",
"load_shouts_by", "load_shouts_by",
"rate_author", "rate_author",
"load_my_subscriptions",
"search",
# follower # follower
"follow", "follow",
"unfollow", "unfollow",
@ -57,6 +59,4 @@ __all__ = [
# community # community
"get_community", "get_community",
"get_communities_all", "get_communities_all",
# search
"search",
] ]

View File

@ -254,3 +254,30 @@ async def search(_, info, text, limit=50, offset=0):
return SearchService.search(text, limit, offset) return SearchService.search(text, limit, offset)
else: else:
return [] return []
@query.field("loadMySubscriptions")
@login_required
async def load_my_subscriptions(_, info):
user_id = info.context["user_id"]
with local_session() as session:
author = session.query(Author).filter(Author.user == user_id).first()
authors_query = (
select(User)
.join(AuthorFollower, AuthorFollower.author == User.id)
.where(AuthorFollower.follower == author.id)
)
topics_query = select(Topic).join(TopicFollower).where(TopicFollower.follower == author.id)
topics = []
authors = []
for [author] in session.execute(authors_query):
authors.append(author)
for [topic] in session.execute(topics_query):
topics.append(topic)
return {"topics": topics, "authors": authors}

View File

@ -314,8 +314,11 @@ type Query {
loadShout(slug: String, shout_id: Int): Shout loadShout(slug: String, shout_id: Int): Shout
loadShouts(options: LoadShoutsOptions): [Shout] loadShouts(options: LoadShoutsOptions): [Shout]
loadFeed(options: LoadShoutsOptions): [Shout] loadFeed(options: LoadShoutsOptions): [Shout]
loadMySubscriptions: Result
loadDrafts: [Shout] loadDrafts: [Shout]
search(text: String!, limit: Int, offset: Int): [Shout]
loadReactionsBy(by: ReactionBy!, limit: Int, offset: Int): [Reaction] loadReactionsBy(by: ReactionBy!, limit: Int, offset: Int): [Reaction]
followedReactions(follower_id: Int!): [Shout] followedReactions(follower_id: Int!): [Shout]
@ -334,6 +337,4 @@ type Query {
communitiesAll: [Community] communitiesAll: [Community]
getCommunity: Community getCommunity: Community
search(text: String!, limit: Int, offset: Int): [Shout]
} }