]> uap-core.de Git - note.git/commitdiff
add get_notes backend function main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Thu, 21 May 2026 19:22:34 +0000 (21:22 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Thu, 21 May 2026 19:22:34 +0000 (21:22 +0200)
application/src/backend.rs

index 86446926441cc8164865842569b25cda6692b3d2..405034403df83418846e56393506083ea51411e0 100644 (file)
@@ -7,9 +7,10 @@ use tokio::sync::{broadcast, mpsc};
 use migration::{Migrator, MigratorTrait};
 use ui_rs::ui;
 
-use entity::{collection, profile};
+use entity::{collection, note, profile};
 use entity::profile::Entity as Profile;
 use entity::collection::{create_notebook_hierarchy, CollectionType, Entity as Collection, Node};
+use entity::note::{Entity as Note};
 
 pub struct Backend {
     rt: Arc<Runtime>,
@@ -252,4 +253,16 @@ impl BackendHandle {
         });
         let _ = self.tx.send(cmd);
     }
+
+    pub fn get_notes<F>(&self, collection_id: i32, callback: F)
+    where F: FnOnce(Result<Vec<note::Model>, DbErr>) + Send + 'static {
+        let backend = self.backend.clone();
+        let cmd = Box::pin(async move {
+            let result = Note::find()
+                .filter(note::Column::CollectionId.eq(collection_id))
+                .order_by_id_asc().all(&backend.db).await;
+            callback(result);
+        });
+        let _ = self.tx.send(cmd);
+    }
 }