support-organizer/backend/fgo_request_manager/routes/requests/interact.py

41 lines
1.5 KiB
Python
Raw Normal View History

from flask_smorest import abort
from flask.views import MethodView
2023-11-24 19:50:18 +00:00
from ...database import Database
from ...models.requests import UuidSchema, RequestsInteractionDelete, RequestStatus
from ...models.requestentry import RequestDatabaseEntry
from . import routes_requests as blp
db = Database.get_instance().db
@blp.route("/<string:uuid>")
class InteractRequest(MethodView):
@blp.doc(summary="Returns a specific request by its UID")
@blp.arguments(UuidSchema, location='path', as_kwargs=True)
2023-10-03 16:25:35 +00:00
@blp.response(200, RequestDatabaseEntry, description="Successful operation")
@blp.alt_response(404)
def get(self, uuid):
response = db.at("requests", key=uuid).read()
if response is None:
abort(404, message=f"Request {uuid} does not exist.")
2023-10-03 16:25:35 +00:00
response.update({
"status": RequestStatus(response["status"])
})
return response
@blp.doc(summary="Deletes a specific request by its UID")
@blp.arguments(UuidSchema, location='path', as_kwargs=True)
@blp.response(200, RequestsInteractionDelete, description="Successful operation")
@blp.alt_response(404)
def delete(self, uuid):
if not db.at("requests", key=uuid).exists():
abort(404, message=f"Request {uuid} does not exist.")
with db.at("requests").session() as (session, requests):
del requests[uuid]
session.write()
response = {
2023-10-02 13:29:19 +00:00
"status": RequestStatus.DELETED,
"message": f"Request {uuid} was deleted."
}
return response