from uuid import uuid4 from flask.views import MethodView import marshmallow as ma from database import Database from . import routes_requests as blp db = Database.get_instance().db class RequestsCreate(ma.Schema): status = ma.fields.String(example="Request 3f6dd2e5-8cb1-4ce0-82e4-b68edf4ce37a was created") uuid = ma.fields.String(example="3f6dd2e5-8cb1-4ce0-82e4-b68edf4ce37a") @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": f"Request {uuid} was created", "uuid": uuid } return response