1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00
royalnet/royalpack/stars/api_poll_list.py
2020-06-26 16:13:11 +02:00

25 lines
683 B
Python

from typing import *
import royalnet.constellation.api as rca
import royalnet.utils as ru
from ..tables import Poll
class ApiPollsListStar(rca.ApiStar):
path = "/api/poll/list/v2"
tags = ["poll"]
@rca.magic
async def get(self, data: rca.ApiData) -> ru.JSON:
"""Get a list of all polls."""
PollT = self.alchemy.get(Poll)
polls: List[Poll] = await ru.asyncify(data.session.query(PollT).all)
return list(map(lambda p: {
"id": p.id,
"question": p.question,
"creator": p.creator.json(),
"expires": p.expires.isoformat(),
"created": p.created.isoformat(),
}, polls))