support-organizer/backend/fgo_request_manager/routes/requests/interact.py
Firq 03901e1d12
All checks were successful
/ build:package (push) Successful in 11s
/ backend-pylint (push) Successful in 21s
updated package to conform to pylint
2023-12-21 17:11:47 +01:00

41 lines
1.5 KiB
Python

from flask_smorest import abort
from flask.views import MethodView
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)
@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.")
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 = {
"status": RequestStatus.DELETED,
"message": f"Request {uuid} was deleted."
}
return response