From 5d3cb7b6bf15c9789d37d7621e23ee6ed08695c2 Mon Sep 17 00:00:00 2001 From: Ske Date: Fri, 30 Nov 2018 20:45:04 +0100 Subject: [PATCH] Add basic stats endpoint --- src/api_main.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/api_main.py b/src/api_main.py index d7d37471..87d96f2b 100644 --- a/src/api_main.py +++ b/src/api_main.py @@ -104,6 +104,18 @@ async def get_switch_color(request: web.Request, conn): members, stamp = await utils.get_fronters(conn, system.id) return web.Response(text=members[0].color if members else "#ffffff") +@db_handler +async def get_stats(request: web.Request, conn): + system_count = await db.system_count(conn) + member_count = await db.member_count(conn) + message_count = await db.message_count(conn) + + return web.json_response({ + "systems": system_count, + "members": member_count, + "messages": message_count + }) + app = web.Application() app.add_routes([ web.get("/systems/{id}", get_system), @@ -112,7 +124,8 @@ app.add_routes([ web.get("/systems/{id}/switch/name", get_switch_name), web.get("/systems/{id}/switch/color", get_switch_color), web.get("/members/{id}", get_member), - web.get("/messages/{id}", get_message) + web.get("/messages/{id}", get_message), + web.get("/stats", get_stats) ])