Add protocol for cursor pagination

This commit is contained in:
2023-12-17 22:18:05 +03:00
parent 3b9d0d2ba6
commit 6ed38dd3fc
4 changed files with 24 additions and 9 deletions

View File

@@ -2,10 +2,11 @@
## ToDo
1. Implement cursor pagination on backends
1. Implement cursor pagination on backends and server
2. Implement infinity scroll
3. Implement S3 backend client
4. Implement FTP backend client
3. Add filters: min timestamp, max timestamp, emotions
4. Implement S3 backend client
5. Implement FTP backend client
## User Flow

View File

@@ -110,8 +110,8 @@ class BaseBackend:
def is_auth(self) -> bool:
return all((self._token, self._encryption_key))
async def get_sense_list(self) -> SenseList:
encrypted_sense_list = await self.fetch_sense_list()
async def get_sense_list(self, cursor: str | None = None, limit: int = 10) -> SenseList:
encrypted_sense_list = await self.fetch_sense_list(cursor=cursor, limit=limit)
senses = [
self.convert_encrypted_sense_to_sense(encrypted_sense)
for encrypted_sense in encrypted_sense_list.senses
@@ -176,7 +176,11 @@ class BaseBackend:
async def get_options(self) -> Options:
raise NotImplementedError
async def fetch_sense_list(self) -> EncryptedSenseList:
async def fetch_sense_list(
self,
cursor: str | None = None,
limit: int = 10,
) -> EncryptedSenseList:
raise NotImplementedError
async def fetch_sense(self, sense_id: uuid.UUID) -> EncryptedSense:

View File

@@ -60,7 +60,11 @@ class LocalBackend(BaseBackend):
async def get_options(self) -> Options:
return Options(registration_enabled=True)
async def fetch_sense_list(self) -> EncryptedSenseList:
async def fetch_sense_list(
self,
cursor: str | None = None,
limit: int = 10,
) -> EncryptedSenseList:
if not self.is_auth:
raise NonAuthenticatedException()

View File

@@ -117,10 +117,16 @@ class SoulBackend(BaseBackend):
return Options.model_validate(response)
async def fetch_sense_list(self) -> EncryptedSenseList:
async def fetch_sense_list(
self,
cursor: str | None = None,
limit: int = 10,
) -> EncryptedSenseList:
path = "/senses/"
params = {"limit": limit, "cursor": cursor}
params = {key: value for key, value in params.items() if value is not None}
response = await self.request(method="GET", path=path)
response = await self.request(method="GET", path=path, params=params)
senses = [EncryptedSense.model_validate(sense) for sense in response["data"]]
return EncryptedSenseList(senses=senses)