1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 21:44:21 +00:00
royalnet/royalpack/stars/api_diario_get.py

23 lines
793 B
Python
Raw Normal View History

2019-11-11 08:56:08 +00:00
from starlette.requests import Request
from starlette.responses import *
from royalnet.web import *
from royalnet.utils import *
from ..tables import Diario
class ApiDiarioGetStar(PageStar):
path = "/api/diario/get/{diario_id}"
tables = {Diario}
async def page(self, request: Request) -> JSONResponse:
diario_id_str = request.path_params.get("diario_id", "")
try:
diario_id = int(diario_id_str)
except (ValueError, TypeError):
return error(400, "Invalid diario_id")
async with self.alchemy.session_acm() as session:
entry: Diario = await asyncify(session.query(self.alchemy.User).get, diario_id)
if entry is None:
return error(404, "No such user")
return JSONResponse(entry.json())