1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-24 03:54:20 +00:00
royalnet/royalpack/stars/api_diario_latest.py

32 lines
808 B
Python
Raw Normal View History

2020-08-29 22:08:13 +00:00
from typing import *
import royalnet.constellation.api as rca
import royalnet.utils as ru
from ..tables import *
from sqlalchemy import func
class ApiDiarioLatestStar(rca.ApiStar):
path = "/api/diario/latest/v3"
parameters = {
"get": {
"amount": "The number of diario entries to get."
}
}
tags = ["diario"]
@rca.magic
async def get(self, data: rca.ApiData) -> ru.JSON:
"""Get the latest diario entries."""
DiarioT = self.alchemy.get(Diario)
entries: List[Diario] = await ru.asyncify(
data.session
.query(DiarioT)
.order_by(func.random())
.limit(data.int("amount", optional=False))
.all
)
return list(map(lambda e: e.json(), entries))