Esempio n. 1
0
    def register(self, app: FastAPI) -> None:
        """register extension with the application"""
        items_request_model = _create_request_model(schemas.Items)

        router = APIRouter()
        router.add_api_route(
            name="Bulk Create Item",
            path="/collections/{collectionId}/bulk_items",
            response_model=str,
            response_model_exclude_unset=True,
            response_model_exclude_none=True,
            methods=["POST"],
            endpoint=create_endpoint_from_model(self.client.bulk_item_insert,
                                                items_request_model),
        )
        app.include_router(router, tags=["Bulk Transaction Extension"])
Esempio n. 2
0
 def register_core(self):
     """register stac core endpoints"""
     search_request_model = _create_request_model(schemas.STACSearch)
     fields_ext = self.get_extension(FieldsExtension)
     router = APIRouter()
     router.add_api_route(
         name="Landing Page",
         path="/",
         response_model=LandingPage,
         response_model_exclude_unset=True,
         response_model_exclude_none=True,
         methods=["GET"],
         endpoint=create_endpoint_with_depends(self.client.landing_page,
                                               EmptyRequest),
     )
     router.add_api_route(
         name="Conformance Classes",
         path="/conformance",
         response_model=ConformanceClasses,
         response_model_exclude_unset=True,
         response_model_exclude_none=True,
         methods=["GET"],
         endpoint=create_endpoint_with_depends(self.client.conformance,
                                               EmptyRequest),
     )
     router.add_api_route(
         name="Get Item",
         path="/collections/{collectionId}/items/{itemId}",
         response_model=schemas.Item,
         response_model_exclude_unset=True,
         response_model_exclude_none=True,
         methods=["GET"],
         endpoint=create_endpoint_with_depends(self.client.get_item,
                                               ItemUri),
     )
     router.add_api_route(
         name="Search",
         path="/search",
         response_model=ItemCollection if not fields_ext else None,
         response_model_exclude_unset=True,
         response_model_exclude_none=True,
         methods=["POST"],
         endpoint=create_endpoint_from_model(self.client.post_search,
                                             search_request_model),
     ),
     router.add_api_route(
         name="Search",
         path="/search",
         response_model=ItemCollection if not fields_ext else None,
         response_model_exclude_unset=True,
         response_model_exclude_none=True,
         methods=["GET"],
         endpoint=create_endpoint_with_depends(self.client.get_search,
                                               SearchGetRequest),
     )
     router.add_api_route(
         name="Get Collections",
         path="/collections",
         response_model=List[schemas.Collection],
         response_model_exclude_unset=True,
         response_model_exclude_none=True,
         methods=["GET"],
         endpoint=create_endpoint_with_depends(self.client.all_collections,
                                               EmptyRequest),
     )
     router.add_api_route(
         name="Get Collection",
         path="/collections/{collectionId}",
         response_model=schemas.Collection,
         response_model_exclude_unset=True,
         response_model_exclude_none=True,
         methods=["GET"],
         endpoint=create_endpoint_with_depends(self.client.get_collection,
                                               CollectionUri),
     )
     router.add_api_route(
         name="Get ItemCollection",
         path="/collections/{collectionId}/items",
         response_model=ItemCollection,
         response_model_exclude_unset=True,
         response_model_exclude_none=True,
         methods=["GET"],
         endpoint=create_endpoint_with_depends(self.client.item_collection,
                                               ItemCollectionUri),
     )
     self.app.include_router(router)
Esempio n. 3
0
def create_core_router(client: BaseCoreClient,
                       settings: ApiSettings) -> APIRouter:
    """Create API router with item endpoints"""
    search_request_model = _create_request_model(schemas.STACSearch, settings)
    router = APIRouter()
    router.add_api_route(
        name="Landing Page",
        path="/",
        response_model=LandingPage,
        response_model_exclude_unset=True,
        response_model_exclude_none=True,
        methods=["GET"],
        endpoint=create_endpoint_with_depends(client.landing_page,
                                              EmptyRequest),
    )
    router.add_api_route(
        name="Conformance Classes",
        path="/conformance",
        response_model=ConformanceClasses,
        response_model_exclude_unset=True,
        response_model_exclude_none=True,
        methods=["GET"],
        endpoint=create_endpoint_with_depends(client.conformance,
                                              EmptyRequest),
    )
    router.add_api_route(
        name="Get Item",
        path="/collections/{collectionId}/items/{itemId}",
        response_model=schemas.Item,
        response_model_exclude_unset=True,
        response_model_exclude_none=True,
        methods=["GET"],
        endpoint=create_endpoint_with_depends(client.get_item, ItemUri),
    )
    router.add_api_route(
        name="Search",
        path="/search",
        response_model=None if settings.api_extension_is_enabled(
            ApiExtensions.fields) else ItemCollection,
        response_model_exclude_unset=True,
        response_model_exclude_none=True,
        methods=["POST"],
        endpoint=create_endpoint_from_model(client.post_search,
                                            search_request_model),
    ),
    router.add_api_route(
        name="Search",
        path="/search",
        response_model=None if settings.api_extension_is_enabled(
            ApiExtensions.fields) else ItemCollection,
        response_model_exclude_unset=True,
        response_model_exclude_none=True,
        methods=["GET"],
        endpoint=create_endpoint_with_depends(client.get_search,
                                              SearchGetRequest),
    )
    router.add_api_route(name="Get Collections",
                         path="/collections",
                         response_model=List[schemas.Collection],
                         response_model_exclude_unset=True,
                         response_model_exclude_none=True,
                         methods=["GET"],
                         endpoint=create_endpoint_with_depends(
                             client.all_collections, EmptyRequest),
                         dependencies=[Depends(oauth2_scheme)])
    router.add_api_route(
        name="Get Collection",
        path="/collections/{collectionId}",
        response_model=schemas.Collection,
        response_model_exclude_unset=True,
        response_model_exclude_none=True,
        methods=["GET"],
        endpoint=create_endpoint_with_depends(client.get_collection,
                                              CollectionUri),
    )
    router.add_api_route(
        name="Get ItemCollection",
        path="/collections/{collectionId}/items",
        response_model=ItemCollection,
        response_model_exclude_unset=True,
        response_model_exclude_none=True,
        methods=["GET"],
        endpoint=create_endpoint_with_depends(client.item_collection,
                                              ItemCollectionUri),
    )
    return router
