diff --git a/basics/todo/src/api.rs b/basics/todo/src/api.rs index ae8900d..00725ce 100644 --- a/basics/todo/src/api.rs +++ b/basics/todo/src/api.rs @@ -1,5 +1,6 @@ use actix_files::NamedFile; use actix_session::Session; +use actix_web::http::StatusCode; use actix_web::{ dev, error, middleware::ErrorHandlerResponse, web, Error, HttpResponse, Responder, Result, }; @@ -50,7 +51,7 @@ pub async fn create( ) -> Result { if params.description.is_empty() { session::set_flash(&session, FlashMessage::error("Description cannot be empty"))?; - Ok(Redirect::to("/")) + Ok(Redirect::to("/").using_status_code(StatusCode::FOUND)) } else { db::create_task(params.into_inner().description, &pool) .await @@ -58,7 +59,7 @@ pub async fn create( session::set_flash(&session, FlashMessage::success("Task successfully added"))?; - Ok(Redirect::to("/")) + Ok(Redirect::to("/").using_status_code(StatusCode::FOUND)) } } @@ -85,7 +86,8 @@ pub async fn update( let msg = format!("Unsupported HTTP method: {unsupported_method}"); return Err(error::ErrorBadRequest(msg)); } - })) + }) + .using_status_code(StatusCode::FOUND)) } async fn toggle(