from uuid import uuid4 from flask.views import MethodView from database import Database from models.requests import RequestsCreate, RequestStatus 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.response(200, RequestsCreate, description="Successful operation") def post(self): uuid = str(uuid4()) with db.at("requests").session() as (session, requests): requests[uuid] = { "status": "created" } session.write() response = { "status": RequestStatus.CREATED, "message": f"Request {uuid} was created", "uuid": uuid } return response