Add API endpoint to query current fronters (/s/<hid>/fronters)

This commit is contained in:
Bella | Nightshade 2019-03-27 08:45:37 +09:30 committed by Astrid
parent bbb3e66fcb
commit a67ed70539

View File

@ -80,6 +80,24 @@ class Handlers:
return web.json_response([await s.to_json(hid_getter) for s in switches])
async def get_system_fronters(request):
system_id = request.match_info.get("system")
system = await System.get_by_hid(request["conn"], system_id)
if not system:
raise web.HTTPNotFound()
members, stamp = await utils.get_fronters(request["conn"], system.id)
if not stamp:
# No switch has been registered at all
raise web.HTTPNotFound()
data = {
"timestamp": stamp.isoformat(),
"members": [member.to_json() for member in members]
}
return web.json_response(data)
@require_system
async def patch_system(request):
req = await request.json()
@ -203,6 +221,7 @@ async def run():
web.get("/s/{system}", Handlers.get_other_system),
web.get("/s/{system}/members", Handlers.get_system_members),
web.get("/s/{system}/switches", Handlers.get_system_switches),
web.get("/s/{system}/fronters", Handlers.get_system_fronters),
web.patch("/s", Handlers.patch_system),
web.get("/m/{member}", Handlers.get_member),
web.post("/m", Handlers.post_member),