Esempio n. 4
0
def create_transactions_router(client: BaseTransactionsClient,
                               settings: ApiSettings) -> APIRouter:
    """Create API router for transactions extension"""
    item_request_model = _create_request_model(schemas.Item, settings)
    collection_request_model = _create_request_model(schemas.Collection,
                                                     settings)
    router = APIRouter()
    router.add_api_route(
        name="Create Item",
        path="/collections/{collectionId}/items",
        response_model=schemas.Item,
        response_model_exclude_unset=True,
        response_model_exclude_none=True,
        methods=["POST"],
        endpoint=create_endpoint_from_model(client.create_item,
                                            item_request_model),
    )
    router.add_api_route(
        name="Update Item",
        path="/collections/{collectionId}/items",
        response_model=schemas.Item,
        response_model_exclude_unset=True,
        response_model_exclude_none=True,
        methods=["PUT"],
        endpoint=create_endpoint_from_model(client.update_item,
                                            item_request_model),
    )
    router.add_api_route(
        name="Delete Item",
        path="/collections/{collectionId}/items/{itemId}",
        response_model=schemas.Item,
        response_model_exclude_unset=True,
        response_model_exclude_none=True,
        methods=["DELETE"],
        endpoint=create_endpoint_with_depends(client.delete_item, ItemUri),
    )
    router.add_api_route(
        name="Create Collection",
        path="/collections",
        response_model=schemas.Collection,
        response_model_exclude_unset=True,
        response_model_exclude_none=True,
        methods=["POST"],
        endpoint=create_endpoint_from_model(client.create_collection,
                                            collection_request_model),
    )
    router.add_api_route(
        name="Update Collection",
        path="/collections",
        response_model=schemas.Collection,
        response_model_exclude_unset=True,
        response_model_exclude_none=True,
        methods=["PUT"],
        endpoint=create_endpoint_from_model(client.update_collection,
                                            collection_request_model),
    )
    router.add_api_route(
        name="Delete Collection",
        path="/collections/{collectionId}",
        response_model=schemas.Collection,
        response_model_exclude_unset=True,
        response_model_exclude_none=True,
        methods=["DELETE"],
        endpoint=create_endpoint_with_depends(client.delete_collection,
                                              CollectionUri),
    )
    return router
Esempio n. 5
0
    def register(self, app: FastAPI) -> None:
        """register extension with the application"""

        item_request_model = _create_request_model(schemas.Item)
        collection_request_model = _create_request_model(schemas.Collection)

        router = APIRouter()
        router.add_api_route(
            name="Create Item",
            path="/collections/{collectionId}/items",
            response_model=schemas.Item,
            response_model_exclude_unset=True,
            response_model_exclude_none=True,
            methods=["POST"],
            endpoint=create_endpoint_from_model(self.client.create_item,
                                                item_request_model),
        )
        router.add_api_route(
            name="Update Item",
            path="/collections/{collectionId}/items",
            response_model=schemas.Item,
            response_model_exclude_unset=True,
            response_model_exclude_none=True,
            methods=["PUT"],
            endpoint=create_endpoint_from_model(self.client.update_item,
                                                item_request_model),
        )
        router.add_api_route(
            name="Delete Item",
            path="/collections/{collectionId}/items/{itemId}",
            response_model=schemas.Item,
            response_model_exclude_unset=True,
            response_model_exclude_none=True,
            methods=["DELETE"],
            endpoint=create_endpoint_with_depends(self.client.delete_item,
                                                  ItemUri),
        )
        router.add_api_route(
            name="Create Collection",
            path="/collections",
            response_model=schemas.Collection,
            response_model_exclude_unset=True,
            response_model_exclude_none=True,
            methods=["POST"],
            endpoint=create_endpoint_from_model(self.client.create_collection,
                                                collection_request_model),
        )
        router.add_api_route(
            name="Update Collection",
            path="/collections",
            response_model=schemas.Collection,
            response_model_exclude_unset=True,
            response_model_exclude_none=True,
            methods=["PUT"],
            endpoint=create_endpoint_from_model(self.client.update_collection,
                                                collection_request_model),
        )
        router.add_api_route(
            name="Delete Collection",
            path="/collections/{collectionId}",
            response_model=schemas.Collection,
            response_model_exclude_unset=True,
            response_model_exclude_none=True,
            methods=["DELETE"],
            endpoint=create_endpoint_with_depends(
                self.client.delete_collection, CollectionUri),
        )
        app.include_router(router, tags=["Transaction Extension"])