Skip to content

Commit

Permalink
Create a submission deletion endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Chiara Rasi committed Nov 15, 2024
1 parent 9d99f37 commit 4710fbd
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions preClinVar/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

from preClinVar.__version__ import VERSION
from preClinVar.build import build_header, build_submission
from preClinVar.constants import DRY_RUN_SUBMISSION_URL, SUBMISSION_URL, VALIDATE_SUBMISSION_URL
from preClinVar.constants import (
DRY_RUN_SUBMISSION_URL,
SUBMISSION_URL,
VALIDATE_SUBMISSION_URL,
)
from preClinVar.file_parser import csv_lines, file_fields_to_submission, tsv_lines
from preClinVar.validate import validate_submission

Expand All @@ -34,7 +38,9 @@ async def root():


@app.post("/apitest-status")
async def apitest_status(api_key: str = Form(), submission_id: str = Form()) -> JSONResponse:
async def apitest_status(
api_key: str = Form(), submission_id: str = Form()
) -> JSONResponse:
"""Returns the status (validation) of a test submission to the apitest endpoint."""

# Create a submission header
Expand Down Expand Up @@ -156,7 +162,9 @@ async def tsv_2_json(
)
return JSONResponse(
status_code=400,
content={"message": f"Created json file contains validation errors: {valid_results[1]}"},
content={
"message": f"Created json file contains validation errors: {valid_results[1]}"
},
)


Expand Down Expand Up @@ -215,7 +223,9 @@ async def csv_2_json(
)
return JSONResponse(
status_code=400,
content={"message": f"Created json file contains validation errors: {valid_results[1]}"},
content={
"message": f"Created json file contains validation errors: {valid_results[1]}"
},
)


Expand All @@ -234,16 +244,18 @@ async def status(api_key: str = Form(), submission_id: str = Form()) -> JSONResp
content=actions_resp.json(),
)


@app.post("/delete")
async def dry_run(api_key: str = Form(), json_file: UploadFile = File(...)):
async def dry_run(api_key: str = Form(), clinvar_accession: str = Form()):
"""A proxy to the dry run submission ClinVar API endpoint"""
# Create a submission header
header = build_header(api_key)

# Get json file content as dict:
delete_obj = json.load(json_file.file)
# Create a submission deletion object
delete_obj = {
"clinvarDeletion": {"accessionSet": [{"accession": clinvar_accession}]}
}

# And use it in POST request to API
data = {
"actions": [
{
Expand All @@ -253,6 +265,7 @@ async def dry_run(api_key: str = Form(), json_file: UploadFile = File(...)):
}
]
}
# And send a POST request to the API
resp = requests.post(SUBMISSION_URL, data=json.dumps(data), headers=header)

# A successful response will be an empty response with code 204 (A dry-run submission was successful and no submission was created)
Expand All @@ -265,5 +278,3 @@ async def dry_run(api_key: str = Form(), json_file: UploadFile = File(...)):
status_code=resp.status_code,
content=resp.json(),
)


0 comments on commit 4710fbd

Please sign in to comment.