-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c25229e
commit 3c790b4
Showing
8 changed files
with
242 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
"""elasticsearch extensions modifications.""" | ||
|
||
from .collection_post_search import CollectionSearchPostExtension | ||
from .query import Operator, QueryableTypes, QueryExtension | ||
|
||
__all__ = ["Operator", "QueryableTypes", "QueryExtension"] | ||
__all__ = [ | ||
"Operator", | ||
"QueryableTypes", | ||
"QueryExtension", | ||
"CollectionSearchPostExtension", | ||
] |
90 changes: 90 additions & 0 deletions
90
stac_fastapi/core/stac_fastapi/core/extensions/collection_post_search.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
"""Request model for the Aggregation extension.""" | ||
|
||
from typing import List, Optional, Union | ||
|
||
import attr | ||
from fastapi import APIRouter, FastAPI | ||
from stac_pydantic.api.collections import Collections | ||
from stac_pydantic.shared import MimeTypes | ||
|
||
from stac_fastapi.api.models import GeoJSONResponse | ||
from stac_fastapi.api.routes import create_async_endpoint | ||
from stac_fastapi.extensions.core.collection_search import ( | ||
CollectionSearchExtension, | ||
ConformanceClasses, | ||
) | ||
from stac_fastapi.extensions.core.collection_search.client import ( | ||
AsyncBaseCollectionSearchClient, | ||
BaseCollectionSearchClient, | ||
) | ||
from stac_fastapi.extensions.core.collection_search.request import ( | ||
BaseCollectionSearchGetRequest, | ||
BaseCollectionSearchPostRequest, | ||
) | ||
from stac_fastapi.types.config import ApiSettings | ||
|
||
|
||
@attr.s | ||
class CollectionSearchPostExtension(CollectionSearchExtension): | ||
"""Collection-Search Extension. | ||
Extents the collection-search extension with an additional | ||
POST - /collections endpoint | ||
NOTE: the POST - /collections endpoint can be conflicting with the | ||
POST /collections endpoint registered for the Transaction extension. | ||
https://github.com/stac-api-extensions/collection-search | ||
Attributes: | ||
conformance_classes (list): Defines the list of conformance classes for | ||
the extension | ||
""" | ||
|
||
client: Union[ | ||
AsyncBaseCollectionSearchClient, BaseCollectionSearchClient | ||
] = attr.ib() | ||
settings: ApiSettings = attr.ib() | ||
conformance_classes: List[str] = attr.ib( | ||
default=[ConformanceClasses.COLLECTIONSEARCH, ConformanceClasses.BASIS] | ||
) | ||
schema_href: Optional[str] = attr.ib(default=None) | ||
router: APIRouter = attr.ib(factory=APIRouter) | ||
|
||
GET: BaseCollectionSearchGetRequest = attr.ib( | ||
default=BaseCollectionSearchGetRequest | ||
) | ||
POST: BaseCollectionSearchPostRequest = attr.ib( | ||
default=BaseCollectionSearchPostRequest | ||
) | ||
|
||
def register(self, app: FastAPI) -> None: | ||
"""Register the extension with a FastAPI application. | ||
Args: | ||
app: target FastAPI application. | ||
Returns: | ||
None | ||
""" | ||
self.router.prefix = app.state.router_prefix | ||
|
||
self.router.add_api_route( | ||
name="Collections searcb", | ||
path="/collections-search", | ||
methods=["POST"], | ||
response_model=( | ||
Collections if self.settings.enable_response_models else None | ||
), | ||
responses={ | ||
200: { | ||
"content": { | ||
MimeTypes.json.value: {}, | ||
}, | ||
"model": Collections, | ||
}, | ||
}, | ||
response_class=GeoJSONResponse, | ||
endpoint=create_async_endpoint(self.client.post_all_collections, self.POST), | ||
) | ||
app.include_router(self.router) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
"""stac_fastapi.elasticsearch.models module.""" | ||
from .search import CollectionSearchPostRequest | ||
|
||
"""elasticsearch extensions modifications.""" | ||
__all__ = ["CollectionSearchPostRequest"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,35 @@ | ||
"""Unused search model.""" | ||
"""Search model.""" | ||
|
||
from typing import List, Optional | ||
|
||
from stac_fastapi.extensions.core.collection_search.collection_search import ( | ||
BaseCollectionSearchPostRequest, | ||
) | ||
from stac_fastapi.types.search import BaseSearchPostRequest | ||
|
||
|
||
# CollectionSearchPostRequest model. | ||
class CollectionSearchPostRequest( | ||
BaseCollectionSearchPostRequest, BaseSearchPostRequest | ||
): | ||
"""The CollectionSearchPostRequest class.""" | ||
|
||
query: Optional[str] = None | ||
token: Optional[str] = None | ||
fields: Optional[List[str]] = None | ||
sortby: Optional[str] = None | ||
intersects: Optional[str] = None | ||
filter: Optional[str] = None | ||
filter_lang: Optional[str] = None | ||
q: Optional[str] = None | ||
|
||
def __init__(self, **kwargs): | ||
"""Run the Constructor.""" | ||
super().__init__(**kwargs) | ||
self.query = kwargs.get("query", None) | ||
self.token = kwargs.get("token", None) | ||
self.sortby = kwargs.get("sortby", None) | ||
self.fields = kwargs.get("fields", None) | ||
self.filter = kwargs.get("filter", None) | ||
self.filter_lang = kwargs.get("filter-lang", None) | ||
self.q = kwargs.get("q", None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.