Skip to content

Commit 0a2c6d9

Browse files
committed
apply suggestions from review
1 parent 1cd6833 commit 0a2c6d9

File tree

3 files changed

+31
-55
lines changed

3 files changed

+31
-55
lines changed

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"orjson",
1111
"pydantic",
1212
"stac_pydantic==3.1.*",
13-
"stac-fastapi.api~=3.0.0b3",
14-
"stac-fastapi.extensions~=3.0.0b3",
15-
"stac-fastapi.types~=3.0.0b3",
13+
"stac-fastapi.api~=3.0.0",
14+
"stac-fastapi.extensions~=3.0.0",
15+
"stac-fastapi.types~=3.0.0",
1616
"asyncpg",
1717
"buildpg",
1818
"brotli_asgi",

stac_fastapi/pgstac/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
collections_get_request_model = EmptyRequest
8787

8888
post_request_model = create_post_request_model(extensions, base_model=PgstacSearch)
89-
get_request_model = create_get_request_model(extensions)
89+
get_request_model = create_get_request_model(extensions + collection_extensions)
9090

9191
api = StacApi(
9292
settings=settings,

stac_fastapi/pgstac/core.py

Lines changed: 27 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import re
44
from typing import Any, Dict, List, Optional, Set, Union
5-
from urllib.parse import unquote_plus, urljoin
5+
from urllib.parse import unquote_plus
66

77
import attr
88
import orjson
@@ -14,13 +14,14 @@
1414
from pygeofilter.parsers.cql2_text import parse as parse_cql2_text
1515
from pypgstac.hydration import hydrate
1616
from stac_fastapi.api.models import JSONResponse
17+
from stac_fastapi.extensions.core.collection_search.request import (
18+
BaseCollectionSearchPostRequest,
19+
)
1720
from stac_fastapi.types.core import AsyncBaseCoreClient
1821
from stac_fastapi.types.errors import InvalidQueryParameter, NotFoundError
19-
from stac_fastapi.types.requests import get_base_url
2022
from stac_fastapi.types.rfc3339 import DateTimeType
2123
from stac_fastapi.types.stac import Collection, Collections, Item, ItemCollection
22-
from stac_pydantic.links import Relations
23-
from stac_pydantic.shared import BBox, MimeTypes
24+
from stac_pydantic.shared import BBox
2425

2526
from stac_fastapi.pgstac.config import Settings
2627
from stac_fastapi.pgstac.models.links import (
@@ -39,13 +40,17 @@
3940
class CoreCrudClient(AsyncBaseCoreClient):
4041
"""Client for core endpoints defined by stac."""
4142

43+
collections_post_request_model: BaseCollectionSearchPostRequest = attr.ib(
44+
default=BaseCollectionSearchPostRequest
45+
)
46+
4247
async def all_collections( # noqa: C901
4348
self,
4449
request: Request,
50+
# Extensions
4551
bbox: Optional[BBox] = None,
4652
datetime: Optional[DateTimeType] = None,
4753
limit: Optional[int] = None,
48-
# Extensions
4954
query: Optional[str] = None,
5055
token: Optional[str] = None,
5156
fields: Optional[List[str]] = None,
@@ -62,13 +67,6 @@ async def all_collections( # noqa: C901
6267
Collections which match the search criteria, returns all
6368
collections by default.
6469
"""
65-
query_params = str(request.query_params)
66-
67-
# Kludgy fix because using factory does not allow alias for filter-lang
68-
if filter_lang is None:
69-
match = re.search(r"filter-lang=([a-z0-9-]+)", query_params, re.IGNORECASE)
70-
if match:
71-
filter_lang = match.group(1)
7270

7371
# Parse request parameters
7472
base_args = {
@@ -89,7 +87,8 @@ async def all_collections( # noqa: C901
8987

9088
# Do the request
9189
try:
92-
search_request = self.post_request_model(**clean)
90+
search_request = self.collections_post_request_model(**clean)
91+
# search_request = self.post_request_model(**clean)
9392
except ValidationError as e:
9493
raise HTTPException(
9594
status_code=400, detail=f"Invalid parameters provided {e}"
@@ -102,9 +101,9 @@ async def _collection_search_base( # noqa: C901
102101
search_request: PgstacSearch,
103102
request: Request,
104103
) -> Collections:
105-
"""Cross catalog search (POST).
104+
"""Cross catalog search (GET).
106105
107-
Called with `POST /search`.
106+
Called with `GET /search`.
108107
109108
Args:
110109
search_request: search request parameters.
@@ -113,16 +112,6 @@ async def _collection_search_base( # noqa: C901
113112
All collections which match the search criteria.
114113
"""
115114

116-
base_url = get_base_url(request)
117-
118-
settings: Settings = request.app.state.settings
119-
120-
if search_request.datetime:
121-
search_request.datetime = format_datetime_range(search_request.datetime)
122-
123-
search_request.conf = search_request.conf or {}
124-
search_request.conf["nohydrate"] = settings.use_api_hydrate
125-
126115
search_request_json = search_request.model_dump_json(
127116
exclude_none=True, by_alias=True
128117
)
@@ -141,8 +130,12 @@ async def _collection_search_base( # noqa: C901
141130
f"Datetime parameter {search_request.datetime} is invalid."
142131
) from e
143132

144-
# next: Optional[str] = collections_result["links"].pop("next")
145-
# prev: Optional[str] = collections_result["links"].pop("prev")
133+
next: Optional[str] = None
134+
prev: Optional[str] = None
135+
136+
if links := collections_result.get("links"):
137+
next = collections_result["links"].pop("next")
138+
prev = collections_result["links"].pop("prev")
146139

147140
linked_collections: List[Collection] = []
148141
collections = collections_result["collections"]
@@ -167,32 +160,15 @@ async def _collection_search_base( # noqa: C901
167160

168161
linked_collections.append(coll)
169162

170-
# paging_links = await PagingLinks(
171-
# request=request,
172-
# next=next,
173-
# prev=prev,
174-
# ).get_links()
175-
176-
links = [
177-
{
178-
"rel": Relations.root.value,
179-
"type": MimeTypes.json,
180-
"href": base_url,
181-
},
182-
{
183-
"rel": Relations.parent.value,
184-
"type": MimeTypes.json,
185-
"href": base_url,
186-
},
187-
{
188-
"rel": Relations.self.value,
189-
"type": MimeTypes.json,
190-
"href": urljoin(base_url, "collections"),
191-
},
192-
]
163+
links = await PagingLinks(
164+
request=request,
165+
next=next,
166+
prev=prev,
167+
).get_links()
168+
193169
return Collections(
194170
collections=linked_collections or [],
195-
links=links, # + paging_links
171+
links=links,
196172
)
197173

198174
async def get_collection(

0 commit comments

Comments
 (0)