shoutsRatedByUser only for auth user

This commit is contained in:
knst-kotov 2022-04-29 11:01:04 +03:00
parent 6919b2603c
commit 86383cb6c0
2 changed files with 15 additions and 4 deletions

View File

@ -490,12 +490,18 @@ async def shouts_commented_by_user(_, info, slug, page, size):
return shouts return shouts
@query.field("shoutsRatedByUser") @query.field("shoutsRatedByUser")
async def shouts_rated_by_user(_, info, slug, page, size): @login_required
async def shouts_rated_by_user(_, info, page, size):
user = info.context["request"].user
with local_session() as session: with local_session() as session:
shouts = session.query(Shout).\ shouts = session.query(Shout).\
join(ShoutRating).\ join(ShoutRating).\
where(ShoutRating.rater == slug).\ where(ShoutRating.rater == user.slug).\
order_by(desc(ShoutRating.ts)).\ order_by(desc(ShoutRating.ts)).\
limit(size).\ limit(size).\
offset( (page - 1) * size) offset( (page - 1) * size)
return shouts
return {
"shouts" : shouts
}

View File

@ -50,6 +50,11 @@ type ShoutResult {
shout: Shout shout: Shout
} }
type ShoutsResult {
error: String
shouts: [Shout]
}
type CommentResult { type CommentResult {
error: String error: String
comment: Comment comment: Comment
@ -140,8 +145,8 @@ type Query {
userSubscribers(slug: String!): [User]! userSubscribers(slug: String!): [User]!
userSubscribedTopics(slug: String!): [String]! userSubscribedTopics(slug: String!): [String]!
shoutsRatedByUser(page: Int!, size: Int!): ShoutsResult!
shoutsCommentedByUser(slug: String!, page: Int!, size: Int!): [Shout]! shoutsCommentedByUser(slug: String!, page: Int!, size: Int!): [Shout]!
shoutsRatedByUser(slug: String!, page: Int!, size: Int!): [Shout]!
# shouts # shouts
getShoutBySlug(slug: String!): Shout! getShoutBySlug(slug: String!): Shout!