refactor: migrate to clean architecture with trait-based DI (v0.2.0)
Complete architectural overhaul across all 12 crates: - Replace validator crate with zod-rs for all DTO validation - Replace manual pagination with paginator-rs/paginator-sea-orm - Migrate all modules (iam, cms, gacha, dimentorin) to clean architecture: domain → application → infrastructure layers - Introduce trait-based DI (Arc<dyn Trait>) at every layer for repositories and services - Delete all v1/ legacy SurrealDB-era code across every crate - Replace opaque response helpers with typed IntoResponse structs (ApiSuccess, ApiCreated, ApiPaginated, ApiMessage) - Remove dual_mode_repository, migration_validation_errors, validator.rs dead code - Zero cargo clippy warnings; release build clean Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
1b3366d735
commit
e432a1a743
@@ -0,0 +1,77 @@
|
||||
use std::sync::Arc;
|
||||
use axum::{Extension, extract::Path, http::HeaderMap, response::IntoResponse};
|
||||
use imphnen_libs::{AppState, ValidatedJson};
|
||||
use imphnen_utils::{ApiSuccess, ApiMessage};
|
||||
use imphnen_entities::ResponseSuccessDto;
|
||||
use imphnen_iam::{PermissionsEnum, require_permissions};
|
||||
use imphnen_utils::AppError;
|
||||
use uuid::Uuid;
|
||||
use super::dto::{GachaClaimCreateRequestDto, GachaClaimDetailDto};
|
||||
use crate::gacha_claims::domain::{GachaClaimEntity, GachaClaimService};
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
security(("Bearer" = [])),
|
||||
path = "/v1/gacha/claims/detail/{id}",
|
||||
params(
|
||||
("id" = String, Path, description = "Gacha Claim ID")
|
||||
),
|
||||
responses(
|
||||
(status = 200, description = "[ADMIN] Get gacha claim by ID", body = ResponseSuccessDto<GachaClaimDetailDto>)
|
||||
),
|
||||
tag = "Gacha"
|
||||
)]
|
||||
pub async fn get_gacha_claim_by_id(
|
||||
headers: HeaderMap,
|
||||
Extension(state): Extension<AppState>,
|
||||
Extension(service): Extension<Arc<dyn GachaClaimService>>,
|
||||
Path(id): Path<String>,
|
||||
) -> Result<impl IntoResponse, AppError> {
|
||||
require_permissions!(headers, state, [PermissionsEnum::ReadDetailGachaClaims], {
|
||||
let uuid = Uuid::parse_str(&id)
|
||||
.map_err(|e| AppError::BadRequestError(format!("Invalid UUID: {e}")))?;
|
||||
let detail = service.get_claim(uuid).await?;
|
||||
Ok(ApiSuccess(GachaClaimDetailDto::from(detail)))
|
||||
})
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
post,
|
||||
security(("Bearer" = [])),
|
||||
path = "/v1/gacha/claims/create",
|
||||
request_body = GachaClaimCreateRequestDto,
|
||||
responses(
|
||||
(status = 201, description = "[ADMIN] Create new gacha claim")
|
||||
),
|
||||
tag = "Gacha"
|
||||
)]
|
||||
pub async fn post_create_gacha_claim(
|
||||
headers: HeaderMap,
|
||||
Extension(state): Extension<AppState>,
|
||||
Extension(service): Extension<Arc<dyn GachaClaimService>>,
|
||||
ValidatedJson(payload): ValidatedJson<GachaClaimCreateRequestDto>,
|
||||
) -> Result<impl IntoResponse, AppError> {
|
||||
require_permissions!(headers, state, [PermissionsEnum::CreateGachaClaims], {
|
||||
let user_id = Uuid::parse_str(&payload.user_id)
|
||||
.map_err(|e| AppError::BadRequestError(format!("Invalid user_id UUID: {e}")))?;
|
||||
let item_id = Uuid::parse_str(&payload.item_id)
|
||||
.map_err(|e| AppError::BadRequestError(format!("Invalid item_id UUID: {e}")))?;
|
||||
let entity = GachaClaimEntity {
|
||||
id: Uuid::new_v4(),
|
||||
user_id,
|
||||
gacha_item_id: item_id,
|
||||
claim_id: Uuid::new_v4(),
|
||||
claim_type: "standard".to_string(),
|
||||
status: "claimed".to_string(),
|
||||
quantity: 1,
|
||||
metadata: None,
|
||||
is_deleted: false,
|
||||
claimed_at: chrono::Utc::now(),
|
||||
created_at: chrono::Utc::now(),
|
||||
updated_at: chrono::Utc::now(),
|
||||
deleted_at: None,
|
||||
};
|
||||
service.create_claim(entity).await?;
|
||||
Ok(ApiMessage::created("Gacha claim created"))
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user