Skip to content

Commit

Permalink
Added API endpoint for listing coverage configuration parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogsilva committed May 20, 2024
1 parent 2f0e644 commit 2d1d6ce
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
28 changes: 28 additions & 0 deletions arpav_ppcv/webapp/api_v2/routers/coverages.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,34 @@
logger = logging.getLogger(__name__)
router = APIRouter()

@router.get(
"/configuration-parameters",
response_model=coverage_schemas.ConfigurationParameterList
)
async def list_configuration_parameters(
request: Request,
db_session: Annotated[Session, Depends(dependencies.get_db_session)],
list_params: Annotated[dependencies.CommonListFilterParameters, Depends()],
):
"""List configuration parameters."""
config_params, filtered_total = db.list_configuration_parameters(
db_session,
limit=list_params.limit,
offset=list_params.offset,
include_total=True
)
_, unfiltered_total = db.list_configuration_parameters(
db_session, limit=1, offset=0, include_total=True
)
return coverage_schemas.ConfigurationParameterList.from_items(
config_params,
request,
limit=list_params.limit,
offset=list_params.offset,
filtered_total=filtered_total,
unfiltered_total=unfiltered_total
)


@router.get(
"/coverage-configurations",
Expand Down
31 changes: 27 additions & 4 deletions arpav_ppcv/webapp/api_v2/schemas/coverages.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,30 @@
from ....schemas import coverages as app_models


class ForecastModelScenario(pydantic.BaseModel):
class ConfigurationParameterValueEmbeddedInConfigurationParameter(pydantic.BaseModel):
name: str
code: str
description: str


class ConfigurationParameterReadListItem(pydantic.BaseModel):
name: str
description: str
allowed_values: list[ConfigurationParameterValueEmbeddedInConfigurationParameter]

@classmethod
def from_db_instance(
cls,
instance: app_models.ConfigurationParameter,
request: Request,
):
return cls(
**instance.model_dump(),
allowed_values=[
ConfigurationParameterValueEmbeddedInConfigurationParameter(
**pv.model_dump()
) for pv in instance.allowed_values
]
)


class ConfigurationParameterPossibleValueRead(pydantic.BaseModel):
Expand Down Expand Up @@ -92,8 +113,10 @@ class CoverageIdentifierList(WebResourceList):
path_operation_name = "list_coverage_identifiers"


class ForecastModelScenarioList(WebResourceList):
items: list[ForecastModelScenario]
class ConfigurationParameterList(WebResourceList):
items: list[ConfigurationParameterReadListItem]
list_item_type = ConfigurationParameterReadListItem
path_operation_name = "list_configuration_parameters"


class TimeSeriesItem(pydantic.BaseModel):
Expand Down

0 comments on commit 2d1d6ce

Please sign in to comment.