Skip to content

Commit

Permalink
Merge pull request #41 from drnextgis/search-dependency
Browse files Browse the repository at this point in the history
Add search_dependency
  • Loading branch information
vincentsarago authored Feb 23, 2022
2 parents 10184cb + d461991 commit 93eb9d3
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions titiler/pgstac/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
import os
from dataclasses import dataclass, field
from typing import Callable, Dict, Optional, Type
from typing import Any, Callable, Dict, Optional, Tuple, Type
from urllib.parse import urlencode

import rasterio
Expand Down Expand Up @@ -31,6 +31,17 @@ def PathParams(searchid: str = Path(..., description="Search Id")) -> str:
return searchid


def SearchParams(body: SearchQuery) -> Tuple[str, Optional[Dict[str, Any]]]:
"""Search parameters."""
search = body.json(
exclude_none=True,
exclude={"metadata"},
by_alias=True,
)
metadata = body.metadata or {}
return search, metadata


@dataclass
class PgSTACParams(DefaultDependency):
"""PgSTAC parameters."""
Expand Down Expand Up @@ -68,6 +79,11 @@ class MosaicTilerFactory(BaseTilerFactory):
# TileMatrixSet dependency
tms_dependency: Callable[..., TileMatrixSet] = TMSParams

# Search dependency
search_dependency: Callable[
..., Tuple[str, Optional[Dict[str, Any]]]
] = SearchParams

backend_options: Dict = field(default_factory=dict)

def register_routes(self) -> None:
Expand Down Expand Up @@ -339,14 +355,11 @@ def _search_routes(self) -> None:
"/register",
responses={200: {"description": "Register a Search."}},
)
def register_search(request: Request, body: SearchQuery):
def register_search(
request: Request, search_query=Depends(self.search_dependency)
):
"""Register a Search query."""
search = body.json(
exclude_none=True,
exclude={"metadata"},
by_alias=True,
)
metadata = body.metadata or {}
search, metadata = search_query

with request.app.state.dbpool.connection() as conn:
with conn.cursor() as cursor:
Expand Down

0 comments on commit 93eb9d3

Please sign in to comment.