use crate::prelude2::*;
use std::collections::HashMap;
#[derive(Debug, serde::Deserialize, serde::Serialize)]
#[allow(dead_code)]
pub struct Record {
pub city: String,
pub region: String,
pub country: String,
pub population: Option<u64>,
}
pub async fn read_csv_file(
query: web::Form<HashMap<String, String>>,
request: HttpRequest,
) -> impl Responder {
let file_path = query
.get("file_path")
.ok_or_else(|| Error::invalid_request("Missing query string parameter: file_path"))?;
let (list, _) = crate::core::csv::read_file::<Record>(file_path, ',', true)
.map_err(|e| anyhow::anyhow!(e))?;
request.json(200, R::ok(list))
}