Skip to content

Commit

Permalink
feat(custom_exports-yaml): adds a yaml endpoint for custom exports
Browse files Browse the repository at this point in the history
It will simply enhance the endpoint by supporting yaml input along with json , considering in mind both endpoints are different
  • Loading branch information
kshitijrajsharma committed Jun 19, 2024
1 parent 9731637 commit 7808d59
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
46 changes: 46 additions & 0 deletions API/custom_exports.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Third party imports
import yaml
from fastapi import APIRouter, Body, Depends, HTTPException, Request
from fastapi.responses import JSONResponse
from fastapi_versioning import version
from pydantic import ValidationError

# Reader imports
from src.config import DEFAULT_QUEUE_NAME
from src.config import LIMITER as limiter
from src.config import RATE_LIMIT_PER_MIN
Expand Down Expand Up @@ -816,3 +820,45 @@ async def process_custom_requests(
kwargs={"user": user.model_dump()},
)
return JSONResponse({"task_id": task.id, "track_link": f"/tasks/status/{task.id}/"})


@router.post(
"/snapshot/yaml/",
openapi_extra={
"requestBody": {
"content": {
"multipart/mixed": {
"schema": {
"type": "object",
"properties": {
"geometry": {"$ref": "#/components/schemas/GeometryModel"},
"yaml_body": {
"type": "string",
"format": "yaml",
},
},
"required": ["geometry", "yaml_body"],
}
}
},
"required": True,
},
},
)
@limiter.limit(f"{RATE_LIMIT_PER_MIN}/minute")
@version(1)
async def process_custom_requests_yaml(
request: Request,
user: AuthUser = Depends(staff_required),
):
print(DynamicCategoriesModel.model_json_schema())
raw_body = await request.body()
try:
data = yaml.safe_load(raw_body)
except yaml.YAMLError:
raise HTTPException(status_code=422, detail="Invalid YAML")
try:
validated_data = DynamicCategoriesModel.model_validate(data)
except ValidationError as e:
raise HTTPException(status_code=422, detail=e.errors(include_url=False))
return validated_data
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ osm-login-python==1.0.2
humanize==4.9.0
python-slugify==8.0.1
geomet==1.1.0

PyYAML==6.0.1
## documentation
# mkdocs-material==8.5.11
# mkdocs-jupyter==0.22.0
Expand Down

0 comments on commit 7808d59

Please sign in to comment.