feat: migrate imphnen-backend-hackathon into workspace as imphnen-hackathon crate
Consolidates the standalone hackathon backend (16 crates) into a single imphnen-hackathon crate following the existing clean architecture patterns. All endpoints are exposed under /v1/hackathon/ via the gateway. Features migrated: - Auth: Supabase-based signup/login/GitHub OAuth/password reset (own JWT) - Users: profile management with team listing - Teams: CRUD with city validation, deadline enforcement, invite system - Invitations: team member invitations with accept/reject flow - Join Requests: team join request workflow - Chat: team messaging with author/leader delete permissions - Submissions: project submission lifecycle (draft→pending→submitted) - Storage: Supabase Storage file upload endpoints - Certificates: public user certificate data endpoint - Winners: public winners listing - Admin: admin-only CRUD for all entities Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
05a5b39195
commit
11442c6285
@@ -0,0 +1,140 @@
|
||||
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>,
|
||||
}
|
||||
|
||||
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 }
|
||||
}
|
||||
}
|
||||
|
||||
#[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>>,
|
||||
}
|
||||
|
||||
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 }
|
||||
}
|
||||
}
|
||||
|
||||
#[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>>,
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[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>,
|
||||
}
|
||||
|
||||
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 }
|
||||
}
|
||||
}
|
||||
|
||||
#[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>,
|
||||
}
|
||||
|
||||
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 }
|
||||
}
|
||||
}
|
||||
|
||||
#[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,
|
||||
}
|
||||
|
||||
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 }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
pub struct TeamListResponse {
|
||||
pub data: Vec<TeamResponse>,
|
||||
pub total: i64,
|
||||
pub page: i64,
|
||||
pub per_page: i64,
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
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 crate::middleware::hackathon_auth::HackathonAuthUser;
|
||||
use crate::teams::domain::service::TeamService;
|
||||
use super::dto::*;
|
||||
|
||||
pub async fn create_team_handler(
|
||||
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())
|
||||
}
|
||||
|
||||
pub async fn get_team_handler(
|
||||
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())
|
||||
}
|
||||
|
||||
pub async fn browse_teams_handler(
|
||||
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())
|
||||
}
|
||||
|
||||
pub async fn get_my_teams_handler(
|
||||
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())
|
||||
}
|
||||
|
||||
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>,
|
||||
) -> 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())
|
||||
}
|
||||
|
||||
pub async fn delete_team_handler(
|
||||
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())
|
||||
}
|
||||
|
||||
pub async fn leave_team_handler(
|
||||
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())
|
||||
}
|
||||
|
||||
pub async fn remove_member_handler(
|
||||
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())
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
pub mod dto;
|
||||
pub mod handlers;
|
||||
pub mod routes;
|
||||
@@ -0,0 +1,32 @@
|
||||
use axum::{middleware::from_fn, routing::{delete, get, post, put}, Extension, Router};
|
||||
use sqlx::PgPool;
|
||||
use std::sync::Arc;
|
||||
use crate::teams::application::team_service::TeamServiceImpl;
|
||||
use crate::teams::domain::service::TeamService;
|
||||
use crate::teams::infrastructure::persistence::PostgresTeamRepository;
|
||||
use crate::common::hackathon_jwt::HackathonJwtService;
|
||||
use crate::middleware::hackathon_auth::hackathon_auth_middleware;
|
||||
use super::handlers::*;
|
||||
|
||||
pub fn build_team_routes(pool: Arc<PgPool>, jwt: Arc<HackathonJwtService>) -> Router {
|
||||
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 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(Extension(jwt))
|
||||
.layer(from_fn(hackathon_auth_middleware));
|
||||
|
||||
Router::new().merge(public).merge(protected)
|
||||
}
|
||||
Reference in New Issue
Block a user