2023-10-01 19:40:06 +00:00
|
|
|
from uuid import uuid4
|
2023-10-01 17:47:35 +00:00
|
|
|
from flask.views import MethodView
|
|
|
|
import marshmallow as ma
|
|
|
|
|
2023-10-01 19:40:06 +00:00
|
|
|
from database import Database
|
2023-10-01 17:47:35 +00:00
|
|
|
from . import routes_requests as blp
|
|
|
|
|
2023-10-01 19:40:06 +00:00
|
|
|
db = Database.get_instance().db
|
2023-10-01 17:47:35 +00:00
|
|
|
|
|
|
|
class RequestsCreate(ma.Schema):
|
2023-10-01 19:40:06 +00:00
|
|
|
status = ma.fields.String(example="Request 3f6dd2e5-8cb1-4ce0-82e4-b68edf4ce37a was created")
|
|
|
|
uuid = ma.fields.String(example="3f6dd2e5-8cb1-4ce0-82e4-b68edf4ce37a")
|
2023-10-01 17:47:35 +00:00
|
|
|
|
|
|
|
@blp.route("/create")
|
|
|
|
class CreateRequest(MethodView):
|
|
|
|
@blp.doc(summary="Create a new request")
|
|
|
|
@blp.response(200, RequestsCreate, description="Successful operation")
|
|
|
|
def post(self):
|
2023-10-01 19:40:06 +00:00
|
|
|
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
|
|
|
|
}
|
2023-10-01 17:47:35 +00:00
|
|
|
return response
|