From db0cb0cb20b9ffee515beac6183677ba53498f93 Mon Sep 17 00:00:00 2001 From: TheAwiteb Date: Thu, 23 Feb 2023 17:40:37 +0300 Subject: [PATCH] Use `UpdateTodoSchema` in update todo endpoint --- src/api/todo/update.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/api/todo/update.rs b/src/api/todo/update.rs index 8a5ed32..592fd5f 100644 --- a/src/api/todo/update.rs +++ b/src/api/todo/update.rs @@ -1,7 +1,7 @@ use crate::api::auth::utils::req_auth; use crate::api::todo::utils; use crate::errors::Result as ApiResult; -use crate::schemas::todo::{TodoContentSchema, TodoSchema}; +use crate::schemas::todo::{TodoSchema, UpdateTodoSchema}; use crate::schemas::{message::MessageSchema, traits::OpenApiExample}; use actix_web::{put, web, HttpRequest}; use sea_orm::DatabaseConnection; @@ -10,7 +10,7 @@ use uuid::Uuid; /// Update a single todo by uuid, only the title and status can be updated. #[utoipa::path( context_path = "/api/todos", - request_body = TodoContentSchema, + request_body = UpdateTodoSchema, params( ( "uuid", description = "The uuid of the todo", @@ -33,7 +33,7 @@ use uuid::Uuid; #[put("/{uuid}")] pub async fn update_todo( req: HttpRequest, - payload: web::Json, + payload: web::Json, uuid: web::Path, db: web::Data, ) -> ApiResult { @@ -42,8 +42,8 @@ pub async fn update_todo( let user = req_auth(req, db).await?; let todo = utils::find_todo_by_uuid(*uuid, user.id, db).await?; // If the title is not changed, then set it to None. Otherwise, set it to Some(payload.title) - let todo_title = todo.title.ne(&payload.title).then_some(payload.title); - utils::update_todo(todo, todo_title, Some(payload.status), db) + let todo_title = payload.title.filter(|title| title != &todo.title); + utils::update_todo(todo, todo_title, payload.status, db) .await .map(TodoSchema::from) }