-
Couldn't load subscription status.
- Fork 42
add query/sort/fields extension support for item_collection #192
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c009e32
add query/sort/fields extension support for item_collection and refac…
vincentsarago d4e229d
update for stac-fastapi 5.0
vincentsarago 12977bf
more tests
vincentsarago a43377b
do not migrate items
vincentsarago 3ff324a
update changelog
vincentsarago 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
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 |
|---|---|---|
| @@ -1,11 +1,24 @@ | ||
| """Get Queryables.""" | ||
|
|
||
| from typing import Any, Dict, Optional | ||
| from typing import Any, Dict, List, Optional, Type | ||
|
|
||
| import attr | ||
| from buildpg import render | ||
| from fastapi import Request | ||
| from fastapi import APIRouter, FastAPI, Request | ||
| from stac_fastapi.api.models import CollectionUri, EmptyRequest, JSONSchemaResponse | ||
| from stac_fastapi.api.routes import create_async_endpoint | ||
| from stac_fastapi.extensions.core import FilterExtension | ||
| from stac_fastapi.extensions.core.collection_search.collection_search import ( | ||
| ConformanceClasses as CollectionSearchConformanceClasses, | ||
| ) | ||
| from stac_fastapi.extensions.core.filter.client import AsyncBaseFiltersClient | ||
| from stac_fastapi.extensions.core.filter.filter import FilterConformanceClasses | ||
| from stac_fastapi.extensions.core.filter.request import ( | ||
| FilterExtensionGetRequest, | ||
| FilterExtensionPostRequest, | ||
| ) | ||
| from stac_fastapi.types.errors import NotFoundError | ||
| from starlette.responses import Response | ||
|
|
||
|
|
||
| class FiltersClient(AsyncBaseFiltersClient): | ||
|
|
@@ -40,3 +53,124 @@ async def get_queryables( | |
|
|
||
| queryables["$id"] = str(request.url) | ||
| return queryables | ||
|
|
||
|
|
||
| @attr.s | ||
| class SearchFilterExtension(FilterExtension): | ||
| """Item Search Filter Extension.""" | ||
|
|
||
| GET = FilterExtensionGetRequest | ||
| POST = FilterExtensionPostRequest | ||
|
|
||
| client: FiltersClient = attr.ib(factory=FiltersClient) | ||
| conformance_classes: List[str] = attr.ib( | ||
| default=[ | ||
| FilterConformanceClasses.FILTER, | ||
| FilterConformanceClasses.ITEM_SEARCH_FILTER, | ||
| FilterConformanceClasses.BASIC_CQL2, | ||
| FilterConformanceClasses.CQL2_JSON, | ||
| FilterConformanceClasses.CQL2_TEXT, | ||
| ] | ||
| ) | ||
| router: APIRouter = attr.ib(factory=APIRouter) | ||
| response_class: Type[Response] = attr.ib(default=JSONSchemaResponse) | ||
vincentsarago marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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="Queryables", | ||
| path="/queryables", | ||
| methods=["GET"], | ||
| responses={ | ||
| 200: { | ||
| "content": { | ||
| "application/schema+json": {}, | ||
| }, | ||
| # TODO: add output model in stac-pydantic | ||
| }, | ||
| }, | ||
| response_class=self.response_class, | ||
| endpoint=create_async_endpoint(self.client.get_queryables, EmptyRequest), | ||
| ) | ||
| app.include_router(self.router, tags=["Filter Extension"]) | ||
vincentsarago marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| @attr.s | ||
| class ItemCollectionFilterExtension(FilterExtension): | ||
| """Item Collection Filter Extension.""" | ||
|
|
||
| GET = FilterExtensionGetRequest | ||
| POST = FilterExtensionPostRequest | ||
|
|
||
| client: FiltersClient = attr.ib(factory=FiltersClient) | ||
| conformance_classes: List[str] = attr.ib( | ||
| default=[ | ||
| FilterConformanceClasses.FILTER, | ||
| FilterConformanceClasses.FEATURES_FILTER, | ||
| FilterConformanceClasses.BASIC_CQL2, | ||
| FilterConformanceClasses.CQL2_JSON, | ||
| FilterConformanceClasses.CQL2_TEXT, | ||
| ] | ||
| ) | ||
| router: APIRouter = attr.ib(factory=APIRouter) | ||
| response_class: Type[Response] = attr.ib(default=JSONSchemaResponse) | ||
|
|
||
| def register(self, app: FastAPI) -> None: | ||
| """Register the extension with a FastAPI application. | ||
|
|
||
| Args: | ||
| app: target FastAPI application. | ||
|
|
||
| Returns: | ||
| None | ||
| """ | ||
| self.router.add_api_route( | ||
| name="Collection Queryables", | ||
| path="/collections/{collection_id}/queryables", | ||
| methods=["GET"], | ||
| responses={ | ||
| 200: { | ||
| "content": { | ||
| "application/schema+json": {}, | ||
| }, | ||
| # TODO: add output model in stac-pydantic | ||
| }, | ||
| }, | ||
| response_class=self.response_class, | ||
| endpoint=create_async_endpoint(self.client.get_queryables, CollectionUri), | ||
| ) | ||
| app.include_router(self.router, tags=["Filter Extension"]) | ||
|
||
|
|
||
|
|
||
| @attr.s | ||
| class CollectionSearchFilterExtension(FilterExtension): | ||
| """Collection Search Filter Extension.""" | ||
|
|
||
| GET = FilterExtensionGetRequest | ||
| POST = FilterExtensionPostRequest | ||
|
|
||
| client: FiltersClient = attr.ib(factory=FiltersClient) | ||
| conformance_classes: List[str] = attr.ib( | ||
| default=[CollectionSearchConformanceClasses.FILTER] | ||
| ) | ||
| router: APIRouter = attr.ib(factory=APIRouter) | ||
| response_class: Type[Response] = attr.ib(default=JSONSchemaResponse) | ||
|
|
||
| def register(self, app: FastAPI) -> None: | ||
| """Register the extension with a FastAPI application. | ||
|
|
||
| Args: | ||
| app: target FastAPI application. | ||
|
|
||
| Returns: | ||
| None | ||
| """ | ||
| pass | ||
vincentsarago marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
vincentsarago marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.