fix: include product_id in Customization aggregate obj #50
6 changed files with 8 additions and 58 deletions
|
@ -49,6 +49,7 @@ pub mod tests {
|
|||
let customization = CustomizationBuilder::default()
|
||||
.name("customization_name".into())
|
||||
.customization_id(UUID)
|
||||
.product_id(UUID)
|
||||
.deleted(false)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
|
|
@ -62,6 +62,7 @@ mod tests {
|
|||
let customization = {
|
||||
CustomizationBuilder::default()
|
||||
.name(customization_name.into())
|
||||
.product_id(UUID)
|
||||
.customization_id(UUID)
|
||||
.deleted(false)
|
||||
.build()
|
||||
|
|
|
@ -35,6 +35,7 @@ impl From<CustomizationView> for Customization {
|
|||
CustomizationBuilder::default()
|
||||
.name(v.name)
|
||||
.customization_id(v.customization_id)
|
||||
.product_id(v.product_id)
|
||||
.deleted(v.deleted)
|
||||
.build()
|
||||
.unwrap()
|
||||
|
@ -49,8 +50,8 @@ impl View<Customization> for CustomizationView {
|
|||
match &event.payload {
|
||||
InventoryEvent::CustomizationAdded(val) => {
|
||||
self.name = val.customization().name().into();
|
||||
self.product_id = val.product_id().clone();
|
||||
self.customization_id = val.customization().customization_id().clone();
|
||||
self.product_id = *val.customization().product_id();
|
||||
self.customization_id = *val.customization().customization_id();
|
||||
|
||||
self.deleted = false;
|
||||
}
|
||||
|
@ -59,58 +60,6 @@ impl View<Customization> for CustomizationView {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct InnerCustomization {
|
||||
name: String,
|
||||
customization_id: Uuid,
|
||||
product_id: Uuid,
|
||||
deleted: bool,
|
||||
}
|
||||
|
||||
impl From<InnerCustomization> for Customization {
|
||||
fn from(value: InnerCustomization) -> Self {
|
||||
CustomizationBuilder::default()
|
||||
.name(value.name)
|
||||
.customization_id(value.customization_id)
|
||||
.deleted(value.deleted)
|
||||
.build()
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
//impl InnerCustomizationView {
|
||||
// async fn get_customizations(
|
||||
// &self,
|
||||
// db: &InventoryDBPostgresAdapter,
|
||||
// ) -> Result<Vec<Customization>, PersistenceError> {
|
||||
// let customizations = if self.customizations_available {
|
||||
// let mut inner_customizations = sqlx::query_as!(
|
||||
// InnerCustomization,
|
||||
// "SELECT
|
||||
// name,
|
||||
// customization_id,
|
||||
// deleted,
|
||||
// customization_id
|
||||
// FROM
|
||||
// cqrs_inventory_product_customizations_query
|
||||
// WHERE
|
||||
// customization_id = $1;",
|
||||
// self.customization_id
|
||||
// )
|
||||
// .fetch_all(&db.pool)
|
||||
// .await
|
||||
// .map_err(PostgresAggregateError::from)?;
|
||||
//
|
||||
// let mut customizations = Vec::with_capacity(inner_customizations.len());
|
||||
// for c in inner_customizations.drain(0..) {
|
||||
// customizations.push(c.into());
|
||||
// }
|
||||
// customizations
|
||||
// } else {
|
||||
// Vec::default()
|
||||
// };
|
||||
// Ok(customizations)
|
||||
// }
|
||||
//}
|
||||
|
||||
#[async_trait]
|
||||
impl ViewRepository<CustomizationView, Customization> for InventoryDBPostgresAdapter {
|
||||
|
|
|
@ -76,6 +76,7 @@ impl AddCustomizationUseCase for AddCustomizationService {
|
|||
let customization = CustomizationBuilder::default()
|
||||
.name(cmd.name().into())
|
||||
.deleted(false)
|
||||
.product_id(*cmd.product_id())
|
||||
.customization_id(customization_id)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
@ -90,7 +91,6 @@ impl AddCustomizationUseCase for AddCustomizationService {
|
|||
|
||||
Ok(CustomizationAddedEventBuilder::default()
|
||||
.customization(customization)
|
||||
.product_id(cmd.product_id().clone())
|
||||
.build()
|
||||
.unwrap())
|
||||
}
|
||||
|
@ -144,7 +144,6 @@ pub mod tests {
|
|||
|
||||
let res = s.add_customization(cmd.clone()).await.unwrap();
|
||||
assert_eq!(res.customization().name(), cmd.name());
|
||||
assert_eq!(res.product_id(), cmd.product_id());
|
||||
// assert_eq!(customization_added_events.len(), cmd.customizations().len());
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ use super::customization_aggregate::*;
|
|||
)]
|
||||
pub struct CustomizationAddedEvent {
|
||||
customization: Customization,
|
||||
product_id: Uuid,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -31,13 +30,13 @@ pub mod tests {
|
|||
let customization = CustomizationBuilder::default()
|
||||
.name(cmd.name().into())
|
||||
.deleted(false)
|
||||
.product_id(*cmd.product_id())
|
||||
.customization_id(UUID.clone())
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
CustomizationAddedEventBuilder::default()
|
||||
.customization(customization)
|
||||
.product_id(cmd.product_id().clone())
|
||||
.build()
|
||||
.unwrap()
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ use crate::inventory::application::services::InventoryServicesInterface;
|
|||
pub struct Customization {
|
||||
name: String,
|
||||
customization_id: Uuid,
|
||||
product_id: Uuid,
|
||||
#[builder(default = "false")]
|
||||
deleted: bool,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue