Files
imphnen-backend-service/imphnen-gateway/src/lib.rs
T
maulanasdqnandClaude Sonnet 4.6 11442c6285 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>
2026-04-02 15:15:00 +07:00

76 lines
2.9 KiB
Rust

use axum::{
Extension,
Router,
middleware::from_fn,
response::Redirect,
routing::get,
};
use imphnen_cms::{
events_protected_routes,
events_public_routes,
testimonials_protected_routes,
testimonials_public_routes,
};
use imphnen_dimentorin::{
mentors_public_routes, mentors_protected_routes,
sessions_public_routes, sessions_protected_routes,
};
use imphnen_gacha::gacha_router;
use imphnen_hackathon::{hackathon_router, HackathonConfig};
use imphnen_iam::{
auth_public_routes,
permissions_protected_routes,
roles_protected_routes,
users_protected_routes,
};
use imphnen_libs::services::PostgresAuthRepository as AuthRepoImpl;
use imphnen_libs::PostgresUserLookupService;
use imphnen_libs::{AppState, axum::PostgresClients};
use imphnen_middleware::{auth_middleware, cors_middleware, rate_limiting_middleware, security_headers_middleware};
use std::sync::Arc;
use utoipa_swagger_ui::SwaggerUi;
pub mod docs;
pub use docs::{ApiDoc, SecurityAddon, docs_router};
pub async fn gateway_service(
postgres_clients: PostgresClients,
) -> Router {
let state = AppState {
postgres_connection: postgres_clients.main.clone(),
user_lookup_service: Arc::new(PostgresUserLookupService::new()),
auth_repository: Arc::new(AuthRepoImpl::new()),
};
let db = state.postgres_connection.conn.clone();
let state_arc = Arc::new(state.clone());
let hackathon_config = Arc::new(HackathonConfig::from_env());
let public_routes = Router::new()
.merge(auth_public_routes(db.clone(), Arc::clone(&state_arc)).layer(from_fn(rate_limiting_middleware)))
.merge(testimonials_public_routes(db.clone()))
.merge(events_public_routes(db.clone()))
.merge(mentors_public_routes(db.clone(), Arc::clone(&state_arc)))
.merge(sessions_public_routes(db.clone()));
let protected_routes = Router::new()
.merge(users_protected_routes(db.clone(), Arc::clone(&state_arc)))
.merge(roles_protected_routes(db.clone(), Arc::clone(&state_arc)))
.merge(permissions_protected_routes(db.clone(), Arc::clone(&state_arc)))
.merge(events_protected_routes(db.clone()))
.merge(testimonials_protected_routes(db.clone()))
.merge(mentors_protected_routes(db.clone(), Arc::clone(&state_arc)))
.merge(sessions_protected_routes(db.clone(), Arc::clone(&state_arc)))
.nest("/gacha", gacha_router(db.clone(), Arc::clone(&state_arc)))
.layer(from_fn(auth_middleware));
Router::new()
.route("/", get(Redirect::to("/docs")))
.nest("/v1", public_routes.merge(protected_routes))
.nest("/v1/hackathon", hackathon_router(db.clone(), hackathon_config))
.merge(SwaggerUi::new("/docs").url("/openapi.json", docs_router()))
.layer(cors_middleware())
.layer(from_fn(security_headers_middleware))
.layer(Extension(state))
}