| 73 | } |
| 74 | |
| 75 | pub async fn update( |
| 76 | db: web::Data<SqlitePool>, |
| 77 | params: web::Path<UpdateParams>, |
| 78 | form: web::Form<UpdateForm>, |
| 79 | session: Session, |
| 80 | ) -> Result<impl Responder, Error> { |
| 81 | Ok(web::Redirect::to(match form._method.as_ref() { |
| 82 | "put" => toggle(db, params).await?, |
| 83 | "delete" => delete(db, params, session).await?, |
| 84 | unsupported_method => { |
| 85 | let msg = format!("Unsupported HTTP method: {unsupported_method}"); |
| 86 | return Err(error::ErrorBadRequest(msg)); |
| 87 | } |
| 88 | }) |
| 89 | .using_status_code(StatusCode::FOUND)) |
| 90 | } |
| 91 | |
| 92 | async fn toggle( |
| 93 | pool: web::Data<SqlitePool>, |