implemented delete origin endpoint for frontend

This commit is contained in:
Oscar Krause 2023-01-04 09:51:43 +01:00
parent c8df32375a
commit dcbcba88cb
2 changed files with 17 additions and 0 deletions

View File

@ -196,6 +196,13 @@ async def _origins_delete(request: Request):
return Response(status_code=201) 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') @app.get('/-/leases', summary='* Leases')
async def _leases(request: Request, origin: bool = False): async def _leases(request: Request, origin: bool = False):
session = sessionmaker(bind=db)() session = sessionmaker(bind=db)()

View File

@ -105,6 +105,16 @@ async function deleteOrigins() {
await fetchOriginsWithLeases() 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) { async function deleteLease(lease_ref) {
if (lease_ref === undefined) if (lease_ref === undefined)
lease_ref = window.prompt("Please enter 'lease_ref' which should be deleted"); lease_ref = window.prompt("Please enter 'lease_ref' which should be deleted");