refactor: introduce IngestTransaction port to reduce IngestAssetHandler from 7 to 4 ports
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use super::entities::{
|
||||
IngestSession, LibraryPath, QuotaDefinition, StorageVolume, UsageLedgerEntry, UsageType,
|
||||
};
|
||||
use crate::catalog::entities::Asset;
|
||||
use crate::common::errors::DomainError;
|
||||
use crate::common::value_objects::{DateTimeStamp, SystemId};
|
||||
use async_trait::async_trait;
|
||||
@@ -63,6 +64,25 @@ pub trait UsageLedgerRepository: Send + Sync {
|
||||
) -> Result<u64, DomainError>;
|
||||
}
|
||||
|
||||
// --- IngestTransaction ---
|
||||
|
||||
/// Bundles the four persistence concerns that the ingest use-case touches
|
||||
/// (asset, session, quota, ledger) behind a single port so the handler only
|
||||
/// needs one `Arc<dyn IngestTransaction>` instead of four separate repos.
|
||||
#[async_trait]
|
||||
pub trait IngestTransaction: Send + Sync {
|
||||
async fn save_asset(&self, asset: &Asset) -> Result<(), DomainError>;
|
||||
async fn save_session(&self, session: &IngestSession) -> Result<(), DomainError>;
|
||||
async fn find_quota(&self, owner_id: &SystemId) -> Result<Option<QuotaDefinition>, DomainError>;
|
||||
async fn sum_usage(
|
||||
&self,
|
||||
user_id: &SystemId,
|
||||
usage_type: UsageType,
|
||||
since: Option<DateTimeStamp>,
|
||||
) -> Result<u64, DomainError>;
|
||||
async fn record_usage(&self, entry: &UsageLedgerEntry) -> Result<(), DomainError>;
|
||||
}
|
||||
|
||||
// --- FileStoragePort ---
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
||||
Reference in New Issue
Block a user