feat: Enhance hackathon submission process with additional fields and validation checks
This commit is contained in:
@@ -9,7 +9,7 @@ use super::hackathon_service::{HackathonService, HackathonServiceTrait};
|
||||
use super::hackathon_schema::SubmissionStatus;
|
||||
use crate::v1::hackathon::HackathonRepository;
|
||||
use crate::{AppState, ResponseSuccessDto, ErrorDto};
|
||||
use imphnen_entities::PermissionsEnum;
|
||||
use imphnen_entities::{PermissionsEnum, UsersDetailQueryDto};
|
||||
use imphnen_libs::{MetaRequestDto, ResponseListSuccessDto};
|
||||
use axum::{
|
||||
extract::{Extension, Path, Query},
|
||||
@@ -569,9 +569,11 @@ pub async fn update_hackathon_submission(
|
||||
)]
|
||||
pub async fn submit_hackathon_submission(
|
||||
Extension(state): Extension<AppState>,
|
||||
Extension(user): Extension<UsersDetailQueryDto>,
|
||||
Path(id): Path<String>,
|
||||
) -> impl IntoResponse {
|
||||
match HackathonService::submit_hackathon_submission(id, &state).await {
|
||||
let user_id = user.id.id.to_raw();
|
||||
match HackathonService::submit_hackathon_submission(id, user_id, &state).await {
|
||||
Ok(response) => (axum::http::StatusCode::OK, Json(response)).into_response(),
|
||||
Err(error) => (StatusCode::from_u16(error.status).unwrap(), Json(error)).into_response(),
|
||||
}
|
||||
|
||||
@@ -315,9 +315,18 @@ pub struct HackathonSubmissionCreateRequestDto {
|
||||
#[validate(length(min = 1, message = "Description cannot be empty"))]
|
||||
pub description: String,
|
||||
pub repository_url: Option<String>,
|
||||
pub upload_file_url: Option<String>, // URL to uploaded zip/pdf file
|
||||
pub demo_url: Option<String>,
|
||||
pub slides_url: Option<String>,
|
||||
pub technologies: Vec<String>,
|
||||
// Social media contacts for demo (at least one required)
|
||||
pub contact_instagram: Option<String>,
|
||||
pub contact_twitter: Option<String>,
|
||||
pub contact_linkedin: Option<String>,
|
||||
pub contact_facebook: Option<String>,
|
||||
pub contact_youtube: Option<String>,
|
||||
pub contact_tiktok: Option<String>,
|
||||
pub contact_other: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, Validate)]
|
||||
@@ -331,11 +340,27 @@ pub struct HackathonSubmissionUpdateRequestDto {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub repository_url: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub upload_file_url: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub demo_url: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub slides_url: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub technologies: Option<Vec<String>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub contact_instagram: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub contact_twitter: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub contact_linkedin: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub contact_facebook: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub contact_youtube: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub contact_tiktok: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub contact_other: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
|
||||
@@ -346,9 +371,17 @@ pub struct HackathonSubmissionDto {
|
||||
pub project_name: String,
|
||||
pub description: String,
|
||||
pub repository_url: Option<String>,
|
||||
pub upload_file_url: Option<String>,
|
||||
pub demo_url: Option<String>,
|
||||
pub slides_url: Option<String>,
|
||||
pub technologies: Vec<String>,
|
||||
pub contact_instagram: Option<String>,
|
||||
pub contact_twitter: Option<String>,
|
||||
pub contact_linkedin: Option<String>,
|
||||
pub contact_facebook: Option<String>,
|
||||
pub contact_youtube: Option<String>,
|
||||
pub contact_tiktok: Option<String>,
|
||||
pub contact_other: Option<String>,
|
||||
#[serde(rename = "status")]
|
||||
pub submission_status: SubmissionStatus,
|
||||
pub judge_feedback: Option<String>,
|
||||
@@ -498,9 +531,17 @@ impl From<HackathonSubmissionsSchema> for HackathonSubmissionDto {
|
||||
project_name: schema.project_name.unwrap_or_default(),
|
||||
description: schema.description.unwrap_or_default(),
|
||||
repository_url: schema.repository_url,
|
||||
upload_file_url: schema.upload_file_url,
|
||||
demo_url: schema.demo_url,
|
||||
slides_url: schema.slides_url,
|
||||
technologies: schema.technologies.unwrap_or_default(),
|
||||
contact_instagram: schema.contact_instagram,
|
||||
contact_twitter: schema.contact_twitter,
|
||||
contact_linkedin: schema.contact_linkedin,
|
||||
contact_facebook: schema.contact_facebook,
|
||||
contact_youtube: schema.contact_youtube,
|
||||
contact_tiktok: schema.contact_tiktok,
|
||||
contact_other: schema.contact_other,
|
||||
submission_status: schema.submission_status.unwrap_or(super::hackathon_schema::SubmissionStatus::Draft),
|
||||
judge_feedback: schema.judge_feedback,
|
||||
submitted_at: schema.submitted_at.unwrap_or(chrono::Utc::now()),
|
||||
|
||||
@@ -529,9 +529,17 @@ impl<'a> HackathonRepository<'a> {
|
||||
project_name: Some(submission.project_name),
|
||||
description: Some(submission.description),
|
||||
repository_url: submission.repository_url,
|
||||
upload_file_url: submission.upload_file_url,
|
||||
demo_url: submission.demo_url,
|
||||
slides_url: submission.slides_url,
|
||||
technologies: Some(submission.technologies),
|
||||
contact_instagram: submission.contact_instagram,
|
||||
contact_twitter: submission.contact_twitter,
|
||||
contact_linkedin: submission.contact_linkedin,
|
||||
contact_facebook: submission.contact_facebook,
|
||||
contact_youtube: submission.contact_youtube,
|
||||
contact_tiktok: submission.contact_tiktok,
|
||||
contact_other: submission.contact_other,
|
||||
submission_status: Some(super::hackathon_schema::SubmissionStatus::Draft),
|
||||
judge_feedback: None,
|
||||
submitted_at: Some(chrono::Utc::now()),
|
||||
@@ -648,6 +656,9 @@ impl<'a> HackathonRepository<'a> {
|
||||
if let Some(repository_url) = updates.repository_url {
|
||||
existing.repository_url = Some(repository_url);
|
||||
}
|
||||
if let Some(upload_file_url) = updates.upload_file_url {
|
||||
existing.upload_file_url = Some(upload_file_url);
|
||||
}
|
||||
if let Some(demo_url) = updates.demo_url {
|
||||
existing.demo_url = Some(demo_url);
|
||||
}
|
||||
@@ -657,6 +668,27 @@ impl<'a> HackathonRepository<'a> {
|
||||
if let Some(technologies) = updates.technologies {
|
||||
existing.technologies = Some(technologies);
|
||||
}
|
||||
if let Some(contact_instagram) = updates.contact_instagram {
|
||||
existing.contact_instagram = Some(contact_instagram);
|
||||
}
|
||||
if let Some(contact_twitter) = updates.contact_twitter {
|
||||
existing.contact_twitter = Some(contact_twitter);
|
||||
}
|
||||
if let Some(contact_linkedin) = updates.contact_linkedin {
|
||||
existing.contact_linkedin = Some(contact_linkedin);
|
||||
}
|
||||
if let Some(contact_facebook) = updates.contact_facebook {
|
||||
existing.contact_facebook = Some(contact_facebook);
|
||||
}
|
||||
if let Some(contact_youtube) = updates.contact_youtube {
|
||||
existing.contact_youtube = Some(contact_youtube);
|
||||
}
|
||||
if let Some(contact_tiktok) = updates.contact_tiktok {
|
||||
existing.contact_tiktok = Some(contact_tiktok);
|
||||
}
|
||||
if let Some(contact_other) = updates.contact_other {
|
||||
existing.contact_other = Some(contact_other);
|
||||
}
|
||||
|
||||
existing.updated_at = Some(get_iso_date());
|
||||
|
||||
|
||||
@@ -70,9 +70,17 @@ pub struct HackathonSubmissionsSchema {
|
||||
pub project_name: Option<String>,
|
||||
pub description: Option<String>,
|
||||
pub repository_url: Option<String>,
|
||||
pub upload_file_url: Option<String>,
|
||||
pub demo_url: Option<String>,
|
||||
pub slides_url: Option<String>,
|
||||
pub technologies: Option<Vec<String>>,
|
||||
pub contact_instagram: Option<String>,
|
||||
pub contact_twitter: Option<String>,
|
||||
pub contact_linkedin: Option<String>,
|
||||
pub contact_facebook: Option<String>,
|
||||
pub contact_youtube: Option<String>,
|
||||
pub contact_tiktok: Option<String>,
|
||||
pub contact_other: Option<String>,
|
||||
pub submission_status: Option<SubmissionStatus>,
|
||||
pub judge_feedback: Option<String>,
|
||||
pub submitted_at: Option<DateTime<Utc>>,
|
||||
@@ -310,9 +318,17 @@ impl Default for HackathonSubmissionsSchema {
|
||||
project_name: Some(String::new()),
|
||||
description: Some(String::new()),
|
||||
repository_url: None,
|
||||
upload_file_url: None,
|
||||
demo_url: None,
|
||||
slides_url: None,
|
||||
technologies: Some(vec![]),
|
||||
contact_instagram: None,
|
||||
contact_twitter: None,
|
||||
contact_linkedin: None,
|
||||
contact_facebook: None,
|
||||
contact_youtube: None,
|
||||
contact_tiktok: None,
|
||||
contact_other: None,
|
||||
submission_status: Some(SubmissionStatus::Draft),
|
||||
judge_feedback: None,
|
||||
submitted_at: Some(Utc::now()),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use std::pin::Pin;
|
||||
use std::future::Future;
|
||||
use serde::Deserialize;
|
||||
// Type alias to shorten complex future return types used across the service trait
|
||||
type ListServiceFut<T> = Pin<Box<dyn Future<Output = Result<imphnen_libs::ResponseListSuccessDto<Vec<T>>, ErrorDto>> + Send>>;
|
||||
use super::hackathon_dto::{
|
||||
@@ -111,6 +112,7 @@ pub trait HackathonServiceTrait: Send + Sync + 'static {
|
||||
) -> Pin<Box<dyn Future<Output = Result<ResponseSuccessDto<HackathonSubmissionDto>, ErrorDto>> + Send>>;
|
||||
fn submit_hackathon_submission(
|
||||
id: String,
|
||||
user_id: String,
|
||||
state: &AppState,
|
||||
) -> Pin<Box<dyn Future<Output = Result<ResponseSuccessDto<HackathonSubmissionDto>, ErrorDto>> + Send>>;
|
||||
fn update_submission_status(
|
||||
@@ -881,13 +883,14 @@ impl HackathonServiceTrait for HackathonService {
|
||||
|
||||
fn submit_hackathon_submission(
|
||||
id: String,
|
||||
user_id: String,
|
||||
state: &AppState,
|
||||
) -> Pin<Box<dyn Future<Output = Result<ResponseSuccessDto<HackathonSubmissionDto>, ErrorDto>> + Send>> {
|
||||
let state = state.to_owned();
|
||||
Box::pin(async move {
|
||||
let repo = HackathonRepository::new(&state);
|
||||
|
||||
// Get submission to extract hackathon_id for timeline validation
|
||||
// Get submission to extract hackathon_id for timeline validation and team_id for leader check
|
||||
let submission = match repo.get_hackathon_submission_by_id(id.clone()).await {
|
||||
Ok(sub) => sub,
|
||||
Err(e) => {
|
||||
@@ -909,6 +912,97 @@ impl HackathonServiceTrait for HackathonService {
|
||||
}
|
||||
};
|
||||
|
||||
// VALIDATION 1: Check if user is the team leader
|
||||
if let Some(team_id_thing) = &submission.team_id {
|
||||
let team_id = team_id_thing.id.to_raw();
|
||||
// Get team information to check leader
|
||||
let team_query = format!(
|
||||
"SELECT leader_id FROM app_teams WHERE id = type::thing('app_teams', '{}')",
|
||||
team_id
|
||||
);
|
||||
|
||||
match state.surrealdb_ws.query(&team_query).await {
|
||||
Ok(mut result) => {
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct TeamLeader {
|
||||
leader_id: surrealdb::sql::Thing,
|
||||
}
|
||||
|
||||
let team: Option<TeamLeader> = result.take(0).ok().flatten();
|
||||
if let Some(team) = team {
|
||||
let leader_id = team.leader_id.id.to_raw();
|
||||
if leader_id != user_id {
|
||||
return Err(ErrorDto {
|
||||
status: StatusCode::FORBIDDEN.as_u16(),
|
||||
message: "Only team leader can submit the project".to_string(),
|
||||
details: Some(serde_json::json!({
|
||||
"team_leader_id": leader_id,
|
||||
"your_user_id": user_id
|
||||
})),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return Err(ErrorDto {
|
||||
status: StatusCode::NOT_FOUND.as_u16(),
|
||||
message: "Team not found".to_string(),
|
||||
details: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Failed to get team information: {}", e);
|
||||
return Err(ErrorDto {
|
||||
status: StatusCode::INTERNAL_SERVER_ERROR.as_u16(),
|
||||
message: "Failed to verify team leader".to_string(),
|
||||
details: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return Err(ErrorDto {
|
||||
status: StatusCode::BAD_REQUEST.as_u16(),
|
||||
message: "Submission has no associated team".to_string(),
|
||||
details: None,
|
||||
});
|
||||
}
|
||||
|
||||
// VALIDATION 2: Must have repository_url OR upload_file_url
|
||||
let has_repo = submission.repository_url.as_ref().map(|s| !s.trim().is_empty()).unwrap_or(false);
|
||||
let has_upload = submission.upload_file_url.as_ref().map(|s| !s.trim().is_empty()).unwrap_or(false);
|
||||
|
||||
if !has_repo && !has_upload {
|
||||
return Err(ErrorDto {
|
||||
status: StatusCode::BAD_REQUEST.as_u16(),
|
||||
message: "Submission must include either repository URL or uploaded file (zip/pdf)".to_string(),
|
||||
details: Some(serde_json::json!({
|
||||
"required": "repository_url OR upload_file_url"
|
||||
})),
|
||||
});
|
||||
}
|
||||
|
||||
// VALIDATION 3: Must have at least one social media contact
|
||||
let has_contact = [
|
||||
&submission.contact_instagram,
|
||||
&submission.contact_twitter,
|
||||
&submission.contact_linkedin,
|
||||
&submission.contact_facebook,
|
||||
&submission.contact_youtube,
|
||||
&submission.contact_tiktok,
|
||||
&submission.contact_other,
|
||||
].iter().any(|contact| {
|
||||
contact.as_ref().map(|s| !s.trim().is_empty()).unwrap_or(false)
|
||||
});
|
||||
|
||||
if !has_contact {
|
||||
return Err(ErrorDto {
|
||||
status: StatusCode::BAD_REQUEST.as_u16(),
|
||||
message: "Submission must include at least one social media contact for demo".to_string(),
|
||||
details: Some(serde_json::json!({
|
||||
"required": "At least one of: contact_instagram, contact_twitter, contact_linkedin, contact_facebook, contact_youtube, contact_tiktok, contact_other"
|
||||
})),
|
||||
});
|
||||
}
|
||||
|
||||
// Check submission timeline phase
|
||||
match repo.get_submission_timeline_phase(submission.hackathon_id.id.to_raw()).await {
|
||||
Ok(Some(timeline_phase)) => {
|
||||
|
||||
Reference in New Issue
Block a user