style: cargo fmt --all
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
use std::sync::Arc;
|
||||
use domain::{
|
||||
catalog::entities::{Asset, AssetType, DuplicateGroup, SourceReference},
|
||||
errors::DomainError,
|
||||
@@ -6,6 +5,7 @@ use domain::{
|
||||
ports::{AssetRepository, DuplicateRepository, EventPublisher},
|
||||
value_objects::{Checksum, DateTimeStamp, SystemId},
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct RegisterAssetCommand {
|
||||
@@ -30,10 +30,17 @@ impl RegisterAssetHandler {
|
||||
duplicate_repo: Arc<dyn DuplicateRepository>,
|
||||
event_pub: Arc<dyn EventPublisher>,
|
||||
) -> Self {
|
||||
Self { asset_repo, duplicate_repo, event_pub }
|
||||
Self {
|
||||
asset_repo,
|
||||
duplicate_repo,
|
||||
event_pub,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn execute(&self, cmd: RegisterAssetCommand) -> Result<(Asset, Option<DuplicateGroup>), DomainError> {
|
||||
pub async fn execute(
|
||||
&self,
|
||||
cmd: RegisterAssetCommand,
|
||||
) -> Result<(Asset, Option<DuplicateGroup>), DomainError> {
|
||||
let checksum = Checksum::new(&cmd.checksum)?;
|
||||
|
||||
let existing = self.asset_repo.find_by_checksum(&checksum).await?;
|
||||
@@ -44,7 +51,13 @@ impl RegisterAssetHandler {
|
||||
checksum,
|
||||
};
|
||||
|
||||
let asset = Asset::new(source_ref, cmd.asset_type, cmd.mime_type, cmd.file_size, cmd.owner_id);
|
||||
let asset = Asset::new(
|
||||
source_ref,
|
||||
cmd.asset_type,
|
||||
cmd.mime_type,
|
||||
cmd.file_size,
|
||||
cmd.owner_id,
|
||||
);
|
||||
self.asset_repo.save(&asset).await?;
|
||||
|
||||
let dup_group = if let Some(first) = existing.first() {
|
||||
@@ -55,11 +68,13 @@ impl RegisterAssetHandler {
|
||||
None
|
||||
};
|
||||
|
||||
self.event_pub.publish(DomainEvent::AssetIngested {
|
||||
asset_id: asset.asset_id,
|
||||
owner_user_id: asset.owner_user_id,
|
||||
timestamp: DateTimeStamp::now(),
|
||||
}).await?;
|
||||
self.event_pub
|
||||
.publish(DomainEvent::AssetIngested {
|
||||
asset_id: asset.asset_id,
|
||||
owner_user_id: asset.owner_user_id,
|
||||
timestamp: DateTimeStamp::now(),
|
||||
})
|
||||
.await?;
|
||||
|
||||
Ok((asset, dup_group))
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use std::sync::Arc;
|
||||
use domain::{
|
||||
catalog::entities::{AssetMetadata, MetadataSource},
|
||||
errors::DomainError,
|
||||
events::DomainEvent,
|
||||
ports::{AssetRepository, AssetMetadataRepository, EventPublisher},
|
||||
ports::{AssetMetadataRepository, AssetRepository, EventPublisher},
|
||||
value_objects::{DateTimeStamp, StructuredData, SystemId},
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct UpdateMetadataCommand {
|
||||
@@ -26,21 +26,29 @@ impl UpdateMetadataHandler {
|
||||
metadata_repo: Arc<dyn AssetMetadataRepository>,
|
||||
event_pub: Arc<dyn EventPublisher>,
|
||||
) -> Self {
|
||||
Self { asset_repo, metadata_repo, event_pub }
|
||||
Self {
|
||||
asset_repo,
|
||||
metadata_repo,
|
||||
event_pub,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn execute(&self, cmd: UpdateMetadataCommand) -> Result<AssetMetadata, DomainError> {
|
||||
self.asset_repo.find_by_id(&cmd.asset_id).await?
|
||||
self.asset_repo
|
||||
.find_by_id(&cmd.asset_id)
|
||||
.await?
|
||||
.ok_or_else(|| DomainError::NotFound(format!("Asset {} not found", cmd.asset_id)))?;
|
||||
|
||||
let metadata = AssetMetadata::new(cmd.asset_id, MetadataSource::UserEdited, cmd.data);
|
||||
self.metadata_repo.save(&metadata).await?;
|
||||
|
||||
self.event_pub.publish(DomainEvent::MetadataUpdated {
|
||||
asset_id: cmd.asset_id,
|
||||
updated_by: cmd.user_id,
|
||||
timestamp: DateTimeStamp::now(),
|
||||
}).await?;
|
||||
self.event_pub
|
||||
.publish(DomainEvent::MetadataUpdated {
|
||||
asset_id: cmd.asset_id,
|
||||
updated_by: cmd.user_id,
|
||||
timestamp: DateTimeStamp::now(),
|
||||
})
|
||||
.await?;
|
||||
|
||||
Ok(metadata)
|
||||
}
|
||||
|
||||
@@ -3,5 +3,5 @@ pub mod queries;
|
||||
|
||||
pub use commands::register_asset::{RegisterAssetCommand, RegisterAssetHandler};
|
||||
pub use commands::update_metadata::{UpdateMetadataCommand, UpdateMetadataHandler};
|
||||
pub use queries::get_timeline::{GetTimelineQuery, GetTimelineHandler};
|
||||
pub use queries::get_asset::{GetAssetQuery, GetAssetHandler};
|
||||
pub use queries::get_asset::{GetAssetHandler, GetAssetQuery};
|
||||
pub use queries::get_timeline::{GetTimelineHandler, GetTimelineQuery};
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use std::sync::Arc;
|
||||
use domain::{
|
||||
catalog::entities::Asset,
|
||||
catalog::services::resolve_metadata,
|
||||
errors::DomainError,
|
||||
ports::{AssetRepository, AssetMetadataRepository},
|
||||
ports::{AssetMetadataRepository, AssetRepository},
|
||||
value_objects::{StructuredData, SystemId},
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct GetAssetQuery {
|
||||
@@ -22,11 +22,20 @@ impl GetAssetHandler {
|
||||
asset_repo: Arc<dyn AssetRepository>,
|
||||
metadata_repo: Arc<dyn AssetMetadataRepository>,
|
||||
) -> Self {
|
||||
Self { asset_repo, metadata_repo }
|
||||
Self {
|
||||
asset_repo,
|
||||
metadata_repo,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn execute(&self, query: GetAssetQuery) -> Result<(Asset, StructuredData), DomainError> {
|
||||
let asset = self.asset_repo.find_by_id(&query.asset_id).await?
|
||||
pub async fn execute(
|
||||
&self,
|
||||
query: GetAssetQuery,
|
||||
) -> Result<(Asset, StructuredData), DomainError> {
|
||||
let asset = self
|
||||
.asset_repo
|
||||
.find_by_id(&query.asset_id)
|
||||
.await?
|
||||
.ok_or_else(|| DomainError::NotFound(format!("Asset {} not found", query.asset_id)))?;
|
||||
|
||||
let layers = self.metadata_repo.find_by_asset(&asset.asset_id).await?;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use std::sync::Arc;
|
||||
use domain::{
|
||||
catalog::entities::Asset,
|
||||
catalog::services::resolve_metadata,
|
||||
errors::DomainError,
|
||||
ports::{AssetRepository, AssetMetadataRepository},
|
||||
ports::{AssetMetadataRepository, AssetRepository},
|
||||
value_objects::{StructuredData, SystemId},
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct GetTimelineQuery {
|
||||
@@ -24,11 +24,20 @@ impl GetTimelineHandler {
|
||||
asset_repo: Arc<dyn AssetRepository>,
|
||||
metadata_repo: Arc<dyn AssetMetadataRepository>,
|
||||
) -> Self {
|
||||
Self { asset_repo, metadata_repo }
|
||||
Self {
|
||||
asset_repo,
|
||||
metadata_repo,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn execute(&self, query: GetTimelineQuery) -> Result<Vec<(Asset, StructuredData)>, DomainError> {
|
||||
let assets = self.asset_repo.find_by_owner(&query.owner_id, query.limit, query.offset).await?;
|
||||
pub async fn execute(
|
||||
&self,
|
||||
query: GetTimelineQuery,
|
||||
) -> Result<Vec<(Asset, StructuredData)>, DomainError> {
|
||||
let assets = self
|
||||
.asset_repo
|
||||
.find_by_owner(&query.owner_id, query.limit, query.offset)
|
||||
.await?;
|
||||
|
||||
let mut results = Vec::with_capacity(assets.len());
|
||||
for asset in assets {
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
pub mod get_timeline;
|
||||
pub mod get_asset;
|
||||
pub mod get_timeline;
|
||||
|
||||
Reference in New Issue
Block a user