mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-12-17 23:24:20 +00:00
25 lines
683 B
Python
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))
|