|
121 | 121 |
|
122 | 122 | extensions = [aggregation_extension] + search_extensions |
123 | 123 |
|
| 124 | +# Collection search related variables |
| 125 | +collections_get_request_model = None |
| 126 | + |
124 | 127 | # Create collection search extensions if enabled |
125 | 128 | if ENABLE_COLLECTIONS_SEARCH: |
126 | 129 | # Create collection search extensions |
|
140 | 143 | ) |
141 | 144 | collections_get_request_model = collection_search_ext.GET |
142 | 145 |
|
143 | | -# Create a post request model for collection search |
144 | | -collection_search_post_request_model = create_post_request_model( |
145 | | - collection_search_extensions |
146 | | -) |
| 146 | + # Create a post request model for collection search |
| 147 | + collection_search_post_request_model = create_post_request_model( |
| 148 | + collection_search_extensions |
| 149 | + ) |
147 | 150 |
|
148 | | -# Initialize collection search POST extension |
149 | | -collection_search_post_ext = CollectionSearchPostExtension( |
150 | | - client=CoreClient( |
151 | | - database=database_logic, |
152 | | - session=session, |
153 | | - post_request_model=collection_search_post_request_model, |
154 | | - landing_page_id=os.getenv("STAC_FASTAPI_LANDING_PAGE_ID", "stac-fastapi"), |
155 | | - ), |
156 | | - settings=settings, |
157 | | - POST=collection_search_post_request_model, |
158 | | - conformance_classes=[ |
159 | | - "https://api.stacspec.org/v1.0.0-rc.1/collection-search", |
160 | | - "http://www.opengis.net/spec/ogcapi-common-2/1.0/conf/simple-query", |
161 | | - "https://api.stacspec.org/v1.0.0-rc.1/collection-search#filter", |
162 | | - "https://api.stacspec.org/v1.0.0-rc.1/collection-search#free-text", |
163 | | - "https://api.stacspec.org/v1.0.0-rc.1/collection-search#query", |
164 | | - "https://api.stacspec.org/v1.0.0-rc.1/collection-search#sort", |
165 | | - "https://api.stacspec.org/v1.0.0-rc.1/collection-search#fields", |
166 | | - ], |
167 | | -) |
| 151 | + # Initialize collection search POST extension |
| 152 | + collection_search_post_ext = CollectionSearchPostExtension( |
| 153 | + client=CoreClient( |
| 154 | + database=database_logic, |
| 155 | + session=session, |
| 156 | + post_request_model=collection_search_post_request_model, |
| 157 | + landing_page_id=os.getenv("STAC_FASTAPI_LANDING_PAGE_ID", "stac-fastapi"), |
| 158 | + ), |
| 159 | + settings=settings, |
| 160 | + POST=collection_search_post_request_model, |
| 161 | + conformance_classes=[ |
| 162 | + "https://api.stacspec.org/v1.0.0-rc.1/collection-search", |
| 163 | + QueryConformanceClasses.COLLECTIONS, |
| 164 | + FilterConformanceClasses.COLLECTIONS, |
| 165 | + FreeTextConformanceClasses.COLLECTIONS, |
| 166 | + QueryConformanceClasses.COLLECTIONS, |
| 167 | + SortConformanceClasses.COLLECTIONS, |
| 168 | + FieldsConformanceClasses.COLLECTIONS, |
| 169 | + ], |
| 170 | + ) |
168 | 171 |
|
169 | | -# Initialize collections-search endpoint extension |
170 | | -collections_search_endpoint_ext = CollectionsSearchEndpointExtension( |
171 | | - client=CoreClient( |
172 | | - database=database_logic, |
173 | | - session=session, |
174 | | - post_request_model=collection_search_post_request_model, |
175 | | - landing_page_id=os.getenv("STAC_FASTAPI_LANDING_PAGE_ID", "stac-fastapi"), |
176 | | - ), |
177 | | - settings=settings, |
178 | | - GET=collections_get_request_model, |
179 | | - POST=collection_search_post_request_model, |
180 | | - conformance_classes=[ |
181 | | - "https://api.stacspec.org/v1.0.0-rc.1/collection-search", |
182 | | - "http://www.opengis.net/spec/ogcapi-common-2/1.0/conf/simple-query", |
183 | | - "https://api.stacspec.org/v1.0.0-rc.1/collection-search#filter", |
184 | | - "https://api.stacspec.org/v1.0.0-rc.1/collection-search#free-text", |
185 | | - "https://api.stacspec.org/v1.0.0-rc.1/collection-search#query", |
186 | | - "https://api.stacspec.org/v1.0.0-rc.1/collection-search#sort", |
187 | | - "https://api.stacspec.org/v1.0.0-rc.1/collection-search#fields", |
188 | | - ], |
189 | | -) |
| 172 | + # Initialize collections-search endpoint extension |
| 173 | + collections_search_endpoint_ext = CollectionsSearchEndpointExtension( |
| 174 | + client=CoreClient( |
| 175 | + database=database_logic, |
| 176 | + session=session, |
| 177 | + post_request_model=collection_search_post_request_model, |
| 178 | + landing_page_id=os.getenv("STAC_FASTAPI_LANDING_PAGE_ID", "stac-fastapi"), |
| 179 | + ), |
| 180 | + settings=settings, |
| 181 | + GET=collections_get_request_model, |
| 182 | + POST=collection_search_post_request_model, |
| 183 | + conformance_classes=[ |
| 184 | + "https://api.stacspec.org/v1.0.0-rc.1/collection-search", |
| 185 | + QueryConformanceClasses.COLLECTIONS, |
| 186 | + FilterConformanceClasses.COLLECTIONS, |
| 187 | + FreeTextConformanceClasses.COLLECTIONS, |
| 188 | + QueryConformanceClasses.COLLECTIONS, |
| 189 | + SortConformanceClasses.COLLECTIONS, |
| 190 | + FieldsConformanceClasses.COLLECTIONS, |
| 191 | + ], |
| 192 | + ) |
| 193 | + |
| 194 | + extensions.append(collection_search_ext) |
| 195 | + extensions.append(collection_search_post_ext) |
| 196 | + extensions.append(collections_search_endpoint_ext) |
190 | 197 |
|
191 | | -extensions.append(collection_search_ext) |
192 | | -extensions.append(collection_search_post_ext) |
193 | | -extensions.append(collections_search_endpoint_ext) |
194 | 198 |
|
195 | 199 | database_logic.extensions = [type(ext).__name__ for ext in extensions] |
196 | 200 |
|
|
230 | 234 | "route_dependencies": get_route_dependencies(), |
231 | 235 | } |
232 | 236 |
|
233 | | -# Add collections_get_request_model if collection search is enabled |
234 | | -if ENABLE_COLLECTIONS_SEARCH: |
| 237 | +# Add collections_get_request_model if it was created |
| 238 | +if collections_get_request_model: |
235 | 239 | app_config["collections_get_request_model"] = collections_get_request_model |
236 | 240 |
|
237 | 241 | api = StacApi(**app_config) |
|
0 commit comments