feat: v0.3.0 — standardize codebase, centralize infra, merge QR into CMS
- 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>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
2ae43b3bcc
commit
331a4a4e88
@@ -6,95 +6,95 @@ use zod_rs::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, ZodSchema)]
|
||||
pub struct AuthLoginRequestDto {
|
||||
#[zod(email, min_length(1))]
|
||||
pub email: String,
|
||||
#[zod(min_length(1))]
|
||||
pub password: String,
|
||||
#[zod(email, min_length(1))]
|
||||
pub email: String,
|
||||
#[zod(min_length(1))]
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
impl ZodValidate for AuthLoginRequestDto {
|
||||
fn zod_validate(value: &serde_json::Value) -> Result<Self, String> {
|
||||
Self::validate_and_parse(value).map_err(|e| e.to_string())
|
||||
}
|
||||
fn zod_validate(value: &serde_json::Value) -> Result<Self, String> {
|
||||
Self::validate_and_parse(value).map_err(|e| e.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, Default)]
|
||||
pub struct TokenDto {
|
||||
pub access_token: String,
|
||||
pub refresh_token: String,
|
||||
pub access_token: String,
|
||||
pub refresh_token: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
|
||||
pub struct AuthLoginResponsetDto {
|
||||
pub token: TokenDto,
|
||||
pub user: UsersDetailItemDto,
|
||||
pub token: TokenDto,
|
||||
pub user: UsersDetailItemDto,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, ZodSchema)]
|
||||
pub struct AuthRegisterRequestDto {
|
||||
#[zod(email, min_length(1))]
|
||||
pub email: String,
|
||||
#[zod(min_length(8), regex(pattern = "^[A-Za-z\\d@$!%*?&]{8,}$"))]
|
||||
pub password: String,
|
||||
#[zod(min_length(2))]
|
||||
pub fullname: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub phone_number: Option<String>,
|
||||
#[zod(email, min_length(1))]
|
||||
pub email: String,
|
||||
#[zod(min_length(8), regex(pattern = "^[A-Za-z\\d@$!%*?&]{8,}$"))]
|
||||
pub password: String,
|
||||
#[zod(min_length(2))]
|
||||
pub fullname: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub phone_number: Option<String>,
|
||||
}
|
||||
|
||||
impl ZodValidate for AuthRegisterRequestDto {
|
||||
fn zod_validate(value: &serde_json::Value) -> Result<Self, String> {
|
||||
Self::validate_and_parse(value).map_err(|e| e.to_string())
|
||||
}
|
||||
fn zod_validate(value: &serde_json::Value) -> Result<Self, String> {
|
||||
Self::validate_and_parse(value).map_err(|e| e.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, ZodSchema)]
|
||||
pub struct AuthVerifyEmailRequestDto {
|
||||
#[zod(email, min_length(1))]
|
||||
pub email: String,
|
||||
pub otp: u32,
|
||||
#[zod(email, min_length(1))]
|
||||
pub email: String,
|
||||
pub otp: u32,
|
||||
}
|
||||
|
||||
impl ZodValidate for AuthVerifyEmailRequestDto {
|
||||
fn zod_validate(value: &serde_json::Value) -> Result<Self, String> {
|
||||
Self::validate_and_parse(value).map_err(|e| e.to_string())
|
||||
}
|
||||
fn zod_validate(value: &serde_json::Value) -> Result<Self, String> {
|
||||
Self::validate_and_parse(value).map_err(|e| e.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, ZodSchema)]
|
||||
pub struct AuthResendOtpRequestDto {
|
||||
#[zod(email, min_length(1))]
|
||||
pub email: String,
|
||||
#[zod(email, min_length(1))]
|
||||
pub email: String,
|
||||
}
|
||||
|
||||
impl ZodValidate for AuthResendOtpRequestDto {
|
||||
fn zod_validate(value: &serde_json::Value) -> Result<Self, String> {
|
||||
Self::validate_and_parse(value).map_err(|e| e.to_string())
|
||||
}
|
||||
fn zod_validate(value: &serde_json::Value) -> Result<Self, String> {
|
||||
Self::validate_and_parse(value).map_err(|e| e.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, ZodSchema)]
|
||||
pub struct AuthRefreshTokenRequestDto {
|
||||
#[zod(min_length(1))]
|
||||
pub refresh_token: String,
|
||||
#[zod(min_length(1))]
|
||||
pub refresh_token: String,
|
||||
}
|
||||
|
||||
impl ZodValidate for AuthRefreshTokenRequestDto {
|
||||
fn zod_validate(value: &serde_json::Value) -> Result<Self, String> {
|
||||
Self::validate_and_parse(value).map_err(|e| e.to_string())
|
||||
}
|
||||
fn zod_validate(value: &serde_json::Value) -> Result<Self, String> {
|
||||
Self::validate_and_parse(value).map_err(|e| e.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, ZodSchema)]
|
||||
pub struct AuthNewPasswordRequestDto {
|
||||
#[zod(min_length(1))]
|
||||
pub token: String,
|
||||
#[zod(min_length(8), regex(pattern = "^[A-Za-z\\d@$!%*?&]{8,}$"))]
|
||||
pub password: String,
|
||||
#[zod(min_length(1))]
|
||||
pub token: String,
|
||||
#[zod(min_length(8), regex(pattern = "^[A-Za-z\\d@$!%*?&]{8,}$"))]
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
impl ZodValidate for AuthNewPasswordRequestDto {
|
||||
fn zod_validate(value: &serde_json::Value) -> Result<Self, String> {
|
||||
Self::validate_and_parse(value).map_err(|e| e.to_string())
|
||||
}
|
||||
fn zod_validate(value: &serde_json::Value) -> Result<Self, String> {
|
||||
Self::validate_and_parse(value).map_err(|e| e.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,43 @@
|
||||
use std::sync::Arc;
|
||||
use axum::{Extension, response::IntoResponse};
|
||||
use imphnen_libs::ValidatedJson;
|
||||
use imphnen_utils::{ApiSuccess, ApiMessage, AppError};
|
||||
use super::dto::{
|
||||
AuthLoginRequestDto, AuthRegisterRequestDto, AuthResendOtpRequestDto,
|
||||
AuthVerifyEmailRequestDto, AuthNewPasswordRequestDto, AuthRefreshTokenRequestDto,
|
||||
AuthLoginRequestDto, AuthLoginResponsetDto, AuthNewPasswordRequestDto,
|
||||
AuthRefreshTokenRequestDto, AuthRegisterRequestDto, AuthResendOtpRequestDto,
|
||||
AuthVerifyEmailRequestDto, TokenDto,
|
||||
};
|
||||
use crate::auth::domain::AuthService;
|
||||
use crate::auth::domain::types::{
|
||||
LoginInput, NewPasswordInput, RefreshTokenInput, RegisterInput, ResendOtpInput,
|
||||
VerifyEmailInput,
|
||||
};
|
||||
use crate::users::infrastructure::http::dto::UsersDetailItemDto;
|
||||
use axum::{Extension, response::IntoResponse};
|
||||
use imphnen_entities::RolesDetailItemDto;
|
||||
use imphnen_libs::ValidatedJson;
|
||||
use imphnen_utils::{ApiMessage, ApiSuccess, AppError};
|
||||
use std::sync::Arc;
|
||||
|
||||
fn login_resp_to_dto(
|
||||
output: crate::auth::domain::types::LoginOutput,
|
||||
) -> AuthLoginResponsetDto {
|
||||
let u = output.user;
|
||||
AuthLoginResponsetDto {
|
||||
token: TokenDto {
|
||||
access_token: output.token.access_token,
|
||||
refresh_token: output.token.refresh_token,
|
||||
},
|
||||
user: UsersDetailItemDto {
|
||||
id: u.id,
|
||||
role: RolesDetailItemDto::from(&u.role),
|
||||
fullname: u.fullname,
|
||||
legal_name: u.legal_name,
|
||||
email: u.email,
|
||||
avatar: u.avatar,
|
||||
is_active: u.is_active,
|
||||
profile_extension: u.profile_extension,
|
||||
created_at: u.created_at,
|
||||
updated_at: u.updated_at,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
post,
|
||||
@@ -19,11 +50,15 @@ use crate::auth::domain::AuthService;
|
||||
tag = "Authentication"
|
||||
)]
|
||||
pub async fn post_login(
|
||||
Extension(service): Extension<Arc<dyn AuthService>>,
|
||||
ValidatedJson(payload): ValidatedJson<AuthLoginRequestDto>,
|
||||
Extension(service): Extension<Arc<dyn AuthService>>,
|
||||
ValidatedJson(payload): ValidatedJson<AuthLoginRequestDto>,
|
||||
) -> Result<impl IntoResponse, AppError> {
|
||||
let resp = service.login(payload).await?;
|
||||
Ok(ApiSuccess(resp))
|
||||
let input = LoginInput {
|
||||
email: payload.email,
|
||||
password: payload.password,
|
||||
};
|
||||
let resp = service.login(input).await?;
|
||||
Ok(ApiSuccess(login_resp_to_dto(resp)))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
@@ -38,11 +73,15 @@ pub async fn post_login(
|
||||
tag = "Authentication"
|
||||
)]
|
||||
pub async fn post_login_mentor(
|
||||
Extension(service): Extension<Arc<dyn AuthService>>,
|
||||
ValidatedJson(payload): ValidatedJson<AuthLoginRequestDto>,
|
||||
Extension(service): Extension<Arc<dyn AuthService>>,
|
||||
ValidatedJson(payload): ValidatedJson<AuthLoginRequestDto>,
|
||||
) -> Result<impl IntoResponse, AppError> {
|
||||
let resp = service.login_mentor(payload).await?;
|
||||
Ok(ApiSuccess(resp))
|
||||
let input = LoginInput {
|
||||
email: payload.email,
|
||||
password: payload.password,
|
||||
};
|
||||
let resp = service.login_mentor(input).await?;
|
||||
Ok(ApiSuccess(login_resp_to_dto(resp)))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
@@ -56,11 +95,17 @@ pub async fn post_login_mentor(
|
||||
tag = "Authentication"
|
||||
)]
|
||||
pub async fn post_register(
|
||||
Extension(service): Extension<Arc<dyn AuthService>>,
|
||||
ValidatedJson(payload): ValidatedJson<AuthRegisterRequestDto>,
|
||||
Extension(service): Extension<Arc<dyn AuthService>>,
|
||||
ValidatedJson(payload): ValidatedJson<AuthRegisterRequestDto>,
|
||||
) -> Result<impl IntoResponse, AppError> {
|
||||
service.register(payload).await?;
|
||||
Ok(ApiMessage::created("Registration successful"))
|
||||
let input = RegisterInput {
|
||||
email: payload.email,
|
||||
password: payload.password,
|
||||
fullname: payload.fullname,
|
||||
phone_number: payload.phone_number,
|
||||
};
|
||||
service.register(input).await?;
|
||||
Ok(ApiMessage::created("Registration successful"))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
@@ -74,11 +119,15 @@ pub async fn post_register(
|
||||
tag = "Authentication"
|
||||
)]
|
||||
pub async fn post_verify_email(
|
||||
Extension(service): Extension<Arc<dyn AuthService>>,
|
||||
ValidatedJson(payload): ValidatedJson<AuthVerifyEmailRequestDto>,
|
||||
Extension(service): Extension<Arc<dyn AuthService>>,
|
||||
ValidatedJson(payload): ValidatedJson<AuthVerifyEmailRequestDto>,
|
||||
) -> Result<impl IntoResponse, AppError> {
|
||||
service.verify_email(payload).await?;
|
||||
Ok(ApiMessage::ok("Email verified successfully"))
|
||||
let input = VerifyEmailInput {
|
||||
email: payload.email,
|
||||
otp: payload.otp,
|
||||
};
|
||||
service.verify_email(input).await?;
|
||||
Ok(ApiMessage::ok("Email verified successfully"))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
@@ -92,11 +141,14 @@ pub async fn post_verify_email(
|
||||
tag = "Authentication"
|
||||
)]
|
||||
pub async fn post_resend_otp(
|
||||
Extension(service): Extension<Arc<dyn AuthService>>,
|
||||
ValidatedJson(payload): ValidatedJson<AuthResendOtpRequestDto>,
|
||||
Extension(service): Extension<Arc<dyn AuthService>>,
|
||||
ValidatedJson(payload): ValidatedJson<AuthResendOtpRequestDto>,
|
||||
) -> Result<impl IntoResponse, AppError> {
|
||||
service.resend_otp(payload).await?;
|
||||
Ok(ApiMessage::ok("OTP sent"))
|
||||
let input = ResendOtpInput {
|
||||
email: payload.email,
|
||||
};
|
||||
service.resend_otp(input).await?;
|
||||
Ok(ApiMessage::ok("OTP sent"))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
@@ -109,13 +161,16 @@ pub async fn post_resend_otp(
|
||||
tag = "Authentication"
|
||||
)]
|
||||
pub async fn post_forgot_password(
|
||||
Extension(service): Extension<Arc<dyn AuthService>>,
|
||||
ValidatedJson(payload): ValidatedJson<AuthResendOtpRequestDto>,
|
||||
Extension(service): Extension<Arc<dyn AuthService>>,
|
||||
ValidatedJson(payload): ValidatedJson<AuthResendOtpRequestDto>,
|
||||
) -> Result<impl IntoResponse, AppError> {
|
||||
service.forgot_password(payload).await?;
|
||||
Ok(ApiMessage::ok(
|
||||
"If your email is registered, you will receive a password reset link.",
|
||||
))
|
||||
let input = ResendOtpInput {
|
||||
email: payload.email,
|
||||
};
|
||||
service.forgot_password(input).await?;
|
||||
Ok(ApiMessage::ok(
|
||||
"If your email is registered, you will receive a password reset link.",
|
||||
))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
@@ -129,11 +184,15 @@ pub async fn post_forgot_password(
|
||||
tag = "Authentication"
|
||||
)]
|
||||
pub async fn post_new_password(
|
||||
Extension(service): Extension<Arc<dyn AuthService>>,
|
||||
ValidatedJson(payload): ValidatedJson<AuthNewPasswordRequestDto>,
|
||||
Extension(service): Extension<Arc<dyn AuthService>>,
|
||||
ValidatedJson(payload): ValidatedJson<AuthNewPasswordRequestDto>,
|
||||
) -> Result<impl IntoResponse, AppError> {
|
||||
service.new_password(payload).await?;
|
||||
Ok(ApiMessage::ok("Password updated successfully"))
|
||||
let input = NewPasswordInput {
|
||||
token: payload.token,
|
||||
password: payload.password,
|
||||
};
|
||||
service.new_password(input).await?;
|
||||
Ok(ApiMessage::ok("Password updated successfully"))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
@@ -147,10 +206,15 @@ pub async fn post_new_password(
|
||||
tag = "Authentication"
|
||||
)]
|
||||
pub async fn post_refresh_token(
|
||||
Extension(service): Extension<Arc<dyn AuthService>>,
|
||||
ValidatedJson(payload): ValidatedJson<AuthRefreshTokenRequestDto>,
|
||||
Extension(service): Extension<Arc<dyn AuthService>>,
|
||||
ValidatedJson(payload): ValidatedJson<AuthRefreshTokenRequestDto>,
|
||||
) -> Result<impl IntoResponse, AppError> {
|
||||
let resp = service.refresh_token(payload).await?;
|
||||
Ok(ApiSuccess(resp))
|
||||
let input = RefreshTokenInput {
|
||||
refresh_token: payload.refresh_token,
|
||||
};
|
||||
let tokens = service.refresh_token(input).await?;
|
||||
Ok(ApiSuccess(TokenDto {
|
||||
access_token: tokens.access_token,
|
||||
refresh_token: tokens.refresh_token,
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
@@ -1,29 +1,34 @@
|
||||
use std::sync::Arc;
|
||||
use axum::{Router, routing::post, Extension};
|
||||
use sea_orm::DatabaseConnection;
|
||||
use imphnen_libs::AppState;
|
||||
use crate::auth::domain::AuthService;
|
||||
use crate::auth::application::AuthServiceImpl;
|
||||
use crate::users::infrastructure::persistence::PostgresUserRepository;
|
||||
use crate::roles::infrastructure::persistence::PostgresRoleRepository;
|
||||
use super::handlers::{
|
||||
post_login, post_login_mentor, post_register, post_verify_email,
|
||||
post_resend_otp, post_forgot_password, post_new_password, post_refresh_token,
|
||||
post_forgot_password, post_login, post_login_mentor, post_new_password,
|
||||
post_refresh_token, post_register, post_resend_otp, post_verify_email,
|
||||
};
|
||||
use crate::auth::application::AuthServiceImpl;
|
||||
use crate::auth::domain::AuthService;
|
||||
use crate::roles::infrastructure::persistence::PostgresRoleRepository;
|
||||
use crate::users::infrastructure::persistence::PostgresUserRepository;
|
||||
use axum::{Extension, Router, routing::post};
|
||||
use imphnen_libs::AppState;
|
||||
use sea_orm::DatabaseConnection;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub fn auth_public_routes(_db: DatabaseConnection, state: Arc<AppState>) -> Router {
|
||||
let user_repo = Arc::new(PostgresUserRepository::new(state.postgres_connection.conn.clone()));
|
||||
let role_repo = Arc::new(PostgresRoleRepository::new(state.postgres_connection.conn.clone()));
|
||||
let auth_service: Arc<dyn AuthService> = Arc::new(AuthServiceImpl::new(user_repo, role_repo));
|
||||
Router::new()
|
||||
.route("/auth/login", post(post_login))
|
||||
.route("/auth/login-mentor", post(post_login_mentor))
|
||||
.route("/auth/register", post(post_register))
|
||||
.route("/auth/verify-email", post(post_verify_email))
|
||||
.route("/auth/send-otp", post(post_resend_otp))
|
||||
.route("/auth/forgot", post(post_forgot_password))
|
||||
.route("/auth/new-password", post(post_new_password))
|
||||
.route("/auth/refresh", post(post_refresh_token))
|
||||
.layer(Extension(auth_service))
|
||||
.layer(Extension((*state).clone()))
|
||||
let user_repo = Arc::new(PostgresUserRepository::new(
|
||||
state.postgres_connection.conn.clone(),
|
||||
));
|
||||
let role_repo = Arc::new(PostgresRoleRepository::new(
|
||||
state.postgres_connection.conn.clone(),
|
||||
));
|
||||
let auth_service: Arc<dyn AuthService> =
|
||||
Arc::new(AuthServiceImpl::new(user_repo, role_repo));
|
||||
Router::new()
|
||||
.route("/auth/login", post(post_login))
|
||||
.route("/auth/login-mentor", post(post_login_mentor))
|
||||
.route("/auth/register", post(post_register))
|
||||
.route("/auth/verify-email", post(post_verify_email))
|
||||
.route("/auth/send-otp", post(post_resend_otp))
|
||||
.route("/auth/forgot", post(post_forgot_password))
|
||||
.route("/auth/new-password", post(post_new_password))
|
||||
.route("/auth/refresh", post(post_refresh_token))
|
||||
.layer(Extension(auth_service))
|
||||
.layer(Extension((*state).clone()))
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
// Auth persistence - uses v1 AuthRepository directly
|
||||
|
||||
|
||||
Reference in New Issue
Block a user