28 lines
779 B
Rust
28 lines
779 B
Rust
use std::sync::Arc;
|
|
|
|
use axum::response::{IntoResponse, Response};
|
|
use axum::{Extension, Json};
|
|
use serde::Serialize;
|
|
|
|
use crate::auth::session::SessionState;
|
|
use crate::config::AppConfig;
|
|
use crate::db;
|
|
use crate::error::AppError;
|
|
|
|
#[derive(Serialize)]
|
|
struct ResetSettingsResponse {
|
|
ok: bool,
|
|
}
|
|
|
|
pub async fn reset_all_settings(
|
|
Extension(session): Extension<SessionState>,
|
|
Extension(config): Extension<Arc<AppConfig>>,
|
|
) -> Result<Response, AppError> {
|
|
let mut conn = db::pool::open_user_db(&config.data_dir, &session.user_hash)
|
|
.map_err(|error| AppError::InternalError(format!("Database error: {error}")))?;
|
|
|
|
db::settings::reset_all(&mut conn).map_err(AppError::InternalError)?;
|
|
|
|
Ok(Json(ResetSettingsResponse { ok: true }).into_response())
|
|
}
|