refactor: extract view-model mappers from presentation handlers
Some checks failed
CI / Check / Test (push) Has been cancelled
Some checks failed
CI / Check / Test (push) Has been cancelled
Move mapping logic (domain→DTO/template structs) into mappers/ module. Handlers now call mapper fns instead of inline conversions.
This commit is contained in:
@@ -24,12 +24,12 @@ use application::import::{
|
||||
};
|
||||
use domain::models::{
|
||||
AnnotatedRow, FieldMapping, FileFormat,
|
||||
import::{DomainField, RowResult, Transform},
|
||||
import::{DomainField, Transform},
|
||||
};
|
||||
use domain::value_objects::ImportSessionId;
|
||||
use template_askama::{
|
||||
ImportMappingTemplate, ImportPreviewRow, ImportPreviewTemplate, ImportProfileView,
|
||||
ImportRowStatus, ImportUploadTemplate,
|
||||
ImportUploadTemplate,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
@@ -98,34 +98,7 @@ fn parse_mapping_form(form: &HashMap<String, String>) -> Vec<FieldMapping> {
|
||||
mappings
|
||||
}
|
||||
|
||||
fn annotated_to_preview_row(idx: usize, annotated: &AnnotatedRow) -> ImportPreviewRow {
|
||||
match &annotated.result {
|
||||
RowResult::Valid(row) => {
|
||||
let cells = vec![
|
||||
row.title.clone().unwrap_or_default(),
|
||||
row.release_year.clone().unwrap_or_default(),
|
||||
row.director.clone().unwrap_or_default(),
|
||||
row.rating.clone().unwrap_or_default(),
|
||||
row.watched_at.clone().unwrap_or_default(),
|
||||
row.comment.clone().unwrap_or_default(),
|
||||
];
|
||||
ImportPreviewRow {
|
||||
index: idx,
|
||||
status: if annotated.is_duplicate {
|
||||
ImportRowStatus::Duplicate
|
||||
} else {
|
||||
ImportRowStatus::Valid
|
||||
},
|
||||
cells,
|
||||
}
|
||||
}
|
||||
RowResult::Invalid { errors, raw } => ImportPreviewRow {
|
||||
index: idx,
|
||||
status: ImportRowStatus::Invalid(errors.join("; ")),
|
||||
cells: raw.iter().map(|(_, v)| v.clone()).collect(),
|
||||
},
|
||||
}
|
||||
}
|
||||
use crate::mappers::import::annotated_to_preview_row;
|
||||
|
||||
// ── HTML wizard handlers ───────────────────────────────────────────────────
|
||||
|
||||
|
||||
Reference in New Issue
Block a user