Skip to content

Commit 22d6a01

Browse files
committed
Merge branch 'master' into remove/backend-packages
2 parents de6c57c + 06218c5 commit 22d6a01

File tree

5 files changed

+71
-5
lines changed

5 files changed

+71
-5
lines changed

CHANGES.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,24 @@
22

33
## Unreleased
44

5+
### Added
6+
7+
* Add support in pgstac backend for /queryables and /collections/{collection_id}/queryables endpoints with functions exposed in pgstac 0.6.8
8+
* Add `bbox` and `datetime` query parameters to `/collections/{collection_id}/items`. [476](https://github.com/stac-utils/stac-fastapi/issues/476) [380](https://github.com/stac-utils/stac-fastapi/issues/380)
9+
* Update pgstac requirement to 0.6.10
10+
11+
### Changed
12+
513
### Removed
614

7-
- The SQLAlchemy and PgSTAC backend implementations have been moved to their own repos
15+
* The SQLAlchemy and PgSTAC backend implementations have been moved to their own repos
816
([stac-utils/stac-fastapi-sqlalchemy](https://github.com/stac-utils/stac-fastapi-sqlalchemy)
917
and [stac-utils/stac-fastapi-pgstac](https://github.com/stac-utils/stac-fastapi-pgstac), respectively).
1018
These backends will be distributed and versioned separately going forward.
1119
([#450](https://github.com/stac-utils/stac-fastapi/pull/450))
1220

21+
* Fix pgstac backend for /queryables endpoint to return 404 for non-existent collections [#482](https://github.com/stac-utils/stac-fastapi/pull/482)
22+
1323
## [2.4.2]
1424

1525
### Added

stac_fastapi/api/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
APIRequest,
1414
BaseSearchGetRequest,
1515
BaseSearchPostRequest,
16+
str2list,
1617
)
1718

1819

@@ -123,6 +124,8 @@ class ItemCollectionUri(CollectionUri):
123124
"""Get item collection."""
124125

125126
limit: int = attr.ib(default=10)
127+
bbox: Optional[str] = attr.ib(default=None, converter=str2list)
128+
datetime: Optional[str] = attr.ib(default=None)
126129

127130

128131
class POSTTokenPagination(BaseModel):

stac_fastapi/extensions/core/transaction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
class PostItem(CollectionUri):
1919
"""Create Item."""
2020

21-
item: stac_types.Item = attr.ib(default=Body())
21+
item: stac_types.Item = attr.ib(default=Body(None))
2222

2323

2424
@attr.s
2525
class PutItem(ItemUri):
2626
"""Update Item."""
2727

28-
item: stac_types.Item = attr.ib(default=Body())
28+
item: stac_types.Item = attr.ib(default=Body(None))
2929

3030

3131
@attr.s
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""Get Queryables."""
2+
from typing import Any, Optional
3+
4+
from buildpg import render
5+
from fastapi import Request
6+
from fastapi.responses import JSONResponse
7+
8+
from stac_fastapi.types.core import AsyncBaseFiltersClient
9+
from stac_fastapi.types.errors import NotFoundError
10+
11+
12+
class FiltersClient(AsyncBaseFiltersClient):
13+
"""Defines a pattern for implementing the STAC filter extension."""
14+
15+
async def get_queryables(
16+
self, request: Request, collection_id: Optional[str] = None, **kwargs: Any
17+
) -> JSONResponse:
18+
"""Get the queryables available for the given collection_id.
19+
20+
If collection_id is None, returns the intersection of all
21+
queryables over all collections.
22+
This base implementation returns a blank queryable schema. This is not allowed
23+
under OGC CQL but it is allowed by the STAC API Filter Extension
24+
https://github.com/radiantearth/stac-api-spec/tree/master/fragments/filter#queryables
25+
"""
26+
pool = request.app.state.readpool
27+
28+
async with pool.acquire() as conn:
29+
q, p = render(
30+
"""
31+
SELECT * FROM get_queryables(:collection::text);
32+
""",
33+
collection=collection_id,
34+
)
35+
queryables = await conn.fetchval(q, *p)
36+
if not queryables:
37+
raise NotFoundError(f"Collection {collection_id} not found")
38+
39+
queryables["$id"] = str(request.url)
40+
headers = {"Content-Type": "application/schema+json"}
41+
return JSONResponse(queryables, headers=headers)

stac_fastapi/types/core.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,13 @@ def get_collection(self, collection_id: str, **kwargs) -> stac_types.Collection:
489489

490490
@abc.abstractmethod
491491
def item_collection(
492-
self, collection_id: str, limit: int = 10, token: str = None, **kwargs
492+
self,
493+
collection_id: str,
494+
bbox: Optional[List[NumType]] = None,
495+
datetime: Optional[Union[str, datetime]] = None,
496+
limit: int = 10,
497+
token: str = None,
498+
**kwargs,
493499
) -> stac_types.ItemCollection:
494500
"""Get all items from a specific collection.
495501
@@ -684,7 +690,13 @@ async def get_collection(
684690

685691
@abc.abstractmethod
686692
async def item_collection(
687-
self, collection_id: str, limit: int = 10, token: str = None, **kwargs
693+
self,
694+
collection_id: str,
695+
bbox: Optional[List[NumType]] = None,
696+
datetime: Optional[Union[str, datetime]] = None,
697+
limit: int = 10,
698+
token: str = None,
699+
**kwargs,
688700
) -> stac_types.ItemCollection:
689701
"""Get all items from a specific collection.
690702

0 commit comments

Comments
 (0)