This commit is contained in:
@@ -20,7 +20,7 @@ from resolvers.topic import (
|
||||
)
|
||||
|
||||
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
|
||||
|
||||
__all__ = [
|
||||
@@ -33,6 +33,8 @@ __all__ = [
|
||||
"load_shout",
|
||||
"load_shouts_by",
|
||||
"rate_author",
|
||||
"load_my_subscriptions",
|
||||
"search",
|
||||
# follower
|
||||
"follow",
|
||||
"unfollow",
|
||||
@@ -57,6 +59,4 @@ __all__ = [
|
||||
# community
|
||||
"get_community",
|
||||
"get_communities_all",
|
||||
# search
|
||||
"search",
|
||||
]
|
||||
|
@@ -254,3 +254,30 @@ async def search(_, info, text, limit=50, offset=0):
|
||||
return SearchService.search(text, limit, offset)
|
||||
else:
|
||||
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}
|
||||
|
Reference in New Issue
Block a user