Skip to content

Commit

Permalink
Add /collections/observations endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-phaf committed Nov 2, 2023
1 parent 536688a commit d10d72c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
18 changes: 14 additions & 4 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import datastore_pb2 as dstore
import datastore_pb2_grpc as dstore_grpc
import grpc
import metadata_endpoints
from brotli_asgi import BrotliMiddleware
from covjson_pydantic.coverage import Coverage
from covjson_pydantic.coverage import CoverageCollection
Expand All @@ -22,6 +23,7 @@
from covjson_pydantic.reference_system import ReferenceSystemConnectionObject
from covjson_pydantic.unit import Unit
from edr_pydantic.capabilities import LandingPageModel
from edr_pydantic.collections import Collection
from edr_pydantic.collections import Collections
from fastapi import FastAPI
from fastapi import Path
Expand All @@ -30,8 +32,6 @@
from geojson_pydantic import Feature
from geojson_pydantic import FeatureCollection
from geojson_pydantic import Point
from metadata_endpoints import get_collections_metadata
from metadata_endpoints import get_landing_page
from pydantic import AwareDatetime
from shapely import buffer
from shapely import geometry
Expand Down Expand Up @@ -119,7 +119,7 @@ def get_data_for_time_series(get_obs_request):
response_model_exclude_none=True,
)
async def landing_page(request: Request) -> LandingPageModel:
return get_landing_page(request)
return metadata_endpoints.get_landing_page(request)


@app.get(
Expand All @@ -129,7 +129,17 @@ async def landing_page(request: Request) -> LandingPageModel:
response_model_exclude_none=True,
)
async def get_collections(request: Request) -> Collections:
return get_collections_metadata(request)
return metadata_endpoints.get_collections(request)


@app.get(
"/collections/observations",
tags=["Collection metadata"],
response_model=Collection,
response_model_exclude_none=True,
)
async def get_collection_metadata(request: Request) -> Collection:
return metadata_endpoints.get_collection_metadata(request)


@app.get(
Expand Down
7 changes: 5 additions & 2 deletions api/metadata_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get_landing_page(request):
)


def get_collections_metadata(request):
def get_collection_metadata(request) -> Collection:
collection = Collection(
id="observations",
links=[
Expand Down Expand Up @@ -63,10 +63,13 @@ def get_collections_metadata(request):
output_formats=["CoverageJSON"],
parameter_names={}, # TODO: Get these from database
)
return collection


def get_collections(request) -> Collections:
return Collections(
links=[
Link(href=f"{request.url}", rel="self"),
],
collections=[collection],
collections=[get_collection_metadata(request)],
)

0 comments on commit d10d72c

Please sign in to comment.