diff --git a/dataherald/api/fastapi.py b/dataherald/api/fastapi.py index b48024cf..c6fde9b4 100644 --- a/dataherald/api/fastapi.py +++ b/dataherald/api/fastapi.py @@ -360,7 +360,7 @@ def get_golden_records( page=page, limit=limit, ) - return golden_records_repository.find_all() + return golden_records_repository.find_all(page=page, limit=limit) @override def add_instruction(self, instruction_request: InstructionRequest) -> Instruction: @@ -382,7 +382,7 @@ def get_instructions( page=page, limit=limit, ) - return instruction_repository.find_all() + return instruction_repository.find_all(page=page, limit=limit) @override def delete_instruction(self, instruction_id: str) -> dict: diff --git a/dataherald/db/__init__.py b/dataherald/db/__init__.py index 4488ce4d..27a40421 100644 --- a/dataherald/db/__init__.py +++ b/dataherald/db/__init__.py @@ -40,7 +40,7 @@ def find( pass @abstractmethod - def find_all(self, collection: str) -> list: + def find_all(self, collection: str, page: int = 0, limit: int = 0) -> list: pass @abstractmethod diff --git a/dataherald/db/mongo.py b/dataherald/db/mongo.py index b2a7a41a..822632a1 100644 --- a/dataherald/db/mongo.py +++ b/dataherald/db/mongo.py @@ -57,7 +57,12 @@ def find( return list(cursor) @override - def find_all(self, collection: str) -> list: + def find_all(self, collection: str, page: int = 0, limit: int = 0) -> list: + if page > 0 and limit > 0: + skip_count = (page - 1) * limit + return list( + self._data_store[collection].find({}).skip(skip_count).limit(limit) + ) return list(self._data_store[collection].find({})) @override diff --git a/dataherald/repositories/golden_records.py b/dataherald/repositories/golden_records.py index c455bc1d..7775d6cd 100644 --- a/dataherald/repositories/golden_records.py +++ b/dataherald/repositories/golden_records.py @@ -41,8 +41,8 @@ def find_by( rows = self.storage.find(DB_COLLECTION, query, page=page, limit=limit) return [GoldenRecord(id=str(row["_id"]), **row) for row in rows] - def find_all(self) -> list[GoldenRecord]: - rows = self.storage.find_all(DB_COLLECTION) + def find_all(self, page: int = 0, limit: int = 0) -> list[GoldenRecord]: + rows = self.storage.find_all(DB_COLLECTION, page=page, limit=limit) return [GoldenRecord(id=str(row["_id"]), **row) for row in rows] def delete_by_id(self, id: str) -> int: diff --git a/dataherald/repositories/instructions.py b/dataherald/repositories/instructions.py index 1c08858a..8087729e 100644 --- a/dataherald/repositories/instructions.py +++ b/dataherald/repositories/instructions.py @@ -39,8 +39,8 @@ def find_by(self, query: dict, page: int = 1, limit: int = 10) -> list[Instructi rows = self.storage.find(DB_COLLECTION, query, page=page, limit=limit) return [Instruction(id=str(row["_id"]), **row) for row in rows] - def find_all(self) -> list[Instruction]: - rows = self.storage.find_all(DB_COLLECTION) + def find_all(self, page: int = 0, limit: int = 0) -> list[Instruction]: + rows = self.storage.find_all(DB_COLLECTION, page=page, limit=limit) return [Instruction(id=str(row["_id"]), **row) for row in rows] def delete_by_id(self, id: str) -> int: