-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor and streamline backend API for accessing surfaces (#669)
- Loading branch information
Showing
30 changed files
with
1,348 additions
and
744 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
backend_py/primary/primary/routers/surface/dependencies.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import logging | ||
from typing import Annotated | ||
|
||
from fastapi import Query | ||
from fastapi.exceptions import RequestValidationError | ||
from pydantic import ValidationError | ||
|
||
from primary.utils.query_string_utils import decode_key_val_str | ||
|
||
from . import schemas | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
def get_resample_to_param_from_json( | ||
# fmt:off | ||
resample_to_def_json_str: Annotated[str | None, Query(description="Definition of the surface onto which the data should be resampled. Should be a serialized JSON representation of a SurfaceDef object")] = None | ||
# fmt:on | ||
) -> schemas.SurfaceDef | None: | ||
if resample_to_def_json_str is None: | ||
return None | ||
|
||
try: | ||
surf_def_obj: schemas.SurfaceDef = schemas.SurfaceDef.model_validate_json(resample_to_def_json_str) | ||
except ValidationError as exc: | ||
raise RequestValidationError(errors=exc.errors()) from exc | ||
|
||
return surf_def_obj | ||
|
||
|
||
def get_resample_to_param_from_keyval_str( | ||
# fmt:off | ||
resample_to_def_str: Annotated[str | None, Query(description="Definition of the surface onto which the data should be resampled. *SurfaceDef* object properties encoded as a `KeyValStr` string.")] = None | ||
# fmt:on | ||
) -> schemas.SurfaceDef | None: | ||
if resample_to_def_str is None: | ||
return None | ||
|
||
prop_dict = decode_key_val_str(resample_to_def_str) | ||
surf_def_obj = schemas.SurfaceDef.model_validate(prop_dict) | ||
|
||
return surf_def_obj |
Oops, something went wrong.