new queries

This commit is contained in:
Untone 2021-09-03 10:16:19 +03:00
parent a8d3ffd5e6
commit ed9c42a871
2 changed files with 21 additions and 10 deletions

View File

@ -1,9 +0,0 @@
## Based on
- pyjwt
- [ariadne](https://github.com/mirumee/ariadne)
- [aioredis](https://github.com/aio-libs/aioredis)
- [starlette](https://github.com/encode/starlette)、
- sqlalchmy ORM
token is valid for one day, user can choose to logout, logout is revoke token

View File

@ -173,4 +173,24 @@ async def update_shout(_, info, id, input):
"shout" : shout
}
# TODO: paginate, get, update, delete
# TODO: get shout with comments query
@query.field("getShout")
async def get_shout(_, info, shout_slug):
month_ago = datetime.now() - timedelta(days = 30)
with local_session() as session:
stmt = select(Shout, func.sum(ShoutRating.value).label("rating")).\
join(ShoutRating).\
where(ShoutRating.ts > month_ago).\
# where(Shout.replyTo == shout_slug).\
# join(ShoutComment)
group_by(Shout.id).\
order_by(desc("rating")).\
limit(limit)
shouts = []
for row in session.execute(stmt):
shout = row.Shout
shout.rating = row.rating
shout.comments
shouts.append(shout)
return shout