Skip to content

Commit

Permalink
Add search_dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
drnextgis committed Feb 22, 2022
1 parent 10184cb commit d461991
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 d461991

Please sign in to comment.