unrated shouts query (#110)

Co-authored-by: Igor Lobanov <igor.lobanov@onetwotrip.com>
This commit is contained in:
Igor Lobanov
2023-12-14 19:40:12 +01:00
committed by GitHub
parent f9bc1d67ae
commit f5a3e273a6
2 changed files with 29 additions and 0 deletions

View File

@@ -245,6 +245,34 @@ async def load_random_top_shouts(_, info, params):
return get_shouts_from_query(q)
@query.field("loadUnratedShouts")
async def load_unrated_shouts(_, info, limit):
q = (
select(Shout)
.options(
joinedload(Shout.authors),
joinedload(Shout.topics),
)
.outerjoin(
Reaction,
and_(
Reaction.shout == Shout.id,
Reaction.replyTo.is_(None),
Reaction.kind.in_([ReactionKind.LIKE, ReactionKind.DISLIKE]),
),
)
.where(and_(Shout.deletedAt.is_(None), Shout.layout.is_not(None), Reaction.id.is_(None)))
)
q = add_stat_columns(q)
q = q.group_by(Shout.id).order_by(desc(Shout.createdAt)).limit(limit)
# print(q.compile(compile_kwargs={"literal_binds": True}))
return get_shouts_from_query(q)
@query.field("loadDrafts")
@login_required
async def get_drafts(_, info):