| 1 |
|
| 2 |
|
| 3 |
use axum::{ |
| 4 |
Form, |
| 5 |
extract::State, |
| 6 |
response::{Html, IntoResponse, Response}, |
| 7 |
}; |
| 8 |
use serde::Deserialize; |
| 9 |
|
| 10 |
use sqlx::PgPool; |
| 11 |
|
| 12 |
use crate::{auth::AuthUser, db, error::Result, templates::SaveStatusTemplate}; |
| 13 |
|
| 14 |
#[derive(Debug, Deserialize)] |
| 15 |
pub(crate) struct StripeTaxForm { |
| 16 |
pub stripe_tax_enabled: Option<String>, |
| 17 |
} |
| 18 |
|
| 19 |
|
| 20 |
#[tracing::instrument(skip_all, name = "users::toggle_stripe_tax")] |
| 21 |
pub(in crate::routes::api) async fn toggle_stripe_tax( |
| 22 |
State(db): State<PgPool>, |
| 23 |
AuthUser(user): AuthUser, |
| 24 |
Form(form): Form<StripeTaxForm>, |
| 25 |
) -> Result<Response> { |
| 26 |
let enabled = form.stripe_tax_enabled.as_deref() == Some("on"); |
| 27 |
|
| 28 |
db::users::update_stripe_tax_enabled(&db, user.id, enabled).await?; |
| 29 |
|
| 30 |
Ok(Html( |
| 31 |
SaveStatusTemplate { |
| 32 |
success: true, |
| 33 |
message: "Tax setting saved".to_string(), |
| 34 |
} |
| 35 |
.render_string()?, |
| 36 |
) |
| 37 |
.into_response()) |
| 38 |
} |
| 39 |
|