11"""Item crud client."""
22import json
33import logging
4+ from base64 import urlsafe_b64encode
45from datetime import datetime as datetime_type
56from datetime import timezone
67from typing import Any , Dict , List , Optional , Set , Type , Union
7- from base64 import urlsafe_b64encode
8+ from urllib . parse import urljoin
89
910import attr
1011import stac_pydantic
1112from fastapi import HTTPException
1213from overrides import overrides
1314from pydantic import ValidationError
14- from starlette .requests import Request
1515from stac_pydantic .links import Relations
1616from stac_pydantic .shared import MimeTypes
17- from urllib . parse import urljoin
17+ from starlette . requests import Request
1818
1919from stac_fastapi .elasticsearch import serializers
2020from stac_fastapi .elasticsearch .config import ElasticsearchSettings
@@ -71,12 +71,7 @@ class CoreClient(AsyncBaseCoreClient):
7171 database = DatabaseLogic ()
7272
7373 @overrides
74- async def all_collections (
75- self ,
76- limit : Optional [int ] = 10 ,
77- token : Optional [str ] = None ,
78- ** kwargs
79- ) -> Collections :
74+ async def all_collections (self , ** kwargs ) -> Collections :
8075 """Read all collections from the database.
8176
8277 Returns:
@@ -89,20 +84,23 @@ async def all_collections(
8984 request : Request = kwargs ["request" ]
9085 base_url = str (kwargs ["request" ].base_url )
9186
92- hits = self .database .get_all_collections (limit = limit , token = token )
87+ limit = int (request .query_params ["limit" ]) if "limit" in request .query_params else 10
88+ token = request .query_params ["token" ] if "token" in request .query_params else None
89+
90+ hits = await self .database .get_all_collections (limit = limit , token = token )
9391
9492 next_search_after = None
9593 next_link = None
9694 if len (hits ) == limit :
9795 last_hit = hits [- 1 ]
98- next_search_after = last_hit [' sort' ]
99- next_token = urlsafe_b64encode (',' . join ( map ( str , next_search_after )). encode ()). decode ()
100- paging_links = PagingLinks (
101- next = next_token , request = request
102- )
96+ next_search_after = last_hit [" sort" ]
97+ next_token = urlsafe_b64encode (
98+ "," . join ( map ( str , next_search_after )). encode ()
99+ ). decode ()
100+ paging_links = PagingLinks ( next = next_token , request = request )
103101 next_link = paging_links .link_next ()
104102
105- links = [
103+ links = [
106104 {
107105 "rel" : Relations .root .value ,
108106 "type" : MimeTypes .json ,
@@ -117,18 +115,18 @@ async def all_collections(
117115 "rel" : Relations .self .value ,
118116 "type" : MimeTypes .json ,
119117 "href" : urljoin (base_url , "collections" ),
120- }
118+ },
121119 ]
122120
123121 if next_link :
124122 links .append (next_link )
125-
123+
126124 return Collections (
127125 collections = [
128126 self .collection_serializer .db_to_stac (c ["_source" ], base_url = base_url )
129127 for c in hits
130128 ],
131- links = links
129+ links = links ,
132130 )
133131
134132 @overrides
0 commit comments