diff --git a/src/server/projects.rs b/src/server/projects.rs index 8ae58b2..3ced634 100644 --- a/src/server/projects.rs +++ b/src/server/projects.rs @@ -12,6 +12,10 @@ pub(crate) async fn create_project(new_project: NewProject) -> Result>> { use crate::schema::projects; + // TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13) + let mut new_project = new_project; + new_project.title = new_project.title.trim().to_owned(); + new_project.validate() .map_err::, _>(|errors| errors.into())?; @@ -54,6 +58,10 @@ pub(crate) async fn edit_project(project_id: i32, new_project: NewProject) -> Result>> { use crate::schema::projects::dsl::*; + // TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13) + let mut new_project = new_project; + new_project.title = new_project.title.trim().to_owned(); + new_project.validate() .map_err::, _>(|errors| errors.into())?; diff --git a/src/server/subtasks.rs b/src/server/subtasks.rs index 844a7a3..a30dc63 100644 --- a/src/server/subtasks.rs +++ b/src/server/subtasks.rs @@ -13,6 +13,10 @@ pub(crate) async fn create_subtask(new_subtask: NewSubtask) -> Result>> { use crate::schema::subtasks; + // TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13) + let mut new_subtask = new_subtask; + new_subtask.title = new_subtask.title.trim().to_owned(); + new_subtask.validate() .map_err::, _>(|errors| errors.into())?; @@ -55,6 +59,10 @@ pub(crate) async fn edit_subtask(subtask_id: i32, new_subtask: NewSubtask) -> Result>> { use crate::schema::subtasks::dsl::*; + // TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13) + let mut new_subtask = new_subtask; + new_subtask.title = new_subtask.title.trim().to_owned(); + new_subtask.validate() .map_err::, _>(|errors| errors.into())?; diff --git a/src/server/tasks.rs b/src/server/tasks.rs index 192726f..707fe27 100644 --- a/src/server/tasks.rs +++ b/src/server/tasks.rs @@ -17,6 +17,10 @@ use crate::server::subtasks::restore_subtasks_of_task; pub(crate) async fn create_task(new_task: NewTask) -> Result>> { use crate::schema::tasks; + + // TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13) + let mut new_task = new_task; + new_task.title = new_task.title.trim().to_owned(); new_task.validate() .map_err::, _>(|errors| errors.into())?; @@ -105,10 +109,14 @@ pub(crate) async fn get_tasks_with_subtasks_in_category(filtered_category: Categ } #[server] -pub(crate) async fn edit_task(task_id: i32, new_task: NewTask) +pub(crate) async fn edit_task(task_id: i32, mut new_task: NewTask) -> Result>> { use crate::schema::tasks::dsl::*; + // TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13) + let mut new_task = new_task; + new_task.title = new_task.title.trim().to_owned(); + new_task.validate() .map_err::, _>(|errors| errors.into())?;