Skip to content

Commit

Permalink
feat: Implement find_all method in CompanyRepository
Browse files Browse the repository at this point in the history
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 <pro.nathaelbonnal@gmail.com>
  • Loading branch information
NathaelB committed Nov 12, 2024
1 parent 7606e5a commit 107089b
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/lib/infrastructure/company/neo4j/company_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,24 @@ impl CompanyRepository for Neo4jCompanyRepository {
}

async fn find_all(&self) -> Result<Vec<Company>, 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<Option<Company>, CompanyError> {
Expand Down

0 comments on commit 107089b

Please # to comment.