Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

controllers need updating for the latest Axum crate version #2

Open
fvzwieten opened this issue Dec 17, 2022 · 3 comments
Open

controllers need updating for the latest Axum crate version #2

fvzwieten opened this issue Dec 17, 2022 · 3 comments

Comments

@fvzwieten
Copy link

Both all_tasks and update_task controllers need to use the Json argument as the last one if you use the latest Axum create.

@carlosm27
Copy link
Owner

Hey @fvzwieten, thank you for notifying me of this. I didn't realize about Axum's last changes.

Just to be clear, you mean that now the controllers should be written like this:

pub async fn update_task(Path(id): Path<i32>, Extension(pool): Extension<PgPool>,
 Json(task): Json<task::UpdateTask>) -> Result <(StatusCode, Json<task::UpdateTask>), CustomError> {


    let sql = "SELECT * FROM task where id=$1".to_string();

    let _find: task::Task = sqlx::query_as(&sql).bind(id).fetch_one(&pool).await
        .map_err(|_| {
            CustomError::TaskNotFound
        })?;

    sqlx::query("UPDATE task SET task=$1 WHERE id=$2")
        .bind(&task.task)
        .bind(id)
        .execute(&pool)
        .await;
        
    
    Ok((StatusCode::OK, Json(task)))
}

@fvzwieten
Copy link
Author

Correct

@carlosm27
Copy link
Owner

Thank you @fvzwieten

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants