-
Notifications
You must be signed in to change notification settings - Fork 116
Adding Collection Search Extension #681
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 7 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
adf4cc6
Added collection search extension
tjellicoe-tpzuk e01a758
Merge pull request #1 from UKEODHP/feature/EODHP-219-add-collection-s…
tjellicoe-tpzuk 16e2443
Corrected collection search response class
tjellicoe-tpzuk 948ce1e
Updating collection search response model
tjellicoe-tpzuk 6a12507
Updating response model for collection search
tjellicoe-tpzuk cb30fbb
Updating response model for collection search
tjellicoe-tpzuk 7c4c11f
Merge pull request #2 from UKEODHP/bugfix/json-response-type-error-co…
tjellicoe-tpzuk 5072729
Add catalogs to stac fastapi and updated to maintain root link for co…
tjellicoe-tpzuk 4c0694f
Added catalogs to stac fastapi
tjellicoe-tpzuk 8b63cd1
Moving collection-search to a core extension
tjellicoe-tpzuk 8efbe92
Adding discovery-level search for catalogue search
tjellicoe-tpzuk a27a7a4
Adding discovery-search extension
tjellicoe-tpzuk 569eb0c
Adding free-text search to collection-search
tjellicoe-tpzuk 441a252
Adding free-text search to collection-search
tjellicoe-tpzuk a84d63f
Updates to support catalog search )discovery-level) via free-text
tjellicoe-tpzuk 5dab508
Added converter for datetime and updated cataloguri definition
tjellicoe-tpzuk a22d035
Added support for catalogues and reformatting code
tjellicoe-tpzuk 31fbeeb
Code reformatting
tjellicoe-tpzuk d2b2863
Corrected catalogs endpoint spelling
tjellicoe-tpzuk 61118e4
Corrected class name
tjellicoe-tpzuk d8700c8
Corrected link handling
tjellicoe-tpzuk 43005fd
Removed old link comment
tjellicoe-tpzuk c59c3e3
Merge pull request #3 from UKEODHP/feature/EODHP-27-resource-catalogu…
tjellicoe-tpzuk bcd5c72
Corrected endpoint path for create collection
tjellicoe-tpzuk 33d3431
Merge pull request #4 from UKEODHP/bugfix/EODHP-27-correct-create-col…
tjellicoe-tpzuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
6 changes: 6 additions & 0 deletions
6
stac_fastapi/extensions/stac_fastapi/extensions/core/collectionSearch/__init__.py
This file contains hidden or 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,6 @@ | ||
| """Filter extension module.""" | ||
|
|
||
|
|
||
| from .collectionSearch import CollectionSearchExtension | ||
|
|
||
| __all__ = ["CollectionSearchExtension"] |
108 changes: 108 additions & 0 deletions
108
stac_fastapi/extensions/stac_fastapi/extensions/core/collectionSearch/collectionSearch.py
This file contains hidden or 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,108 @@ | ||
| # encoding: utf-8 | ||
| """Collection Search Extension.""" | ||
| from enum import Enum | ||
| from typing import List, Type, Union | ||
|
|
||
| import attr | ||
| from fastapi import APIRouter, FastAPI | ||
| from starlette.responses import JSONResponse, Response | ||
| from stac_pydantic.api.collections import Collections | ||
|
|
||
| from stac_fastapi.api.models import JSONSchemaResponse | ||
| from stac_fastapi.api.routes import create_async_endpoint | ||
| from stac_fastapi.types.core import AsyncCollectionSearchClient, CollectionSearchClient | ||
| from stac_fastapi.types.extension import ApiExtension | ||
| from stac_fastapi.types.search import BaseCollectionSearchGetRequest, BaseCollectionSearchPostRequest | ||
|
|
||
| from .request import CollectionSearchExtensionGetRequest, CollectionSearchExtensionPostRequest | ||
|
|
||
| class CollectionSearchConformanceClasses(str, Enum): | ||
| """Conformance classes for the Collection Search extension. | ||
|
|
||
| See | ||
| https://github.com/stac-api-extensions/collection-search | ||
| """ | ||
|
|
||
| CORE = "https://api.stacspec.org/v1.0.0-rc.1/core" | ||
| COLLECTION_SEARCH = "https://api.stacspec.org/v1.0.0-rc.1/collection-search" | ||
| SIMPLE_QUERY = "http://www.opengis.net/spec/ogcapi-common-2/1.0/conf/simple-query" | ||
|
|
||
| @attr.s | ||
| class CollectionSearchExtension(ApiExtension): | ||
| """CollectionSearch Extension. | ||
|
|
||
| The collection search extension adds two endpoints which allow searching of | ||
| collections via GET and POST: | ||
| GET /collection-search | ||
| POST /collection-search | ||
|
|
||
| https://github.com/stac-api-extensions/collection-search | ||
|
|
||
| Attributes: | ||
| search_get_request_model: Get request model for collection search | ||
| search_post_request_model: Post request model for collection search | ||
| client: Collection Search endpoint logic | ||
| conformance_classes: Conformance classes provided by the extension | ||
| """ | ||
|
|
||
| GET = CollectionSearchExtensionGetRequest | ||
| POST = CollectionSearchExtensionPostRequest | ||
|
|
||
| collection_search_get_request_model: Type[BaseCollectionSearchGetRequest] = attr.ib( | ||
| default=BaseCollectionSearchGetRequest | ||
| ) | ||
| collection_search_post_request_model: Type[BaseCollectionSearchPostRequest] = attr.ib( | ||
| default=BaseCollectionSearchPostRequest | ||
| ) | ||
|
|
||
| client: Union[AsyncCollectionSearchClient, CollectionSearchClient] = attr.ib( | ||
| factory=CollectionSearchClient | ||
| ) | ||
|
|
||
| conformance_classes: List[str] = attr.ib( | ||
| default=[ | ||
| CollectionSearchConformanceClasses.CORE, | ||
| CollectionSearchConformanceClasses.COLLECTION_SEARCH, | ||
| CollectionSearchConformanceClasses.SIMPLE_QUERY, | ||
| ] | ||
| ) | ||
| router: APIRouter = attr.ib(factory=APIRouter) | ||
| response_class: Type[Response] = attr.ib(default=JSONResponse) | ||
|
|
||
| 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="Collection Search", | ||
| path="/collection-search", | ||
| response_model=None, | ||
| response_class=self.response_class, | ||
| response_model_exclude_unset=True, | ||
| response_model_exclude_none=True, | ||
| methods=["GET"], | ||
| endpoint=create_async_endpoint( | ||
| self.client.get_collection_search, self.collection_search_get_request_model | ||
| ), | ||
| ) | ||
|
|
||
| self.router.add_api_route( | ||
| name="Collection Search", | ||
| path="/collection-search", | ||
| response_model=None, | ||
| response_class=self.response_class, | ||
| response_model_exclude_unset=True, | ||
| response_model_exclude_none=True, | ||
| methods=["POST"], | ||
| endpoint=create_async_endpoint( | ||
| self.client.post_collection_search, self.collection_search_post_request_model | ||
| ), | ||
| ) | ||
|
|
||
| app.include_router(self.router, tags=["Collection Search Extension"]) | ||
28 changes: 28 additions & 0 deletions
28
stac_fastapi/extensions/stac_fastapi/extensions/core/collectionSearch/request.py
This file contains hidden or 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,28 @@ | ||
| """Collection Search extension request models.""" | ||
|
|
||
| from enum import Enum | ||
| from typing import Any, Dict, Optional, List | ||
|
|
||
| import attr | ||
| from pydantic import BaseModel, Field | ||
| from stac_pydantic.shared import BBox | ||
|
|
||
| from stac_fastapi.types.search import APIRequest, Limit, str2bbox | ||
|
|
||
| from stac_fastapi.types.rfc3339 import DateTimeType, str_to_interval | ||
|
|
||
| @attr.s | ||
| class CollectionSearchExtensionGetRequest(APIRequest): | ||
| """Collection Search extension GET request model.""" | ||
|
|
||
| bbox: Optional[BBox] = attr.ib(default=None, converter=str2bbox) | ||
| datetime: Optional[DateTimeType] = attr.ib(default=None, converter=str_to_interval) | ||
| limit: Optional[int] = attr.ib(default=10) | ||
|
|
||
|
|
||
| class CollectionSearchExtensionPostRequest(BaseModel): | ||
| """Collection Search extension POST request model.""" | ||
|
|
||
| bbox: Optional[BBox] | ||
| datetime: Optional[DateTimeType] | ||
| limit: Optional[Limit] = Field(default=10) |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should add a note that the extension seems to mention
GET /collectionsandPOST /collectionsbut due to possible conflict with thetransactionextension we should to use/collection-searchalso wonder if we should use
/collections-searchor/search/collections🤷♂️