Files
movies-diary/crates/adapters/importer/src/lib.rs
Gabriel Kaszewski 19171806b9
Some checks failed
CI / Check / Test / Build (push) Has been cancelled
fmt
2026-05-13 23:38:57 +02:00

33 lines
971 B
Rust

mod mapper;
mod parsers;
use domain::{
models::{AnnotatedRow, FieldMapping, FileFormat, ImportError, ParsedFile},
ports::DocumentParser,
};
pub struct ImporterDocumentParser;
impl DocumentParser for ImporterDocumentParser {
fn parse(&self, bytes: &[u8], format: FileFormat) -> Result<ParsedFile, ImportError> {
match format {
FileFormat::Csv => parsers::parse_csv(bytes),
FileFormat::Json => parsers::parse_json(bytes),
FileFormat::Xlsx => {
#[cfg(feature = "xlsx")]
{
parsers::parse_xlsx(bytes)
}
#[cfg(not(feature = "xlsx"))]
{
Err(ImportError::Xlsx("XLSX support not compiled in".into()))
}
}
}
}
fn apply_mapping(&self, file: &ParsedFile, mappings: &[FieldMapping]) -> Vec<AnnotatedRow> {
mapper::apply_mapping(file, mappings)
}
}