refactor: store typed WrapUpReport in domain, serialize in adapters
Some checks failed
CI / Check / Test (push) Failing after 45s

This commit is contained in:
2026-06-03 01:24:02 +02:00
parent e4b8ba550e
commit d94ccbe057
9 changed files with 33 additions and 32 deletions

View File

@@ -4,7 +4,7 @@ use async_trait::async_trait;
use chrono::NaiveDate;
use domain::{
errors::DomainError,
models::wrapup::{DateRange, WrapUpRecord, WrapUpScope, WrapUpStatus},
models::wrapup::{DateRange, WrapUpRecord, WrapUpReport, WrapUpScope, WrapUpStatus},
ports::{WrapUpMovieRow, WrapUpRepository, WrapUpStatsQuery},
value_objects::WrapUpId,
};
@@ -79,7 +79,7 @@ impl WrapUpRepository for SqliteWrapUpRepository {
.bind(&start)
.bind(&end)
.bind(status)
.bind(&record.report_json)
.bind(record.report.as_ref().and_then(|r| serde_json::to_string(r).ok()))
.bind(&record.error_message)
.bind(&created)
.bind(&completed)
@@ -110,15 +110,17 @@ impl WrapUpRepository for SqliteWrapUpRepository {
Ok(())
}
async fn set_complete(&self, id: &WrapUpId, report_json: &str) -> Result<(), DomainError> {
async fn set_complete(&self, id: &WrapUpId, report: &WrapUpReport) -> Result<(), DomainError> {
let id_str = id.value().to_string();
let json = serde_json::to_string(report)
.map_err(|e| DomainError::InfrastructureError(e.to_string()))?;
sqlx::query(
"UPDATE wrap_up_records \
SET status = 'ready', report_json = ?, completed_at = strftime('%Y-%m-%d %H:%M:%S', 'now') \
WHERE id = ?",
)
.bind(report_json)
.bind(&json)
.bind(&id_str)
.execute(&self.pool)
.await
@@ -238,13 +240,15 @@ fn row_to_record(row: &sqlx::sqlite::SqliteRow) -> Result<WrapUpRecord, DomainEr
let user_id = user_id_str.as_deref().map(parse_uuid).transpose()?;
let report = report_json.and_then(|j| serde_json::from_str(&j).ok());
Ok(WrapUpRecord {
id: WrapUpId::from_uuid(parse_uuid(&id_str)?),
user_id,
start_date: parse_date(&start_date_str)?,
end_date: parse_date(&end_date_str)?,
status: parse_status(&status_str)?,
report_json,
report,
error_message,
created_at: parse_datetime(&created_at_str)?,
completed_at: completed_at_str