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
@@ -0,0 +1,10 @@
|
||||
pub mod mutation_handlers;
|
||||
pub mod query_handlers;
|
||||
|
||||
pub use mutation_handlers::{
|
||||
delete_mentor, post_register_mentor, put_update_mentor, put_update_mentor_me,
|
||||
put_update_mentor_no_id, put_verify_mentor,
|
||||
};
|
||||
pub use query_handlers::{
|
||||
get_mentor_by_id, get_mentor_list, get_mentor_me, get_mentor_status,
|
||||
};
|
||||
@@ -0,0 +1,192 @@
|
||||
use super::super::dto::{
|
||||
MentorDetailResponseDto, MentorRegisterResponseDto, MentorUpdateRequestDto,
|
||||
MentorUserRegisterRequestDto, MentorVerifyRequestDto,
|
||||
};
|
||||
use crate::mentors::domain::MentorService;
|
||||
use axum::{
|
||||
extract::{Extension, Path},
|
||||
http::HeaderMap,
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
use imphnen_iam::{PermissionsEnum, require_permissions};
|
||||
use imphnen_libs::{AppState, ValidatedJson};
|
||||
use imphnen_utils::AppError;
|
||||
use imphnen_utils::{ApiMessage, ApiSuccess, extract_email};
|
||||
use std::sync::Arc;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/v1/mentors/create",
|
||||
request_body = MentorUserRegisterRequestDto,
|
||||
responses(
|
||||
(status = 200, description = "[PUBLIC] Mentor registered successfully", body = MentorRegisterResponseDto),
|
||||
(status = 400, description = "[PUBLIC] Bad request - validation error"),
|
||||
(status = 409, description = "[PUBLIC] Conflict - user already has mentor profile"),
|
||||
(status = 500, description = "[PUBLIC] Internal server error")
|
||||
),
|
||||
tag = "Mentors"
|
||||
)]
|
||||
pub async fn post_register_mentor(
|
||||
Extension(service): Extension<Arc<dyn MentorService>>,
|
||||
ValidatedJson(dto): ValidatedJson<MentorUserRegisterRequestDto>,
|
||||
) -> Response {
|
||||
match service.register(dto.into()).await {
|
||||
Ok(resp) => axum::response::IntoResponse::into_response(
|
||||
imphnen_utils::ApiSuccess(MentorRegisterResponseDto::from(resp)),
|
||||
),
|
||||
Err(e) => ApiMessage::new(e.status_code(), e.to_string()).into_response(),
|
||||
}
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
put,
|
||||
path = "/v1/mentors/update/{id}",
|
||||
params(
|
||||
("id" = String, Path, description = "Mentor ID")
|
||||
),
|
||||
request_body = MentorUpdateRequestDto,
|
||||
responses(
|
||||
(status = 200, description = "[ADMIN] Mentor updated successfully", body = MentorDetailResponseDto),
|
||||
(status = 400, description = "[ADMIN] Bad request - validation error"),
|
||||
(status = 404, description = "[ADMIN] Mentor not found"),
|
||||
(status = 500, description = "[ADMIN] Internal server error")
|
||||
),
|
||||
tag = "Mentors - Admin",
|
||||
security(("Bearer" = []))
|
||||
)]
|
||||
pub async fn put_update_mentor(
|
||||
headers: HeaderMap,
|
||||
Extension(state): Extension<AppState>,
|
||||
Extension(service): Extension<Arc<dyn MentorService>>,
|
||||
Path(id): Path<String>,
|
||||
ValidatedJson(dto): ValidatedJson<MentorUpdateRequestDto>,
|
||||
) -> Result<impl IntoResponse, AppError> {
|
||||
let mentor_uuid = Uuid::parse_str(&id).map_err(|_| {
|
||||
AppError::BadRequestError(
|
||||
"Invalid mentor ID format. Must be a valid UUID.".to_string(),
|
||||
)
|
||||
})?;
|
||||
require_permissions!(headers, state, [PermissionsEnum::UpdateMentors], {
|
||||
let result =
|
||||
MentorDetailResponseDto::from(service.update(mentor_uuid, dto.into()).await?);
|
||||
Ok(ApiSuccess(result))
|
||||
})
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
delete,
|
||||
path = "/v1/mentors/delete/{id}",
|
||||
params(
|
||||
("id" = String, Path, description = "Mentor ID")
|
||||
),
|
||||
responses(
|
||||
(status = 200, description = "[ADMIN] Mentor deleted successfully"),
|
||||
(status = 404, description = "[ADMIN] Mentor not found"),
|
||||
(status = 500, description = "[ADMIN] Internal server error")
|
||||
),
|
||||
tag = "Mentors - Admin",
|
||||
security(("Bearer" = []))
|
||||
)]
|
||||
pub async fn delete_mentor(
|
||||
headers: HeaderMap,
|
||||
Extension(state): Extension<AppState>,
|
||||
Extension(service): Extension<Arc<dyn MentorService>>,
|
||||
Path(id): Path<String>,
|
||||
) -> Result<impl IntoResponse, AppError> {
|
||||
let mentor_uuid = Uuid::parse_str(&id).map_err(|_| {
|
||||
AppError::BadRequestError(
|
||||
"Invalid mentor ID format. Must be a valid UUID.".to_string(),
|
||||
)
|
||||
})?;
|
||||
require_permissions!(headers, state, [PermissionsEnum::DeleteMentors], {
|
||||
service.delete(mentor_uuid).await?;
|
||||
Ok(ApiMessage::ok("Mentor deleted successfully"))
|
||||
})
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
put,
|
||||
path = "/v1/mentors/verify/{id}",
|
||||
params(
|
||||
("id" = String, Path, description = "Mentor ID")
|
||||
),
|
||||
request_body = MentorVerifyRequestDto,
|
||||
responses(
|
||||
(status = 200, description = "[ADMIN] Mentor verified successfully", body = MentorDetailResponseDto),
|
||||
(status = 400, description = "[ADMIN] Bad request - validation error"),
|
||||
(status = 404, description = "[ADMIN] Mentor not found"),
|
||||
(status = 500, description = "[ADMIN] Internal server error")
|
||||
),
|
||||
tag = "Mentors - Admin",
|
||||
security(("Bearer" = []))
|
||||
)]
|
||||
pub async fn put_verify_mentor(
|
||||
headers: HeaderMap,
|
||||
Extension(state): Extension<AppState>,
|
||||
Extension(service): Extension<Arc<dyn MentorService>>,
|
||||
Path(id): Path<String>,
|
||||
ValidatedJson(dto): ValidatedJson<MentorVerifyRequestDto>,
|
||||
) -> Result<impl IntoResponse, AppError> {
|
||||
let mentor_uuid = Uuid::parse_str(&id).map_err(|_| {
|
||||
AppError::BadRequestError(
|
||||
"Invalid mentor ID format. Must be a valid UUID.".to_string(),
|
||||
)
|
||||
})?;
|
||||
require_permissions!(headers, state, [PermissionsEnum::VerifyMentors], {
|
||||
let result =
|
||||
MentorDetailResponseDto::from(service.verify(mentor_uuid, dto.into()).await?);
|
||||
Ok(ApiSuccess(result))
|
||||
})
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
put,
|
||||
path = "/v1/mentors/me/update",
|
||||
request_body = MentorUpdateRequestDto,
|
||||
responses(
|
||||
(status = 200, description = "[MENTOR] Mentor profile updated successfully", body = MentorDetailResponseDto),
|
||||
(status = 400, description = "[MENTOR] Bad request - validation error"),
|
||||
(status = 401, description = "[MENTOR] Unauthorized - invalid token"),
|
||||
(status = 404, description = "[MENTOR] Mentor profile not found"),
|
||||
(status = 500, description = "[MENTOR] Internal server error")
|
||||
),
|
||||
tag = "Mentors",
|
||||
security(("Bearer" = []))
|
||||
)]
|
||||
pub async fn put_update_mentor_me(
|
||||
headers: HeaderMap,
|
||||
Extension(state): Extension<AppState>,
|
||||
Extension(service): Extension<Arc<dyn MentorService>>,
|
||||
ValidatedJson(dto): ValidatedJson<MentorUpdateRequestDto>,
|
||||
) -> Result<impl IntoResponse, AppError> {
|
||||
require_permissions!(
|
||||
headers.clone(),
|
||||
state,
|
||||
[PermissionsEnum::UpdateOwnMentorProfile],
|
||||
{
|
||||
let email = extract_email(&headers).ok_or_else(|| {
|
||||
AppError::AuthenticationError("Token tidak valid".to_string())
|
||||
})?;
|
||||
let resp =
|
||||
MentorDetailResponseDto::from(service.update_me(&email, dto.into()).await?);
|
||||
Ok(ApiSuccess(resp))
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
put,
|
||||
path = "/v1/mentors/update",
|
||||
request_body = MentorUpdateRequestDto,
|
||||
responses(
|
||||
(status = 400, description = "[PUBLIC] Bad request - Mentor ID is required for update"),
|
||||
),
|
||||
tag = "Mentors - Admin"
|
||||
)]
|
||||
pub async fn put_update_mentor_no_id() -> impl IntoResponse {
|
||||
ApiMessage::new(
|
||||
axum::http::StatusCode::BAD_REQUEST,
|
||||
"Mentor ID is required for update",
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
use super::super::dto::{MentorDetailResponseDto, MentorListResponseDto};
|
||||
use crate::mentors::domain::MentorService;
|
||||
use axum::{
|
||||
extract::{Extension, Path},
|
||||
http::HeaderMap,
|
||||
response::IntoResponse,
|
||||
};
|
||||
use imphnen_iam::{PermissionsEnum, require_permissions};
|
||||
use imphnen_libs::AppState;
|
||||
use imphnen_utils::AppError;
|
||||
use imphnen_utils::{ApiMessage, ApiPaginated, ApiSuccess, extract_email};
|
||||
use paginator_axum::PaginationQuery;
|
||||
use paginator_utils::PaginatorResponse;
|
||||
use std::sync::Arc;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/v1/mentors",
|
||||
params(
|
||||
("page" = Option<u64>, Query, description = "Page number"),
|
||||
("per_page" = Option<u64>, Query, description = "Items per page"),
|
||||
("search" = Option<String>, Query, description = "Search query"),
|
||||
("sort_by" = Option<String>, Query, description = "Sort by field"),
|
||||
("order" = Option<String>, Query, description = "Sort order (ASC/DESC)"),
|
||||
),
|
||||
responses(
|
||||
(status = 200, description = "[ADMIN] Get list of mentors", body = Vec<MentorListResponseDto>),
|
||||
(status = 500, description = "[ADMIN] Internal server error")
|
||||
),
|
||||
tag = "Mentors",
|
||||
security(("Bearer" = []))
|
||||
)]
|
||||
pub async fn get_mentor_list(
|
||||
headers: HeaderMap,
|
||||
Extension(state): Extension<AppState>,
|
||||
Extension(service): Extension<Arc<dyn MentorService>>,
|
||||
PaginationQuery(params): PaginationQuery,
|
||||
) -> Result<impl IntoResponse, AppError> {
|
||||
require_permissions!(headers, state, [PermissionsEnum::ReadListMentors], {
|
||||
let result = service.list(params).await?;
|
||||
let mapped = PaginatorResponse {
|
||||
data: result
|
||||
.data
|
||||
.into_iter()
|
||||
.map(MentorListResponseDto::from)
|
||||
.collect(),
|
||||
meta: result.meta,
|
||||
};
|
||||
Ok(ApiPaginated(mapped))
|
||||
})
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/v1/mentors/detail/{id}",
|
||||
params(
|
||||
("id" = String, Path, description = "Mentor ID")
|
||||
),
|
||||
responses(
|
||||
(status = 200, description = "[ADMIN] Get mentor by ID", body = MentorDetailResponseDto),
|
||||
(status = 404, description = "[ADMIN] Mentor not found"),
|
||||
(status = 500, description = "[ADMIN] Internal server error")
|
||||
),
|
||||
tag = "Mentors",
|
||||
security(("Bearer" = []))
|
||||
)]
|
||||
pub async fn get_mentor_by_id(
|
||||
headers: HeaderMap,
|
||||
Extension(state): Extension<AppState>,
|
||||
Extension(service): Extension<Arc<dyn MentorService>>,
|
||||
Path(id): Path<String>,
|
||||
) -> Result<impl IntoResponse, AppError> {
|
||||
let mentor_uuid = Uuid::parse_str(&id).map_err(|_| {
|
||||
AppError::BadRequestError(
|
||||
"Invalid mentor ID format. Must be a valid UUID.".to_string(),
|
||||
)
|
||||
})?;
|
||||
require_permissions!(headers, state, [PermissionsEnum::ReadDetailMentors], {
|
||||
let dto = MentorDetailResponseDto::from(service.get_by_id(mentor_uuid).await?);
|
||||
Ok(ApiSuccess(dto))
|
||||
})
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/v1/mentors/me",
|
||||
responses(
|
||||
(status = 200, description = "[MENTOR] Current user's mentor profile", body = MentorDetailResponseDto),
|
||||
(status = 401, description = "[MENTOR] Unauthorized - invalid token"),
|
||||
(status = 403, description = "[MENTOR] Mentor profile not found for current user"),
|
||||
(status = 500, description = "[MENTOR] Internal server error")
|
||||
),
|
||||
tag = "Mentors",
|
||||
security(("Bearer" = []))
|
||||
)]
|
||||
pub async fn get_mentor_me(
|
||||
headers: HeaderMap,
|
||||
Extension(state): Extension<AppState>,
|
||||
Extension(service): Extension<Arc<dyn MentorService>>,
|
||||
) -> Result<impl IntoResponse, AppError> {
|
||||
require_permissions!(
|
||||
headers.clone(),
|
||||
state,
|
||||
[PermissionsEnum::ReadOwnMentorProfile],
|
||||
{
|
||||
let email = extract_email(&headers).ok_or_else(|| {
|
||||
AppError::AuthenticationError("Token tidak valid".to_string())
|
||||
})?;
|
||||
let detail = service.get_by_email(&email).await.map_err(|_| {
|
||||
AppError::ForbiddenError(
|
||||
"Mentor profile not found for current user".to_string(),
|
||||
)
|
||||
})?;
|
||||
Ok(ApiSuccess(MentorDetailResponseDto::from(detail)))
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/v1/mentors/me/status",
|
||||
responses(
|
||||
(status = 200, description = "[MENTOR] Mentor application status", body = String),
|
||||
(status = 401, description = "[MENTOR] Unauthorized - invalid token"),
|
||||
(status = 403, description = "[MENTOR] No mentor application found for current user"),
|
||||
(status = 500, description = "[MENTOR] Internal server error")
|
||||
),
|
||||
tag = "Mentors",
|
||||
security(("Bearer" = []))
|
||||
)]
|
||||
pub async fn get_mentor_status(
|
||||
headers: HeaderMap,
|
||||
Extension(state): Extension<AppState>,
|
||||
Extension(service): Extension<Arc<dyn MentorService>>,
|
||||
) -> Result<impl IntoResponse, AppError> {
|
||||
require_permissions!(
|
||||
headers.clone(),
|
||||
state,
|
||||
[PermissionsEnum::ReadOwnMentorStatus],
|
||||
{
|
||||
let email = extract_email(&headers).ok_or_else(|| {
|
||||
AppError::AuthenticationError("Token tidak valid".to_string())
|
||||
})?;
|
||||
let status = service.get_status(&email).await.map_err(|_| {
|
||||
AppError::ForbiddenError(
|
||||
"No mentor application found for current user".to_string(),
|
||||
)
|
||||
})?;
|
||||
Ok(ApiMessage::ok(&status))
|
||||
}
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user