fix(domain): typed VOs in MovieEnrichmentRequested and PersonEnrichmentRequested

This commit is contained in:
2026-06-12 01:34:47 +02:00
parent aec5f6b058
commit cedb13d7a8
9 changed files with 24 additions and 15 deletions

View File

@@ -2,7 +2,7 @@ use chrono::NaiveDateTime;
use domain::{ use domain::{
errors::DomainError, errors::DomainError,
events::DomainEvent, events::DomainEvent,
models::PersonId, models::{ExternalPersonId, PersonId},
value_objects::{ value_objects::{
ExternalMetadataId, GoalId, MovieId, PosterPath, Rating, ReviewId, UserId, WrapUpId, ExternalMetadataId, GoalId, MovieId, PosterPath, Rating, ReviewId, UserId, WrapUpId,
}, },
@@ -210,7 +210,7 @@ impl From<&DomainEvent> for EventPayload {
external_metadata_id, external_metadata_id,
} => EventPayload::MovieEnrichmentRequested { } => EventPayload::MovieEnrichmentRequested {
movie_id: movie_id.value().to_string(), movie_id: movie_id.value().to_string(),
external_metadata_id: external_metadata_id.clone(), external_metadata_id: external_metadata_id.value().to_string(),
}, },
DomainEvent::ImageStored { key } => EventPayload::ImageStored { key: key.clone() }, DomainEvent::ImageStored { key } => EventPayload::ImageStored { key: key.clone() },
DomainEvent::WatchlistEntryAdded { DomainEvent::WatchlistEntryAdded {
@@ -322,7 +322,7 @@ impl From<&DomainEvent> for EventPayload {
external_person_id, external_person_id,
} => EventPayload::PersonEnrichmentRequested { } => EventPayload::PersonEnrichmentRequested {
person_id: person_id.value().to_string(), person_id: person_id.value().to_string(),
external_person_id: external_person_id.clone(), external_person_id: external_person_id.value().to_string(),
}, },
} }
} }
@@ -391,7 +391,8 @@ impl TryFrom<EventPayload> for DomainEvent {
external_metadata_id, external_metadata_id,
} => Ok(DomainEvent::MovieEnrichmentRequested { } => Ok(DomainEvent::MovieEnrichmentRequested {
movie_id: MovieId::from_uuid(parse_uuid(&movie_id, "movie_id")?), movie_id: MovieId::from_uuid(parse_uuid(&movie_id, "movie_id")?),
external_metadata_id, external_metadata_id: ExternalMetadataId::new(external_metadata_id)
.map_err(|e| DomainError::InfrastructureError(e.to_string()))?,
}), }),
EventPayload::ImageStored { key } => Ok(DomainEvent::ImageStored { key }), EventPayload::ImageStored { key } => Ok(DomainEvent::ImageStored { key }),
EventPayload::WatchlistEntryAdded { EventPayload::WatchlistEntryAdded {
@@ -514,7 +515,7 @@ impl TryFrom<EventPayload> for DomainEvent {
external_person_id, external_person_id,
} => Ok(DomainEvent::PersonEnrichmentRequested { } => Ok(DomainEvent::PersonEnrichmentRequested {
person_id: PersonId::from_uuid(parse_uuid(&person_id, "person_id")?), person_id: PersonId::from_uuid(parse_uuid(&person_id, "person_id")?),
external_person_id, external_person_id: ExternalPersonId::new(external_person_id),
}), }),
} }
} }

View File

@@ -123,7 +123,7 @@ impl EventHandler for PosterSyncHandler {
if already_has_poster { if already_has_poster {
return Ok(()); return Ok(());
} }
(movie_id.value(), external_metadata_id.clone()) (movie_id.value(), external_metadata_id.value().to_owned())
} }
_ => return Ok(()), _ => return Ok(()),
}; };

View File

