33 lines
932 B
Rust
33 lines
932 B
Rust
use crate::controllers::users::UsersController;
|
|
use crate::utils::{database::*, error::*, models::*};
|
|
use axum::{extract::State, response::Json};
|
|
|
|
pub async fn get_setup_status(
|
|
State(pool): State<DbPool>,
|
|
) -> Result<Json<SetupStatusResponse>, AppError> {
|
|
let first_user_exists = check_first_user_exists(&pool).await?;
|
|
Ok(success_response(SetupStatusResponse { first_user_exists }))
|
|
}
|
|
|
|
pub async fn init_setup(
|
|
State(pool): State<DbPool>,
|
|
Json(request): Json<InitSetupRequest>,
|
|
) -> Result<Json<serde_json::Value>, AppError> {
|
|
let first_user_exists = check_first_user_exists(&pool).await?;
|
|
|
|
if first_user_exists {
|
|
return Err(validation_error("Setup already completed"));
|
|
}
|
|
|
|
UsersController::create_user(
|
|
&pool,
|
|
&request.username,
|
|
&request.password,
|
|
UserRole::Admin,
|
|
0,
|
|
)
|
|
.await?;
|
|
|
|
Ok(success_message("Setup completed successfully"))
|
|
}
|