From f8a40657edf43ceaf781a9833cc56e4dd4de7733 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Sun, 12 Jul 2026 17:12:51 +0200 Subject: [PATCH] move nodename generation to the backend --- application/backend/src/backend.rs | 16 +++++++++++----- application/note/src/note.rs | 5 ++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/application/backend/src/backend.rs b/application/backend/src/backend.rs index 27b0357..f67f855 100644 --- a/application/backend/src/backend.rs +++ b/application/backend/src/backend.rs @@ -459,15 +459,21 @@ impl BackendHandle { callback(SaveNoteResult::ValidationError("collection_id not set")); return; }; - let Set(nn) = ¬e.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) = ¬e.title else { + callback(SaveNoteResult::ValidationError("title not set")); + return; + }; + + let mut nodename = if let Set(nn) = ¬e.nodename { + nn.clone() + } else { + // generate nodename from title + title.clone() + }; let bhandle = self.clone(); let cmd = Box::pin(async move { diff --git a/application/note/src/note.rs b/application/note/src/note.rs index f0e63df..171be4c 100644 --- a/application/note/src/note.rs +++ b/application/note/src/note.rs @@ -47,6 +47,7 @@ pub struct Note { pub notebook_instance_id: u64, pub id: NoteId, + pub nodename: Option, pub lock: Option, 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()), -- 2.52.0