Add /checkin and /checkout api.

This commit is contained in:
sfigato 2019-08-01 16:17:47 +02:00 committed by blallo
parent 7ccb42e90f
commit 49f5f41d30
Signed by: blallo
GPG Key ID: 0CBE577C9B72DC3F

View File

@ -9,7 +9,7 @@ import datetime
import logging
import typing as T
from aiohttp_session import get_session
from aiohttp_session import get_session, Session
from bot_z.async_operator import AsyncOperator
from api.async_bot import login, logout, checkin, checkout, status
@ -60,8 +60,34 @@ async def logout_handler(request: web.Request) -> web.Response:
return web.json_response({"error": "No session"}, status=404)
res = await logout(op)
alog.debug("logout result: %s", res)
# FIX: assess if better to invalidate session and dump the browser session.
# FIX: assess if better to invalidate session and dump the browser instance.
return web.json_response({"logged_in": res}, status=200)
@routes.post("/checkin")
async def checkin_handler(request: web.Request) -> web.Response:
alog.debug("checkin")
session = await get_session(request)
op = OPERATORS.get(session.get("async_operator"))
if not op:
return web.json_response({"error": "No session"}, status=404)
res = await checkin(op)
alog.debug("checkin result: %s", res)
return web.json_response({"checked_in": res}, status=200)
@routes.post("/checkout")
async def checkout_handler(request: web.Request) -> web.Response:
alog.debug("checkout")
session = await get_session(request)
op = OPERATORS.get(session.get("async_operator"))
if not op:
return web.json_response({"error": "No session"}, status=404)
res = await checkout(op)
alog.debug("checkout result: %s", res)
return web.json_response({"checked_in": res}, status=200)
@routes.get("/movements")
async def movements_handle(request: web.Request) -> web.Response:
alog.debug("movements")