fix: use product ID from customization obj

This commit is contained in:
Aravinth Manivannan 2024-07-16 20:56:31 +05:30
parent 7c416feacd
commit feaab33d33
Signed by: realaravinth
GPG key ID: F8F50389936984FF
3 changed files with 9 additions and 11 deletions

View file

@ -14,7 +14,6 @@ impl CustomizationNameExistsForProductDBPort for InventoryDBPostgresAdapter {
async fn customization_name_exists_for_product(
&self,
c: &Customization,
product_id: &Uuid,
) -> InventoryDBResult<bool> {
let res = sqlx::query!(
"SELECT EXISTS (
@ -28,7 +27,7 @@ impl CustomizationNameExistsForProductDBPort for InventoryDBPostgresAdapter {
deleted = false
);",
c.name(),
product_id,
c.product_id()
)
.fetch_one(&self.pool)
.await?;
@ -71,7 +70,7 @@ mod tests {
// state doesn't exist
assert!(!db
.customization_name_exists_for_product(&customization, &product_id)
.customization_name_exists_for_product(&customization)
.await
.unwrap());
@ -79,7 +78,7 @@ mod tests {
// state exists
assert!(db
.customization_name_exists_for_product(&customization, &product_id)
.customization_name_exists_for_product(&customization)
.await
.unwrap());
@ -103,7 +102,7 @@ mod tests {
.await
.unwrap();
assert!(!db
.customization_name_exists_for_product(&customization, &product_id)
.customization_name_exists_for_product(&customization)
.await
.unwrap());

View file

@ -19,7 +19,6 @@ pub trait CustomizationNameExistsForProductDBPort: Send + Sync {
async fn customization_name_exists_for_product(
&self,
c: &Customization,
product_id: &Uuid,
) -> InventoryDBResult<bool>;
}
@ -39,10 +38,10 @@ pub mod tests {
if let Some(times) = times {
m.expect_customization_name_exists_for_product()
.times(times)
.returning(|_, _| Ok(false));
.returning(|_| Ok(false));
} else {
m.expect_customization_name_exists_for_product()
.returning(|_, _| Ok(false));
.returning(|_| Ok(false));
}
Arc::new(m)
@ -55,10 +54,10 @@ pub mod tests {
if let Some(times) = times {
m.expect_customization_name_exists_for_product()
.times(times)
.returning(|_, _| Ok(true));
.returning(|_| Ok(true));
} else {
m.expect_customization_name_exists_for_product()
.returning(|_, _| Ok(true));
.returning(|_| Ok(true));
}
Arc::new(m)

View file

@ -83,7 +83,7 @@ impl AddCustomizationUseCase for AddCustomizationService {
if self
.db_customization_name_exists_for_product
.customization_name_exists_for_product(&customization, cmd.product_id())
.customization_name_exists_for_product(&customization)
.await?
{
return Err(InventoryError::DuplicateCustomizationName);