1- from fastapi import FastAPI
1+ from typing import Annotated
22
3+ from fastapi import Depends , FastAPI , Query
4+
5+ from .backend import Backend
36from .item_collection import ItemCollection
47from .root import Root
8+ from .search import GetSearch , Search
9+ from .settings import Settings
510
611
7- def build () -> FastAPI :
12+ def build (settings : Settings | None = None ) -> FastAPI :
813 """Builds a new TiStac application."""
914
15+ if settings is None :
16+ settings = Settings () # type: ignore
17+
18+ async def get_settings () -> Settings :
19+ return settings
20+
21+ backend = settings .get_backend ()
22+
23+ async def get_backend () -> Backend :
24+ return backend
25+
1026 app = FastAPI ()
1127
1228 @app .get ("/" )
@@ -16,15 +32,24 @@ async def root() -> Root:
1632 return Root ()
1733
1834 @app .get ("/search" )
19- async def get_search () -> ItemCollection :
35+ async def get_search (
36+ get_search : Annotated [GetSearch , Query ()],
37+ backend : Annotated [Backend , Depends (get_backend )],
38+ settings : Annotated [Settings , Depends (get_settings )],
39+ ) -> ItemCollection :
2040 """Searches this STAC API via a GET request."""
21-
22- return ItemCollection ()
41+ search = get_search .into_search ()
42+ search = settings .update_search (search )
43+ return await backend .search (search )
2344
2445 @app .post ("/search" )
25- async def post_search () -> ItemCollection :
46+ async def post_search (
47+ search : Search ,
48+ backend : Annotated [Backend , Depends (get_backend )],
49+ settings : Annotated [Settings , Depends (get_settings )],
50+ ) -> ItemCollection :
2651 """Searches this STAC API via a POST request."""
27-
28- return ItemCollection ( )
52+ search = settings . update_search ( search )
53+ return await backend . search ( search )
2954
3055 return app
0 commit comments