refactor: introduce IngestTransaction port to reduce IngestAssetHandler from 7 to 4 ports
This commit is contained in:
@@ -3,13 +3,13 @@ use async_trait::async_trait;
|
||||
use chrono::{DateTime, Utc};
|
||||
use domain::{
|
||||
entities::{
|
||||
IngestSession, IngestStatus, LibraryPath, OwnershipPolicy, QuotaDefinition, QuotaRule,
|
||||
StorageVolume, TimePeriod, UsageLedgerEntry, UsageType,
|
||||
Asset, IngestSession, IngestStatus, LibraryPath, OwnershipPolicy, QuotaDefinition,
|
||||
QuotaRule, StorageVolume, TimePeriod, UsageLedgerEntry, UsageType,
|
||||
},
|
||||
errors::DomainError,
|
||||
ports::{
|
||||
IngestSessionRepository, LibraryPathRepository, QuotaRepository, StorageVolumeRepository,
|
||||
UsageLedgerRepository,
|
||||
IngestSessionRepository, IngestTransaction, LibraryPathRepository, QuotaRepository,
|
||||
StorageVolumeRepository, UsageLedgerRepository,
|
||||
},
|
||||
value_objects::{Checksum, DateTimeStamp, SystemId},
|
||||
};
|
||||
@@ -565,3 +565,51 @@ impl UsageLedgerRepository for PostgresUsageLedgerRepository {
|
||||
Ok(row.total as u64)
|
||||
}
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────────
|
||||
// IngestTransaction (composite port)
|
||||
// ──────────────────────────────────────────────
|
||||
|
||||
pg_repo!(PostgresIngestTransaction);
|
||||
|
||||
#[async_trait]
|
||||
impl IngestTransaction for PostgresIngestTransaction {
|
||||
async fn save_asset(&self, asset: &Asset) -> Result<(), DomainError> {
|
||||
use domain::ports::AssetRepository;
|
||||
crate::PostgresAssetRepository::new(self.pool.clone())
|
||||
.save(asset)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn save_session(&self, session: &IngestSession) -> Result<(), DomainError> {
|
||||
PostgresIngestSessionRepository::new(self.pool.clone())
|
||||
.save(session)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn find_quota(
|
||||
&self,
|
||||
owner_id: &SystemId,
|
||||
) -> Result<Option<QuotaDefinition>, DomainError> {
|
||||
PostgresQuotaRepository::new(self.pool.clone())
|
||||
.find_by_owner(owner_id)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn sum_usage(
|
||||
&self,
|
||||
user_id: &SystemId,
|
||||
usage_type: UsageType,
|
||||
since: Option<DateTimeStamp>,
|
||||
) -> Result<u64, DomainError> {
|
||||
PostgresUsageLedgerRepository::new(self.pool.clone())
|
||||
.sum_usage(user_id, usage_type, since)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn record_usage(&self, entry: &UsageLedgerEntry) -> Result<(), DomainError> {
|
||||
PostgresUsageLedgerRepository::new(self.pool.clone())
|
||||
.record(entry)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user