Skip to main content

CatalogWriteService

Struct CatalogWriteService 

Source
pub struct CatalogWriteService { /* private fields */ }

Implementations§

Source§

impl CatalogWriteService

Source

pub fn new(db_pool: PgPool) -> Self

Source

pub async fn lookup_item( &self, code: &str, ) -> Result<Option<ItemHit>, CatalogWriteError>

Resolve a scanned code (barcode OR SKU/item_code) to a sellable identity. Matches the base item first (by barcode or item_code), then a variant (by barcode or sku). None = unknown code. Tenant-agnostic: the lookups ride the request-dedicated scoped connection when the composed host mounts one, so out-of-scope rows are simply not found.

Source

pub async fn create_item_group( &self, g: NewItemGroup, ) -> Result<Uuid, CatalogWriteError>

Source

pub async fn create_item(&self, i: NewItem) -> Result<Uuid, CatalogWriteError>

Source

pub async fn create_uom(&self, u: NewUom) -> Result<Uuid, CatalogWriteError>

Create a Uom (leaf master) on the parent-store tree (ADR-0023). Validated create so the guarded surface can mount Uom read-only (generic delete/patch would orphan items that FK-point at it — council 2026-07-01). With relative_uom_id set the unit becomes a child of that reference unit and its stored factor is derived as parent.factor * relative_factor; without it the unit is a new tree root (factor 1).

Source

pub async fn set_uom_relative( &self, uom_id: Uuid, relative: Option<(Uuid, Decimal)>, ) -> Result<(), CatalogWriteError>

Re-parent a live unit onto a new reference unit (or detach it to become a tree root by passing None). After the link changes, every stored factor in the affected tree is re-derived (the unit’s own and all its descendants’). Guards: shape (both fields together), positivity, parent existence, and the cycle rule — a unit may never point at itself or its own descendant.

Source

pub async fn convert_quantity( &self, qty: Decimal, from_uom: Uuid, to_uom: Uuid, rounding: ConversionRounding, ) -> Result<Decimal, CatalogWriteError>

Convert qty from one unit to another over the parent-store tree (ADR-0023).

Application-side math over the stored factors: qty * factor_from / factor_to, with the rounding policy declared by the caller. Units in different trees fail LOUDLY with a typed error naming both trees — never a silent numeric result.

Source

pub async fn delete_uom(&self, uom_id: Uuid) -> Result<(), CatalogWriteError>

Retire (soft-delete) a unit of measure through the validated path (UM-4).

User-created units are deletable once nothing leans on them; module-seeded reference units (is_protected) refuse deletion with a typed error — retire those through the status lifecycle (active -> inactive) instead. The guards, in order: the unit must exist and be live, must not be protected, must not be the live parent of live units, and must not be the default unit of any live item (the orphaning hazard that keeps generic delete off the guarded surface, ADR-005). The database-level protected-unit triggers are the backstop if a protected row ever slips past the service check.

Source

pub async fn create_attribute( &self, a: NewAttribute, ) -> Result<Uuid, CatalogWriteError>

Source

pub async fn create_attribute_value( &self, v: NewAttributeValue, ) -> Result<Uuid, CatalogWriteError>

Source

pub async fn create_item_variant( &self, v: NewItemVariant, ) -> Result<Uuid, CatalogWriteError>

Create a variant SKU. Validates the item exists, every option maps to a known attribute+value in the registry, then persists the variant and flips the item’s has_variants flag. variant_label defaults to the option value labels joined “ / “.

Source

pub async fn delete_item_variant( &self, variant_id: Uuid, ) -> Result<(), CatalogWriteError>

Soft-delete a variant and keep Item.has_variants honest: if the item has no live variants left, flip the flag back to false so the storefront picker never lies.

Source

pub async fn transition_item_status( &self, item_id: Uuid, target: CatalogStatus, ) -> Result<(), CatalogWriteError>

Transition an Item’s lifecycle status, enforcing the CatalogStatus state machine declared in schema/hooks/catalog.hook.yaml (active ↔ inactive, active|inactive → discontinued; discontinued is terminal).

Source

pub async fn create_brand(&self, b: NewBrand) -> Result<Uuid, CatalogWriteError>

Create a Brand (leaf master). Validated create — same rationale as create_uom.

Trait Implementations§

Source§

impl Clone for CatalogWriteService

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more