1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-12-17 23:24:20 +00:00
royalnet/royalpack/stars/api_poll_list.py

26 lines
683 B
Python
Raw Normal View History

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))