Skip to content

Commit f9cbca9

Browse files
authored
fix: empty body (#15)
For items that need to be ordered, we provide a retrieve link using a POST request with a body to place the order. This PR removes the body when it's empty. The POST request can now be made without a body when it's not needed.
1 parent 72ab97c commit f9cbca9

4 files changed

Lines changed: 15 additions & 7 deletions

File tree

stac_fastapi/eodag/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
class Settings(ApiSettings):
3333
"""EODAG Server config"""
34+
3435
debug: bool = False
3536

3637
keep_origin_url: bool = Field(

stac_fastapi/eodag/extensions/collection_order.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,21 @@ def order_collection(
7373
self,
7474
collection_id: str,
7575
request: Request,
76-
request_body: CollectionOrderBody,
76+
request_body: Optional[CollectionOrderBody] = None,
7777
) -> Item:
7878
"""Order a product with its collection id and a fake id"""
7979

8080
dag = cast(EODataAccessGateway, request.app.state.dag)
8181

82-
federation_backend = request_body.federation_backends[0] if request_body.federation_backends else None
82+
if request_body is None:
83+
federation_backend = None
84+
request_params = {}
85+
else:
86+
federation_backend = request_body.federation_backends[0] if request_body.federation_backends else None
8387

84-
request_params = request_body.model_dump(exclude={"federation_backends": True})
88+
request_params = request_body.model_dump(exclude={"federation_backends": True})
8589
search_results = dag.search(productType=collection_id, provider=federation_backend, **request_params)
90+
8691
if len(search_results) > 0:
8792
product = cast(EOProduct, search_results[0])
8893

@@ -152,7 +157,7 @@ def register(self, app: FastAPI) -> None:
152157

153158
async def _retrieve_endpoint(
154159
request: Request,
155-
request_data: CollectionOrderBody,
160+
request_data: Optional[CollectionOrderBody] = None,
156161
request_path: CollectionOrderUri = Depends(), # noqa: B008
157162
):
158163
"""Retrieve endpoint."""

stac_fastapi/eodag/extensions/pagination.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
# limitations under the License.
1818
"""Pagination extension. Override to default page to 1."""
1919

20-
from dataclasses import dataclass
2120
from typing import Annotated
2221

2322
import attr

stac_fastapi/eodag/models/links.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,14 @@ def link_collection(self) -> dict[str, str]:
286286
def collection_order_extension_link_retrieve(self) -> Optional[dict[str, Any]]:
287287
"""Create the `retrieve` link."""
288288
href = self.resolve(f"collections/{self.collection_id}/order")
289-
return {
289+
link = {
290290
"rel": "retrieve",
291291
"type": MimeTypes.geojson.value,
292292
"href": href,
293293
"method": "POST",
294-
"body": self.retrieve_body or {},
295294
"title": "Retrieve",
296295
}
296+
if self.retrieve_body:
297+
link["body"] = self.retrieve_body
298+
299+
return link

0 commit comments

Comments
 (0)