use axum::{
extract::{Path, State},
Json,
};
use minifly_core::models::{Volume, VolumeState, CreateVolumeRequest};
use minifly_core::{SuccessResponse, Error as CoreError};
use chrono::Utc;
use crate::state::AppState;
use crate::error::Result;
pub async fn list_volumes(
State(_state): State<AppState>,
Path(_app_name): Path<String>,
) -> Result<Json<Vec<Volume>>> {
Ok(Json(Vec::<Volume>::new()))
}
pub async fn create_volume(
State(_state): State<AppState>,
Path(_app_name): Path<String>,
Json(req): Json<CreateVolumeRequest>,
) -> Result<Json<Volume>> {
let volume = Volume {
id: format!("vol_{}", uuid::Uuid::new_v4().simple()),
name: req.name,
state: VolumeState::Created,
size_gb: req.size_gb.unwrap_or(1),
region: req.region,
zone: "a".to_string(),
encrypted: req.encrypted.unwrap_or(true),
attached_machine_id: None,
attached_alloc_id: None,
created_at: Utc::now(),
};
Ok(Json(volume))
}
pub async fn get_volume(
State(_state): State<AppState>,
Path((_app_name, _volume_id)): Path<(String, String)>,
) -> Result<Json<Volume>> {
Err(CoreError::NotFound.into())
}
pub async fn delete_volume(
State(_state): State<AppState>,
Path((_app_name, _volume_id)): Path<(String, String)>,
) -> Result<Json<SuccessResponse>> {
Ok(Json(SuccessResponse { ok: true }))
}