Add /checkin and /checkout api.
This commit is contained in:
parent
7ccb42e90f
commit
49f5f41d30
30
api/rest.py
30
api/rest.py
|
@ -9,7 +9,7 @@ import datetime
|
||||||
import logging
|
import logging
|
||||||
import typing as T
|
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 bot_z.async_operator import AsyncOperator
|
||||||
from api.async_bot import login, logout, checkin, checkout, status
|
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)
|
return web.json_response({"error": "No session"}, status=404)
|
||||||
res = await logout(op)
|
res = await logout(op)
|
||||||
alog.debug("logout result: %s", res)
|
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)
|
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")
|
@routes.get("/movements")
|
||||||
async def movements_handle(request: web.Request) -> web.Response:
|
async def movements_handle(request: web.Request) -> web.Response:
|
||||||
alog.debug("movements")
|
alog.debug("movements")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user