add userComments

This commit is contained in:
knst-kotov 2022-02-16 13:44:26 +03:00
parent 873d05e000
commit 57d9072ba1
2 changed files with 20 additions and 2 deletions

View File

@ -1,10 +1,11 @@
from orm import User, UserRole, Role, UserRating
from orm.user import AuthorSubscription
from orm.user import AuthorSubscription, UserStorage
from orm.comment import Comment
from orm.base import local_session
from resolvers.base import mutation, query, subscription
from auth.authenticate import login_required
from sqlalchemy import func, and_
from sqlalchemy import func, and_, desc
from sqlalchemy.orm import selectinload
import asyncio
@ -48,6 +49,22 @@ async def update_profile(_, info, profile):
return {}
@query.field("userComments")
async def user_comments(_, info, slug, page, size):
user = await UserStorage.get_user_by_slug(slug)
if not user:
return
page = page - 1
with local_session() as session:
comments = session.query(Comment).\
filter(Comment.author == user.id).\
order_by(desc(Comment.createdAt)).\
limit(size).\
offset(page * size)
return comments
@mutation.field("authorSubscribe")
@login_required
async def author_subscribe(_, info, slug):

View File

@ -168,6 +168,7 @@ type Query {
getUsersBySlugs(slugs: [String]!): [User]!
# rateUser(shout: Int): Int!
getUserRoles(slug: String!): [Role]!
userComments(slug: String!, page: Int!, size: Int!): [Comment]!
# messages
enterChat(chatId: String!, size: Int = 50): EnterChatResult!