From ed9c42a8711c7278224bee52aeae7dd39afff331 Mon Sep 17 00:00:00 2001 From: Untone Date: Fri, 3 Sep 2021 10:16:19 +0300 Subject: [PATCH] new queries --- auth/README.md | 9 --------- resolvers/zine.py | 22 +++++++++++++++++++++- 2 files changed, 21 insertions(+), 10 deletions(-) delete mode 100644 auth/README.md diff --git a/auth/README.md b/auth/README.md deleted file mode 100644 index 8629a3d9..00000000 --- a/auth/README.md +++ /dev/null @@ -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 diff --git a/resolvers/zine.py b/resolvers/zine.py index e8bd40a4..2525b65c 100644 --- a/resolvers/zine.py +++ b/resolvers/zine.py @@ -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 \ No newline at end of file