Skip to content
This repository was archived by the owner on Apr 2, 2025. It is now read-only.

Commit 8351530

Browse files
fix: reworked search opportunity request model so limit and paginatino token are in POST body, and changed tests and implementation to refelct this change in the model
1 parent e82101f commit 8351530

File tree

3 files changed

+21
-25
lines changed

3 files changed

+21
-25
lines changed

src/stapi_fastapi/models/opportunity.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class OpportunityRequest(BaseModel):
2222
# TODO: validate the CQL2 filter?
2323
filter: CQL2Filter | None = None
2424
model_config = ConfigDict(strict=True)
25+
next: str | None = None
26+
limit: int = 10
2527

2628

2729
G = TypeVar("G", bound=Geometry)

src/stapi_fastapi/routers/product_router.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import logging
44
import traceback
5-
from typing import TYPE_CHECKING, Annotated, Self
5+
from typing import TYPE_CHECKING, Self
66

7-
from fastapi import APIRouter, Body, HTTPException, Request, Response, status
7+
from fastapi import APIRouter, HTTPException, Request, Response, status
88
from geojson_pydantic.geometries import Geometry
99
from returns.maybe import Some
1010
from returns.result import Failure, Success
@@ -165,8 +165,6 @@ async def search_opportunities(
165165
self,
166166
search: OpportunityRequest,
167167
request: Request,
168-
next: Annotated[str | None, Body()] = None,
169-
limit: Annotated[int, Body()] = 10,
170168
) -> OpportunityCollection:
171169
"""
172170
Explore the opportunities available for a particular set of constraints
@@ -175,18 +173,16 @@ async def search_opportunities(
175173
match await self.product._search_opportunities(
176174
self,
177175
search,
178-
next,
179-
limit,
176+
search.next,
177+
search.limit,
180178
request,
181179
):
182180
case Success((features, Some(pagination_token))):
183181
links.append(self.order_link(request))
184-
body = {
185-
"search": search.model_dump(mode="json"),
186-
"next": pagination_token,
187-
"limit": limit,
188-
}
189-
links.append(self.pagination_link(request, body))
182+
search.next = pagination_token
183+
links.append(
184+
self.pagination_link(request, search.model_dump(mode="json"))
185+
)
190186
case Success((features, Nothing)): # noqa: F841
191187
links.append(self.order_link(request))
192188
case Failure(e) if isinstance(e, ConstraintsException):

tests/test_opportunity.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,17 @@ def test_search_opportunities_pagination(
8181
end_string = rfc3339_strftime(end, format)
8282

8383
request_payload = {
84-
"search": {
85-
"geometry": {
86-
"type": "Point",
87-
"coordinates": [0, 0],
88-
},
89-
"datetime": f"{start_string}/{end_string}",
90-
"filter": {
91-
"op": "and",
92-
"args": [
93-
{"op": ">", "args": [{"property": "off_nadir"}, 0]},
94-
{"op": "<", "args": [{"property": "off_nadir"}, 45]},
95-
],
96-
},
84+
"geometry": {
85+
"type": "Point",
86+
"coordinates": [0, 0],
87+
},
88+
"datetime": f"{start_string}/{end_string}",
89+
"filter": {
90+
"op": "and",
91+
"args": [
92+
{"op": ">", "args": [{"property": "off_nadir"}, 0]},
93+
{"op": "<", "args": [{"property": "off_nadir"}, 45]},
94+
],
9795
},
9896
"limit": limit,
9997
}

0 commit comments

Comments
 (0)