Skip to content
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

update pagination for collection-search #155

Merged
merged 16 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions stac_fastapi/pgstac/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ async def all_collections( # noqa: C901

linked_collections.append(coll)

if not collections:
next_link = None

links = await CollectionSearchPagingLinks(
request=request,
next=next_link,
Expand Down
18 changes: 1 addition & 17 deletions stac_fastapi/pgstac/models/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,23 +206,7 @@ def link_prev(self):
if self.prev is not None:
method = self.request.method
if method == "GET":
u = urlparse(self.url)
params = parse_qs(u.query)
params.update(self.prev["body"])

# if offset is equal to default value (0), drop it
if params.get("offset", -1) == 0:
_ = params.pop("offset")

param_string = unquote(urlencode(params, True))
href = ParseResult(
scheme=u.scheme,
netloc=u.netloc,
path=u.path,
params=u.params,
query=param_string,
fragment=u.fragment,
).geturl()
href = merge_params(self.url, self.prev["body"])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted this and now we will return URLs with offset=0


# if prev link is equal to this link, skip it
if href == self.url:
Expand Down
2 changes: 1 addition & 1 deletion tests/resources/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ async def test_get_collections_search_pagination(
assert len(links) == 3
assert {"root", "self", "previous"} == {link["rel"] for link in links}
prev_link = list(filter(lambda link: link["rel"] == "previous", links))[0]
assert "offset" not in prev_link["href"]
assert "offset" in prev_link["href"]

###################
# offset=0, should not have next/previous link
Expand Down
Loading