@@ -83,7 +83,7 @@ impl EventHandler for MovieEnrichmentHandler {
self.enrichment_client.as_ref(), self.enrichment_client.as_ref(),
&self.profile_repo, &self.profile_repo,
movie_id.clone(), movie_id.clone(),
&external_metadata_id, external_metadata_id.value(),
) )
.await? .await?
else { else {

View File

@@ -40,6 +40,6 @@ impl EventHandler for PersonEnrichmentHandler {
_ => return Ok(()), _ => return Ok(()),
}; };
application::person::enrich::execute(&self.deps, person_id, &external_person_id).await application::person::enrich::execute(&self.deps, person_id, external_person_id.value()).await
} }
} }

View File

@@ -112,7 +112,7 @@ async fn publish_events(
publisher publisher
.publish(&DomainEvent::MovieEnrichmentRequested { .publish(&DomainEvent::MovieEnrichmentRequested {
movie_id: movie.id().clone(), movie_id: movie.id().clone(),
external_metadata_id: ext_id.value().to_string(), external_metadata_id: ext_id.clone(),
}) })
.await?; .await?;
} }

View File

@@ -6,6 +6,7 @@ use domain::{
errors::DomainError, errors::DomainError,
events::DomainEvent, events::DomainEvent,
ports::{EventPublisher, MovieProfileRepository, PeriodicJob}, ports::{EventPublisher, MovieProfileRepository, PeriodicJob},
value_objects::ExternalMetadataId,
}; };
pub struct EnrichmentStalenessJob { pub struct EnrichmentStalenessJob {
@@ -38,9 +39,16 @@ impl PeriodicJob for EnrichmentStalenessJob {
} }
tracing::info!("enrichment scan: {} stale movies", stale.len()); tracing::info!("enrichment scan: {} stale movies", stale.len());
for (movie_id, external_metadata_id) in stale { for (movie_id, external_metadata_id) in stale {
let ext_id = match ExternalMetadataId::new(external_metadata_id) {
Ok(id) => id,
Err(e) => {
tracing::warn!("skipping stale movie with malformed external_metadata_id: {e}");
continue;
}
};
let event = DomainEvent::MovieEnrichmentRequested { let event = DomainEvent::MovieEnrichmentRequested {
movie_id, movie_id,
external_metadata_id, external_metadata_id: ext_id,
}; };
self.event_publisher.publish(&event).await?; self.event_publisher.publish(&event).await?;
} }

View File

@@ -18,7 +18,7 @@ pub async fn execute(deps: &GetPersonDeps, id: PersonId) -> Result<Option<Person
.event_publisher .event_publisher
.publish(&DomainEvent::PersonEnrichmentRequested { .publish(&DomainEvent::PersonEnrichmentRequested {
person_id: id, person_id: id,
external_person_id: p.external_id().value().to_string(), external_person_id: p.external_id().clone(),
}) })
.await; .await;
} }

View File

@@ -16,7 +16,7 @@ pub async fn execute(deps: &GetPersonDeps, id: PersonId) -> Result<PersonCredits
.event_publisher .event_publisher
.publish(&DomainEvent::PersonEnrichmentRequested { .publish(&DomainEvent::PersonEnrichmentRequested {
person_id: id, person_id: id,
external_person_id: credits.person.external_id().value().to_string(), external_person_id: credits.person.external_id().clone(),
}) })
.await; .await;
} }

View File

@@ -3,7 +3,7 @@ use chrono::NaiveDateTime;
use crate::{ use crate::{
errors::DomainError, errors::DomainError,
models::PersonId, models::{ExternalPersonId, PersonId},
value_objects::{ value_objects::{
ExternalMetadataId, GoalId, MovieId, PosterPath, Rating, ReviewId, UserId, WrapUpId, ExternalMetadataId, GoalId, MovieId, PosterPath, Rating, ReviewId, UserId, WrapUpId,
}, },
@@ -42,11 +42,11 @@ pub enum DomainEvent {
}, },
MovieEnrichmentRequested { MovieEnrichmentRequested {
movie_id: MovieId, movie_id: MovieId,
external_metadata_id: String, external_metadata_id: ExternalMetadataId,
}, },
PersonEnrichmentRequested { PersonEnrichmentRequested {
person_id: PersonId, person_id: PersonId,
external_person_id: String, external_person_id: ExternalPersonId,
}, },
ImageStored { ImageStored {
key: String, key: String,