2020-03-23 21:38:37 +00:00
|
|
|
from typing import *
|
2020-06-26 14:13:11 +00:00
|
|
|
import royalnet.constellation.api as rca
|
|
|
|
import royalnet.utils as ru
|
2020-03-23 21:38:37 +00:00
|
|
|
from ..tables import Poll
|
|
|
|
|
|
|
|
|
2020-06-26 14:13:11 +00:00
|
|
|
class ApiPollsListStar(rca.ApiStar):
|
2020-06-22 17:27:11 +00:00
|
|
|
path = "/api/poll/list/v2"
|
2020-03-23 21:38:37 +00:00
|
|
|
|
2020-06-22 17:27:11 +00:00
|
|
|
tags = ["poll"]
|
2020-03-23 21:38:37 +00:00
|
|
|
|
2020-06-26 14:13:11 +00:00
|
|
|
@rca.magic
|
|
|
|
async def get(self, data: rca.ApiData) -> ru.JSON:
|
2020-06-22 17:27:11 +00:00
|
|
|
"""Get a list of all polls."""
|
2020-03-23 21:38:37 +00:00
|
|
|
PollT = self.alchemy.get(Poll)
|
|
|
|
|
2020-06-26 14:13:11 +00:00
|
|
|
polls: List[Poll] = await ru.asyncify(data.session.query(PollT).all)
|
2020-03-23 21:38:37 +00:00
|
|
|
|
|
|
|
return list(map(lambda p: {
|
|
|
|
"id": p.id,
|
|
|
|
"question": p.question,
|
|
|
|
"creator": p.creator.json(),
|
|
|
|
"expires": p.expires.isoformat(),
|
|
|
|
"created": p.created.isoformat(),
|
|
|
|
}, polls))
|