support-organizer/backend/src/routes/requests/create.py

32 lines
975 B
Python
Raw Normal View History

from uuid import uuid4
from flask.views import MethodView
from database import Database
2023-10-02 13:29:19 +00:00
from models.requests import RequestsCreate, RequestStatus
2023-10-02 18:18:21 +00:00
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")
2023-10-03 16:25:35 +00:00
@blp.arguments(RequestPostData)
@blp.response(200, RequestsCreate, description="Successful operation")
2023-10-02 18:18:21 +00:00
def post(self, data):
print(data)
uuid = str(uuid4())
with db.at("requests").session() as (session, requests):
2023-10-03 16:25:35 +00:00
data.update({
"status": RequestStatus.ACTIVE,
"uuid": uuid
})
requests[uuid] = data
session.write()
response = {
2023-10-02 13:29:19 +00:00
"status": RequestStatus.CREATED,
"message": f"Request {uuid} was created",
"uuid": uuid
}
return response