domain: add person enrichment fields, event, port
This commit is contained in:
@@ -2,6 +2,7 @@ use chrono::NaiveDateTime;
|
||||
use domain::{
|
||||
errors::DomainError,
|
||||
events::DomainEvent,
|
||||
models::PersonId,
|
||||
value_objects::{
|
||||
ExternalMetadataId, GoalId, MovieId, PosterPath, Rating, ReviewId, UserId, WrapUpId,
|
||||
},
|
||||
@@ -109,6 +110,10 @@ pub enum EventPayload {
|
||||
user_id: String,
|
||||
year: u16,
|
||||
},
|
||||
PersonEnrichmentRequested {
|
||||
person_id: String,
|
||||
external_person_id: String,
|
||||
},
|
||||
}
|
||||
|
||||
impl EventPayload {
|
||||
@@ -135,6 +140,7 @@ impl EventPayload {
|
||||
EventPayload::GoalCreated { .. } => "GoalCreated",
|
||||
EventPayload::GoalUpdated { .. } => "GoalUpdated",
|
||||
EventPayload::GoalDeleted { .. } => "GoalDeleted",
|
||||
EventPayload::PersonEnrichmentRequested { .. } => "PersonEnrichmentRequested",
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -311,6 +317,13 @@ impl From<&DomainEvent> for EventPayload {
|
||||
user_id: user_id.value().to_string(),
|
||||
year: *year,
|
||||
},
|
||||
DomainEvent::PersonEnrichmentRequested {
|
||||
person_id,
|
||||
external_person_id,
|
||||
} => EventPayload::PersonEnrichmentRequested {
|
||||
person_id: person_id.value().to_string(),
|
||||
external_person_id: external_person_id.clone(),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -496,6 +509,13 @@ impl TryFrom<EventPayload> for DomainEvent {
|
||||
user_id: UserId::from_uuid(parse_uuid(&user_id, "user_id")?),
|
||||
year,
|
||||
}),
|
||||
EventPayload::PersonEnrichmentRequested {
|
||||
person_id,
|
||||
external_person_id,
|
||||
} => Ok(DomainEvent::PersonEnrichmentRequested {
|
||||
person_id: PersonId::from_uuid(parse_uuid(&person_id, "person_id")?),
|
||||
external_person_id,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ pub fn event_to_subject(prefix: &str, event: &DomainEvent) -> String {
|
||||
DomainEvent::GoalCreated { .. } => "goal.created",
|
||||
DomainEvent::GoalUpdated { .. } => "goal.updated",
|
||||
DomainEvent::GoalDeleted { .. } => "goal.deleted",
|
||||
DomainEvent::PersonEnrichmentRequested { .. } => "person.enrichment.requested",
|
||||
};
|
||||
format!("{prefix}.{suffix}")
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
use async_trait::async_trait;
|
||||
use domain::{
|
||||
errors::DomainError,
|
||||
models::{CastCredit, CrewCredit, ExternalPersonId, Person, PersonCredits, PersonId},
|
||||
models::{
|
||||
CastCredit, CrewCredit, ExternalPersonId, Person, PersonCredits, PersonEnrichmentData,
|
||||
PersonId,
|
||||
},
|
||||
ports::{PersonCommand, PersonQuery},
|
||||
value_objects::MovieId,
|
||||
};
|
||||
@@ -111,6 +114,14 @@ impl PersonCommand for PostgresPersonAdapter {
|
||||
}
|
||||
Ok((count, has_more))
|
||||
}
|
||||
|
||||
async fn update_enrichment(
|
||||
&self,
|
||||
_id: &PersonId,
|
||||
_data: &PersonEnrichmentData,
|
||||
) -> Result<(), DomainError> {
|
||||
todo!("person enrichment persistence")
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -135,7 +146,7 @@ impl PersonQuery for PostgresPersonAdapter {
|
||||
|
||||
Ok(row.map(|r| {
|
||||
let ext = ExternalPersonId::new(r.external_id);
|
||||
Person::new(
|
||||
Person::basic(
|
||||
PersonId::from_uuid(uuid::Uuid::parse_str(&r.id).unwrap_or_default()),
|
||||
ext,
|
||||
r.name,
|
||||
@@ -168,7 +179,7 @@ impl PersonQuery for PostgresPersonAdapter {
|
||||
|
||||
Ok(row.map(|r| {
|
||||
let ext = ExternalPersonId::new(r.external_id);
|
||||
Person::new(
|
||||
Person::basic(
|
||||
PersonId::from_uuid(uuid::Uuid::parse_str(&r.id).unwrap_or_default()),
|
||||
ext,
|
||||
r.name,
|
||||
@@ -283,7 +294,7 @@ impl PersonQuery for PostgresPersonAdapter {
|
||||
.into_iter()
|
||||
.map(|r| {
|
||||
let ext = ExternalPersonId::new(r.external_id);
|
||||
Person::new(
|
||||
Person::basic(
|
||||
PersonId::from_uuid(uuid::Uuid::parse_str(&r.id).unwrap_or_default()),
|
||||
ext,
|
||||
r.name,
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
use async_trait::async_trait;
|
||||
use domain::{
|
||||
errors::DomainError,
|
||||
models::{CastCredit, CrewCredit, ExternalPersonId, Person, PersonCredits, PersonId},
|
||||
models::{
|
||||
CastCredit, CrewCredit, ExternalPersonId, Person, PersonCredits, PersonEnrichmentData,
|
||||
PersonId,
|
||||
},
|
||||
ports::{PersonCommand, PersonQuery},
|
||||
value_objects::MovieId,
|
||||
};
|
||||
@@ -111,6 +114,14 @@ impl PersonCommand for SqlitePersonAdapter {
|
||||
}
|
||||
Ok((count, has_more))
|
||||
}
|
||||
|
||||
async fn update_enrichment(
|
||||
&self,
|
||||
_id: &PersonId,
|
||||
_data: &PersonEnrichmentData,
|
||||
) -> Result<(), DomainError> {
|
||||
todo!("person enrichment persistence")
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -259,7 +270,7 @@ struct PersonRow {
|
||||
impl PersonRow {
|
||||
fn into_person(self) -> Person {
|
||||
let ext = ExternalPersonId::new(self.external_id);
|
||||
Person::new(
|
||||
Person::basic(
|
||||
PersonId::from_uuid(uuid::Uuid::parse_str(&self.id).unwrap_or_default()),
|
||||
ext,
|
||||
self.name,
|
||||
|
||||
@@ -46,7 +46,7 @@ async fn pool_with_schema() -> SqlitePool {
|
||||
|
||||
fn make_person(tmdb_id: i64, name: &str, dept: Option<&str>) -> Person {
|
||||
let ext = ExternalPersonId::new(format!("tmdb:{tmdb_id}"));
|
||||
Person::new(
|
||||
Person::basic(
|
||||
PersonId::from_external(&ext),
|
||||
ext,
|
||||
name.to_string(),
|
||||
|
||||
Reference in New Issue
Block a user