You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

27 lines
938 B

use crate::application::{config::ImportDictConfig, services::DictImporter};
use crate::infrastructure::json_file_dict_source::JsonFileDictSource;
use tracing::{debug, error, info};
pub async fn run(config: ImportDictConfig, importer: DictImporter) -> Result<(), anyhow::Error> {
debug!("Importing dict with config {:?}", config);
info!(
"Starting import of dictionary '{}' from file '{}'",
config.name, config.path
);
// Create the JSON file source (will auto-generate IDs starting from 1)
let source = JsonFileDictSource::new(&config.path)?;
// Perform the import (this will call create() first)
match importer.import(source).await {
Ok(()) => {
info!("Successfully imported dictionary '{}'", config.name);
Ok(())
}
Err(e) => {
error!("Failed to import dictionary '{}': {}", config.name, e);
Err(e)
}
}
}