From: Olaf Wintermann Date: Wed, 29 Jul 2026 19:48:07 +0000 (+0200) Subject: add method for moving notes to the trash collection X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=HEAD;p=note.git add method for moving notes to the trash collection --- diff --git a/application/backend/src/backend.rs b/application/backend/src/backend.rs index 2a984dc..1e65654 100644 --- a/application/backend/src/backend.rs +++ b/application/backend/src/backend.rs @@ -30,7 +30,7 @@ use std::future::Future; use std::io::Error; use std::path::{Path, PathBuf}; use std::pin::Pin; -use sea_orm::{ActiveModelTrait, Database, DatabaseConnection, EntityTrait, QueryFilter, ColumnTrait, Set, QueryOrder, DbErr, ExprTrait, UpdateResult}; +use sea_orm::{ActiveModelTrait, Database, DatabaseConnection, EntityTrait, QueryFilter, ColumnTrait, Set, QueryOrder, DbErr, ExprTrait, UpdateResult, QuerySelect}; use tokio::runtime::Runtime; use std::sync::{Arc}; use std::thread::JoinHandle; @@ -764,6 +764,43 @@ impl BackendHandle { }); let _ = self.tx.send(cmd); } + + pub fn move_note_to_trash(&self, note_id: i32, callback: F) + where F: FnOnce(Result<(), DbErr>) + Send + 'static { + let backend = self.backend.clone(); + let cmd = Box::pin(async move { + let profile_id = backend.current_profile.id; + + let res: Result<(), DbErr> = async { + let trash_id = BackendHandle::get_trash_id(&backend.db, profile_id) + .await? + .ok_or_else(|| DbErr::Custom("Trash not found".into()))?; + + let result = note::Entity::update_many() + .filter(note::Column::NoteId.eq(note_id)) + .col_expr(Column::CollectionId, Expr::value(trash_id)) + .exec(&backend.db).await?; + + if result.rows_affected == 1 { + Ok(()) + } else { + Err(DbErr::Custom("unexpected number of affected rows".into())) + } + }.await; + + callback(res); + }); + let _ = self.tx.send(cmd); + } + + async fn get_trash_id(db: &DatabaseConnection, profile_id: i32) -> Result, DbErr> { + Collection::find() + .filter(collection::Column::ProfileId.eq(profile_id)) + .select_only() + .column(collection::Column::CollectionId) + .into_tuple::<(i32)>() + .one(db).await + } }