refactor: introduce IngestTransaction port to reduce IngestAssetHandler from 7 to 4 ports

This commit is contained in:
2026-05-31 18:44:51 +02:00
parent aa09aec66b
commit 0b2237860e
7 changed files with 189 additions and 67 deletions

View File

@@ -3,23 +3,18 @@ use application::storage::{
RegisterVolumeCommand, RegisterVolumeHandler,
};
use application::testing::{
InMemoryAssetRepository, InMemoryFileStorage, InMemoryIngestSessionRepository,
InMemoryLibraryPathRepository, InMemoryQuotaRepository, InMemoryStorageVolumeRepository,
InMemoryUsageLedgerRepository, StubEventPublisher,
InMemoryFileStorage, InMemoryIngestTransaction, InMemoryLibraryPathRepository,
InMemoryStorageVolumeRepository, StubEventPublisher,
};
use bytes::Bytes;
use domain::entities::{IngestStatus, QuotaDefinition, TimePeriod, UsageType};
use domain::errors::DomainError;
use domain::ports::QuotaRepository;
use domain::value_objects::SystemId;
use std::sync::Arc;
struct Harness {
ingest_repo: Arc<InMemoryIngestSessionRepository>,
tx: Arc<InMemoryIngestTransaction>,
path_repo: Arc<InMemoryLibraryPathRepository>,
quota_repo: Arc<InMemoryQuotaRepository>,
ledger_repo: Arc<InMemoryUsageLedgerRepository>,
asset_repo: Arc<InMemoryAssetRepository>,
file_storage: Arc<InMemoryFileStorage>,
event_pub: Arc<StubEventPublisher>,
vol_repo: Arc<InMemoryStorageVolumeRepository>,
@@ -28,11 +23,8 @@ struct Harness {
impl Harness {
fn new() -> Self {
Self {
ingest_repo: Arc::new(InMemoryIngestSessionRepository::new()),
tx: Arc::new(InMemoryIngestTransaction::new()),
path_repo: Arc::new(InMemoryLibraryPathRepository::new()),
quota_repo: Arc::new(InMemoryQuotaRepository::new()),
ledger_repo: Arc::new(InMemoryUsageLedgerRepository::new()),
asset_repo: Arc::new(InMemoryAssetRepository::new()),
file_storage: Arc::new(InMemoryFileStorage::new()),
event_pub: Arc::new(StubEventPublisher::new()),
vol_repo: Arc::new(InMemoryStorageVolumeRepository::new()),
@@ -41,11 +33,8 @@ impl Harness {
fn ingest_handler(&self) -> IngestAssetHandler {
IngestAssetHandler::new(
self.ingest_repo.clone(),
self.tx.clone(),
self.path_repo.clone(),
self.quota_repo.clone(),
self.ledger_repo.clone(),
self.asset_repo.clone(),
self.file_storage.clone(),
self.event_pub.clone(),
)
@@ -111,7 +100,7 @@ async fn rejects_quota_exceeded() {
let mut quota = QuotaDefinition::new(user);
quota.add_rule(UsageType::StorageBytes, 500, TimePeriod::Lifetime);
h.quota_repo.save(&quota).await.unwrap();
h.tx.insert_quota(&quota).await;
let handler = h.ingest_handler();
let result = handler