From 107089b7cc60b37fa6bea4afd41c17604a4364fc Mon Sep 17 00:00:00 2001 From: nathaelbonnal Date: Mon, 11 Nov 2024 16:25:48 +0100 Subject: [PATCH] feat: Implement find_all method in CompanyRepository This commit implements the `find_all` method in the `CompanyRepository` trait. The method retrieves all companies from the Neo4j database and returns a `Result` containing the list of companies or a `CompanyError` if an error occurs during the retrieval process. Note: The recent user commits and repository commits are not relevant for generating the commit message. Signed-off-by: nathaelbonnal --- .../company/neo4j/company_repository.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/lib/infrastructure/company/neo4j/company_repository.rs b/src/lib/infrastructure/company/neo4j/company_repository.rs index dd3a80a..e1a0e09 100644 --- a/src/lib/infrastructure/company/neo4j/company_repository.rs +++ b/src/lib/infrastructure/company/neo4j/company_repository.rs @@ -60,7 +60,24 @@ impl CompanyRepository for Neo4jCompanyRepository { } async fn find_all(&self) -> Result, CompanyError> { - todo!() + let query = query("MATCH (c:Company) RETURN c"); + + let mut result = self + .neo4j + .get_graph() + .execute(query) + .await + .map_err(|_| CompanyError::NotFound)?; + + let mut companies = Vec::new(); + while let Ok(Some(row)) = result.next().await { + let company: Company = row + .get("c") + .map_err(|e| CompanyError::Unkown(e.to_string()))?; + companies.push(company); + } + + Ok(companies) } async fn find_by_id(&self, id: String) -> Result, CompanyError> {