upload picture now working well

This commit is contained in:
Priec
2026-06-22 16:56:14 +02:00
parent 681c88f85d
commit f724e9763f
2 changed files with 7 additions and 3 deletions

View File

@@ -526,7 +526,7 @@ async fn update(
if let Some(data) = form.image { if let Some(data) = form.image {
let filename = store_image(&ctx, data).await?; let filename = store_image(&ctx, data).await?;
let next_position = product_images::count_for(&ctx, id).await?; let next_position = product_images::count_for(&txn, id).await?;
product_images::ActiveModel { product_images::ActiveModel {
product_id: Set(id), product_id: Set(id),
image_id: Set(filename), image_id: Set(filename),

View File

@@ -38,10 +38,14 @@ pub async fn first_for(ctx: &AppContext, product_id: i32) -> Result<Option<Strin
} }
/// Number of images already attached to a product, used to position new uploads. /// Number of images already attached to a product, used to position new uploads.
pub async fn count_for(ctx: &AppContext, product_id: i32) -> Result<i32> { ///
/// Takes a connection rather than the `AppContext` so it can run on an open
/// transaction; calling it on `ctx.db` while a transaction holds the pool's only
/// connection would deadlock the pool.
pub async fn count_for<C: ConnectionTrait>(db: &C, product_id: i32) -> Result<i32> {
use sea_orm::PaginatorTrait; use sea_orm::PaginatorTrait;
Ok(Entity::find() Ok(Entity::find()
.filter(Column::ProductId.eq(product_id)) .filter(Column::ProductId.eq(product_id))
.count(&ctx.db) .count(db)
.await? as i32) .await? as i32)
} }