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
@@ -1,140 +1,188 @@
|
||||
use crate::teams::domain::entity::*;
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utoipa::ToSchema;
|
||||
use uuid::Uuid;
|
||||
use chrono::{DateTime, Utc};
|
||||
use crate::teams::domain::entity::*;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
pub struct UserInfoResponse {
|
||||
pub id: Uuid,
|
||||
pub email: String,
|
||||
pub fullname: String,
|
||||
pub avatar: Option<String>,
|
||||
pub phone_number: Option<String>,
|
||||
pub location: Option<String>,
|
||||
pub bio: Option<String>,
|
||||
pub skills: Option<Vec<String>>,
|
||||
pub is_active: Option<bool>,
|
||||
pub id: Uuid,
|
||||
pub email: String,
|
||||
pub fullname: String,
|
||||
pub avatar: Option<String>,
|
||||
pub phone_number: Option<String>,
|
||||
pub location: Option<String>,
|
||||
pub bio: Option<String>,
|
||||
pub skills: Option<Vec<String>>,
|
||||
pub is_active: Option<bool>,
|
||||
}
|
||||
|
||||
impl From<TeamUserInfo> for UserInfoResponse {
|
||||
fn from(u: TeamUserInfo) -> Self {
|
||||
Self { id: u.id, email: u.email, fullname: u.fullname, avatar: u.avatar,
|
||||
phone_number: u.phone_number, location: u.location, bio: u.bio,
|
||||
skills: u.skills, is_active: u.is_active }
|
||||
}
|
||||
fn from(u: TeamUserInfo) -> Self {
|
||||
Self {
|
||||
id: u.id,
|
||||
email: u.email,
|
||||
fullname: u.fullname,
|
||||
avatar: u.avatar,
|
||||
phone_number: u.phone_number,
|
||||
location: u.location,
|
||||
bio: u.bio,
|
||||
skills: u.skills,
|
||||
is_active: u.is_active,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
pub struct TeamMemberResponse {
|
||||
pub id: Uuid,
|
||||
pub team_id: Uuid,
|
||||
pub user_id: Uuid,
|
||||
pub user: UserInfoResponse,
|
||||
pub role: String,
|
||||
pub status: String,
|
||||
pub joined_at: Option<DateTime<Utc>>,
|
||||
pub id: Uuid,
|
||||
pub team_id: Uuid,
|
||||
pub user_id: Uuid,
|
||||
pub user: UserInfoResponse,
|
||||
pub role: String,
|
||||
pub status: String,
|
||||
pub joined_at: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
impl From<TeamMemberEntity> for TeamMemberResponse {
|
||||
fn from(m: TeamMemberEntity) -> Self {
|
||||
Self { id: m.id, team_id: m.team_id, user_id: m.user_id,
|
||||
user: UserInfoResponse::from(m.user), role: m.role, status: m.status, joined_at: m.joined_at }
|
||||
}
|
||||
fn from(m: TeamMemberEntity) -> Self {
|
||||
Self {
|
||||
id: m.id,
|
||||
team_id: m.team_id,
|
||||
user_id: m.user_id,
|
||||
user: UserInfoResponse::from(m.user),
|
||||
role: m.role,
|
||||
status: m.status,
|
||||
joined_at: m.joined_at,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
pub struct TeamResponse {
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
pub description: Option<String>,
|
||||
pub city: String,
|
||||
pub visibility: String,
|
||||
pub logo: Option<String>,
|
||||
pub banner: Option<String>,
|
||||
pub leader_id: Uuid,
|
||||
pub leader: Option<UserInfoResponse>,
|
||||
pub members: Option<Vec<TeamMemberResponse>>,
|
||||
pub member_count: Option<i64>,
|
||||
pub has_submission: Option<bool>,
|
||||
pub created_at: Option<DateTime<Utc>>,
|
||||
pub updated_at: Option<DateTime<Utc>>,
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
pub description: Option<String>,
|
||||
pub city: String,
|
||||
pub visibility: String,
|
||||
pub logo: Option<String>,
|
||||
pub banner: Option<String>,
|
||||
pub leader_id: Uuid,
|
||||
pub leader: Option<UserInfoResponse>,
|
||||
pub members: Option<Vec<TeamMemberResponse>>,
|
||||
pub member_count: Option<i64>,
|
||||
pub has_submission: Option<bool>,
|
||||
pub created_at: Option<DateTime<Utc>>,
|
||||
pub updated_at: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
impl From<TeamWithDetails> for TeamResponse {
|
||||
fn from(t: TeamWithDetails) -> Self {
|
||||
Self {
|
||||
id: t.id, name: t.name, description: t.description, city: t.city,
|
||||
visibility: t.visibility, logo: t.logo, banner: t.banner, leader_id: t.leader_id,
|
||||
leader: t.leader.map(UserInfoResponse::from),
|
||||
members: t.members.map(|ms| ms.into_iter().map(TeamMemberResponse::from).collect()),
|
||||
member_count: t.member_count, has_submission: t.has_submission,
|
||||
created_at: t.created_at, updated_at: t.updated_at,
|
||||
}
|
||||
}
|
||||
fn from(t: TeamWithDetails) -> Self {
|
||||
Self {
|
||||
id: t.id,
|
||||
name: t.name,
|
||||
description: t.description,
|
||||
city: t.city,
|
||||
visibility: t.visibility,
|
||||
logo: t.logo,
|
||||
banner: t.banner,
|
||||
leader_id: t.leader_id,
|
||||
leader: t.leader.map(UserInfoResponse::from),
|
||||
members: t
|
||||
.members
|
||||
.map(|ms| ms.into_iter().map(TeamMemberResponse::from).collect()),
|
||||
member_count: t.member_count,
|
||||
has_submission: t.has_submission,
|
||||
created_at: t.created_at,
|
||||
updated_at: t.updated_at,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
pub struct CreateTeamRequest {
|
||||
pub name: String,
|
||||
pub description: Option<String>,
|
||||
pub city: String,
|
||||
pub visibility: String,
|
||||
pub logo: Option<String>,
|
||||
pub banner: Option<String>,
|
||||
pub name: String,
|
||||
pub description: Option<String>,
|
||||
pub city: String,
|
||||
pub visibility: String,
|
||||
pub logo: Option<String>,
|
||||
pub banner: Option<String>,
|
||||
}
|
||||
|
||||
impl From<CreateTeamRequest> for CreateTeamInput {
|
||||
fn from(r: CreateTeamRequest) -> Self {
|
||||
Self { name: r.name, description: r.description, city: r.city,
|
||||
visibility: r.visibility, logo: r.logo, banner: r.banner }
|
||||
}
|
||||
fn from(r: CreateTeamRequest) -> Self {
|
||||
Self {
|
||||
name: r.name,
|
||||
description: r.description,
|
||||
city: r.city,
|
||||
visibility: r.visibility,
|
||||
logo: r.logo,
|
||||
banner: r.banner,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
pub struct UpdateTeamRequest {
|
||||
pub name: Option<String>,
|
||||
pub description: Option<String>,
|
||||
pub city: Option<String>,
|
||||
pub visibility: Option<String>,
|
||||
pub logo: Option<String>,
|
||||
pub banner: Option<String>,
|
||||
pub name: Option<String>,
|
||||
pub description: Option<String>,
|
||||
pub city: Option<String>,
|
||||
pub visibility: Option<String>,
|
||||
pub logo: Option<String>,
|
||||
pub banner: Option<String>,
|
||||
}
|
||||
|
||||
impl From<UpdateTeamRequest> for UpdateTeamInput {
|
||||
fn from(r: UpdateTeamRequest) -> Self {
|
||||
Self { name: r.name, description: r.description, city: r.city,
|
||||
visibility: r.visibility, logo: r.logo, banner: r.banner }
|
||||
}
|
||||
fn from(r: UpdateTeamRequest) -> Self {
|
||||
Self {
|
||||
name: r.name,
|
||||
description: r.description,
|
||||
city: r.city,
|
||||
visibility: r.visibility,
|
||||
logo: r.logo,
|
||||
banner: r.banner,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, ToSchema)]
|
||||
pub struct BrowseTeamsQuery {
|
||||
pub search: Option<String>,
|
||||
pub city: Option<String>,
|
||||
pub min_members: Option<i64>,
|
||||
pub max_members: Option<i64>,
|
||||
pub has_submission: Option<bool>,
|
||||
#[serde(default = "default_page")]
|
||||
pub page: i64,
|
||||
#[serde(default = "default_per_page")]
|
||||
pub per_page: i64,
|
||||
pub search: Option<String>,
|
||||
pub city: Option<String>,
|
||||
pub min_members: Option<i64>,
|
||||
pub max_members: Option<i64>,
|
||||
pub has_submission: Option<bool>,
|
||||
#[serde(default = "default_page")]
|
||||
pub page: i64,
|
||||
#[serde(default = "default_per_page")]
|
||||
pub per_page: i64,
|
||||
}
|
||||
|
||||
fn default_page() -> i64 { 1 }
|
||||
fn default_per_page() -> i64 { 10 }
|
||||
fn default_page() -> i64 {
|
||||
1
|
||||
}
|
||||
fn default_per_page() -> i64 {
|
||||
10
|
||||
}
|
||||
|
||||
impl From<BrowseTeamsQuery> for BrowseTeamsInput {
|
||||
fn from(q: BrowseTeamsQuery) -> Self {
|
||||
Self { search: q.search, city: q.city, min_members: q.min_members, max_members: q.max_members,
|
||||
has_submission: q.has_submission, page: q.page, per_page: q.per_page }
|
||||
}
|
||||
fn from(q: BrowseTeamsQuery) -> Self {
|
||||
Self {
|
||||
search: q.search,
|
||||
city: q.city,
|
||||
min_members: q.min_members,
|
||||
max_members: q.max_members,
|
||||
has_submission: q.has_submission,
|
||||
page: q.page,
|
||||
per_page: q.per_page,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
pub struct TeamListResponse {
|
||||
pub data: Vec<TeamResponse>,
|
||||
pub total: i64,
|
||||
pub page: i64,
|
||||
pub per_page: i64,
|
||||
pub data: Vec<TeamResponse>,
|
||||
pub total: i64,
|
||||
pub page: i64,
|
||||
pub per_page: i64,
|
||||
}
|
||||
|
||||
@@ -1,82 +1,104 @@
|
||||
use axum::{Extension, Json, extract::{Path, Query}, response::IntoResponse};
|
||||
use std::sync::Arc;
|
||||
use uuid::Uuid;
|
||||
use imphnen_utils::{errors::AppError, response_format::{ApiSuccess, ApiMessage}};
|
||||
use super::dto::*;
|
||||
use crate::middleware::hackathon_auth::HackathonAuthUser;
|
||||
use crate::teams::domain::service::TeamService;
|
||||
use super::dto::*;
|
||||
use axum::{
|
||||
Extension, Json,
|
||||
extract::{Path, Query},
|
||||
response::IntoResponse,
|
||||
};
|
||||
use imphnen_utils::{
|
||||
errors::AppError,
|
||||
response_format::{ApiMessage, ApiSuccess},
|
||||
};
|
||||
use std::sync::Arc;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub async fn create_team_handler(
|
||||
Extension(service): Extension<Arc<dyn TeamService>>,
|
||||
Extension(auth): Extension<HackathonAuthUser>,
|
||||
Json(body): Json<CreateTeamRequest>,
|
||||
Extension(service): Extension<Arc<dyn TeamService>>,
|
||||
Extension(auth): Extension<HackathonAuthUser>,
|
||||
Json(body): Json<CreateTeamRequest>,
|
||||
) -> Result<axum::response::Response, AppError> {
|
||||
let team = service.create_team(auth.user_id, body.into()).await?;
|
||||
Ok(ApiSuccess(TeamResponse::from(team)).into_response())
|
||||
let team = service.create_team(auth.user_id, body.into()).await?;
|
||||
Ok(ApiSuccess(TeamResponse::from(team)).into_response())
|
||||
}
|
||||
|
||||
pub async fn get_team_handler(
|
||||
Extension(service): Extension<Arc<dyn TeamService>>,
|
||||
Path(team_id): Path<Uuid>,
|
||||
Extension(service): Extension<Arc<dyn TeamService>>,
|
||||
Path(team_id): Path<Uuid>,
|
||||
) -> Result<axum::response::Response, AppError> {
|
||||
let team = service.get_team_by_id(team_id).await?;
|
||||
Ok(ApiSuccess(TeamResponse::from(team)).into_response())
|
||||
let team = service.get_team_by_id(team_id).await?;
|
||||
Ok(ApiSuccess(TeamResponse::from(team)).into_response())
|
||||
}
|
||||
|
||||
pub async fn browse_teams_handler(
|
||||
Extension(service): Extension<Arc<dyn TeamService>>,
|
||||
Query(query): Query<BrowseTeamsQuery>,
|
||||
Extension(service): Extension<Arc<dyn TeamService>>,
|
||||
Query(query): Query<BrowseTeamsQuery>,
|
||||
) -> Result<axum::response::Response, AppError> {
|
||||
let result = service.browse_teams(query.into()).await?;
|
||||
Ok(ApiSuccess(TeamListResponse {
|
||||
data: result.teams.into_iter().map(TeamResponse::from).collect(),
|
||||
total: result.total,
|
||||
page: result.page,
|
||||
per_page: result.per_page,
|
||||
}).into_response())
|
||||
let result = service.browse_teams(query.into()).await?;
|
||||
Ok(
|
||||
ApiSuccess(TeamListResponse {
|
||||
data: result.teams.into_iter().map(TeamResponse::from).collect(),
|
||||
total: result.total,
|
||||
page: result.page,
|
||||
per_page: result.per_page,
|
||||
})
|
||||
.into_response(),
|
||||
)
|
||||
}
|
||||
|
||||
pub async fn get_my_teams_handler(
|
||||
Extension(service): Extension<Arc<dyn TeamService>>,
|
||||
Extension(auth): Extension<HackathonAuthUser>,
|
||||
Extension(service): Extension<Arc<dyn TeamService>>,
|
||||
Extension(auth): Extension<HackathonAuthUser>,
|
||||
) -> Result<axum::response::Response, AppError> {
|
||||
let teams = service.get_user_teams(auth.user_id).await?;
|
||||
Ok(ApiSuccess(teams.into_iter().map(TeamResponse::from).collect::<Vec<_>>()).into_response())
|
||||
let teams = service.get_user_teams(auth.user_id).await?;
|
||||
Ok(
|
||||
ApiSuccess(
|
||||
teams
|
||||
.into_iter()
|
||||
.map(TeamResponse::from)
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
.into_response(),
|
||||
)
|
||||
}
|
||||
|
||||
pub async fn update_team_handler(
|
||||
Extension(service): Extension<Arc<dyn TeamService>>,
|
||||
Extension(auth): Extension<HackathonAuthUser>,
|
||||
Path(team_id): Path<Uuid>,
|
||||
Json(body): Json<UpdateTeamRequest>,
|
||||
Extension(service): Extension<Arc<dyn TeamService>>,
|
||||
Extension(auth): Extension<HackathonAuthUser>,
|
||||
Path(team_id): Path<Uuid>,
|
||||
Json(body): Json<UpdateTeamRequest>,
|
||||
) -> Result<axum::response::Response, AppError> {
|
||||
let team = service.update_team(team_id, auth.user_id, body.into()).await?;
|
||||
Ok(ApiSuccess(TeamResponse::from(team)).into_response())
|
||||
let team = service
|
||||
.update_team(team_id, auth.user_id, body.into())
|
||||
.await?;
|
||||
Ok(ApiSuccess(TeamResponse::from(team)).into_response())
|
||||
}
|
||||
|
||||
pub async fn delete_team_handler(
|
||||
Extension(service): Extension<Arc<dyn TeamService>>,
|
||||
Extension(auth): Extension<HackathonAuthUser>,
|
||||
Path(team_id): Path<Uuid>,
|
||||
Extension(service): Extension<Arc<dyn TeamService>>,
|
||||
Extension(auth): Extension<HackathonAuthUser>,
|
||||
Path(team_id): Path<Uuid>,
|
||||
) -> Result<axum::response::Response, AppError> {
|
||||
service.delete_team(team_id, auth.user_id).await?;
|
||||
Ok(ApiMessage::ok("Team deleted successfully").into_response())
|
||||
service.delete_team(team_id, auth.user_id).await?;
|
||||
Ok(ApiMessage::ok("Team deleted successfully").into_response())
|
||||
}
|
||||
|
||||
pub async fn leave_team_handler(
|
||||
Extension(service): Extension<Arc<dyn TeamService>>,
|
||||
Extension(auth): Extension<HackathonAuthUser>,
|
||||
Path(team_id): Path<Uuid>,
|
||||
Extension(service): Extension<Arc<dyn TeamService>>,
|
||||
Extension(auth): Extension<HackathonAuthUser>,
|
||||
Path(team_id): Path<Uuid>,
|
||||
) -> Result<axum::response::Response, AppError> {
|
||||
service.leave_team(team_id, auth.user_id).await?;
|
||||
Ok(ApiMessage::ok("Left team successfully").into_response())
|
||||
service.leave_team(team_id, auth.user_id).await?;
|
||||
Ok(ApiMessage::ok("Left team successfully").into_response())
|
||||
}
|
||||
|
||||
pub async fn remove_member_handler(
|
||||
Extension(service): Extension<Arc<dyn TeamService>>,
|
||||
Extension(auth): Extension<HackathonAuthUser>,
|
||||
Path((team_id, member_id)): Path<(Uuid, Uuid)>,
|
||||
Extension(service): Extension<Arc<dyn TeamService>>,
|
||||
Extension(auth): Extension<HackathonAuthUser>,
|
||||
Path((team_id, member_id)): Path<(Uuid, Uuid)>,
|
||||
) -> Result<axum::response::Response, AppError> {
|
||||
service.remove_team_member(team_id, auth.user_id, member_id).await?;
|
||||
Ok(ApiMessage::ok("Member removed successfully").into_response())
|
||||
service
|
||||
.remove_team_member(team_id, auth.user_id, member_id)
|
||||
.await?;
|
||||
Ok(ApiMessage::ok("Member removed successfully").into_response())
|
||||
}
|
||||
|
||||
@@ -1,30 +1,40 @@
|
||||
use axum::{middleware::from_fn, routing::{delete, get, post, put}, Extension, Router};
|
||||
use sqlx::PgPool;
|
||||
use std::sync::Arc;
|
||||
use super::handlers::*;
|
||||
use crate::middleware::hackathon_auth::hackathon_auth_middleware;
|
||||
use crate::teams::application::team_service::TeamServiceImpl;
|
||||
use crate::teams::domain::service::TeamService;
|
||||
use crate::teams::infrastructure::persistence::PostgresTeamRepository;
|
||||
use crate::middleware::hackathon_auth::hackathon_auth_middleware;
|
||||
use super::handlers::*;
|
||||
use axum::{
|
||||
Extension, Router,
|
||||
middleware::from_fn,
|
||||
routing::{delete, get, post, put},
|
||||
};
|
||||
use sqlx::PgPool;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub fn build_team_routes(pool: Arc<PgPool>) -> Router {
|
||||
let repo = Arc::new(PostgresTeamRepository::new(pool.clone()));
|
||||
let service: Arc<dyn TeamService> = Arc::new(TeamServiceImpl::new(repo));
|
||||
let repo = Arc::new(PostgresTeamRepository::new(pool.clone()));
|
||||
let service: Arc<dyn TeamService> = Arc::new(TeamServiceImpl::new(repo));
|
||||
|
||||
let public = Router::new()
|
||||
.route("/teams/browse", get(browse_teams_handler))
|
||||
.route("/teams/:team_id", get(get_team_handler))
|
||||
.layer(Extension(service.clone()));
|
||||
let public = Router::new()
|
||||
.route("/teams/browse", get(browse_teams_handler))
|
||||
.route("/teams/:team_id", get(get_team_handler))
|
||||
.layer(Extension(service.clone()));
|
||||
|
||||
let protected = Router::new()
|
||||
.route("/teams", post(create_team_handler))
|
||||
.route("/teams/my", get(get_my_teams_handler))
|
||||
.route("/teams/:team_id", put(update_team_handler).delete(delete_team_handler))
|
||||
.route("/teams/:team_id/leave", post(leave_team_handler))
|
||||
.route("/teams/:team_id/members/:member_id", delete(remove_member_handler))
|
||||
.layer(Extension(service))
|
||||
.layer(Extension(pool.clone()))
|
||||
.layer(from_fn(hackathon_auth_middleware));
|
||||
let protected = Router::new()
|
||||
.route("/teams", post(create_team_handler))
|
||||
.route("/teams/my", get(get_my_teams_handler))
|
||||
.route(
|
||||
"/teams/:team_id",
|
||||
put(update_team_handler).delete(delete_team_handler),
|
||||
)
|
||||
.route("/teams/:team_id/leave", post(leave_team_handler))
|
||||
.route(
|
||||
"/teams/:team_id/members/:member_id",
|
||||
delete(remove_member_handler),
|
||||
)
|
||||
.layer(Extension(service))
|
||||
.layer(Extension(pool.clone()))
|
||||
.layer(from_fn(hackathon_auth_middleware));
|
||||
|
||||
Router::new().merge(public).merge(protected)
|
||||
Router::new().merge(public).merge(protected)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user