1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-12-18 07:34:20 +00:00
royalnet/royalpack/stars/api_polls_create.py

42 lines
1 KiB
Python
Raw Normal View History

2020-03-23 21:38:37 +00:00
from typing import *
import datetime
import uuid
from royalnet.utils import *
from royalnet.constellation.api import *
from ..tables import Poll
class ApiPollsCreate(ApiStar):
path = "/api/polls/create/v1"
summary = "Create a new poll."
parameters = {
"question": "The question to ask in the poll.",
"description": "A longer Markdown-formatted description.",
"expires": "A ISO timestamp of the expiration date for the poll.",
}
requires_auth = True
methods = ["POST"]
tags = ["polls"]
async def api(self, data: ApiData) -> JSON:
PollT = self.alchemy.get(Poll)
poll = PollT(
id=uuid.uuid4(),
creator=await data.user(),
created=datetime.datetime.now(),
expires=datetime.datetime.fromisoformat(data["expires"]) if "expires" in data else None,
question=data["question"],
description=data.get("description"),
)
data.session.add(poll)
await data.session_commit()
return poll.json()