Skip to content

Commit

Permalink
Added URL to the related coverage configuration on the coverage ident…
Browse files Browse the repository at this point in the history
…ifiers API endpoint
  • Loading branch information
ricardogsilva committed Jun 14, 2024
1 parent bf7a30f commit c56c16f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 24 deletions.
24 changes: 3 additions & 21 deletions arpav_ppcv/webapp/api_v2/routers/coverages.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,29 +184,11 @@ def list_coverage_identifiers(
_, unfiltered_total = db.list_coverage_identifiers(
db_session, limit=1, offset=0, include_total=True
)
records = []
for cov_internal in cov_internals:
thredds_url_fragment = cov_internal.configuration.get_thredds_url_fragment(
cov_internal.identifier
)
wms_base_url = "/".join(
(
settings.thredds_server.base_url,
settings.thredds_server.wms_service_url_fragment,
thredds_url_fragment,
)
)
records.append(
coverage_schemas.CoverageIdentifierReadListItem(
identifier=cov_internal.identifier,
wms_base_url=wms_base_url,
wms_main_layer_name=cov_internal.configuration.wms_main_layer_name,
)
)

return coverage_schemas.CoverageIdentifierList.from_items(
records,
request=request,
cov_internals,
request,
settings=settings,
limit=list_params.limit,
offset=list_params.offset,
filtered_total=filtered_total,
Expand Down
42 changes: 39 additions & 3 deletions arpav_ppcv/webapp/api_v2/schemas/coverages.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import pydantic
from fastapi import Request

from .base import WebResourceList
from ....config import ArpavPpcvSettings
from ....schemas import coverages as app_models
from .base import WebResourceList


class ConfigurationParameterValueEmbeddedInConfigurationParameter(pydantic.BaseModel):
Expand Down Expand Up @@ -110,9 +111,40 @@ class CoverageConfigurationList(WebResourceList):

class CoverageIdentifierReadListItem(pydantic.BaseModel):
identifier: str
related_coverage_configuration_url: str
wms_base_url: str
wms_main_layer_name: str | None = None

@classmethod
def from_db_instance(
cls,
instance: app_models.CoverageInternal,
settings: ArpavPpcvSettings,
request: Request,
) -> "CoverageIdentifierReadListItem":
thredds_url_fragment = instance.configuration.get_thredds_url_fragment(
instance.identifier
)
wms_base_url = "/".join(
(
settings.thredds_server.base_url,
settings.thredds_server.wms_service_url_fragment,
thredds_url_fragment,
)
)

return cls(
identifier=instance.identifier,
wms_base_url=wms_base_url,
wms_main_layer_name=instance.configuration.wms_main_layer_name,
related_coverage_configuration_url=str(
request.url_for(
"get_coverage_configuration",
coverage_configuration_id=instance.configuration.id,
)
),
)


class CoverageIdentifierList(WebResourceList):
items: list[CoverageIdentifierReadListItem]
Expand All @@ -121,9 +153,10 @@ class CoverageIdentifierList(WebResourceList):
@classmethod
def from_items(
cls,
items: typing.Sequence[str],
items: typing.Sequence[app_models.CoverageInternal],
request: Request,
*,
settings: ArpavPpcvSettings,
limit: int,
offset: int,
filtered_total: int,
Expand All @@ -134,7 +167,10 @@ def from_items(
links=cls._get_list_links(
request, limit, offset, filtered_total, len(items)
),
items=[i for i in items],
items=[
CoverageIdentifierReadListItem.from_db_instance(i, settings, request)
for i in items
],
)


Expand Down

0 comments on commit c56c16f

Please sign in to comment.