From dcbcba88cb4b44ca1b07feddebc1ed7fce46ea5c 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 828152b..5946cbe 100644 --- a/app/main.py +++ b/app/main.py @@ -196,6 +196,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");