Added variant update functionality.

This commit is contained in:
2026-01-23 23:12:47 +01:00
parent 897f154fae
commit ea482fab07
5 changed files with 144 additions and 19 deletions
+35
View File
@@ -88,3 +88,38 @@ pub async fn insert_variant(article_id: i64, variant: &Variant, pool: PgPool) ->
}
}
}
pub async fn update_variant(variant_id: i64, variant: &Variant, pool: PgPool) -> Option<Variant> {
let mut args = PgArguments::default();
args.add(&variant.id);
args.add(&variant.weight);
args.add(&variant.ean);
args.add(&variant.name);
args.add(&variant.description);
args.add(&variant.ingredients);
info!("Variant: {:#?}", variant);
let statement = format!(
"UPDATE {} SET weight = $2, ean = $3, name = $4, description = $5, ingredients = $6 WHERE id = $1 RETURNING *",
"variant",
);
let res = sqlx::query_with(
statement.as_str(),
args)
.fetch_one(&pool).await;
info!("{:#?}", res);
match res {
Ok(record) => {
let variant = from_postgres_row_small(record);
Some(variant)
}
Err(err) => {
error!("Error while updating variant: {}", variant_id);
None
}
}
}