2020-03-23 22:38:37 +01:00
|
|
|
from typing import *
|
|
|
|
from royalnet.utils import *
|
|
|
|
from royalnet.constellation.api import *
|
|
|
|
from ..tables import Poll
|
|
|
|
import uuid
|
|
|
|
|
|
|
|
|
2020-06-22 19:27:11 +02:00
|
|
|
class ApiPollsListStar(ApiStar):
|
|
|
|
path = "/api/poll/list/v2"
|
2020-03-23 22:38:37 +01:00
|
|
|
|
2020-06-22 19:27:11 +02:00
|
|
|
tags = ["poll"]
|
2020-03-23 22:38:37 +01:00
|
|
|
|
2020-06-22 19:27:11 +02:00
|
|
|
async def get(self, data: ApiData) -> JSON:
|
|
|
|
"""Get a list of all polls."""
|
2020-03-23 22:38:37 +01:00
|
|
|
PollT = self.alchemy.get(Poll)
|
|
|
|
|
|
|
|
polls: List[Poll] = await 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))
|