use std::path::PathBuf; use axum::{Json, extract::State}; use serde::Deserialize; use crate::{error::ApiError, state::AppState}; #[derive(Debug, Deserialize, utoipa::ToSchema)] pub struct ExportRequest { pub format: String, #[schema(value_type = String)] pub destination: PathBuf, } #[utoipa::path( post, path = "/api/v1/export", tag = "export", responses( (status = 200, description = "Export job submitted"), (status = 401, description = "Unauthorized"), (status = 403, description = "Forbidden"), (status = 500, description = "Internal server error"), ), security(("bearer_auth" = [])) )] pub async fn trigger_export( State(state): State, ) -> Result, ApiError> { // Default export to JSON in data dir let dest = pinakes_core::config::Config::default_data_dir().join("export.json"); let kind = pinakes_core::jobs::JobKind::Export { format: pinakes_core::jobs::ExportFormat::Json, destination: dest, }; let job_id = state.job_queue.submit(kind).await; Ok(Json(serde_json::json!({ "job_id": job_id.to_string() }))) } #[utoipa::path( post, path = "/api/v1/export/options", tag = "export", request_body = ExportRequest, responses( (status = 200, description = "Export job submitted"), (status = 401, description = "Unauthorized"), (status = 403, description = "Forbidden"), (status = 500, description = "Internal server error"), ), security(("bearer_auth" = [])) )] pub async fn trigger_export_with_options( State(state): State, Json(req): Json, ) -> Result, ApiError> { let format = match req.format.as_str() { "csv" => pinakes_core::jobs::ExportFormat::Csv, _ => pinakes_core::jobs::ExportFormat::Json, }; let kind = pinakes_core::jobs::JobKind::Export { format, destination: req.destination, }; let job_id = state.job_queue.submit(kind).await; Ok(Json(serde_json::json!({ "job_id": job_id.to_string() }))) }