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
|
|
|
|
|
2023-11-24 19:50:18 +00:00
|
|
|
from ...database import Database
|
|
|
|
from ...models.requests import RequestsCreate, RequestStatus
|
|
|
|
from ...models.requestentry import RequestPostData
|
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
|
|
|
|
|
|
|
@blp.route("/create")
|
|
|
|
class CreateRequest(MethodView):
|
|
|
|
@blp.doc(summary="Create a new request")
|
2023-10-03 16:25:35 +00:00
|
|
|
@blp.arguments(RequestPostData)
|
2023-10-01 17:47:35 +00:00
|
|
|
@blp.response(200, RequestsCreate, description="Successful operation")
|
2023-10-02 18:18:21 +00:00
|
|
|
def post(self, data):
|
|
|
|
print(data)
|
2023-10-01 19:40:06 +00:00
|
|
|
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
|
2023-10-01 19:40:06 +00:00
|
|
|
session.write()
|
|
|
|
response = {
|
2023-10-02 13:29:19 +00:00
|
|
|
"status": RequestStatus.CREATED,
|
|
|
|
"message": f"Request {uuid} was created",
|
2023-10-01 19:40:06 +00:00
|
|
|
"uuid": uuid
|
|
|
|
}
|
2023-10-01 17:47:35 +00:00
|
|
|
return response
|