add shoutsByUserRatingOrComment
This commit is contained in:
parent
68f7733f91
commit
073c5252c3
|
@ -104,6 +104,14 @@ class UserStorage:
|
|||
async with self.lock:
|
||||
return self.users.get(id)
|
||||
|
||||
@staticmethod
|
||||
async def get_user_by_slug(slug):
|
||||
self = UserStorage
|
||||
async with self.lock:
|
||||
for user in self.users.values():
|
||||
if user.slug == slug:
|
||||
return user
|
||||
|
||||
@staticmethod
|
||||
async def add_user(user):
|
||||
self = UserStorage
|
||||
|
|
|
@ -396,3 +396,23 @@ async def shouts_by_community(_, info, community, page, size):
|
|||
limit(size).\
|
||||
offset(page * size)
|
||||
return shouts
|
||||
|
||||
@query.field("shoutsByUserRatingOrComment")
|
||||
async def shouts_by_user_rating_or_comment(_, info, userSlug, page, size):
|
||||
user = await UserStorage.get_user_by_slug(userSlug)
|
||||
if not user:
|
||||
return
|
||||
|
||||
with local_session() as session:
|
||||
shouts_by_rating = session.query(Shout).\
|
||||
join(ShoutRating).\
|
||||
where(and_(Shout.publishedAt != None, ShoutRating.rater == userSlug))
|
||||
shouts_by_comment = session.query(Shout).\
|
||||
join(Comment).\
|
||||
where(and_(Shout.publishedAt != None, Comment.author == user.id))
|
||||
shouts = shouts_by_rating.union(shouts_by_comment).\
|
||||
order_by(desc(Shout.publishedAt)).\
|
||||
limit(size).\
|
||||
offset( (page - 1) * size)
|
||||
|
||||
return shouts
|
||||
|
|
|
@ -196,6 +196,9 @@ type Query {
|
|||
# communities
|
||||
getCommunity(slug: String): Community!
|
||||
getCommunities: [Community]!
|
||||
|
||||
# shoutsByUserSubscriptions(): [Shout]!
|
||||
shoutsByUserRatingOrComment(userSlug: String!, page: Int!, size: Int!): [Shout]!
|
||||
}
|
||||
|
||||
############################################ Subscription
|
||||
|
|
Loading…
Reference in New Issue
Block a user