support-organizer/backend/fgo_request_manager/routes/requests/create.py
Firq 03901e1d12
All checks were successful
/ build:package (push) Successful in 11s
/ backend-pylint (push) Successful in 21s
updated package to conform to pylint
2023-12-21 17:11:47 +01:00

32 lines
984 B
Python

from uuid import uuid4
from flask.views import MethodView
from ...database import Database
from ...models.requests import RequestsCreate, RequestStatus
from ...models.requestentry import RequestPostData
from . import routes_requests as blp
db = Database.get_instance().db
@blp.route("/create")
class CreateRequest(MethodView):
@blp.doc(summary="Create a new request")
@blp.arguments(RequestPostData)
@blp.response(200, RequestsCreate, description="Successful operation")
def post(self, data):
print(data)
uuid = str(uuid4())
with db.at("requests").session() as (session, requests):
data.update({
"status": RequestStatus.ACTIVE,
"uuid": uuid
})
requests[uuid] = data
session.write()
response = {
"status": RequestStatus.CREATED,
"message": f"Request {uuid} was created",
"uuid": uuid
}
return response