Skip to content

Commit 57d3539

Browse files
committed
feat: add get_all() method to NostrContactStoreApi
1 parent b2307a4 commit 57d3539

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

crates/bcr-ebill-persistence/src/db/nostr_contact_store.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ impl NostrContactStoreApi for SurrealNostrContactStore {
6565
Ok(values.unwrap_or_default())
6666
}
6767

68+
/// Get all Nostr contacts from the store.
69+
async fn get_all(&self) -> Result<Vec<NostrContact>> {
70+
let result: Vec<NostrContactDb> = self.db.select_all(Self::TABLE).await?;
71+
let values = result
72+
.into_iter()
73+
.map(|c| c.to_owned().try_into().ok())
74+
.collect::<Option<Vec<NostrContact>>>();
75+
Ok(values.unwrap_or_default())
76+
}
77+
6878
/// Find a Nostr contact by the npub. This is the public Nostr key of the contact.
6979
async fn by_npub(&self, npub: &NostrPublicKey) -> Result<Option<NostrContact>> {
7080
let result: Option<NostrContactDb> = self.db.select_one(Self::TABLE, npub.to_hex()).await?;

crates/bcr-ebill-persistence/src/nostr.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ pub trait NostrContactStoreApi: ServiceTraitBounds {
8484
async fn by_node_id(&self, node_id: &NodeId) -> Result<Option<NostrContact>>;
8585
/// Find multiple Nostr contacts by their node ids.
8686
async fn by_node_ids(&self, node_ids: Vec<NodeId>) -> Result<Vec<NostrContact>>;
87+
/// Get all Nostr contacts from the store.
88+
async fn get_all(&self) -> Result<Vec<NostrContact>>;
8789
/// Find a Nostr contact by the npub. This is the public Nostr key of the contact.
8890
async fn by_npub(&self, npub: &NostrPublicKey) -> Result<Option<NostrContact>>;
8991
/// Creates a new or updates an existing Nostr contact.

0 commit comments

Comments
 (0)