]> uap-core.de Git - note.git/commitdiff
add backend function for getting a list of note attachments main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 19 Aug 2026 16:59:55 +0000 (18:59 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 19 Aug 2026 16:59:55 +0000 (18:59 +0200)
application/backend/src/backend.rs
entity/src/lib.rs

index d5e8d61917c27a958c4ad36e7561164fffbe3309..75dbbf36dd372b360cc313176726a43861126267 100644 (file)
@@ -42,7 +42,7 @@ use tokio::sync::{broadcast, mpsc};
 use tokio::sync::broadcast::error::SendError;
 use migration::{Expr, Migrator, MigratorTrait};
 
-use entity::{collection, filecontent, note, notecontent, profile, repository};
+use entity::{attachment, collection, filecontent, note, notecontent, profile, repository};
 use entity::profile::Entity as Profile;
 use entity::collection::{create_notebook_hierarchy, CollectionType, Entity as Collection, Node};
 use entity::note::{Column, Entity as Note, NoteType};
@@ -874,6 +874,18 @@ impl BackendHandle {
         });
         let _ = self.tx.send(cmd);
     }
+    
+    pub fn get_note_attachments<F>(&self, note_id: i32, callback: F)
+    where F: FnOnce(Result<Vec<attachment::Model>, DbErr>) + Send + 'static {
+        let backend = self.backend.clone();
+        let cmd = Box::pin(async move {
+            let attachments = attachment::Entity::find()
+                .filter(attachment::Column::NoteId.eq(note_id))
+                .all(&backend.db).await;
+            callback(attachments);
+        });
+        let _ = self.tx.send(cmd);
+    }
 
     pub fn open_extern<F>(&self, note_id: i32, callback: F)
     where F: FnOnce(OpenExternResult) + Send + 'static {
index 08b265d8c670152de8f846afe57bbf6f0108ee54..9d8afc080290c983830dc072876261c9fade57bc 100644 (file)
@@ -5,5 +5,5 @@ pub mod note;
 pub mod notecontent;
 pub mod repository;
 pub mod filecontent;
-mod attachment;
-mod attachmentcontent;
\ No newline at end of file
+pub mod attachment;
+pub mod attachmentcontent;
\ No newline at end of file