Skip to content

Commit

Permalink
perf(custom-exports-yaml): moves geometry to request body within yaml…
Browse files Browse the repository at this point in the history
… itself instead of query param
  • Loading branch information
kshitijrajsharma committed Jun 22, 2024
1 parent 2a4511f commit 645c2f4
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions API/custom_exports.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Standard library imports
import json
from typing import Dict

# Third party imports
import yaml
Expand Down Expand Up @@ -825,12 +826,16 @@ async def process_custom_requests(
return JSONResponse({"task_id": task.id, "track_link": f"/tasks/status/{task.id}/"})


class CustomRequestsYaml(CategoriesBase):
geometry: Dict


@router.post(
"/snapshot/yaml/",
openapi_extra={
"requestBody": {
"content": {
"application/x-yaml": {"schema": CategoriesBase.model_json_schema()}
"application/x-yaml": {"schema": CustomRequestsYaml.model_json_schema()}
},
"required": True,
},
Expand All @@ -840,18 +845,13 @@ async def process_custom_requests(
@version(1)
async def process_custom_requests_yaml(
request: Request,
geometry: str,
user: AuthUser = Depends(staff_required),
):
raw_body = await request.body()
try:
data = yaml.safe_load(raw_body)
except yaml.YAMLError:
raise HTTPException(status_code=422, detail="Invalid YAML")
try:
data["geometry"] = json.loads(geometry)
except json.decoder.JSONDecodeError as ex:
raise HTTPException(status_code=422, detail="Invalid Geometry")
try:
validated_data = DynamicCategoriesModel.model_validate(data)
except ValidationError as e:
Expand Down

0 comments on commit 645c2f4

Please sign in to comment.