add getShoutComments
This commit is contained in:
parent
bf4df89bad
commit
ea8fffc25d
|
@ -1,6 +1,7 @@
|
||||||
from orm import Shout, ShoutAuthor, ShoutTopic, ShoutRating, ShoutViewByDay, User, Community, Resource,\
|
from orm import Shout, ShoutAuthor, ShoutTopic, ShoutRating, ShoutViewByDay, User, Community, Resource,\
|
||||||
ShoutRatingStorage, ShoutViewStorage
|
ShoutRatingStorage, ShoutViewStorage, Comment, CommentRating
|
||||||
from orm.base import local_session
|
from orm.base import local_session
|
||||||
|
from orm.user import UserStorage
|
||||||
|
|
||||||
from resolvers.base import mutation, query
|
from resolvers.base import mutation, query
|
||||||
|
|
||||||
|
@ -363,3 +364,18 @@ async def get_shout_by_slug(_, info, slug):
|
||||||
shout.rating = await ShoutRatingStorage.get_rating(shout.id)
|
shout.rating = await ShoutRatingStorage.get_rating(shout.id)
|
||||||
shout.views = await ShoutViewStorage.get_view(shout.id)
|
shout.views = await ShoutViewStorage.get_view(shout.id)
|
||||||
return shout
|
return shout
|
||||||
|
|
||||||
|
@query.field("getShoutComments")
|
||||||
|
async def get_shout_comments(_, info, shout_id):
|
||||||
|
with local_session() as session:
|
||||||
|
rows = session.query(Comment, func.sum(CommentRating.value).label("rating")).\
|
||||||
|
join(CommentRating).\
|
||||||
|
where(Comment.shout == shout_id).\
|
||||||
|
group_by(Comment.id).all()
|
||||||
|
comments = []
|
||||||
|
for row in rows:
|
||||||
|
comment = row.Comment
|
||||||
|
comment.author = await UserStorage.get_user(comment.author)
|
||||||
|
comment.rating = row.rating
|
||||||
|
comments.append(comment)
|
||||||
|
return comments
|
||||||
|
|
|
@ -136,10 +136,11 @@ type Query {
|
||||||
getMessages(count: Int = 100, page: Int = 1): [Message!]!
|
getMessages(count: Int = 100, page: Int = 1): [Message!]!
|
||||||
|
|
||||||
# shouts
|
# shouts
|
||||||
getShoutBySlug(slug: String!): Shout! # NOTE: with .comments: Comments[]
|
getShoutBySlug(slug: String!): Shout!
|
||||||
shoutsByTopic(topic: String!, limit: Int!): [Shout]!
|
shoutsByTopic(topic: String!, limit: Int!): [Shout]!
|
||||||
shoutsByAuthor(author: String!, limit: Int!): [Shout]!
|
shoutsByAuthor(author: String!, limit: Int!): [Shout]!
|
||||||
shoutsByCommunity(community: String!, limit: Int!): [Shout]!
|
shoutsByCommunity(community: String!, limit: Int!): [Shout]!
|
||||||
|
getShoutComments(shout_id: Int!): [Comment]!
|
||||||
|
|
||||||
# mainpage
|
# mainpage
|
||||||
topViewed(limit: Int): [Shout]!
|
topViewed(limit: Int): [Shout]!
|
||||||
|
|
Loading…
Reference in New Issue
Block a user