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,43 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utoipa::ToSchema;
|
||||
use uuid::Uuid;
|
||||
use chrono::{DateTime, Utc};
|
||||
use crate::chat::domain::entity::*;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
pub struct MessageResponse {
|
||||
pub id: Uuid,
|
||||
pub team_id: Uuid,
|
||||
pub user_id: Uuid,
|
||||
pub user_fullname: String,
|
||||
pub user_avatar: Option<String>,
|
||||
pub message: String,
|
||||
pub created_at: Option<DateTime<Utc>>,
|
||||
pub updated_at: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
impl From<MessageWithUser> for MessageResponse {
|
||||
fn from(e: MessageWithUser) -> Self {
|
||||
Self {
|
||||
id: e.id,
|
||||
team_id: e.team_id,
|
||||
user_id: e.user_id,
|
||||
user_fullname: e.user_fullname,
|
||||
user_avatar: e.user_avatar,
|
||||
message: e.message,
|
||||
created_at: e.created_at,
|
||||
updated_at: e.updated_at,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
pub struct SendMessageRequest {
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
impl From<SendMessageRequest> for SendMessageInput {
|
||||
fn from(r: SendMessageRequest) -> Self {
|
||||
Self { message: r.message }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
use axum::{Extension, Json, extract::Path, 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::chat::domain::service::ChatService;
|
||||
use super::dto::*;
|
||||
|
||||
pub async fn get_team_messages_handler(
|
||||
Extension(service): Extension<Arc<dyn ChatService>>,
|
||||
Extension(auth): Extension<HackathonAuthUser>,
|
||||
Path(team_id): Path<Uuid>,
|
||||
) -> Result<axum::response::Response, AppError> {
|
||||
let messages = service.get_team_messages(team_id, auth.user_id).await?;
|
||||
let response: Vec<MessageResponse> = messages.into_iter().map(MessageResponse::from).collect();
|
||||
Ok(ApiSuccess(response).into_response())
|
||||
}
|
||||
|
||||
pub async fn send_message_handler(
|
||||
Extension(service): Extension<Arc<dyn ChatService>>,
|
||||
Extension(auth): Extension<HackathonAuthUser>,
|
||||
Path(team_id): Path<Uuid>,
|
||||
Json(body): Json<SendMessageRequest>,
|
||||
) -> Result<axum::response::Response, AppError> {
|
||||
let message = service.send_message(team_id, auth.user_id, body.into()).await?;
|
||||
Ok(ApiSuccess(MessageResponse::from(message)).into_response())
|
||||
}
|
||||
|
||||
pub async fn delete_message_handler(
|
||||
Extension(service): Extension<Arc<dyn ChatService>>,
|
||||
Extension(auth): Extension<HackathonAuthUser>,
|
||||
Path(message_id): Path<Uuid>,
|
||||
) -> Result<axum::response::Response, AppError> {
|
||||
service.delete_message(message_id, auth.user_id).await?;
|
||||
Ok(ApiMessage::ok("Message deleted").into_response())
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
pub mod dto;
|
||||
pub mod handlers;
|
||||
pub mod routes;
|
||||
@@ -0,0 +1,22 @@
|
||||
use axum::{middleware::from_fn, routing::{delete, get, post}, Extension, Router};
|
||||
use sqlx::PgPool;
|
||||
use std::sync::Arc;
|
||||
use crate::chat::application::chat_service::ChatServiceImpl;
|
||||
use crate::chat::domain::service::ChatService;
|
||||
use crate::chat::infrastructure::persistence::PostgresChatRepository;
|
||||
use crate::common::hackathon_jwt::HackathonJwtService;
|
||||
use crate::middleware::hackathon_auth::hackathon_auth_middleware;
|
||||
use super::handlers::*;
|
||||
|
||||
pub fn build_chat_routes(pool: Arc<PgPool>, jwt: Arc<HackathonJwtService>) -> Router {
|
||||
let service: Arc<dyn ChatService> = Arc::new(ChatServiceImpl::new(
|
||||
Arc::new(PostgresChatRepository::new(pool.clone())),
|
||||
));
|
||||
Router::new()
|
||||
.route("/chat/teams/:team_id", get(get_team_messages_handler).post(send_message_handler))
|
||||
.route("/chat/messages/:message_id", delete(delete_message_handler))
|
||||
.layer(Extension(service))
|
||||
.layer(Extension(jwt.clone()))
|
||||
.layer(Extension(pool))
|
||||
.layer(from_fn(hackathon_auth_middleware))
|
||||
}
|
||||
Reference in New Issue
Block a user