feat: Add endpoint to retrieve hackathon submissions and implement seeding for test submissions

This commit is contained in:
MythEclipse
2025-09-27 19:24:45 +07:00
parent ac462ea771
commit 4c435708c0
4 changed files with 485 additions and 0 deletions
@@ -407,6 +407,29 @@ pub async fn list_hackathon_submissions(
}
}
#[utoipa::path(
get,
path = "/v1/hackathons/submissions/{id}",
params(
("id" = String, Path, description = "Submission ID")
),
responses(
(status = 200, description = "Submission retrieved successfully", body = ResponseSuccessDto<HackathonSubmissionDto>),
(status = 404, description = "Submission not found", body = ErrorDto),
(status = 500, description = "Internal server error", body = ErrorDto)
),
tag = "Hackathon Submissions"
)]
pub async fn get_hackathon_submission(
Extension(state): Extension<AppState>,
Path(id): Path<String>,
) -> impl IntoResponse {
match HackathonService::get_hackathon_submission(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(),
}
}
#[utoipa::path(
put,
path = "/v1/hackathons/submissions/{id}",
@@ -503,6 +526,7 @@ pub fn hackathon_routes() -> Router {
// Hackathon Submissions routes
.route("/{hackathon_id}/teams/{team_id}/submissions", post(create_hackathon_submission))
.route("/{hackathon_id}/submissions", get(list_hackathon_submissions))
.route("/submissions/{id}", get(get_hackathon_submission))
.route("/submissions/{id}", put(update_hackathon_submission))
.route("/submissions/{id}/submit", post(submit_hackathon_submission))
.route("/submissions/{id}", delete(delete_hackathon_submission))
@@ -87,6 +87,10 @@ pub trait HackathonServiceTrait: Send + Sync + 'static {
payload: HackathonSubmissionCreateRequestDto,
state: &AppState,
) -> Pin<Box<dyn Future<Output = Result<ResponseSuccessDto<HackathonSubmissionDto>, ErrorDto>> + Send>>;
fn get_hackathon_submission(
id: String,
state: &AppState,
) -> Pin<Box<dyn Future<Output = Result<ResponseSuccessDto<HackathonSubmissionDto>, ErrorDto>> + Send>>;
fn list_hackathon_submissions(
meta: MetaRequestDto,
hackathon_id: String,
@@ -688,6 +692,31 @@ impl HackathonServiceTrait for HackathonService {
})
}
fn get_hackathon_submission(
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);
match repo.get_hackathon_submission_by_id(id).await {
Ok(submission) => {
let dto = HackathonSubmissionDto::from(submission);
Ok(ResponseSuccessDto { data: dto })
}
Err(e) => {
error!("Failed to get hackathon submission: {}", e);
Err(ErrorDto {
status: StatusCode::NOT_FOUND.as_u16(),
message: "Submission not found".to_string(),
details: None,
})
}
}
})
}
fn list_hackathon_submissions(
meta: MetaRequestDto,
hackathon_id: String,