backbone_inventory/infrastructure/persistence/
stock_entry_item_repository.rs1use anyhow::Result;
12use rust_decimal::Decimal;
13use sqlx::PgPool;
14use uuid::Uuid;
15
16use crate::domain::entity::StockEntryItem;
17
18pub const TABLE_NAME: &str = "inventory.stock_entry_items";
20
21pub struct StockEntryItemRepository(
26 backbone_orm::GenericCrudRepository<StockEntryItem, backbone_orm::SoftDelete>,
27);
28
29impl std::ops::Deref for StockEntryItemRepository {
30 type Target = backbone_orm::GenericCrudRepository<StockEntryItem, backbone_orm::SoftDelete>;
31 fn deref(&self) -> &Self::Target { &self.0 }
32}
33
34impl StockEntryItemRepository {
35 pub fn new(pool: PgPool) -> Self {
37 Self(backbone_orm::GenericCrudRepository::new(pool, TABLE_NAME))
38 }
39}
40
41pub struct NewStockEntryItemRow {
43 pub id: Uuid,
44 pub entry_id: Uuid,
45 pub item_id: Uuid,
46 pub quantity: Decimal,
47}
48
49impl StockEntryItemRepository {
51 pub async fn insert_item(
55 &self,
56 conn: &mut sqlx::PgConnection,
57 l: &NewStockEntryItemRow,
58 ) -> Result<(), sqlx::Error> {
59 sqlx::query("INSERT INTO inventory.stock_entry_items (id, entry_id, item_id, quantity) VALUES ($1,$2,$3,$4)")
60 .bind(l.id).bind(l.entry_id).bind(l.item_id).bind(l.quantity)
61 .execute(conn)
62 .await?;
63 Ok(())
64 }
65}
66
67backbone_core::impl_crud_repository!(StockEntryItemRepository, StockEntryItem, soft_delete);