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,71 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utoipa::ToSchema;
|
||||
use uuid::Uuid;
|
||||
use chrono::{DateTime, Utc};
|
||||
use crate::submissions::domain::entity::*;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
pub struct SubmissionResponse {
|
||||
pub id: Uuid,
|
||||
pub team_id: Uuid,
|
||||
pub project_name: String,
|
||||
pub description: String,
|
||||
pub repository_url: String,
|
||||
pub demo_url: Option<String>,
|
||||
pub presentation_url: Option<String>,
|
||||
pub screenshots: Option<Vec<String>>,
|
||||
pub status: String,
|
||||
pub submitted_at: Option<DateTime<Utc>>,
|
||||
pub submitted_by: Uuid,
|
||||
pub created_at: Option<DateTime<Utc>>,
|
||||
pub updated_at: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
impl From<SubmissionEntity> for SubmissionResponse {
|
||||
fn from(e: SubmissionEntity) -> Self {
|
||||
Self {
|
||||
id: e.id, team_id: e.team_id, project_name: e.project_name, description: e.description,
|
||||
repository_url: e.repository_url, demo_url: e.demo_url, presentation_url: e.presentation_url,
|
||||
screenshots: e.screenshots, status: e.status, submitted_at: e.submitted_at,
|
||||
submitted_by: e.submitted_by, created_at: e.created_at, updated_at: e.updated_at,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
pub struct CreateSubmissionRequest {
|
||||
pub project_name: String,
|
||||
pub description: String,
|
||||
pub repository_url: String,
|
||||
pub demo_url: Option<String>,
|
||||
pub presentation_url: Option<String>,
|
||||
pub screenshots: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
impl From<CreateSubmissionRequest> for CreateSubmissionInput {
|
||||
fn from(r: CreateSubmissionRequest) -> Self {
|
||||
Self {
|
||||
project_name: r.project_name, description: r.description, repository_url: r.repository_url,
|
||||
demo_url: r.demo_url, presentation_url: r.presentation_url, screenshots: r.screenshots,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
pub struct UpdateSubmissionRequest {
|
||||
pub project_name: Option<String>,
|
||||
pub description: Option<String>,
|
||||
pub repository_url: Option<String>,
|
||||
pub demo_url: Option<String>,
|
||||
pub presentation_url: Option<String>,
|
||||
pub screenshots: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
impl From<UpdateSubmissionRequest> for UpdateSubmissionInput {
|
||||
fn from(r: UpdateSubmissionRequest) -> Self {
|
||||
Self {
|
||||
project_name: r.project_name, description: r.description, repository_url: r.repository_url,
|
||||
demo_url: r.demo_url, presentation_url: r.presentation_url, screenshots: r.screenshots,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
use axum::{Extension, Json, extract::Path, response::IntoResponse};
|
||||
use std::sync::Arc;
|
||||
use uuid::Uuid;
|
||||
use imphnen_utils::{errors::AppError, response_format::ApiSuccess};
|
||||
use crate::middleware::hackathon_auth::HackathonAuthUser;
|
||||
use crate::submissions::domain::service::SubmissionService;
|
||||
use super::dto::*;
|
||||
|
||||
pub async fn create_submission_handler(
|
||||
Extension(service): Extension<Arc<dyn SubmissionService>>,
|
||||
Extension(auth): Extension<HackathonAuthUser>,
|
||||
Path(team_id): Path<Uuid>,
|
||||
Json(body): Json<CreateSubmissionRequest>,
|
||||
) -> Result<axum::response::Response, AppError> {
|
||||
let sub = service.create_submission(team_id, auth.user_id, body.into()).await?;
|
||||
Ok(ApiSuccess(SubmissionResponse::from(sub)).into_response())
|
||||
}
|
||||
|
||||
pub async fn get_team_submission_handler(
|
||||
Extension(service): Extension<Arc<dyn SubmissionService>>,
|
||||
Extension(auth): Extension<HackathonAuthUser>,
|
||||
Path(team_id): Path<Uuid>,
|
||||
) -> Result<axum::response::Response, AppError> {
|
||||
let sub = service.get_team_submission(team_id, auth.user_id).await?;
|
||||
Ok(ApiSuccess(SubmissionResponse::from(sub)).into_response())
|
||||
}
|
||||
|
||||
pub async fn update_submission_handler(
|
||||
Extension(service): Extension<Arc<dyn SubmissionService>>,
|
||||
Extension(auth): Extension<HackathonAuthUser>,
|
||||
Path(submission_id): Path<Uuid>,
|
||||
Json(body): Json<UpdateSubmissionRequest>,
|
||||
) -> Result<axum::response::Response, AppError> {
|
||||
let sub = service.update_submission(submission_id, auth.user_id, body.into()).await?;
|
||||
Ok(ApiSuccess(SubmissionResponse::from(sub)).into_response())
|
||||
}
|
||||
|
||||
pub async fn submit_project_handler(
|
||||
Extension(service): Extension<Arc<dyn SubmissionService>>,
|
||||
Extension(auth): Extension<HackathonAuthUser>,
|
||||
Path(submission_id): Path<Uuid>,
|
||||
) -> Result<axum::response::Response, AppError> {
|
||||
let sub = service.submit_project(submission_id, auth.user_id).await?;
|
||||
Ok(ApiSuccess(SubmissionResponse::from(sub)).into_response())
|
||||
}
|
||||
|
||||
pub async fn confirm_submission_handler(
|
||||
Extension(service): Extension<Arc<dyn SubmissionService>>,
|
||||
Extension(auth): Extension<HackathonAuthUser>,
|
||||
Path(submission_id): Path<Uuid>,
|
||||
) -> Result<axum::response::Response, AppError> {
|
||||
let sub = service.confirm_submission(submission_id, auth.user_id).await?;
|
||||
Ok(ApiSuccess(SubmissionResponse::from(sub)).into_response())
|
||||
}
|
||||
|
||||
pub async fn cancel_submission_handler(
|
||||
Extension(service): Extension<Arc<dyn SubmissionService>>,
|
||||
Extension(auth): Extension<HackathonAuthUser>,
|
||||
Path(submission_id): Path<Uuid>,
|
||||
) -> Result<axum::response::Response, AppError> {
|
||||
let sub = service.cancel_submission(submission_id, auth.user_id).await?;
|
||||
Ok(ApiSuccess(SubmissionResponse::from(sub)).into_response())
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
pub mod dto;
|
||||
pub mod handlers;
|
||||
pub mod routes;
|
||||
@@ -0,0 +1,23 @@
|
||||
use axum::{middleware::from_fn, routing::{get, post, put}, Extension, Router};
|
||||
use sqlx::PgPool;
|
||||
use std::sync::Arc;
|
||||
use crate::submissions::application::submission_service::SubmissionServiceImpl;
|
||||
use crate::submissions::domain::service::SubmissionService;
|
||||
use crate::submissions::infrastructure::persistence::PostgresSubmissionRepository;
|
||||
use crate::common::hackathon_jwt::HackathonJwtService;
|
||||
use crate::middleware::hackathon_auth::hackathon_auth_middleware;
|
||||
use super::handlers::*;
|
||||
|
||||
pub fn hackathon_submissions_routes(pool: Arc<PgPool>, jwt: Arc<HackathonJwtService>) -> Router {
|
||||
let service: Arc<dyn SubmissionService> = Arc::new(SubmissionServiceImpl::new(Arc::new(PostgresSubmissionRepository::new(pool.clone()))));
|
||||
Router::new()
|
||||
.route("/submissions/teams/:team_id", get(get_team_submission_handler).post(create_submission_handler))
|
||||
.route("/submissions/:submission_id", put(update_submission_handler))
|
||||
.route("/submissions/:submission_id/submit", post(submit_project_handler))
|
||||
.route("/submissions/:submission_id/confirm", post(confirm_submission_handler))
|
||||
.route("/submissions/:submission_id/cancel", post(cancel_submission_handler))
|
||||
.layer(Extension(service))
|
||||
.layer(Extension(jwt.clone()))
|
||||
.layer(Extension(pool))
|
||||
.layer(from_fn(hackathon_auth_middleware))
|
||||
}
|
||||
Reference in New Issue
Block a user