Skip to content

Commit

Permalink
collection serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhealy1 committed Feb 23, 2024
1 parent b81ab30 commit f9bf949
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
6 changes: 4 additions & 2 deletions stac_fastapi/core/stac_fastapi/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ async def all_collections(self, **kwargs) -> Collections:
token = request.query_params.get("token")

collections, next_token = await self.database.get_all_collections(
token=token, limit=limit
token=token, limit=limit, base_url=base_url
)

links = [
Expand Down Expand Up @@ -238,7 +238,9 @@ async def get_collection(self, collection_id: str, **kwargs) -> Collection:
"""
base_url = str(kwargs["request"].base_url)
collection = await self.database.find_collection(collection_id=collection_id)
return self.collection_serializer.db_to_stac(collection, base_url)
return self.collection_serializer.db_to_stac(
collection=collection, base_url=base_url
)

async def item_collection(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ class DatabaseLogic:
"""CORE LOGIC"""

async def get_all_collections(
self, token: Optional[str], limit: int
self, token: Optional[str], limit: int, base_url: str
) -> Tuple[List[Dict[str, Any]], Optional[str]]:
"""Retrieve a list of all collections from Elasticsearch, supporting pagination.
Expand All @@ -315,7 +315,12 @@ async def get_all_collections(
)

hits = response["hits"]["hits"]
collections = [hit["_source"] for hit in hits]
collections = [
self.collection_serializer.db_to_stac(
collection=hit["_source"], base_url=base_url
)
for hit in hits
]

next_token = None
if len(hits) == limit:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ class DatabaseLogic:
"""CORE LOGIC"""

async def get_all_collections(
self, token: Optional[str], limit: int
self, token: Optional[str], limit: int, base_url: str
) -> Tuple[List[Dict[str, Any]], Optional[str]]:
"""
Retrieve a list of all collections from Opensearch, supporting pagination.
Expand Down Expand Up @@ -339,7 +339,12 @@ async def get_all_collections(
)

hits = response["hits"]["hits"]
collections = [hit["_source"] for hit in hits]
collections = [
self.collection_serializer.db_to_stac(
collection=hit["_source"], base_url=base_url
)
for hit in hits
]

next_token = None
if len(hits) == limit:
Expand Down

0 comments on commit f9bf949

Please sign in to comment.