From 08440d242ff5861702ff49772d12d467a58e3487 Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Wed, 4 Jan 2023 09:51:43 +0100 Subject: [PATCH] implemented delete origin endpoint for frontend --- app/main.py | 7 +++++++ app/static/assets/js/helper.js | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/app/main.py b/app/main.py index 08fa0f1..564d5cf 100644 --- a/app/main.py +++ b/app/main.py @@ -155,6 +155,13 @@ async def _origins_delete(request: Request): return Response(status_code=201) +@app.delete('/-/origins/{origin_ref}', summary='* Origins') +async def _origins_delete_origin_ref(request: Request, origin_ref: str): + if Origin.delete(db, origin_ref) == 1: + return Response(status_code=201) + raise JSONResponse(status_code=404, content={'status': 404, 'detail': 'lease not found'}) + + @app.get('/-/leases', summary='* Leases') async def _leases(request: Request, origin: bool = False): session = sessionmaker(bind=db)() diff --git a/app/static/assets/js/helper.js b/app/static/assets/js/helper.js index d1fd912..28604d5 100644 --- a/app/static/assets/js/helper.js +++ b/app/static/assets/js/helper.js @@ -105,6 +105,16 @@ async function deleteOrigins() { await fetchOriginsWithLeases() } +async function deleteOrigin(origin_ref) { + if (origin_ref === undefined) + origin_ref = window.prompt("Please enter 'origin_ref' which should be deleted"); + if (origin_ref === null || origin_ref === "") + return + let xhr = new XMLHttpRequest(); + xhr.open("DELETE", `/-/origins/${origin_ref}`, true); + xhr.send(); +} + async function deleteLease(lease_ref) { if (lease_ref === undefined) lease_ref = window.prompt("Please enter 'lease_ref' which should be deleted");