Rocket how to make this update function work

Hello,

I try to make a function that will update a customer
So far I have this :

#[put("/<customer>" )]
fn change_data_customer(conn: DbConn, customer : Customer) -> Json<Customer>{
  let result = diesel::update(customer::table.find(customer:columns:id))
     .set(&customer)
     .get_result(&*conn)
     .unwrap(); 
  Json(result)   
}

but now I see these error messages :

    Checking payme v0.1.0 (/home/roelof/payme)
error[E0433]: failed to resolve: use of undeclared type or module `columns`
  --> src/main.rs:85:61
   |
error[E0277]: the trait bound `Customer: rocket::request::FromParam<'_>` is not satisfied
  --> src/main.rs:84:39
   |
84 | fn change_data_customer(conn: DbConn, customer : Customer) -> Json<Customer>{
   |                                       ^^^^^^^^^^^^^^^^^^^ the trait `rocket::request::FromParam<'_>` is not implemented for `Customer`

error[E0277]: the trait bound `&Customer: diesel::query_builder::AsChangeset` is not satisfied
  --> src/main.rs:86:11
   |
86 |      .set(&customer)
   |           ^^^^^^^^^ the trait `diesel::query_builder::AsChangeset` is not implemented for `&Customer`

error: aborting due to 3 previous errors

This looks like a typo, did you mean customer::columns::id?

About trait bounds: could you share the definition of Customer struct?

you are right.

Customer looks like this

#[derive(Queryable, Serialize)]
struct Customer{
  id : i32, 
  name: String, 
  lastname: String, 
  address: String, 
  zipcode: String, 
  city: String, 
  email: String, 
  active: bool
}


#[derive(Insertable,Deserialize)]
#[table_name="customer"]
struct NewCustomer{
  name: String, 
  lastname: String, 
  address: String, 
  zipcode: String, 
  city: String, 
  email: String, 
  active: bool
}

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.