few-more-resolvers

This commit is contained in:
Untone 2023-10-13 13:41:47 +03:00
parent bbd8f61408
commit 85a9077792
2 changed files with 28 additions and 4 deletions

View File

@ -14,7 +14,7 @@ from orm.user import AuthorFollower, Role, User, UserRating, UserRole
# from .community import followed_communities
from services.unread import get_total_unread_counter
from resolvers.topics import followed_by_user
from resolvers.topics import followed_by_user as followed_topics
def add_author_stat_columns(q, full=False):
@ -115,6 +115,7 @@ async def followed_reactions(user_id):
.all()
)
# dufok mod (^*^') :
@query.field("userFollowedTopics")
async def get_followed_topics(_, info, slug) -> List[Topic]:
@ -128,9 +129,6 @@ async def get_followed_topics(_, info, slug) -> List[Topic]:
return await followed_topics(user_id)
async def followed_topics(user_id):
return followed_by_user(user_id)
# dufok mod (^*^') :
@query.field("userFollowedAuthors")
async def get_followed_authors(_, _info, slug) -> List[User]:
@ -144,6 +142,11 @@ async def get_followed_authors(_, _info, slug) -> List[User]:
return await followed_authors(user_id)
@query.field("authorFollowedAuthors")
async def get_followed_authors2(_, info, author_id) -> List[User]:
return await followed_authors(author_id)
# 2. Now, we can use the user_id to get the followed authors
async def followed_authors(user_id):
q = select(User)
@ -262,6 +265,25 @@ async def get_authors_all(_, _info):
return get_authors_from_query(q)
@query.field("getAuthorById")
async def get_author(_, _info, author_id):
q = select(User).where(User.id == author_id)
q = add_author_stat_columns(q)
[author] = get_authors_from_query(q)
with local_session() as session:
comments_count = session.query(Reaction).where(
and_(
Reaction.createdBy == author.id,
Reaction.kind == ReactionKind.COMMENT
)
).count()
author.stat["commented"] = comments_count
return author
@query.field("getAuthor")
async def get_author(_, _info, slug):
q = select(User).where(User.slug == slug)

View File

@ -234,9 +234,11 @@ type Query {
loadDrafts: [Shout]!
loadReactionsBy(by: ReactionBy!, limit: Int, offset: Int): [Reaction]!
userFollowers(slug: String!): [Author]!
authorFollowers(author_id: Int!): [Author]!
userFollowedAuthors(slug: String!): [Author]!
userFollowedTopics(slug: String!): [Topic]!
authorsAll: [Author]!
getAuthorById(author_id: Int!): Author
getAuthor(slug: String!): Author
myFeed(options: LoadShoutsOptions): [Shout]