]> uap-core.de Git - note.git/commitdiff
move nodename generation to the backend main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 12 Jul 2026 15:12:51 +0000 (17:12 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 12 Jul 2026 15:12:51 +0000 (17:12 +0200)
application/backend/src/backend.rs
application/note/src/note.rs

index 27b0357ae648b5838f196b0995602ef8a854d689..f67f855a442941d1b0f9724e28f819c8bddab51c 100644 (file)
@@ -459,15 +459,21 @@ impl BackendHandle {
             callback(SaveNoteResult::ValidationError("collection_id not set"));
             return;
         };
-        let Set(nn) = &note.nodename else {
-            callback(SaveNoteResult::ValidationError("nodename not set"));
-            return;
-        };
-        let mut nodename = nn.clone();
         let Set(version) = note.version else {
             callback(SaveNoteResult::ValidationError("version not set"));
             return;
         };
+        let Set(title) = &note.title else {
+            callback(SaveNoteResult::ValidationError("title not set"));
+            return;
+        };
+
+        let mut nodename = if let Set(nn) = &note.nodename {
+            nn.clone()
+        } else {
+            // generate nodename from title
+            title.clone()
+        };
 
         let bhandle = self.clone();
         let cmd = Box::pin(async move {
index f0e63dfa678a065b1945cd95aca4f68c98a868e8..171be4cf4d8a47c555cb6486c0c6b684cf9fc8f9 100644 (file)
@@ -47,6 +47,7 @@ pub struct Note {
     pub notebook_instance_id: u64,
 
     pub id: NoteId,
+    pub nodename: Option<String>,
     pub lock: Option<NoteLock>,
 
     pub collection_id: i32,
@@ -81,6 +82,7 @@ impl Note {
             collection_id,
 
             id,
+            nodename: None,
             lock: None,
             content_id: 0,
             version: 0,
@@ -144,6 +146,7 @@ impl Note {
 
     pub fn init_from_model(&mut self, model: &entity::note::Model) {
         self.id = NoteId::Id(model.note_id);
+        self.nodename = Some(model.nodename.clone());
         self.version = model.version;
 
         let tab = match model.kind {
@@ -244,7 +247,7 @@ impl Note {
         let note = entity::note::ActiveModel {
             note_id: note_id.clone(),
             collection_id: Set(self.collection_id),
-            nodename: Set(title.clone()), // TODO: create unique nodename
+            nodename: if let Some(nodename) = &self.nodename { Set(nodename.clone())} else { NotSet },
             kind: Set(self.kind.clone()),
             title: Set(title),
             lastmodified: Set(Utc::now().into()),