- Enforce axum best practices across all 13 workspace crates (max 200 LOC/file, no comments, no unwrap, clean architecture) - Fix domain→infrastructure dependency inversions in imphnen-iam and imphnen-dimentorin - Extract imphnen-storage (MinIO) and imphnen-email (Lettre) as standalone crates - Centralize all config in ENV struct: CDN_URL, CORS_ALLOWED_ORIGINS - Centralize SMTP through imphnen-email; remove dead HackathonConfig - Centralize database: QR crate now shares main DB pool (single DATABASE_URL) - Rename QR users table to qr_users to avoid collision with main users table - Merge imphnen-qr into imphnen-cms/src/qr (13 crates, down from 14) - Restructure imphnen-hackathon flat modules into clean architecture - Remove all stale env vars from .env.example (SurrealDB, QR_JWT, Hackathon infra) - Fix Dockerfile to include all current workspace crates - Bump all crate versions 0.2.0 → 0.3.0 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
83 lines
2.3 KiB
Rust
83 lines
2.3 KiB
Rust
use axum::{
|
|
Extension, Json,
|
|
extract::Path,
|
|
response::{IntoResponse, Response},
|
|
};
|
|
use imphnen_utils::{errors::AppError, response_format::ApiSuccess};
|
|
use std::sync::Arc;
|
|
use uuid::Uuid;
|
|
|
|
use crate::qr::{
|
|
middleware::qr_auth::QrAuthUser,
|
|
users::{
|
|
domain::{entity::UpdateUserInput, service::QrUserService},
|
|
infrastructure::http::dto::{UpdateProfileRequest, UpdateRoleRequest},
|
|
},
|
|
};
|
|
|
|
pub async fn get_me_handler(
|
|
Extension(service): Extension<Arc<dyn QrUserService>>,
|
|
Extension(auth_user): Extension<QrAuthUser>,
|
|
) -> Result<Response, AppError> {
|
|
let user = service.get_profile(auth_user.user_id).await?;
|
|
Ok(ApiSuccess(user).into_response())
|
|
}
|
|
|
|
pub async fn update_me_handler(
|
|
Extension(service): Extension<Arc<dyn QrUserService>>,
|
|
Extension(auth_user): Extension<QrAuthUser>,
|
|
Json(body): Json<UpdateProfileRequest>,
|
|
) -> Result<Response, AppError> {
|
|
let input = UpdateUserInput {
|
|
name: body.name,
|
|
email: body.email,
|
|
};
|
|
let user = service.update_profile(auth_user.user_id, input).await?;
|
|
Ok(ApiSuccess(user).into_response())
|
|
}
|
|
|
|
pub async fn list_users_handler(
|
|
Extension(service): Extension<Arc<dyn QrUserService>>,
|
|
Extension(auth_user): Extension<QrAuthUser>,
|
|
) -> Result<Response, AppError> {
|
|
if auth_user.role != "admin" {
|
|
return Err(AppError::ForbiddenError(
|
|
"Admin access required".to_string(),
|
|
));
|
|
}
|
|
let users = service.list_all().await?;
|
|
Ok(ApiSuccess(users).into_response())
|
|
}
|
|
|
|
pub async fn update_role_handler(
|
|
Extension(service): Extension<Arc<dyn QrUserService>>,
|
|
Extension(auth_user): Extension<QrAuthUser>,
|
|
Path(id): Path<Uuid>,
|
|
Json(body): Json<UpdateRoleRequest>,
|
|
) -> Result<Response, AppError> {
|
|
if auth_user.role != "admin" {
|
|
return Err(AppError::ForbiddenError(
|
|
"Admin access required".to_string(),
|
|
));
|
|
}
|
|
let user = service.update_role(id, body.role).await?;
|
|
Ok(ApiSuccess(user).into_response())
|
|
}
|
|
|
|
pub async fn delete_user_handler(
|
|
Extension(service): Extension<Arc<dyn QrUserService>>,
|
|
Extension(auth_user): Extension<QrAuthUser>,
|
|
Path(id): Path<Uuid>,
|
|
) -> Result<Response, AppError> {
|
|
if auth_user.role != "admin" {
|
|
return Err(AppError::ForbiddenError(
|
|
"Admin access required".to_string(),
|
|
));
|
|
}
|
|
service.delete(id).await?;
|
|
Ok(
|
|
imphnen_utils::response_format::ApiMessage::ok("User deleted successfully")
|
|
.into_response(),
|
|
)
|
|
}
|