style: cargo fmt --all
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use domain::{errors::DomainError, ports::TokenIssuer, value_objects::SystemId};
|
use domain::{errors::DomainError, ports::TokenIssuer, value_objects::SystemId};
|
||||||
use jsonwebtoken::{decode, encode, DecodingKey, EncodingKey, Header, Validation};
|
use jsonwebtoken::{DecodingKey, EncodingKey, Header, Validation, decode, encode};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
pub mod db;
|
pub mod db;
|
||||||
pub mod user_repository;
|
pub mod user_repository;
|
||||||
|
|
||||||
pub use db::{connect, run_migrations, PgPool};
|
pub use db::{PgPool, connect, run_migrations};
|
||||||
pub use user_repository::PostgresUserRepository;
|
pub use user_repository::PostgresUserRepository;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::db::PgPool;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use domain::{
|
use domain::{
|
||||||
entities::User,
|
entities::User,
|
||||||
@@ -5,14 +6,15 @@ use domain::{
|
|||||||
ports::UserRepository,
|
ports::UserRepository,
|
||||||
value_objects::{Email, PasswordHash, SystemId},
|
value_objects::{Email, PasswordHash, SystemId},
|
||||||
};
|
};
|
||||||
use crate::db::PgPool;
|
|
||||||
|
|
||||||
pub struct PostgresUserRepository {
|
pub struct PostgresUserRepository {
|
||||||
pool: PgPool,
|
pool: PgPool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PostgresUserRepository {
|
impl PostgresUserRepository {
|
||||||
pub fn new(pool: PgPool) -> Self { Self { pool } }
|
pub fn new(pool: PgPool) -> Self {
|
||||||
|
Self { pool }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -26,12 +28,14 @@ impl UserRepository for PostgresUserRepository {
|
|||||||
.await
|
.await
|
||||||
.map_err(|e| DomainError::Internal(e.to_string()))?;
|
.map_err(|e| DomainError::Internal(e.to_string()))?;
|
||||||
|
|
||||||
row.map(|r| Ok(User {
|
row.map(|r| {
|
||||||
|
Ok(User {
|
||||||
id: SystemId::from_uuid(r.id),
|
id: SystemId::from_uuid(r.id),
|
||||||
email: Email::new(r.email)?,
|
email: Email::new(r.email)?,
|
||||||
password_hash: PasswordHash::from_hash(r.password_hash),
|
password_hash: PasswordHash::from_hash(r.password_hash),
|
||||||
created_at: r.created_at,
|
created_at: r.created_at,
|
||||||
}))
|
})
|
||||||
|
})
|
||||||
.transpose()
|
.transpose()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,12 +48,14 @@ impl UserRepository for PostgresUserRepository {
|
|||||||
.await
|
.await
|
||||||
.map_err(|e| DomainError::Internal(e.to_string()))?;
|
.map_err(|e| DomainError::Internal(e.to_string()))?;
|
||||||
|
|
||||||
row.map(|r| Ok(User {
|
row.map(|r| {
|
||||||
|
Ok(User {
|
||||||
id: SystemId::from_uuid(r.id),
|
id: SystemId::from_uuid(r.id),
|
||||||
email: Email::new(r.email)?,
|
email: Email::new(r.email)?,
|
||||||
password_hash: PasswordHash::from_hash(r.password_hash),
|
password_hash: PasswordHash::from_hash(r.password_hash),
|
||||||
created_at: r.created_at,
|
created_at: r.created_at,
|
||||||
}))
|
})
|
||||||
|
})
|
||||||
.transpose()
|
.transpose()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures::stream::StreamExt;
|
|
||||||
use object_store::{ObjectStore, path::Path, Error as OsError};
|
|
||||||
use domain::errors::DomainError;
|
use domain::errors::DomainError;
|
||||||
use domain::ports::{DataStream, StorageReader, StorageWriter};
|
use domain::ports::{DataStream, StorageReader, StorageWriter};
|
||||||
|
use futures::stream::StreamExt;
|
||||||
|
use object_store::{Error as OsError, ObjectStore, path::Path};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct ObjectStorageAdapter {
|
pub struct ObjectStorageAdapter {
|
||||||
store: Arc<dyn ObjectStore>,
|
store: Arc<dyn ObjectStore>,
|
||||||
@@ -12,7 +12,10 @@ pub struct ObjectStorageAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ObjectStorageAdapter {
|
impl ObjectStorageAdapter {
|
||||||
pub fn new(store: Arc<dyn ObjectStore>, prefix: impl Into<String>) -> Result<Self, DomainError> {
|
pub fn new(
|
||||||
|
store: Arc<dyn ObjectStore>,
|
||||||
|
prefix: impl Into<String>,
|
||||||
|
) -> Result<Self, DomainError> {
|
||||||
let prefix = prefix.into();
|
let prefix = prefix.into();
|
||||||
if !prefix.is_empty() {
|
if !prefix.is_empty() {
|
||||||
validate_key(&prefix)?;
|
validate_key(&prefix)?;
|
||||||
@@ -38,17 +41,19 @@ fn map_err(e: OsError, key: &str) -> DomainError {
|
|||||||
|
|
||||||
fn validate_key(key: &str) -> Result<(), DomainError> {
|
fn validate_key(key: &str) -> Result<(), DomainError> {
|
||||||
if key.is_empty() {
|
if key.is_empty() {
|
||||||
return Err(DomainError::Validation("storage key must not be empty".into()));
|
return Err(DomainError::Validation(
|
||||||
|
"storage key must not be empty".into(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
if key.starts_with('/') {
|
if key.starts_with('/') {
|
||||||
return Err(DomainError::Validation(
|
return Err(DomainError::Validation(format!(
|
||||||
format!("storage key must not start with '/': {key}"),
|
"storage key must not start with '/': {key}"
|
||||||
));
|
)));
|
||||||
}
|
}
|
||||||
if key.split('/').any(|seg| seg == ".." || seg == ".") {
|
if key.split('/').any(|seg| seg == ".." || seg == ".") {
|
||||||
return Err(DomainError::Validation(
|
return Err(DomainError::Validation(format!(
|
||||||
format!("storage key contains invalid path segment: {key}"),
|
"storage key contains invalid path segment: {key}"
|
||||||
));
|
)));
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -79,7 +84,10 @@ impl StorageWriter for ObjectStorageAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
upload.complete().await.map_err(|e| DomainError::Internal(e.to_string()))?;
|
upload
|
||||||
|
.complete()
|
||||||
|
.await
|
||||||
|
.map_err(|e| DomainError::Internal(e.to_string()))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,11 +107,7 @@ impl StorageReader for ObjectStorageAdapter {
|
|||||||
async fn get(&self, key: &str) -> Result<DataStream, DomainError> {
|
async fn get(&self, key: &str) -> Result<DataStream, DomainError> {
|
||||||
validate_key(key)?;
|
validate_key(key)?;
|
||||||
let path = self.path(key);
|
let path = self.path(key);
|
||||||
let result = self
|
let result = self.store.get(&path).await.map_err(|e| map_err(e, key))?;
|
||||||
.store
|
|
||||||
.get(&path)
|
|
||||||
.await
|
|
||||||
.map_err(|e| map_err(e, key))?;
|
|
||||||
let s = result
|
let s = result
|
||||||
.into_stream()
|
.into_stream()
|
||||||
.map(|r| r.map_err(|e| DomainError::Internal(e.to_string())));
|
.map(|r| r.map_err(|e| DomainError::Internal(e.to_string())));
|
||||||
@@ -128,10 +132,12 @@ impl StorageReader for ObjectStorageAdapter {
|
|||||||
let key = meta.location.to_string();
|
let key = meta.location.to_string();
|
||||||
let stripped = if !self.prefix.is_empty() {
|
let stripped = if !self.prefix.is_empty() {
|
||||||
key.strip_prefix(&format!("{}/", self.prefix))
|
key.strip_prefix(&format!("{}/", self.prefix))
|
||||||
.ok_or_else(|| DomainError::Internal(format!(
|
.ok_or_else(|| {
|
||||||
|
DomainError::Internal(format!(
|
||||||
"listed key '{key}' does not start with expected prefix '{}'",
|
"listed key '{key}' does not start with expected prefix '{}'",
|
||||||
self.prefix
|
self.prefix
|
||||||
)))?
|
))
|
||||||
|
})?
|
||||||
.to_string()
|
.to_string()
|
||||||
} else {
|
} else {
|
||||||
key
|
key
|
||||||
@@ -172,7 +178,10 @@ mod tests {
|
|||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn get_missing_is_not_found() {
|
async fn get_missing_is_not_found() {
|
||||||
let a = make_adapter();
|
let a = make_adapter();
|
||||||
assert!(matches!(a.get("nope.txt").await, Err(DomainError::NotFound(_))));
|
assert!(matches!(
|
||||||
|
a.get("nope.txt").await,
|
||||||
|
Err(DomainError::NotFound(_))
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -186,7 +195,10 @@ mod tests {
|
|||||||
let a = make_adapter();
|
let a = make_adapter();
|
||||||
a.put("file.txt", one_shot(b"data")).await.unwrap();
|
a.put("file.txt", one_shot(b"data")).await.unwrap();
|
||||||
a.delete("file.txt").await.unwrap();
|
a.delete("file.txt").await.unwrap();
|
||||||
assert!(matches!(a.get("file.txt").await, Err(DomainError::NotFound(_))));
|
assert!(matches!(
|
||||||
|
a.get("file.txt").await,
|
||||||
|
Err(DomainError::NotFound(_))
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -213,9 +225,15 @@ mod tests {
|
|||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn rejects_empty_key() {
|
async fn rejects_empty_key() {
|
||||||
let a = make_adapter();
|
let a = make_adapter();
|
||||||
assert!(matches!(a.put("", one_shot(b"x")).await, Err(DomainError::Validation(_))));
|
assert!(matches!(
|
||||||
|
a.put("", one_shot(b"x")).await,
|
||||||
|
Err(DomainError::Validation(_))
|
||||||
|
));
|
||||||
assert!(matches!(a.get("").await, Err(DomainError::Validation(_))));
|
assert!(matches!(a.get("").await, Err(DomainError::Validation(_))));
|
||||||
assert!(matches!(a.delete("").await, Err(DomainError::Validation(_))));
|
assert!(matches!(
|
||||||
|
a.delete("").await,
|
||||||
|
Err(DomainError::Validation(_))
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -230,8 +248,14 @@ mod tests {
|
|||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn rejects_path_traversal() {
|
async fn rejects_path_traversal() {
|
||||||
let a = make_adapter();
|
let a = make_adapter();
|
||||||
assert!(matches!(a.get("../escape").await, Err(DomainError::Validation(_))));
|
assert!(matches!(
|
||||||
assert!(matches!(a.get("a/../../../etc").await, Err(DomainError::Validation(_))));
|
a.get("../escape").await,
|
||||||
|
Err(DomainError::Validation(_))
|
||||||
|
));
|
||||||
|
assert!(matches!(
|
||||||
|
a.get("a/../../../etc").await,
|
||||||
|
Err(DomainError::Validation(_))
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -246,8 +270,14 @@ mod tests {
|
|||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn rejects_invalid_list_prefix() {
|
async fn rejects_invalid_list_prefix() {
|
||||||
let a = make_adapter();
|
let a = make_adapter();
|
||||||
assert!(matches!(a.list(Some("")).await, Err(DomainError::Validation(_))));
|
assert!(matches!(
|
||||||
assert!(matches!(a.list(Some("../escape")).await, Err(DomainError::Validation(_))));
|
a.list(Some("")).await,
|
||||||
|
Err(DomainError::Validation(_))
|
||||||
|
));
|
||||||
|
assert!(matches!(
|
||||||
|
a.list(Some("../escape")).await,
|
||||||
|
Err(DomainError::Validation(_))
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -275,7 +305,9 @@ mod tests {
|
|||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn put_bytes_get_bytes_roundtrip() {
|
async fn put_bytes_get_bytes_roundtrip() {
|
||||||
let a = make_adapter();
|
let a = make_adapter();
|
||||||
a.put_bytes("data.bin", Bytes::from("hello bytes")).await.unwrap();
|
a.put_bytes("data.bin", Bytes::from("hello bytes"))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
let got = a.get_bytes("data.bin").await.unwrap();
|
let got = a.get_bytes("data.bin").await.unwrap();
|
||||||
assert_eq!(got.as_ref(), b"hello bytes");
|
assert_eq!(got.as_ref(), b"hello bytes");
|
||||||
}
|
}
|
||||||
@@ -283,7 +315,10 @@ mod tests {
|
|||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn get_bytes_missing_is_not_found() {
|
async fn get_bytes_missing_is_not_found() {
|
||||||
let a = make_adapter();
|
let a = make_adapter();
|
||||||
assert!(matches!(a.get_bytes("nope.bin").await, Err(DomainError::NotFound(_))));
|
assert!(matches!(
|
||||||
|
a.get_bytes("nope.bin").await,
|
||||||
|
Err(DomainError::NotFound(_))
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use object_store::ObjectStore;
|
use object_store::ObjectStore;
|
||||||
use object_store::local::LocalFileSystem;
|
use object_store::local::LocalFileSystem;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
/// All storage configuration. Populate once via `from_env()` and pass
|
/// All storage configuration. Populate once via `from_env()` and pass
|
||||||
/// explicitly to `build_store` and `ObjectStorageAdapter::new`.
|
/// explicitly to `build_store` and `ObjectStorageAdapter::new`.
|
||||||
@@ -41,7 +41,9 @@ impl StorageConfig {
|
|||||||
pub fn build_store(config: &StorageConfig) -> Result<Arc<dyn ObjectStore>> {
|
pub fn build_store(config: &StorageConfig) -> Result<Arc<dyn ObjectStore>> {
|
||||||
match config.backend.as_str() {
|
match config.backend.as_str() {
|
||||||
"local" => {
|
"local" => {
|
||||||
let path = config.local_path.as_deref()
|
let path = config
|
||||||
|
.local_path
|
||||||
|
.as_deref()
|
||||||
.context("STORAGE_PATH must be set when STORAGE_BACKEND=local")?;
|
.context("STORAGE_PATH must be set when STORAGE_BACKEND=local")?;
|
||||||
std::fs::create_dir_all(path)
|
std::fs::create_dir_all(path)
|
||||||
.with_context(|| format!("failed to create storage dir: {path}"))?;
|
.with_context(|| format!("failed to create storage dir: {path}"))?;
|
||||||
@@ -53,18 +55,28 @@ pub fn build_store(config: &StorageConfig) -> Result<Arc<dyn ObjectStore>> {
|
|||||||
use object_store::aws::AmazonS3Builder;
|
use object_store::aws::AmazonS3Builder;
|
||||||
let store = AmazonS3Builder::new()
|
let store = AmazonS3Builder::new()
|
||||||
.with_endpoint(
|
.with_endpoint(
|
||||||
config.s3_endpoint.as_deref().context("S3_ENDPOINT must be set")?,
|
config
|
||||||
|
.s3_endpoint
|
||||||
|
.as_deref()
|
||||||
|
.context("S3_ENDPOINT must be set")?,
|
||||||
)
|
)
|
||||||
.with_access_key_id(
|
.with_access_key_id(
|
||||||
config.s3_access_key_id.as_deref()
|
config
|
||||||
|
.s3_access_key_id
|
||||||
|
.as_deref()
|
||||||
.context("S3_ACCESS_KEY_ID must be set")?,
|
.context("S3_ACCESS_KEY_ID must be set")?,
|
||||||
)
|
)
|
||||||
.with_secret_access_key(
|
.with_secret_access_key(
|
||||||
config.s3_secret_access_key.as_deref()
|
config
|
||||||
|
.s3_secret_access_key
|
||||||
|
.as_deref()
|
||||||
.context("S3_SECRET_ACCESS_KEY must be set")?,
|
.context("S3_SECRET_ACCESS_KEY must be set")?,
|
||||||
)
|
)
|
||||||
.with_bucket_name(
|
.with_bucket_name(
|
||||||
config.s3_bucket.as_deref().context("S3_BUCKET must be set")?,
|
config
|
||||||
|
.s3_bucket
|
||||||
|
.as_deref()
|
||||||
|
.context("S3_BUCKET must be set")?,
|
||||||
)
|
)
|
||||||
.with_region(config.s3_region.as_deref().unwrap_or("us-east-1"))
|
.with_region(config.s3_region.as_deref().unwrap_or("us-east-1"))
|
||||||
.with_allow_http(true)
|
.with_allow_http(true)
|
||||||
@@ -76,7 +88,10 @@ pub fn build_store(config: &StorageConfig) -> Result<Arc<dyn ObjectStore>> {
|
|||||||
use object_store::gcp::GoogleCloudStorageBuilder;
|
use object_store::gcp::GoogleCloudStorageBuilder;
|
||||||
let store = GoogleCloudStorageBuilder::new()
|
let store = GoogleCloudStorageBuilder::new()
|
||||||
.with_bucket_name(
|
.with_bucket_name(
|
||||||
config.gcs_bucket.as_deref().context("GCS_BUCKET must be set")?,
|
config
|
||||||
|
.gcs_bucket
|
||||||
|
.as_deref()
|
||||||
|
.context("GCS_BUCKET must be set")?,
|
||||||
)
|
)
|
||||||
.build()?;
|
.build()?;
|
||||||
Ok(Arc::new(store))
|
Ok(Arc::new(store))
|
||||||
|
|||||||
@@ -2,4 +2,4 @@ pub mod adapter;
|
|||||||
pub mod config;
|
pub mod config;
|
||||||
|
|
||||||
pub use adapter::ObjectStorageAdapter;
|
pub use adapter::ObjectStorageAdapter;
|
||||||
pub use config::{build_store, StorageConfig};
|
pub use config::{StorageConfig, build_store};
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use domain::{
|
use domain::{
|
||||||
catalog::entities::{Asset, AssetType, DuplicateGroup, SourceReference},
|
catalog::entities::{Asset, AssetType, DuplicateGroup, SourceReference},
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
@@ -6,6 +5,7 @@ use domain::{
|
|||||||
ports::{AssetRepository, DuplicateRepository, EventPublisher},
|
ports::{AssetRepository, DuplicateRepository, EventPublisher},
|
||||||
value_objects::{Checksum, DateTimeStamp, SystemId},
|
value_objects::{Checksum, DateTimeStamp, SystemId},
|
||||||
};
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct RegisterAssetCommand {
|
pub struct RegisterAssetCommand {
|
||||||
@@ -30,10 +30,17 @@ impl RegisterAssetHandler {
|
|||||||
duplicate_repo: Arc<dyn DuplicateRepository>,
|
duplicate_repo: Arc<dyn DuplicateRepository>,
|
||||||
event_pub: Arc<dyn EventPublisher>,
|
event_pub: Arc<dyn EventPublisher>,
|
||||||
) -> Self {
|
) -> 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 checksum = Checksum::new(&cmd.checksum)?;
|
||||||
|
|
||||||
let existing = self.asset_repo.find_by_checksum(&checksum).await?;
|
let existing = self.asset_repo.find_by_checksum(&checksum).await?;
|
||||||
@@ -44,7 +51,13 @@ impl RegisterAssetHandler {
|
|||||||
checksum,
|
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?;
|
self.asset_repo.save(&asset).await?;
|
||||||
|
|
||||||
let dup_group = if let Some(first) = existing.first() {
|
let dup_group = if let Some(first) = existing.first() {
|
||||||
@@ -55,11 +68,13 @@ impl RegisterAssetHandler {
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
self.event_pub.publish(DomainEvent::AssetIngested {
|
self.event_pub
|
||||||
|
.publish(DomainEvent::AssetIngested {
|
||||||
asset_id: asset.asset_id,
|
asset_id: asset.asset_id,
|
||||||
owner_user_id: asset.owner_user_id,
|
owner_user_id: asset.owner_user_id,
|
||||||
timestamp: DateTimeStamp::now(),
|
timestamp: DateTimeStamp::now(),
|
||||||
}).await?;
|
})
|
||||||
|
.await?;
|
||||||
|
|
||||||
Ok((asset, dup_group))
|
Ok((asset, dup_group))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use domain::{
|
use domain::{
|
||||||
catalog::entities::{AssetMetadata, MetadataSource},
|
catalog::entities::{AssetMetadata, MetadataSource},
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
events::DomainEvent,
|
events::DomainEvent,
|
||||||
ports::{AssetRepository, AssetMetadataRepository, EventPublisher},
|
ports::{AssetMetadataRepository, AssetRepository, EventPublisher},
|
||||||
value_objects::{DateTimeStamp, StructuredData, SystemId},
|
value_objects::{DateTimeStamp, StructuredData, SystemId},
|
||||||
};
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct UpdateMetadataCommand {
|
pub struct UpdateMetadataCommand {
|
||||||
@@ -26,21 +26,29 @@ impl UpdateMetadataHandler {
|
|||||||
metadata_repo: Arc<dyn AssetMetadataRepository>,
|
metadata_repo: Arc<dyn AssetMetadataRepository>,
|
||||||
event_pub: Arc<dyn EventPublisher>,
|
event_pub: Arc<dyn EventPublisher>,
|
||||||
) -> Self {
|
) -> 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> {
|
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)))?;
|
.ok_or_else(|| DomainError::NotFound(format!("Asset {} not found", cmd.asset_id)))?;
|
||||||
|
|
||||||
let metadata = AssetMetadata::new(cmd.asset_id, MetadataSource::UserEdited, cmd.data);
|
let metadata = AssetMetadata::new(cmd.asset_id, MetadataSource::UserEdited, cmd.data);
|
||||||
self.metadata_repo.save(&metadata).await?;
|
self.metadata_repo.save(&metadata).await?;
|
||||||
|
|
||||||
self.event_pub.publish(DomainEvent::MetadataUpdated {
|
self.event_pub
|
||||||
|
.publish(DomainEvent::MetadataUpdated {
|
||||||
asset_id: cmd.asset_id,
|
asset_id: cmd.asset_id,
|
||||||
updated_by: cmd.user_id,
|
updated_by: cmd.user_id,
|
||||||
timestamp: DateTimeStamp::now(),
|
timestamp: DateTimeStamp::now(),
|
||||||
}).await?;
|
})
|
||||||
|
.await?;
|
||||||
|
|
||||||
Ok(metadata)
|
Ok(metadata)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,5 @@ pub mod queries;
|
|||||||
|
|
||||||
pub use commands::register_asset::{RegisterAssetCommand, RegisterAssetHandler};
|
pub use commands::register_asset::{RegisterAssetCommand, RegisterAssetHandler};
|
||||||
pub use commands::update_metadata::{UpdateMetadataCommand, UpdateMetadataHandler};
|
pub use commands::update_metadata::{UpdateMetadataCommand, UpdateMetadataHandler};
|
||||||
pub use queries::get_timeline::{GetTimelineQuery, GetTimelineHandler};
|
pub use queries::get_asset::{GetAssetHandler, GetAssetQuery};
|
||||||
pub use queries::get_asset::{GetAssetQuery, GetAssetHandler};
|
pub use queries::get_timeline::{GetTimelineHandler, GetTimelineQuery};
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use domain::{
|
use domain::{
|
||||||
catalog::entities::Asset,
|
catalog::entities::Asset,
|
||||||
catalog::services::resolve_metadata,
|
catalog::services::resolve_metadata,
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
ports::{AssetRepository, AssetMetadataRepository},
|
ports::{AssetMetadataRepository, AssetRepository},
|
||||||
value_objects::{StructuredData, SystemId},
|
value_objects::{StructuredData, SystemId},
|
||||||
};
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct GetAssetQuery {
|
pub struct GetAssetQuery {
|
||||||
@@ -22,11 +22,20 @@ impl GetAssetHandler {
|
|||||||
asset_repo: Arc<dyn AssetRepository>,
|
asset_repo: Arc<dyn AssetRepository>,
|
||||||
metadata_repo: Arc<dyn AssetMetadataRepository>,
|
metadata_repo: Arc<dyn AssetMetadataRepository>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { asset_repo, metadata_repo }
|
Self {
|
||||||
|
asset_repo,
|
||||||
|
metadata_repo,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute(&self, query: GetAssetQuery) -> Result<(Asset, StructuredData), DomainError> {
|
pub async fn execute(
|
||||||
let asset = self.asset_repo.find_by_id(&query.asset_id).await?
|
&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)))?;
|
.ok_or_else(|| DomainError::NotFound(format!("Asset {} not found", query.asset_id)))?;
|
||||||
|
|
||||||
let layers = self.metadata_repo.find_by_asset(&asset.asset_id).await?;
|
let layers = self.metadata_repo.find_by_asset(&asset.asset_id).await?;
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use domain::{
|
use domain::{
|
||||||
catalog::entities::Asset,
|
catalog::entities::Asset,
|
||||||
catalog::services::resolve_metadata,
|
catalog::services::resolve_metadata,
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
ports::{AssetRepository, AssetMetadataRepository},
|
ports::{AssetMetadataRepository, AssetRepository},
|
||||||
value_objects::{StructuredData, SystemId},
|
value_objects::{StructuredData, SystemId},
|
||||||
};
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct GetTimelineQuery {
|
pub struct GetTimelineQuery {
|
||||||
@@ -24,11 +24,20 @@ impl GetTimelineHandler {
|
|||||||
asset_repo: Arc<dyn AssetRepository>,
|
asset_repo: Arc<dyn AssetRepository>,
|
||||||
metadata_repo: Arc<dyn AssetMetadataRepository>,
|
metadata_repo: Arc<dyn AssetMetadataRepository>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { asset_repo, metadata_repo }
|
Self {
|
||||||
|
asset_repo,
|
||||||
|
metadata_repo,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute(&self, query: GetTimelineQuery) -> Result<Vec<(Asset, StructuredData)>, DomainError> {
|
pub async fn execute(
|
||||||
let assets = self.asset_repo.find_by_owner(&query.owner_id, query.limit, query.offset).await?;
|
&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());
|
let mut results = Vec::with_capacity(assets.len());
|
||||||
for asset in assets {
|
for asset in assets {
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
pub mod get_timeline;
|
|
||||||
pub mod get_asset;
|
pub mod get_asset;
|
||||||
|
pub mod get_timeline;
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use domain::{
|
use domain::{
|
||||||
entities::User,
|
entities::User,
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
ports::{PasswordHasher, TokenIssuer, UserRepository},
|
ports::{PasswordHasher, TokenIssuer, UserRepository},
|
||||||
value_objects::Email,
|
value_objects::Email,
|
||||||
};
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct LoginUserCommand {
|
pub struct LoginUserCommand {
|
||||||
@@ -24,14 +24,24 @@ impl LoginUserHandler {
|
|||||||
hasher: Arc<dyn PasswordHasher>,
|
hasher: Arc<dyn PasswordHasher>,
|
||||||
issuer: Arc<dyn TokenIssuer>,
|
issuer: Arc<dyn TokenIssuer>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { repo, hasher, issuer }
|
Self {
|
||||||
|
repo,
|
||||||
|
hasher,
|
||||||
|
issuer,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute(&self, cmd: LoginUserCommand) -> Result<(User, String), DomainError> {
|
pub async fn execute(&self, cmd: LoginUserCommand) -> Result<(User, String), DomainError> {
|
||||||
let email = Email::new(&cmd.email)?;
|
let email = Email::new(&cmd.email)?;
|
||||||
let user = self.repo.find_by_email(&email).await?
|
let user = self
|
||||||
|
.repo
|
||||||
|
.find_by_email(&email)
|
||||||
|
.await?
|
||||||
.ok_or_else(|| DomainError::Unauthorized("Invalid credentials".to_string()))?;
|
.ok_or_else(|| DomainError::Unauthorized("Invalid credentials".to_string()))?;
|
||||||
let valid = self.hasher.verify(&cmd.password, &user.password_hash).await?;
|
let valid = self
|
||||||
|
.hasher
|
||||||
|
.verify(&cmd.password, &user.password_hash)
|
||||||
|
.await?;
|
||||||
if !valid {
|
if !valid {
|
||||||
return Err(DomainError::Unauthorized("Invalid credentials".to_string()));
|
return Err(DomainError::Unauthorized("Invalid credentials".to_string()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
pub mod register_user;
|
|
||||||
pub mod login_user;
|
pub mod login_user;
|
||||||
|
pub mod register_user;
|
||||||
|
|
||||||
pub use register_user::{RegisterUserCommand, RegisterUserHandler};
|
|
||||||
pub use login_user::{LoginUserCommand, LoginUserHandler};
|
pub use login_user::{LoginUserCommand, LoginUserHandler};
|
||||||
|
pub use register_user::{RegisterUserCommand, RegisterUserHandler};
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use domain::{
|
use domain::{
|
||||||
entities::User,
|
entities::User,
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
ports::{PasswordHasher, UserRepository},
|
ports::{PasswordHasher, UserRepository},
|
||||||
value_objects::Email,
|
value_objects::Email,
|
||||||
};
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct RegisterUserCommand {
|
pub struct RegisterUserCommand {
|
||||||
@@ -25,17 +25,32 @@ impl RegisterUserHandler {
|
|||||||
|
|
||||||
pub async fn execute(&self, cmd: RegisterUserCommand) -> Result<User, DomainError> {
|
pub async fn execute(&self, cmd: RegisterUserCommand) -> Result<User, DomainError> {
|
||||||
if cmd.username.is_empty() {
|
if cmd.username.is_empty() {
|
||||||
return Err(DomainError::Validation("Username must not be empty".to_string()));
|
return Err(DomainError::Validation(
|
||||||
|
"Username must not be empty".to_string(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
if cmd.password.len() < 8 {
|
if cmd.password.len() < 8 {
|
||||||
return Err(DomainError::Validation("Password must be at least 8 characters".to_string()));
|
return Err(DomainError::Validation(
|
||||||
|
"Password must be at least 8 characters".to_string(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
let email = Email::new(&cmd.email)?;
|
let email = Email::new(&cmd.email)?;
|
||||||
if self.user_repo.find_by_email(&email).await?.is_some() {
|
if self.user_repo.find_by_email(&email).await?.is_some() {
|
||||||
return Err(DomainError::Conflict(format!("Email {} is already registered", email.as_str())));
|
return Err(DomainError::Conflict(format!(
|
||||||
|
"Email {} is already registered",
|
||||||
|
email.as_str()
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
if self.user_repo.find_by_username(&cmd.username).await?.is_some() {
|
if self
|
||||||
return Err(DomainError::Conflict(format!("Username {} is already taken", cmd.username)));
|
.user_repo
|
||||||
|
.find_by_username(&cmd.username)
|
||||||
|
.await?
|
||||||
|
.is_some()
|
||||||
|
{
|
||||||
|
return Err(DomainError::Conflict(format!(
|
||||||
|
"Username {} is already taken",
|
||||||
|
cmd.username
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
let hash = self.hasher.hash(&cmd.password).await?;
|
let hash = self.hasher.hash(&cmd.password).await?;
|
||||||
let user = User::new(&cmd.username, email, hash);
|
let user = User::new(&cmd.username, email, hash);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
pub mod commands;
|
pub mod commands;
|
||||||
pub mod queries;
|
pub mod queries;
|
||||||
|
|
||||||
pub use commands::{RegisterUserCommand, RegisterUserHandler, LoginUserCommand, LoginUserHandler};
|
pub use commands::{LoginUserCommand, LoginUserHandler, RegisterUserCommand, RegisterUserHandler};
|
||||||
pub use queries::{GetProfileQuery, GetProfileHandler};
|
pub use queries::{GetProfileHandler, GetProfileQuery};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use domain::{entities::User, errors::DomainError, ports::UserRepository, value_objects::SystemId};
|
use domain::{entities::User, errors::DomainError, ports::UserRepository, value_objects::SystemId};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct GetProfileQuery {
|
pub struct GetProfileQuery {
|
||||||
@@ -16,7 +16,9 @@ impl GetProfileHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute(&self, query: GetProfileQuery) -> Result<User, DomainError> {
|
pub async fn execute(&self, query: GetProfileQuery) -> Result<User, DomainError> {
|
||||||
self.repo.find_by_id(&query.user_id).await?
|
self.repo
|
||||||
|
.find_by_id(&query.user_id)
|
||||||
|
.await?
|
||||||
.ok_or_else(|| DomainError::NotFound(format!("User {} not found", query.user_id)))
|
.ok_or_else(|| DomainError::NotFound(format!("User {} not found", query.user_id)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
pub mod get_profile;
|
pub mod get_profile;
|
||||||
|
|
||||||
pub use get_profile::{GetProfileQuery, GetProfileHandler};
|
pub use get_profile::{GetProfileHandler, GetProfileQuery};
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
|
pub mod catalog;
|
||||||
pub mod identity;
|
pub mod identity;
|
||||||
pub mod organization;
|
pub mod organization;
|
||||||
pub mod storage;
|
pub mod processing;
|
||||||
pub mod catalog;
|
|
||||||
pub mod sharing;
|
pub mod sharing;
|
||||||
pub mod sidecar;
|
pub mod sidecar;
|
||||||
pub mod processing;
|
pub mod storage;
|
||||||
pub mod testing;
|
pub mod testing;
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use domain::{
|
use domain::{
|
||||||
entities::Album,
|
entities::Album, errors::DomainError, ports::AlbumRepository, value_objects::SystemId,
|
||||||
errors::DomainError,
|
|
||||||
ports::AlbumRepository,
|
|
||||||
value_objects::SystemId,
|
|
||||||
};
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct CreateAlbumCommand {
|
pub struct CreateAlbumCommand {
|
||||||
@@ -23,7 +20,9 @@ impl CreateAlbumHandler {
|
|||||||
|
|
||||||
pub async fn execute(&self, cmd: CreateAlbumCommand) -> Result<Album, DomainError> {
|
pub async fn execute(&self, cmd: CreateAlbumCommand) -> Result<Album, DomainError> {
|
||||||
if cmd.title.is_empty() {
|
if cmd.title.is_empty() {
|
||||||
return Err(DomainError::Validation("Album title must not be empty".to_string()));
|
return Err(DomainError::Validation(
|
||||||
|
"Album title must not be empty".to_string(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
let album = Album::new(&cmd.title, cmd.creator_id);
|
let album = Album::new(&cmd.title, cmd.creator_id);
|
||||||
self.album_repo.save(&album).await?;
|
self.album_repo.save(&album).await?;
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use domain::{
|
use domain::{
|
||||||
entities::Album,
|
entities::Album, errors::DomainError, ports::AlbumRepository, value_objects::SystemId,
|
||||||
errors::DomainError,
|
|
||||||
ports::AlbumRepository,
|
|
||||||
value_objects::SystemId,
|
|
||||||
};
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum AlbumAction {
|
pub enum AlbumAction {
|
||||||
@@ -29,7 +26,10 @@ impl ManageAlbumEntriesHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute(&self, cmd: ManageAlbumEntriesCommand) -> Result<Album, DomainError> {
|
pub async fn execute(&self, cmd: ManageAlbumEntriesCommand) -> Result<Album, DomainError> {
|
||||||
let mut album = self.album_repo.find_by_id(&cmd.album_id).await?
|
let mut album = self
|
||||||
|
.album_repo
|
||||||
|
.find_by_id(&cmd.album_id)
|
||||||
|
.await?
|
||||||
.ok_or_else(|| DomainError::NotFound(format!("Album {} not found", cmd.album_id)))?;
|
.ok_or_else(|| DomainError::NotFound(format!("Album {} not found", cmd.album_id)))?;
|
||||||
|
|
||||||
match cmd.action {
|
match cmd.action {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use domain::{
|
use domain::{
|
||||||
entities::{AssetTag, Tag},
|
entities::{AssetTag, Tag},
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
ports::{AssetRepository, TagRepository},
|
ports::{AssetRepository, TagRepository},
|
||||||
value_objects::SystemId,
|
value_objects::SystemId,
|
||||||
};
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct TagAssetCommand {
|
pub struct TagAssetCommand {
|
||||||
@@ -20,11 +20,16 @@ pub struct TagAssetHandler {
|
|||||||
|
|
||||||
impl TagAssetHandler {
|
impl TagAssetHandler {
|
||||||
pub fn new(asset_repo: Arc<dyn AssetRepository>, tag_repo: Arc<dyn TagRepository>) -> Self {
|
pub fn new(asset_repo: Arc<dyn AssetRepository>, tag_repo: Arc<dyn TagRepository>) -> Self {
|
||||||
Self { asset_repo, tag_repo }
|
Self {
|
||||||
|
asset_repo,
|
||||||
|
tag_repo,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute(&self, cmd: TagAssetCommand) -> Result<(Tag, AssetTag), DomainError> {
|
pub async fn execute(&self, cmd: TagAssetCommand) -> Result<(Tag, AssetTag), 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)))?;
|
.ok_or_else(|| DomainError::NotFound(format!("Asset {} not found", cmd.asset_id)))?;
|
||||||
|
|
||||||
let tag = match self.tag_repo.find_by_name(&cmd.tag_name).await? {
|
let tag = match self.tag_repo.find_by_name(&cmd.tag_name).await? {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
pub mod commands;
|
pub mod commands;
|
||||||
pub mod queries;
|
pub mod queries;
|
||||||
|
|
||||||
pub use commands::{CreateAlbumCommand, CreateAlbumHandler};
|
|
||||||
pub use commands::{AlbumAction, ManageAlbumEntriesCommand, ManageAlbumEntriesHandler};
|
pub use commands::{AlbumAction, ManageAlbumEntriesCommand, ManageAlbumEntriesHandler};
|
||||||
|
pub use commands::{CreateAlbumCommand, CreateAlbumHandler};
|
||||||
pub use commands::{TagAssetCommand, TagAssetHandler};
|
pub use commands::{TagAssetCommand, TagAssetHandler};
|
||||||
pub use queries::get_album::{GetAlbumQuery, GetAlbumHandler};
|
pub use queries::get_album::{GetAlbumHandler, GetAlbumQuery};
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use domain::{
|
use domain::{
|
||||||
entities::Album,
|
entities::Album, errors::DomainError, ports::AlbumRepository, value_objects::SystemId,
|
||||||
errors::DomainError,
|
|
||||||
ports::AlbumRepository,
|
|
||||||
value_objects::SystemId,
|
|
||||||
};
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct GetAlbumQuery {
|
pub struct GetAlbumQuery {
|
||||||
@@ -21,7 +18,9 @@ impl GetAlbumHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute(&self, query: GetAlbumQuery) -> Result<Album, DomainError> {
|
pub async fn execute(&self, query: GetAlbumQuery) -> Result<Album, DomainError> {
|
||||||
self.album_repo.find_by_id(&query.album_id).await?
|
self.album_repo
|
||||||
|
.find_by_id(&query.album_id)
|
||||||
|
.await?
|
||||||
.ok_or_else(|| DomainError::NotFound(format!("Album {} not found", query.album_id)))
|
.ok_or_else(|| DomainError::NotFound(format!("Album {} not found", query.album_id)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use domain::{
|
use domain::{
|
||||||
entities::Job,
|
entities::Job,
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
@@ -6,6 +5,7 @@ use domain::{
|
|||||||
ports::{EventPublisher, JobBatchRepository, JobRepository},
|
ports::{EventPublisher, JobBatchRepository, JobRepository},
|
||||||
value_objects::{DateTimeStamp, StructuredData, SystemId},
|
value_objects::{DateTimeStamp, StructuredData, SystemId},
|
||||||
};
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct CompleteJobCommand {
|
pub struct CompleteJobCommand {
|
||||||
@@ -25,24 +25,35 @@ impl CompleteJobHandler {
|
|||||||
batch_repo: Arc<dyn JobBatchRepository>,
|
batch_repo: Arc<dyn JobBatchRepository>,
|
||||||
event_pub: Arc<dyn EventPublisher>,
|
event_pub: Arc<dyn EventPublisher>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { job_repo, batch_repo, event_pub }
|
Self {
|
||||||
|
job_repo,
|
||||||
|
batch_repo,
|
||||||
|
event_pub,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute(&self, cmd: CompleteJobCommand) -> Result<Job, DomainError> {
|
pub async fn execute(&self, cmd: CompleteJobCommand) -> Result<Job, DomainError> {
|
||||||
let mut job = self.job_repo.find_by_id(&cmd.job_id).await?
|
let mut job = self
|
||||||
|
.job_repo
|
||||||
|
.find_by_id(&cmd.job_id)
|
||||||
|
.await?
|
||||||
.ok_or_else(|| DomainError::NotFound(format!("Job {} not found", cmd.job_id)))?;
|
.ok_or_else(|| DomainError::NotFound(format!("Job {} not found", cmd.job_id)))?;
|
||||||
job.complete(cmd.result);
|
job.complete(cmd.result);
|
||||||
self.job_repo.save(&job).await?;
|
self.job_repo.save(&job).await?;
|
||||||
if let Some(ref batch_id) = job.batch_id {
|
if let Some(ref batch_id) = job.batch_id {
|
||||||
let mut batch = self.batch_repo.find_by_id(batch_id).await?
|
let mut batch =
|
||||||
.ok_or_else(|| DomainError::NotFound(format!("Batch {} not found", batch_id)))?;
|
self.batch_repo.find_by_id(batch_id).await?.ok_or_else(|| {
|
||||||
|
DomainError::NotFound(format!("Batch {} not found", batch_id))
|
||||||
|
})?;
|
||||||
batch.record_completion();
|
batch.record_completion();
|
||||||
self.batch_repo.save(&batch).await?;
|
self.batch_repo.save(&batch).await?;
|
||||||
}
|
}
|
||||||
self.event_pub.publish(DomainEvent::JobCompleted {
|
self.event_pub
|
||||||
|
.publish(DomainEvent::JobCompleted {
|
||||||
job_id: job.job_id,
|
job_id: job.job_id,
|
||||||
timestamp: DateTimeStamp::now(),
|
timestamp: DateTimeStamp::now(),
|
||||||
}).await?;
|
})
|
||||||
|
.await?;
|
||||||
Ok(job)
|
Ok(job)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use domain::{
|
use domain::{
|
||||||
entities::ProcessingPipeline,
|
entities::ProcessingPipeline,
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
ports::{PipelineRepository, PluginRepository},
|
ports::{PipelineRepository, PluginRepository},
|
||||||
value_objects::{StructuredData, SystemId},
|
value_objects::{StructuredData, SystemId},
|
||||||
};
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct PipelineStepConfig {
|
pub struct PipelineStepConfig {
|
||||||
@@ -28,13 +28,23 @@ impl ConfigurePipelineHandler {
|
|||||||
pipeline_repo: Arc<dyn PipelineRepository>,
|
pipeline_repo: Arc<dyn PipelineRepository>,
|
||||||
plugin_repo: Arc<dyn PluginRepository>,
|
plugin_repo: Arc<dyn PluginRepository>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { pipeline_repo, plugin_repo }
|
Self {
|
||||||
|
pipeline_repo,
|
||||||
|
plugin_repo,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute(&self, cmd: ConfigurePipelineCommand) -> Result<ProcessingPipeline, DomainError> {
|
pub async fn execute(
|
||||||
|
&self,
|
||||||
|
cmd: ConfigurePipelineCommand,
|
||||||
|
) -> Result<ProcessingPipeline, DomainError> {
|
||||||
for step in &cmd.steps {
|
for step in &cmd.steps {
|
||||||
self.plugin_repo.find_by_id(&step.plugin_id).await?
|
self.plugin_repo
|
||||||
.ok_or_else(|| DomainError::NotFound(format!("Plugin {} not found", step.plugin_id)))?;
|
.find_by_id(&step.plugin_id)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| {
|
||||||
|
DomainError::NotFound(format!("Plugin {} not found", step.plugin_id))
|
||||||
|
})?;
|
||||||
}
|
}
|
||||||
let mut pipeline = ProcessingPipeline::new(cmd.trigger_event);
|
let mut pipeline = ProcessingPipeline::new(cmd.trigger_event);
|
||||||
for step in cmd.steps {
|
for step in cmd.steps {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use domain::{
|
use domain::{
|
||||||
entities::{Job, JobType},
|
entities::{Job, JobType},
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
@@ -6,6 +5,7 @@ use domain::{
|
|||||||
ports::{EventPublisher, JobRepository},
|
ports::{EventPublisher, JobRepository},
|
||||||
value_objects::{DateTimeStamp, StructuredData, SystemId},
|
value_objects::{DateTimeStamp, StructuredData, SystemId},
|
||||||
};
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct EnqueueJobCommand {
|
pub struct EnqueueJobCommand {
|
||||||
@@ -23,7 +23,10 @@ pub struct EnqueueJobHandler {
|
|||||||
|
|
||||||
impl EnqueueJobHandler {
|
impl EnqueueJobHandler {
|
||||||
pub fn new(job_repo: Arc<dyn JobRepository>, event_pub: Arc<dyn EventPublisher>) -> Self {
|
pub fn new(job_repo: Arc<dyn JobRepository>, event_pub: Arc<dyn EventPublisher>) -> Self {
|
||||||
Self { job_repo, event_pub }
|
Self {
|
||||||
|
job_repo,
|
||||||
|
event_pub,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute(&self, cmd: EnqueueJobCommand) -> Result<Job, DomainError> {
|
pub async fn execute(&self, cmd: EnqueueJobCommand) -> Result<Job, DomainError> {
|
||||||
@@ -35,11 +38,13 @@ impl EnqueueJobHandler {
|
|||||||
job = job.with_batch(id);
|
job = job.with_batch(id);
|
||||||
}
|
}
|
||||||
self.job_repo.save(&job).await?;
|
self.job_repo.save(&job).await?;
|
||||||
self.event_pub.publish(DomainEvent::JobEnqueued {
|
self.event_pub
|
||||||
|
.publish(DomainEvent::JobEnqueued {
|
||||||
job_id: job.job_id,
|
job_id: job.job_id,
|
||||||
job_type: format!("{:?}", cmd.job_type),
|
job_type: format!("{:?}", cmd.job_type),
|
||||||
timestamp: DateTimeStamp::now(),
|
timestamp: DateTimeStamp::now(),
|
||||||
}).await?;
|
})
|
||||||
|
.await?;
|
||||||
Ok(job)
|
Ok(job)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use domain::{
|
use domain::{
|
||||||
entities::{Job, JobStatus},
|
entities::{Job, JobStatus},
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
@@ -6,6 +5,7 @@ use domain::{
|
|||||||
ports::{EventPublisher, JobBatchRepository, JobRepository},
|
ports::{EventPublisher, JobBatchRepository, JobRepository},
|
||||||
value_objects::{DateTimeStamp, SystemId},
|
value_objects::{DateTimeStamp, SystemId},
|
||||||
};
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct FailJobCommand {
|
pub struct FailJobCommand {
|
||||||
@@ -25,32 +25,44 @@ impl FailJobHandler {
|
|||||||
batch_repo: Arc<dyn JobBatchRepository>,
|
batch_repo: Arc<dyn JobBatchRepository>,
|
||||||
event_pub: Arc<dyn EventPublisher>,
|
event_pub: Arc<dyn EventPublisher>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { job_repo, batch_repo, event_pub }
|
Self {
|
||||||
|
job_repo,
|
||||||
|
batch_repo,
|
||||||
|
event_pub,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute(&self, cmd: FailJobCommand) -> Result<Job, DomainError> {
|
pub async fn execute(&self, cmd: FailJobCommand) -> Result<Job, DomainError> {
|
||||||
let mut job = self.job_repo.find_by_id(&cmd.job_id).await?
|
let mut job = self
|
||||||
|
.job_repo
|
||||||
|
.find_by_id(&cmd.job_id)
|
||||||
|
.await?
|
||||||
.ok_or_else(|| DomainError::NotFound(format!("Job {} not found", cmd.job_id)))?;
|
.ok_or_else(|| DomainError::NotFound(format!("Job {} not found", cmd.job_id)))?;
|
||||||
job.fail(&cmd.error);
|
job.fail(&cmd.error);
|
||||||
self.job_repo.save(&job).await?;
|
self.job_repo.save(&job).await?;
|
||||||
if job.status == JobStatus::Failed {
|
if job.status == JobStatus::Failed {
|
||||||
if let Some(ref batch_id) = job.batch_id {
|
if let Some(ref batch_id) = job.batch_id {
|
||||||
let mut batch = self.batch_repo.find_by_id(batch_id).await?
|
let mut batch = self.batch_repo.find_by_id(batch_id).await?.ok_or_else(|| {
|
||||||
.ok_or_else(|| DomainError::NotFound(format!("Batch {} not found", batch_id)))?;
|
DomainError::NotFound(format!("Batch {} not found", batch_id))
|
||||||
|
})?;
|
||||||
batch.record_failure();
|
batch.record_failure();
|
||||||
self.batch_repo.save(&batch).await?;
|
self.batch_repo.save(&batch).await?;
|
||||||
}
|
}
|
||||||
self.event_pub.publish(DomainEvent::JobFailed {
|
self.event_pub
|
||||||
|
.publish(DomainEvent::JobFailed {
|
||||||
job_id: job.job_id,
|
job_id: job.job_id,
|
||||||
error: cmd.error,
|
error: cmd.error,
|
||||||
timestamp: DateTimeStamp::now(),
|
timestamp: DateTimeStamp::now(),
|
||||||
}).await?;
|
})
|
||||||
|
.await?;
|
||||||
} else if job.status == JobStatus::Queued {
|
} else if job.status == JobStatus::Queued {
|
||||||
self.event_pub.publish(DomainEvent::JobEnqueued {
|
self.event_pub
|
||||||
|
.publish(DomainEvent::JobEnqueued {
|
||||||
job_id: job.job_id,
|
job_id: job.job_id,
|
||||||
job_type: format!("{:?}", job.job_type),
|
job_type: format!("{:?}", job.job_type),
|
||||||
timestamp: DateTimeStamp::now(),
|
timestamp: DateTimeStamp::now(),
|
||||||
}).await?;
|
})
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
Ok(job)
|
Ok(job)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use domain::{
|
use domain::{
|
||||||
entities::{Plugin, PluginType},
|
entities::{Plugin, PluginType},
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
ports::PluginRepository,
|
ports::PluginRepository,
|
||||||
value_objects::{StructuredData, SystemId},
|
value_objects::{StructuredData, SystemId},
|
||||||
};
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum PluginAction {
|
pub enum PluginAction {
|
||||||
@@ -34,25 +34,37 @@ impl ManagePluginHandler {
|
|||||||
|
|
||||||
pub async fn execute(&self, cmd: ManagePluginCommand) -> Result<Plugin, DomainError> {
|
pub async fn execute(&self, cmd: ManagePluginCommand) -> Result<Plugin, DomainError> {
|
||||||
match cmd.action {
|
match cmd.action {
|
||||||
PluginAction::Create { name, plugin_type, config } => {
|
PluginAction::Create {
|
||||||
|
name,
|
||||||
|
plugin_type,
|
||||||
|
config,
|
||||||
|
} => {
|
||||||
let mut plugin = Plugin::new(name, plugin_type);
|
let mut plugin = Plugin::new(name, plugin_type);
|
||||||
plugin.configuration = config;
|
plugin.configuration = config;
|
||||||
self.plugin_repo.save(&plugin).await?;
|
self.plugin_repo.save(&plugin).await?;
|
||||||
Ok(plugin)
|
Ok(plugin)
|
||||||
}
|
}
|
||||||
PluginAction::Enable => {
|
PluginAction::Enable => {
|
||||||
let id = cmd.plugin_id
|
let id = cmd.plugin_id.ok_or_else(|| {
|
||||||
.ok_or_else(|| DomainError::Validation("plugin_id required for Enable".into()))?;
|
DomainError::Validation("plugin_id required for Enable".into())
|
||||||
let mut plugin = self.plugin_repo.find_by_id(&id).await?
|
})?;
|
||||||
|
let mut plugin = self
|
||||||
|
.plugin_repo
|
||||||
|
.find_by_id(&id)
|
||||||
|
.await?
|
||||||
.ok_or_else(|| DomainError::NotFound(format!("Plugin {} not found", id)))?;
|
.ok_or_else(|| DomainError::NotFound(format!("Plugin {} not found", id)))?;
|
||||||
plugin.enable();
|
plugin.enable();
|
||||||
self.plugin_repo.save(&plugin).await?;
|
self.plugin_repo.save(&plugin).await?;
|
||||||
Ok(plugin)
|
Ok(plugin)
|
||||||
}
|
}
|
||||||
PluginAction::Disable => {
|
PluginAction::Disable => {
|
||||||
let id = cmd.plugin_id
|
let id = cmd.plugin_id.ok_or_else(|| {
|
||||||
.ok_or_else(|| DomainError::Validation("plugin_id required for Disable".into()))?;
|
DomainError::Validation("plugin_id required for Disable".into())
|
||||||
let mut plugin = self.plugin_repo.find_by_id(&id).await?
|
})?;
|
||||||
|
let mut plugin = self
|
||||||
|
.plugin_repo
|
||||||
|
.find_by_id(&id)
|
||||||
|
.await?
|
||||||
.ok_or_else(|| DomainError::NotFound(format!("Plugin {} not found", id)))?;
|
.ok_or_else(|| DomainError::NotFound(format!("Plugin {} not found", id)))?;
|
||||||
plugin.disable();
|
plugin.disable();
|
||||||
self.plugin_repo.save(&plugin).await?;
|
self.plugin_repo.save(&plugin).await?;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
pub mod enqueue_job;
|
|
||||||
pub mod start_job;
|
|
||||||
pub mod complete_job;
|
pub mod complete_job;
|
||||||
|
pub mod configure_pipeline;
|
||||||
|
pub mod enqueue_job;
|
||||||
pub mod fail_job;
|
pub mod fail_job;
|
||||||
pub mod manage_plugin;
|
pub mod manage_plugin;
|
||||||
pub mod configure_pipeline;
|
pub mod start_job;
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
|
use domain::{entities::Job, errors::DomainError, ports::JobRepository, value_objects::SystemId};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use domain::{
|
|
||||||
entities::Job,
|
|
||||||
errors::DomainError,
|
|
||||||
ports::JobRepository,
|
|
||||||
value_objects::SystemId,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct StartJobCommand {
|
pub struct StartJobCommand {
|
||||||
@@ -21,7 +16,10 @@ impl StartJobHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute(&self, cmd: StartJobCommand) -> Result<Job, DomainError> {
|
pub async fn execute(&self, cmd: StartJobCommand) -> Result<Job, DomainError> {
|
||||||
let mut job = self.job_repo.find_by_id(&cmd.job_id).await?
|
let mut job = self
|
||||||
|
.job_repo
|
||||||
|
.find_by_id(&cmd.job_id)
|
||||||
|
.await?
|
||||||
.ok_or_else(|| DomainError::NotFound(format!("Job {} not found", cmd.job_id)))?;
|
.ok_or_else(|| DomainError::NotFound(format!("Job {} not found", cmd.job_id)))?;
|
||||||
job.start()?;
|
job.start()?;
|
||||||
self.job_repo.save(&job).await?;
|
self.job_repo.save(&job).await?;
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
pub mod commands;
|
pub mod commands;
|
||||||
pub mod queries;
|
pub mod queries;
|
||||||
|
|
||||||
pub use commands::enqueue_job::{EnqueueJobCommand, EnqueueJobHandler};
|
|
||||||
pub use commands::start_job::{StartJobCommand, StartJobHandler};
|
|
||||||
pub use commands::complete_job::{CompleteJobCommand, CompleteJobHandler};
|
pub use commands::complete_job::{CompleteJobCommand, CompleteJobHandler};
|
||||||
|
pub use commands::configure_pipeline::{
|
||||||
|
ConfigurePipelineCommand, ConfigurePipelineHandler, PipelineStepConfig,
|
||||||
|
};
|
||||||
|
pub use commands::enqueue_job::{EnqueueJobCommand, EnqueueJobHandler};
|
||||||
pub use commands::fail_job::{FailJobCommand, FailJobHandler};
|
pub use commands::fail_job::{FailJobCommand, FailJobHandler};
|
||||||
pub use commands::manage_plugin::{ManagePluginCommand, ManagePluginHandler, PluginAction};
|
pub use commands::manage_plugin::{ManagePluginCommand, ManagePluginHandler, PluginAction};
|
||||||
pub use commands::configure_pipeline::{ConfigurePipelineCommand, ConfigurePipelineHandler, PipelineStepConfig};
|
pub use commands::start_job::{StartJobCommand, StartJobHandler};
|
||||||
pub use queries::report_batch_progress::{ReportBatchProgressQuery, ReportBatchProgressHandler, BatchProgress};
|
pub use queries::report_batch_progress::{
|
||||||
|
BatchProgress, ReportBatchProgressHandler, ReportBatchProgressQuery,
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use domain::{
|
use domain::{
|
||||||
entities::{Job, JobBatch},
|
entities::{Job, JobBatch},
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
ports::{JobBatchRepository, JobRepository},
|
ports::{JobBatchRepository, JobRepository},
|
||||||
value_objects::SystemId,
|
value_objects::SystemId,
|
||||||
};
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct ReportBatchProgressQuery {
|
pub struct ReportBatchProgressQuery {
|
||||||
@@ -24,11 +24,20 @@ pub struct ReportBatchProgressHandler {
|
|||||||
|
|
||||||
impl ReportBatchProgressHandler {
|
impl ReportBatchProgressHandler {
|
||||||
pub fn new(batch_repo: Arc<dyn JobBatchRepository>, job_repo: Arc<dyn JobRepository>) -> Self {
|
pub fn new(batch_repo: Arc<dyn JobBatchRepository>, job_repo: Arc<dyn JobRepository>) -> Self {
|
||||||
Self { batch_repo, job_repo }
|
Self {
|
||||||
|
batch_repo,
|
||||||
|
job_repo,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute(&self, query: ReportBatchProgressQuery) -> Result<BatchProgress, DomainError> {
|
pub async fn execute(
|
||||||
let batch = self.batch_repo.find_by_id(&query.batch_id).await?
|
&self,
|
||||||
|
query: ReportBatchProgressQuery,
|
||||||
|
) -> Result<BatchProgress, DomainError> {
|
||||||
|
let batch = self
|
||||||
|
.batch_repo
|
||||||
|
.find_by_id(&query.batch_id)
|
||||||
|
.await?
|
||||||
.ok_or_else(|| DomainError::NotFound(format!("Batch {} not found", query.batch_id)))?;
|
.ok_or_else(|| DomainError::NotFound(format!("Batch {} not found", query.batch_id)))?;
|
||||||
let jobs = self.job_repo.find_by_batch(&query.batch_id).await?;
|
let jobs = self.job_repo.find_by_batch(&query.batch_id).await?;
|
||||||
Ok(BatchProgress { batch, jobs })
|
Ok(BatchProgress { batch, jobs })
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use domain::{
|
use domain::{
|
||||||
entities::{LinkAccessLevel, ScopeType, ShareLink, ShareScope, ShareableType},
|
entities::{LinkAccessLevel, ScopeType, ShareLink, ShareScope, ShareableType},
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
ports::ShareRepository,
|
ports::ShareRepository,
|
||||||
value_objects::{DateTimeStamp, SystemId},
|
value_objects::{DateTimeStamp, SystemId},
|
||||||
};
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct GenerateShareLinkCommand {
|
pub struct GenerateShareLinkCommand {
|
||||||
@@ -25,8 +25,16 @@ impl GenerateShareLinkHandler {
|
|||||||
Self { share_repo }
|
Self { share_repo }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute(&self, cmd: GenerateShareLinkCommand) -> Result<(ShareScope, ShareLink), DomainError> {
|
pub async fn execute(
|
||||||
let scope = ShareScope::new(ScopeType::Link, cmd.shareable_type, cmd.shareable_id, cmd.created_by);
|
&self,
|
||||||
|
cmd: GenerateShareLinkCommand,
|
||||||
|
) -> Result<(ShareScope, ShareLink), DomainError> {
|
||||||
|
let scope = ShareScope::new(
|
||||||
|
ScopeType::Link,
|
||||||
|
cmd.shareable_type,
|
||||||
|
cmd.shareable_id,
|
||||||
|
cmd.created_by,
|
||||||
|
);
|
||||||
let token = uuid::Uuid::new_v4().to_string();
|
let token = uuid::Uuid::new_v4().to_string();
|
||||||
let mut link = ShareLink::new(scope.scope_id, token, cmd.access_level);
|
let mut link = ShareLink::new(scope.scope_id, token, cmd.access_level);
|
||||||
link.expires_at = cmd.expires_at;
|
link.expires_at = cmd.expires_at;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
pub mod share_resource;
|
|
||||||
pub mod generate_share_link;
|
pub mod generate_share_link;
|
||||||
pub mod revoke_share;
|
pub mod revoke_share;
|
||||||
|
pub mod share_resource;
|
||||||
|
|
||||||
pub use share_resource::{ShareResourceCommand, ShareResourceHandler};
|
|
||||||
pub use generate_share_link::{GenerateShareLinkCommand, GenerateShareLinkHandler};
|
pub use generate_share_link::{GenerateShareLinkCommand, GenerateShareLinkHandler};
|
||||||
pub use revoke_share::{RevokeShareCommand, RevokeShareHandler};
|
pub use revoke_share::{RevokeShareCommand, RevokeShareHandler};
|
||||||
|
pub use share_resource::{ShareResourceCommand, ShareResourceHandler};
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use domain::{
|
use domain::{
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
events::DomainEvent,
|
events::DomainEvent,
|
||||||
ports::{EventPublisher, ShareRepository},
|
ports::{EventPublisher, ShareRepository},
|
||||||
value_objects::{DateTimeStamp, SystemId},
|
value_objects::{DateTimeStamp, SystemId},
|
||||||
};
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct RevokeShareCommand {
|
pub struct RevokeShareCommand {
|
||||||
@@ -19,20 +19,29 @@ pub struct RevokeShareHandler {
|
|||||||
|
|
||||||
impl RevokeShareHandler {
|
impl RevokeShareHandler {
|
||||||
pub fn new(share_repo: Arc<dyn ShareRepository>, event_pub: Arc<dyn EventPublisher>) -> Self {
|
pub fn new(share_repo: Arc<dyn ShareRepository>, event_pub: Arc<dyn EventPublisher>) -> Self {
|
||||||
Self { share_repo, event_pub }
|
Self {
|
||||||
|
share_repo,
|
||||||
|
event_pub,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute(&self, cmd: RevokeShareCommand) -> Result<(), DomainError> {
|
pub async fn execute(&self, cmd: RevokeShareCommand) -> Result<(), DomainError> {
|
||||||
self.share_repo.find_scope_by_id(&cmd.scope_id).await?
|
self.share_repo
|
||||||
.ok_or_else(|| DomainError::NotFound(format!("Share scope {} not found", cmd.scope_id)))?;
|
.find_scope_by_id(&cmd.scope_id)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| {
|
||||||
|
DomainError::NotFound(format!("Share scope {} not found", cmd.scope_id))
|
||||||
|
})?;
|
||||||
|
|
||||||
self.share_repo.delete_scope(&cmd.scope_id).await?;
|
self.share_repo.delete_scope(&cmd.scope_id).await?;
|
||||||
|
|
||||||
self.event_pub.publish(DomainEvent::ShareRevoked {
|
self.event_pub
|
||||||
|
.publish(DomainEvent::ShareRevoked {
|
||||||
scope_id: cmd.scope_id,
|
scope_id: cmd.scope_id,
|
||||||
revoked_by: cmd.revoked_by,
|
revoked_by: cmd.revoked_by,
|
||||||
timestamp: DateTimeStamp::now(),
|
timestamp: DateTimeStamp::now(),
|
||||||
}).await?;
|
})
|
||||||
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use domain::{
|
use domain::{
|
||||||
entities::{ScopeType, ShareScope, ShareTarget, ShareableType, TargetType},
|
entities::{ScopeType, ShareScope, ShareTarget, ShareableType, TargetType},
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
@@ -6,6 +5,7 @@ use domain::{
|
|||||||
ports::{EventPublisher, ShareRepository},
|
ports::{EventPublisher, ShareRepository},
|
||||||
value_objects::{DateTimeStamp, SystemId},
|
value_objects::{DateTimeStamp, SystemId},
|
||||||
};
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct ShareResourceCommand {
|
pub struct ShareResourceCommand {
|
||||||
@@ -24,27 +24,40 @@ pub struct ShareResourceHandler {
|
|||||||
|
|
||||||
impl ShareResourceHandler {
|
impl ShareResourceHandler {
|
||||||
pub fn new(share_repo: Arc<dyn ShareRepository>, event_pub: Arc<dyn EventPublisher>) -> Self {
|
pub fn new(share_repo: Arc<dyn ShareRepository>, event_pub: Arc<dyn EventPublisher>) -> Self {
|
||||||
Self { share_repo, event_pub }
|
Self {
|
||||||
|
share_repo,
|
||||||
|
event_pub,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute(&self, cmd: ShareResourceCommand) -> Result<(ShareScope, ShareTarget), DomainError> {
|
pub async fn execute(
|
||||||
|
&self,
|
||||||
|
cmd: ShareResourceCommand,
|
||||||
|
) -> Result<(ShareScope, ShareTarget), DomainError> {
|
||||||
let scope_type = match cmd.target_type {
|
let scope_type = match cmd.target_type {
|
||||||
TargetType::User => ScopeType::User,
|
TargetType::User => ScopeType::User,
|
||||||
TargetType::Group => ScopeType::Group,
|
TargetType::Group => ScopeType::Group,
|
||||||
};
|
};
|
||||||
|
|
||||||
let scope = ShareScope::new(scope_type, cmd.shareable_type, cmd.shareable_id, cmd.created_by);
|
let scope = ShareScope::new(
|
||||||
|
scope_type,
|
||||||
|
cmd.shareable_type,
|
||||||
|
cmd.shareable_id,
|
||||||
|
cmd.created_by,
|
||||||
|
);
|
||||||
let target = ShareTarget::new(scope.scope_id, cmd.target_type, cmd.target_id, cmd.role_id);
|
let target = ShareTarget::new(scope.scope_id, cmd.target_type, cmd.target_id, cmd.role_id);
|
||||||
|
|
||||||
self.share_repo.save_scope(&scope).await?;
|
self.share_repo.save_scope(&scope).await?;
|
||||||
self.share_repo.save_target(&target).await?;
|
self.share_repo.save_target(&target).await?;
|
||||||
|
|
||||||
self.event_pub.publish(DomainEvent::ShareCreated {
|
self.event_pub
|
||||||
|
.publish(DomainEvent::ShareCreated {
|
||||||
scope_id: scope.scope_id,
|
scope_id: scope.scope_id,
|
||||||
shareable_id: cmd.shareable_id,
|
shareable_id: cmd.shareable_id,
|
||||||
created_by: cmd.created_by,
|
created_by: cmd.created_by,
|
||||||
timestamp: DateTimeStamp::now(),
|
timestamp: DateTimeStamp::now(),
|
||||||
}).await?;
|
})
|
||||||
|
.await?;
|
||||||
|
|
||||||
Ok((scope, target))
|
Ok((scope, target))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
pub mod commands;
|
pub mod commands;
|
||||||
pub mod queries;
|
pub mod queries;
|
||||||
|
|
||||||
pub use commands::{ShareResourceCommand, ShareResourceHandler};
|
|
||||||
pub use commands::{GenerateShareLinkCommand, GenerateShareLinkHandler};
|
pub use commands::{GenerateShareLinkCommand, GenerateShareLinkHandler};
|
||||||
pub use commands::{RevokeShareCommand, RevokeShareHandler};
|
pub use commands::{RevokeShareCommand, RevokeShareHandler};
|
||||||
pub use queries::access_shared_resource::{AccessSharedResourceQuery, AccessSharedResourceHandler};
|
pub use commands::{ShareResourceCommand, ShareResourceHandler};
|
||||||
|
pub use queries::access_shared_resource::{AccessSharedResourceHandler, AccessSharedResourceQuery};
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use domain::{
|
use domain::{
|
||||||
entities::{LinkAccessLevel, ShareScope},
|
entities::{LinkAccessLevel, ShareScope},
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
ports::ShareRepository,
|
ports::ShareRepository,
|
||||||
};
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct AccessSharedResourceQuery {
|
pub struct AccessSharedResourceQuery {
|
||||||
@@ -19,18 +19,29 @@ impl AccessSharedResourceHandler {
|
|||||||
Self { share_repo }
|
Self { share_repo }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute(&self, query: AccessSharedResourceQuery) -> Result<(ShareScope, LinkAccessLevel), DomainError> {
|
pub async fn execute(
|
||||||
let mut link = self.share_repo.find_link_by_token(&query.token).await?
|
&self,
|
||||||
|
query: AccessSharedResourceQuery,
|
||||||
|
) -> Result<(ShareScope, LinkAccessLevel), DomainError> {
|
||||||
|
let mut link = self
|
||||||
|
.share_repo
|
||||||
|
.find_link_by_token(&query.token)
|
||||||
|
.await?
|
||||||
.ok_or_else(|| DomainError::NotFound("Share link not found".to_string()))?;
|
.ok_or_else(|| DomainError::NotFound("Share link not found".to_string()))?;
|
||||||
|
|
||||||
if !link.is_valid() {
|
if !link.is_valid() {
|
||||||
return Err(DomainError::Forbidden("Link expired or exhausted".to_string()));
|
return Err(DomainError::Forbidden(
|
||||||
|
"Link expired or exhausted".to_string(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
link.record_use();
|
link.record_use();
|
||||||
self.share_repo.save_link(&link).await?;
|
self.share_repo.save_link(&link).await?;
|
||||||
|
|
||||||
let scope = self.share_repo.find_scope_by_id(&link.scope_id).await?
|
let scope = self
|
||||||
|
.share_repo
|
||||||
|
.find_scope_by_id(&link.scope_id)
|
||||||
|
.await?
|
||||||
.ok_or_else(|| DomainError::NotFound("Share scope not found".to_string()))?;
|
.ok_or_else(|| DomainError::NotFound("Share scope not found".to_string()))?;
|
||||||
|
|
||||||
Ok((scope, link.access_level))
|
Ok((scope, link.access_level))
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::sync::Arc;
|
use crate::sidecar::hash_helper::hash_structured_data;
|
||||||
use domain::{
|
use domain::{
|
||||||
entities::SyncStatus,
|
entities::SyncStatus,
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
ports::{SidecarRepository, SidecarWriterPort},
|
ports::{SidecarRepository, SidecarWriterPort},
|
||||||
};
|
};
|
||||||
use crate::sidecar::hash_helper::hash_structured_data;
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct DetectExternalChangesCommand;
|
pub struct DetectExternalChangesCommand;
|
||||||
@@ -19,7 +19,10 @@ impl DetectExternalChangesHandler {
|
|||||||
sidecar_repo: Arc<dyn SidecarRepository>,
|
sidecar_repo: Arc<dyn SidecarRepository>,
|
||||||
writer: Arc<dyn SidecarWriterPort>,
|
writer: Arc<dyn SidecarWriterPort>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { sidecar_repo, writer }
|
Self {
|
||||||
|
sidecar_repo,
|
||||||
|
writer,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute(&self, _cmd: DetectExternalChangesCommand) -> Result<u32, DomainError> {
|
pub async fn execute(&self, _cmd: DetectExternalChangesCommand) -> Result<u32, DomainError> {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use std::sync::Arc;
|
use crate::sidecar::hash_helper::hash_structured_data;
|
||||||
use domain::{
|
use domain::{
|
||||||
catalog::services::resolve_metadata,
|
catalog::services::resolve_metadata,
|
||||||
entities::SidecarRecord,
|
entities::SidecarRecord,
|
||||||
@@ -6,7 +6,7 @@ use domain::{
|
|||||||
ports::{AssetMetadataRepository, SidecarRepository, SidecarWriterPort},
|
ports::{AssetMetadataRepository, SidecarRepository, SidecarWriterPort},
|
||||||
value_objects::SystemId,
|
value_objects::SystemId,
|
||||||
};
|
};
|
||||||
use crate::sidecar::hash_helper::hash_structured_data;
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct ExportSidecarCommand {
|
pub struct ExportSidecarCommand {
|
||||||
@@ -25,7 +25,11 @@ impl ExportSidecarHandler {
|
|||||||
sidecar_repo: Arc<dyn SidecarRepository>,
|
sidecar_repo: Arc<dyn SidecarRepository>,
|
||||||
writer: Arc<dyn SidecarWriterPort>,
|
writer: Arc<dyn SidecarWriterPort>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { metadata_repo, sidecar_repo, writer }
|
Self {
|
||||||
|
metadata_repo,
|
||||||
|
sidecar_repo,
|
||||||
|
writer,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute(&self, cmd: ExportSidecarCommand) -> Result<SidecarRecord, DomainError> {
|
pub async fn execute(&self, cmd: ExportSidecarCommand) -> Result<SidecarRecord, DomainError> {
|
||||||
@@ -37,7 +41,9 @@ impl ExportSidecarHandler {
|
|||||||
None => SidecarRecord::new(cmd.asset_id, format!("sidecars/{}.xmp", cmd.asset_id)),
|
None => SidecarRecord::new(cmd.asset_id, format!("sidecars/{}.xmp", cmd.asset_id)),
|
||||||
};
|
};
|
||||||
|
|
||||||
self.writer.write_sidecar(&resolved, &record.sidecar_storage_path).await?;
|
self.writer
|
||||||
|
.write_sidecar(&resolved, &record.sidecar_storage_path)
|
||||||
|
.await?;
|
||||||
|
|
||||||
let hash = hash_structured_data(&resolved);
|
let hash = hash_structured_data(&resolved);
|
||||||
record.mark_synced(hash);
|
record.mark_synced(hash);
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
use std::sync::Arc;
|
use crate::sidecar::hash_helper::hash_structured_data;
|
||||||
use domain::{
|
use domain::{
|
||||||
catalog::services::resolve_metadata,
|
catalog::services::resolve_metadata,
|
||||||
entities::SidecarRecord,
|
entities::SidecarRecord,
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
ports::{AssetRepository, AssetMetadataRepository, SidecarRepository, SidecarWriterPort},
|
ports::{AssetMetadataRepository, AssetRepository, SidecarRepository, SidecarWriterPort},
|
||||||
value_objects::SystemId,
|
value_objects::SystemId,
|
||||||
};
|
};
|
||||||
use crate::sidecar::hash_helper::hash_structured_data;
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct FullExportCommand {
|
pub struct FullExportCommand {
|
||||||
@@ -27,11 +27,19 @@ impl FullExportHandler {
|
|||||||
sidecar_repo: Arc<dyn SidecarRepository>,
|
sidecar_repo: Arc<dyn SidecarRepository>,
|
||||||
writer: Arc<dyn SidecarWriterPort>,
|
writer: Arc<dyn SidecarWriterPort>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { asset_repo, metadata_repo, sidecar_repo, writer }
|
Self {
|
||||||
|
asset_repo,
|
||||||
|
metadata_repo,
|
||||||
|
sidecar_repo,
|
||||||
|
writer,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute(&self, cmd: FullExportCommand) -> Result<u32, DomainError> {
|
pub async fn execute(&self, cmd: FullExportCommand) -> Result<u32, DomainError> {
|
||||||
let assets = self.asset_repo.find_by_owner(&cmd.owner_id, u32::MAX, 0).await?;
|
let assets = self
|
||||||
|
.asset_repo
|
||||||
|
.find_by_owner(&cmd.owner_id, u32::MAX, 0)
|
||||||
|
.await?;
|
||||||
let mut count = 0u32;
|
let mut count = 0u32;
|
||||||
|
|
||||||
for asset in &assets {
|
for asset in &assets {
|
||||||
@@ -40,10 +48,14 @@ impl FullExportHandler {
|
|||||||
|
|
||||||
let mut record = match self.sidecar_repo.find_by_asset(&asset.asset_id).await? {
|
let mut record = match self.sidecar_repo.find_by_asset(&asset.asset_id).await? {
|
||||||
Some(r) => r,
|
Some(r) => r,
|
||||||
None => SidecarRecord::new(asset.asset_id, format!("sidecars/{}.xmp", asset.asset_id)),
|
None => {
|
||||||
|
SidecarRecord::new(asset.asset_id, format!("sidecars/{}.xmp", asset.asset_id))
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
self.writer.write_sidecar(&resolved, &record.sidecar_storage_path).await?;
|
self.writer
|
||||||
|
.write_sidecar(&resolved, &record.sidecar_storage_path)
|
||||||
|
.await?;
|
||||||
let hash = hash_structured_data(&resolved);
|
let hash = hash_structured_data(&resolved);
|
||||||
record.mark_synced(hash);
|
record.mark_synced(hash);
|
||||||
self.sidecar_repo.save(&record).await?;
|
self.sidecar_repo.save(&record).await?;
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
use std::sync::Arc;
|
use crate::sidecar::hash_helper::hash_structured_data;
|
||||||
use domain::{
|
use domain::{
|
||||||
catalog::entities::{AssetMetadata, MetadataSource},
|
catalog::entities::{AssetMetadata, MetadataSource},
|
||||||
entities::SidecarRecord,
|
entities::SidecarRecord,
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
ports::{AssetRepository, AssetMetadataRepository, SidecarRepository, SidecarWriterPort},
|
ports::{AssetMetadataRepository, AssetRepository, SidecarRepository, SidecarWriterPort},
|
||||||
value_objects::SystemId,
|
value_objects::SystemId,
|
||||||
};
|
};
|
||||||
use crate::sidecar::hash_helper::hash_structured_data;
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct FullImportCommand {
|
pub struct FullImportCommand {
|
||||||
@@ -27,11 +27,19 @@ impl FullImportHandler {
|
|||||||
sidecar_repo: Arc<dyn SidecarRepository>,
|
sidecar_repo: Arc<dyn SidecarRepository>,
|
||||||
writer: Arc<dyn SidecarWriterPort>,
|
writer: Arc<dyn SidecarWriterPort>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { asset_repo, metadata_repo, sidecar_repo, writer }
|
Self {
|
||||||
|
asset_repo,
|
||||||
|
metadata_repo,
|
||||||
|
sidecar_repo,
|
||||||
|
writer,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute(&self, cmd: FullImportCommand) -> Result<u32, DomainError> {
|
pub async fn execute(&self, cmd: FullImportCommand) -> Result<u32, DomainError> {
|
||||||
let assets = self.asset_repo.find_by_owner(&cmd.owner_id, u32::MAX, 0).await?;
|
let assets = self
|
||||||
|
.asset_repo
|
||||||
|
.find_by_owner(&cmd.owner_id, u32::MAX, 0)
|
||||||
|
.await?;
|
||||||
let mut count = 0u32;
|
let mut count = 0u32;
|
||||||
|
|
||||||
for asset in &assets {
|
for asset in &assets {
|
||||||
@@ -45,7 +53,11 @@ impl FullImportHandler {
|
|||||||
|
|
||||||
match self.writer.read_sidecar(&record.sidecar_storage_path).await {
|
match self.writer.read_sidecar(&record.sidecar_storage_path).await {
|
||||||
Ok(data) => {
|
Ok(data) => {
|
||||||
let metadata = AssetMetadata::new(asset.asset_id, MetadataSource::ExifExtracted, data.clone());
|
let metadata = AssetMetadata::new(
|
||||||
|
asset.asset_id,
|
||||||
|
MetadataSource::ExifExtracted,
|
||||||
|
data.clone(),
|
||||||
|
);
|
||||||
self.metadata_repo.save(&metadata).await?;
|
self.metadata_repo.save(&metadata).await?;
|
||||||
let hash = hash_structured_data(&data);
|
let hash = hash_structured_data(&data);
|
||||||
let mut record = record;
|
let mut record = record;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use std::sync::Arc;
|
use crate::sidecar::hash_helper::hash_structured_data;
|
||||||
use domain::{
|
use domain::{
|
||||||
catalog::entities::{AssetMetadata, MetadataSource},
|
catalog::entities::{AssetMetadata, MetadataSource},
|
||||||
entities::SyncStatus,
|
entities::SyncStatus,
|
||||||
@@ -6,7 +6,7 @@ use domain::{
|
|||||||
ports::{AssetMetadataRepository, SidecarRepository, SidecarWriterPort},
|
ports::{AssetMetadataRepository, SidecarRepository, SidecarWriterPort},
|
||||||
value_objects::SystemId,
|
value_objects::SystemId,
|
||||||
};
|
};
|
||||||
use crate::sidecar::hash_helper::hash_structured_data;
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct ImportSidecarCommand {
|
pub struct ImportSidecarCommand {
|
||||||
@@ -25,21 +25,35 @@ impl ImportSidecarHandler {
|
|||||||
writer: Arc<dyn SidecarWriterPort>,
|
writer: Arc<dyn SidecarWriterPort>,
|
||||||
metadata_repo: Arc<dyn AssetMetadataRepository>,
|
metadata_repo: Arc<dyn AssetMetadataRepository>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { sidecar_repo, writer, metadata_repo }
|
Self {
|
||||||
|
sidecar_repo,
|
||||||
|
writer,
|
||||||
|
metadata_repo,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute(&self, cmd: ImportSidecarCommand) -> Result<AssetMetadata, DomainError> {
|
pub async fn execute(&self, cmd: ImportSidecarCommand) -> Result<AssetMetadata, DomainError> {
|
||||||
let mut record = self.sidecar_repo.find_by_asset(&cmd.asset_id).await?
|
let mut record = self
|
||||||
.ok_or_else(|| DomainError::NotFound(format!("Sidecar record for {} not found", cmd.asset_id)))?;
|
.sidecar_repo
|
||||||
|
.find_by_asset(&cmd.asset_id)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| {
|
||||||
|
DomainError::NotFound(format!("Sidecar record for {} not found", cmd.asset_id))
|
||||||
|
})?;
|
||||||
|
|
||||||
if record.sync_status != SyncStatus::PendingRead {
|
if record.sync_status != SyncStatus::PendingRead {
|
||||||
return Err(DomainError::Validation(
|
return Err(DomainError::Validation(format!(
|
||||||
format!("Sidecar is not pending read (status: {:?})", record.sync_status),
|
"Sidecar is not pending read (status: {:?})",
|
||||||
));
|
record.sync_status
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
let data = self.writer.read_sidecar(&record.sidecar_storage_path).await?;
|
let data = self
|
||||||
let metadata = AssetMetadata::new(cmd.asset_id, MetadataSource::ExifExtracted, data.clone());
|
.writer
|
||||||
|
.read_sidecar(&record.sidecar_storage_path)
|
||||||
|
.await?;
|
||||||
|
let metadata =
|
||||||
|
AssetMetadata::new(cmd.asset_id, MetadataSource::ExifExtracted, data.clone());
|
||||||
self.metadata_repo.save(&metadata).await?;
|
self.metadata_repo.save(&metadata).await?;
|
||||||
|
|
||||||
let hash = hash_structured_data(&data);
|
let hash = hash_structured_data(&data);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
pub mod export_sidecar;
|
|
||||||
pub mod detect_external_changes;
|
pub mod detect_external_changes;
|
||||||
pub mod import_sidecar;
|
pub mod export_sidecar;
|
||||||
pub mod resolve_conflict;
|
|
||||||
pub mod full_export;
|
pub mod full_export;
|
||||||
pub mod full_import;
|
pub mod full_import;
|
||||||
|
pub mod import_sidecar;
|
||||||
|
pub mod resolve_conflict;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use std::sync::Arc;
|
use crate::sidecar::hash_helper::hash_structured_data;
|
||||||
use domain::{
|
use domain::{
|
||||||
catalog::entities::{AssetMetadata, MetadataSource},
|
catalog::entities::{AssetMetadata, MetadataSource},
|
||||||
catalog::services::resolve_metadata,
|
catalog::services::resolve_metadata,
|
||||||
@@ -7,7 +7,7 @@ use domain::{
|
|||||||
ports::{AssetMetadataRepository, SidecarRepository, SidecarWriterPort},
|
ports::{AssetMetadataRepository, SidecarRepository, SidecarWriterPort},
|
||||||
value_objects::SystemId,
|
value_objects::SystemId,
|
||||||
};
|
};
|
||||||
use crate::sidecar::hash_helper::hash_structured_data;
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct ResolveConflictCommand {
|
pub struct ResolveConflictCommand {
|
||||||
@@ -27,36 +27,54 @@ impl ResolveConflictHandler {
|
|||||||
writer: Arc<dyn SidecarWriterPort>,
|
writer: Arc<dyn SidecarWriterPort>,
|
||||||
metadata_repo: Arc<dyn AssetMetadataRepository>,
|
metadata_repo: Arc<dyn AssetMetadataRepository>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { sidecar_repo, writer, metadata_repo }
|
Self {
|
||||||
|
sidecar_repo,
|
||||||
|
writer,
|
||||||
|
metadata_repo,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute(&self, cmd: ResolveConflictCommand) -> Result<SidecarRecord, DomainError> {
|
pub async fn execute(&self, cmd: ResolveConflictCommand) -> Result<SidecarRecord, DomainError> {
|
||||||
let mut record = self.sidecar_repo.find_by_asset(&cmd.asset_id).await?
|
let mut record = self
|
||||||
.ok_or_else(|| DomainError::NotFound(format!("Sidecar record for {} not found", cmd.asset_id)))?;
|
.sidecar_repo
|
||||||
|
.find_by_asset(&cmd.asset_id)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| {
|
||||||
|
DomainError::NotFound(format!("Sidecar record for {} not found", cmd.asset_id))
|
||||||
|
})?;
|
||||||
|
|
||||||
if record.sync_status != SyncStatus::Conflict {
|
if record.sync_status != SyncStatus::Conflict {
|
||||||
return Err(DomainError::Validation(
|
return Err(DomainError::Validation(format!(
|
||||||
format!("Sidecar is not in conflict (status: {:?})", record.sync_status),
|
"Sidecar is not in conflict (status: {:?})",
|
||||||
));
|
record.sync_status
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
match cmd.policy {
|
match cmd.policy {
|
||||||
ConflictPolicy::DbWins => {
|
ConflictPolicy::DbWins => {
|
||||||
let layers = self.metadata_repo.find_by_asset(&cmd.asset_id).await?;
|
let layers = self.metadata_repo.find_by_asset(&cmd.asset_id).await?;
|
||||||
let resolved = resolve_metadata(&layers);
|
let resolved = resolve_metadata(&layers);
|
||||||
self.writer.write_sidecar(&resolved, &record.sidecar_storage_path).await?;
|
self.writer
|
||||||
|
.write_sidecar(&resolved, &record.sidecar_storage_path)
|
||||||
|
.await?;
|
||||||
let hash = hash_structured_data(&resolved);
|
let hash = hash_structured_data(&resolved);
|
||||||
record.mark_synced(hash);
|
record.mark_synced(hash);
|
||||||
}
|
}
|
||||||
ConflictPolicy::FileWins => {
|
ConflictPolicy::FileWins => {
|
||||||
let data = self.writer.read_sidecar(&record.sidecar_storage_path).await?;
|
let data = self
|
||||||
let metadata = AssetMetadata::new(cmd.asset_id, MetadataSource::ExifExtracted, data.clone());
|
.writer
|
||||||
|
.read_sidecar(&record.sidecar_storage_path)
|
||||||
|
.await?;
|
||||||
|
let metadata =
|
||||||
|
AssetMetadata::new(cmd.asset_id, MetadataSource::ExifExtracted, data.clone());
|
||||||
self.metadata_repo.save(&metadata).await?;
|
self.metadata_repo.save(&metadata).await?;
|
||||||
let hash = hash_structured_data(&data);
|
let hash = hash_structured_data(&data);
|
||||||
record.mark_synced(hash);
|
record.mark_synced(hash);
|
||||||
}
|
}
|
||||||
ConflictPolicy::RequireUserDecision => {
|
ConflictPolicy::RequireUserDecision => {
|
||||||
return Err(DomainError::Validation("Manual resolution required".to_string()));
|
return Err(DomainError::Validation(
|
||||||
|
"Manual resolution required".to_string(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use domain::value_objects::{Checksum, StructuredData};
|
use domain::value_objects::{Checksum, StructuredData};
|
||||||
use sha2::{Sha256, Digest};
|
use sha2::{Digest, Sha256};
|
||||||
|
|
||||||
pub fn hash_structured_data(data: &StructuredData) -> Checksum {
|
pub fn hash_structured_data(data: &StructuredData) -> Checksum {
|
||||||
let json = serde_json::to_string(data).unwrap_or_default();
|
let json = serde_json::to_string(data).unwrap_or_default();
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
pub mod commands;
|
pub mod commands;
|
||||||
pub mod hash_helper;
|
pub mod hash_helper;
|
||||||
|
|
||||||
|
pub use commands::detect_external_changes::{
|
||||||
|
DetectExternalChangesCommand, DetectExternalChangesHandler,
|
||||||
|
};
|
||||||
pub use commands::export_sidecar::{ExportSidecarCommand, ExportSidecarHandler};
|
pub use commands::export_sidecar::{ExportSidecarCommand, ExportSidecarHandler};
|
||||||
pub use commands::detect_external_changes::{DetectExternalChangesCommand, DetectExternalChangesHandler};
|
|
||||||
pub use commands::import_sidecar::{ImportSidecarCommand, ImportSidecarHandler};
|
|
||||||
pub use commands::resolve_conflict::{ResolveConflictCommand, ResolveConflictHandler};
|
|
||||||
pub use commands::full_export::{FullExportCommand, FullExportHandler};
|
pub use commands::full_export::{FullExportCommand, FullExportHandler};
|
||||||
pub use commands::full_import::{FullImportCommand, FullImportHandler};
|
pub use commands::full_import::{FullImportCommand, FullImportHandler};
|
||||||
|
pub use commands::import_sidecar::{ImportSidecarCommand, ImportSidecarHandler};
|
||||||
|
pub use commands::resolve_conflict::{ResolveConflictCommand, ResolveConflictHandler};
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use domain::{
|
use domain::{
|
||||||
entities::{Asset, AssetType, IngestSession, IngestStatus, SourceReference, UsageLedgerEntry, UsageType},
|
entities::{
|
||||||
|
Asset, AssetType, IngestSession, IngestStatus, SourceReference, UsageLedgerEntry, UsageType,
|
||||||
|
},
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
events::DomainEvent,
|
events::DomainEvent,
|
||||||
ports::{
|
ports::{
|
||||||
AssetRepository, EventPublisher, FileStoragePort,
|
AssetRepository, EventPublisher, FileStoragePort, IngestSessionRepository,
|
||||||
IngestSessionRepository, LibraryPathRepository, QuotaRepository, UsageLedgerRepository,
|
LibraryPathRepository, QuotaRepository, UsageLedgerRepository,
|
||||||
},
|
},
|
||||||
value_objects::{Checksum, DateTimeStamp, SystemId},
|
value_objects::{Checksum, DateTimeStamp, SystemId},
|
||||||
};
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct IngestAssetCommand {
|
pub struct IngestAssetCommand {
|
||||||
@@ -43,25 +45,53 @@ impl IngestAssetHandler {
|
|||||||
file_storage: Arc<dyn FileStoragePort>,
|
file_storage: Arc<dyn FileStoragePort>,
|
||||||
event_pub: Arc<dyn EventPublisher>,
|
event_pub: Arc<dyn EventPublisher>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { ingest_repo, path_repo, quota_repo, ledger_repo, asset_repo, file_storage, event_pub }
|
Self {
|
||||||
|
ingest_repo,
|
||||||
|
path_repo,
|
||||||
|
quota_repo,
|
||||||
|
ledger_repo,
|
||||||
|
asset_repo,
|
||||||
|
file_storage,
|
||||||
|
event_pub,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute(&self, cmd: IngestAssetCommand) -> Result<(Asset, IngestSession), DomainError> {
|
pub async fn execute(
|
||||||
|
&self,
|
||||||
|
cmd: IngestAssetCommand,
|
||||||
|
) -> Result<(Asset, IngestSession), DomainError> {
|
||||||
let checksum = Checksum::new(&cmd.checksum)?;
|
let checksum = Checksum::new(&cmd.checksum)?;
|
||||||
|
|
||||||
let path = self.path_repo.find_by_id(&cmd.target_path_id).await?
|
let path = self
|
||||||
.ok_or_else(|| DomainError::NotFound(format!("Library path {} not found", cmd.target_path_id)))?;
|
.path_repo
|
||||||
|
.find_by_id(&cmd.target_path_id)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| {
|
||||||
|
DomainError::NotFound(format!("Library path {} not found", cmd.target_path_id))
|
||||||
|
})?;
|
||||||
|
|
||||||
if !path.is_ingest_destination {
|
if !path.is_ingest_destination {
|
||||||
return Err(DomainError::Validation("Target path is not an ingest destination".to_string()));
|
return Err(DomainError::Validation(
|
||||||
|
"Target path is not an ingest destination".to_string(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(quota) = self.quota_repo.find_by_owner(&cmd.uploader_id).await? {
|
if let Some(quota) = self.quota_repo.find_by_owner(&cmd.uploader_id).await? {
|
||||||
let current = self.ledger_repo.sum_usage(&cmd.uploader_id, UsageType::StorageBytes, None).await?;
|
let current = self
|
||||||
let result = domain::storage::services::check_quota("a, UsageType::StorageBytes, current, cmd.file_size);
|
.ledger_repo
|
||||||
|
.sum_usage(&cmd.uploader_id, UsageType::StorageBytes, None)
|
||||||
|
.await?;
|
||||||
|
let result = domain::storage::services::check_quota(
|
||||||
|
"a,
|
||||||
|
UsageType::StorageBytes,
|
||||||
|
current,
|
||||||
|
cmd.file_size,
|
||||||
|
);
|
||||||
if !result.allowed {
|
if !result.allowed {
|
||||||
return Err(DomainError::QuotaExceeded(format!(
|
return Err(DomainError::QuotaExceeded(format!(
|
||||||
"Storage quota exceeded: {} / {} bytes", current + cmd.file_size, result.limit
|
"Storage quota exceeded: {} / {} bytes",
|
||||||
|
current + cmd.file_size,
|
||||||
|
result.limit
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,10 +105,16 @@ impl IngestAssetHandler {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let storage_path = format!("{}/{}", path.relative_path, cmd.filename);
|
let storage_path = format!("{}/{}", path.relative_path, cmd.filename);
|
||||||
self.file_storage.store_file(&storage_path, cmd.data).await?;
|
self.file_storage
|
||||||
|
.store_file(&storage_path, cmd.data)
|
||||||
|
.await?;
|
||||||
|
|
||||||
let mime_type = mime_type_from_filename(&cmd.filename);
|
let mime_type = mime_type_from_filename(&cmd.filename);
|
||||||
let asset_type = if mime_type.starts_with("video") { AssetType::Video } else { AssetType::Image };
|
let asset_type = if mime_type.starts_with("video") {
|
||||||
|
AssetType::Video
|
||||||
|
} else {
|
||||||
|
AssetType::Image
|
||||||
|
};
|
||||||
|
|
||||||
let asset = Asset::new(
|
let asset = Asset::new(
|
||||||
SourceReference {
|
SourceReference {
|
||||||
@@ -105,11 +141,13 @@ impl IngestAssetHandler {
|
|||||||
);
|
);
|
||||||
self.ledger_repo.record(&entry).await?;
|
self.ledger_repo.record(&entry).await?;
|
||||||
|
|
||||||
self.event_pub.publish(DomainEvent::AssetIngested {
|
self.event_pub
|
||||||
|
.publish(DomainEvent::AssetIngested {
|
||||||
asset_id: asset.asset_id,
|
asset_id: asset.asset_id,
|
||||||
owner_user_id: cmd.uploader_id,
|
owner_user_id: cmd.uploader_id,
|
||||||
timestamp: DateTimeStamp::now(),
|
timestamp: DateTimeStamp::now(),
|
||||||
}).await?;
|
})
|
||||||
|
.await?;
|
||||||
|
|
||||||
Ok((asset, session))
|
Ok((asset, session))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
pub mod register_volume;
|
|
||||||
pub mod register_library_path;
|
|
||||||
pub mod ingest_asset;
|
pub mod ingest_asset;
|
||||||
|
pub mod register_library_path;
|
||||||
|
pub mod register_volume;
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use domain::{
|
use domain::{
|
||||||
entities::LibraryPath,
|
entities::LibraryPath,
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
ports::{LibraryPathRepository, StorageVolumeRepository},
|
ports::{LibraryPathRepository, StorageVolumeRepository},
|
||||||
value_objects::SystemId,
|
value_objects::SystemId,
|
||||||
};
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct RegisterLibraryPathCommand {
|
pub struct RegisterLibraryPathCommand {
|
||||||
@@ -24,11 +24,19 @@ impl RegisterLibraryPathHandler {
|
|||||||
volume_repo: Arc<dyn StorageVolumeRepository>,
|
volume_repo: Arc<dyn StorageVolumeRepository>,
|
||||||
path_repo: Arc<dyn LibraryPathRepository>,
|
path_repo: Arc<dyn LibraryPathRepository>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { volume_repo, path_repo }
|
Self {
|
||||||
|
volume_repo,
|
||||||
|
path_repo,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute(&self, cmd: RegisterLibraryPathCommand) -> Result<LibraryPath, DomainError> {
|
pub async fn execute(
|
||||||
self.volume_repo.find_by_id(&cmd.volume_id).await?
|
&self,
|
||||||
|
cmd: RegisterLibraryPathCommand,
|
||||||
|
) -> Result<LibraryPath, DomainError> {
|
||||||
|
self.volume_repo
|
||||||
|
.find_by_id(&cmd.volume_id)
|
||||||
|
.await?
|
||||||
.ok_or_else(|| DomainError::NotFound(format!("Volume {} not found", cmd.volume_id)))?;
|
.ok_or_else(|| DomainError::NotFound(format!("Volume {} not found", cmd.volume_id)))?;
|
||||||
|
|
||||||
let path = LibraryPath::new_user_owned(
|
let path = LibraryPath::new_user_owned(
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
|
use domain::{entities::StorageVolume, errors::DomainError, ports::StorageVolumeRepository};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use domain::{
|
|
||||||
entities::StorageVolume,
|
|
||||||
errors::DomainError,
|
|
||||||
ports::StorageVolumeRepository,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct RegisterVolumeCommand {
|
pub struct RegisterVolumeCommand {
|
||||||
@@ -23,7 +19,9 @@ impl RegisterVolumeHandler {
|
|||||||
|
|
||||||
pub async fn execute(&self, cmd: RegisterVolumeCommand) -> Result<StorageVolume, DomainError> {
|
pub async fn execute(&self, cmd: RegisterVolumeCommand) -> Result<StorageVolume, DomainError> {
|
||||||
if cmd.volume_name.is_empty() {
|
if cmd.volume_name.is_empty() {
|
||||||
return Err(DomainError::Validation("Volume name must not be empty".to_string()));
|
return Err(DomainError::Validation(
|
||||||
|
"Volume name must not be empty".to_string(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
let volume = StorageVolume::new(cmd.volume_name, cmd.uri_prefix, cmd.is_writable);
|
let volume = StorageVolume::new(cmd.volume_name, cmd.uri_prefix, cmd.is_writable);
|
||||||
self.volume_repo.save(&volume).await?;
|
self.volume_repo.save(&volume).await?;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
pub mod commands;
|
pub mod commands;
|
||||||
pub mod queries;
|
pub mod queries;
|
||||||
|
|
||||||
pub use commands::register_volume::{RegisterVolumeCommand, RegisterVolumeHandler};
|
|
||||||
pub use commands::register_library_path::{RegisterLibraryPathCommand, RegisterLibraryPathHandler};
|
|
||||||
pub use commands::ingest_asset::{IngestAssetCommand, IngestAssetHandler};
|
pub use commands::ingest_asset::{IngestAssetCommand, IngestAssetHandler};
|
||||||
pub use queries::check_quota::{CheckQuotaQuery, CheckQuotaHandler};
|
pub use commands::register_library_path::{RegisterLibraryPathCommand, RegisterLibraryPathHandler};
|
||||||
|
pub use commands::register_volume::{RegisterVolumeCommand, RegisterVolumeHandler};
|
||||||
|
pub use queries::check_quota::{CheckQuotaHandler, CheckQuotaQuery};
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use domain::{
|
use domain::{
|
||||||
entities::UsageType,
|
entities::UsageType,
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
ports::{QuotaRepository, UsageLedgerRepository},
|
ports::{QuotaRepository, UsageLedgerRepository},
|
||||||
storage::services::{check_quota, QuotaCheckResult},
|
storage::services::{QuotaCheckResult, check_quota},
|
||||||
value_objects::SystemId,
|
value_objects::SystemId,
|
||||||
};
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct CheckQuotaQuery {
|
pub struct CheckQuotaQuery {
|
||||||
@@ -24,7 +24,10 @@ impl CheckQuotaHandler {
|
|||||||
quota_repo: Arc<dyn QuotaRepository>,
|
quota_repo: Arc<dyn QuotaRepository>,
|
||||||
ledger_repo: Arc<dyn UsageLedgerRepository>,
|
ledger_repo: Arc<dyn UsageLedgerRepository>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { quota_repo, ledger_repo }
|
Self {
|
||||||
|
quota_repo,
|
||||||
|
ledger_repo,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute(&self, query: CheckQuotaQuery) -> Result<QuotaCheckResult, DomainError> {
|
pub async fn execute(&self, query: CheckQuotaQuery) -> Result<QuotaCheckResult, DomainError> {
|
||||||
@@ -39,7 +42,15 @@ impl CheckQuotaHandler {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
let current = self.ledger_repo.sum_usage(&query.user_id, query.usage_type, None).await?;
|
let current = self
|
||||||
Ok(check_quota("a, query.usage_type, current, query.requested_amount))
|
.ledger_repo
|
||||||
|
.sum_usage(&query.user_id, query.usage_type, None)
|
||||||
|
.await?;
|
||||||
|
Ok(check_quota(
|
||||||
|
"a,
|
||||||
|
query.usage_type,
|
||||||
|
current,
|
||||||
|
query.requested_amount,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
use std::collections::HashMap;
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use tokio::sync::Mutex;
|
|
||||||
use domain::{
|
use domain::{
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
events::DomainEvent,
|
events::DomainEvent,
|
||||||
ports::{EventPublisher, FileStoragePort, FileEntry, PasswordHasher, TokenIssuer, SidecarWriterPort},
|
ports::{
|
||||||
|
EventPublisher, FileEntry, FileStoragePort, PasswordHasher, SidecarWriterPort, TokenIssuer,
|
||||||
|
},
|
||||||
value_objects::{PasswordHash, StructuredData, SystemId},
|
value_objects::{PasswordHash, StructuredData, SystemId},
|
||||||
};
|
};
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
// --- StubEventPublisher ---
|
// --- StubEventPublisher ---
|
||||||
|
|
||||||
@@ -17,7 +19,9 @@ pub struct StubEventPublisher {
|
|||||||
|
|
||||||
impl StubEventPublisher {
|
impl StubEventPublisher {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self { events: Mutex::new(Vec::new()) }
|
Self {
|
||||||
|
events: Mutex::new(Vec::new()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn published(&self) -> Vec<DomainEvent> {
|
pub async fn published(&self) -> Vec<DomainEvent> {
|
||||||
@@ -26,7 +30,9 @@ impl StubEventPublisher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Default for StubEventPublisher {
|
impl Default for StubEventPublisher {
|
||||||
fn default() -> Self { Self::new() }
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -45,12 +51,16 @@ pub struct InMemoryFileStorage {
|
|||||||
|
|
||||||
impl InMemoryFileStorage {
|
impl InMemoryFileStorage {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self { files: Mutex::new(HashMap::new()) }
|
Self {
|
||||||
|
files: Mutex::new(HashMap::new()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for InMemoryFileStorage {
|
impl Default for InMemoryFileStorage {
|
||||||
fn default() -> Self { Self::new() }
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -61,7 +71,11 @@ impl FileStoragePort for InMemoryFileStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn read_file(&self, path: &str) -> Result<Bytes, DomainError> {
|
async fn read_file(&self, path: &str) -> Result<Bytes, DomainError> {
|
||||||
self.files.lock().await.get(path).cloned()
|
self.files
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.get(path)
|
||||||
|
.cloned()
|
||||||
.ok_or_else(|| DomainError::NotFound(format!("File not found: {path}")))
|
.ok_or_else(|| DomainError::NotFound(format!("File not found: {path}")))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,8 +86,13 @@ impl FileStoragePort for InMemoryFileStorage {
|
|||||||
|
|
||||||
async fn list_directory(&self, path: &str) -> Result<Vec<FileEntry>, DomainError> {
|
async fn list_directory(&self, path: &str) -> Result<Vec<FileEntry>, DomainError> {
|
||||||
let files = self.files.lock().await;
|
let files = self.files.lock().await;
|
||||||
let prefix = if path.ends_with('/') { path.to_string() } else { format!("{path}/") };
|
let prefix = if path.ends_with('/') {
|
||||||
Ok(files.keys()
|
path.to_string()
|
||||||
|
} else {
|
||||||
|
format!("{path}/")
|
||||||
|
};
|
||||||
|
Ok(files
|
||||||
|
.keys()
|
||||||
.filter(|k| k.starts_with(&prefix))
|
.filter(|k| k.starts_with(&prefix))
|
||||||
.map(|k| FileEntry {
|
.map(|k| FileEntry {
|
||||||
path: k.clone(),
|
path: k.clone(),
|
||||||
@@ -98,7 +117,9 @@ pub struct StubSidecarWriter;
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl SidecarWriterPort for StubSidecarWriter {
|
impl SidecarWriterPort for StubSidecarWriter {
|
||||||
fn format_name(&self) -> &str { "stub" }
|
fn format_name(&self) -> &str {
|
||||||
|
"stub"
|
||||||
|
}
|
||||||
|
|
||||||
async fn write_sidecar(&self, _data: &StructuredData, _path: &str) -> Result<(), DomainError> {
|
async fn write_sidecar(&self, _data: &StructuredData, _path: &str) -> Result<(), DomainError> {
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -117,7 +138,9 @@ pub struct InMemorySidecarWriter {
|
|||||||
|
|
||||||
impl InMemorySidecarWriter {
|
impl InMemorySidecarWriter {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self { data: Mutex::new(HashMap::new()) }
|
Self {
|
||||||
|
data: Mutex::new(HashMap::new()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get(&self, path: &str) -> Option<StructuredData> {
|
pub async fn get(&self, path: &str) -> Option<StructuredData> {
|
||||||
@@ -126,20 +149,31 @@ impl InMemorySidecarWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Default for InMemorySidecarWriter {
|
impl Default for InMemorySidecarWriter {
|
||||||
fn default() -> Self { Self::new() }
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl SidecarWriterPort for InMemorySidecarWriter {
|
impl SidecarWriterPort for InMemorySidecarWriter {
|
||||||
fn format_name(&self) -> &str { "in-memory" }
|
fn format_name(&self) -> &str {
|
||||||
|
"in-memory"
|
||||||
|
}
|
||||||
|
|
||||||
async fn write_sidecar(&self, data: &StructuredData, path: &str) -> Result<(), DomainError> {
|
async fn write_sidecar(&self, data: &StructuredData, path: &str) -> Result<(), DomainError> {
|
||||||
self.data.lock().await.insert(path.to_string(), data.clone());
|
self.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.insert(path.to_string(), data.clone());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn read_sidecar(&self, path: &str) -> Result<StructuredData, DomainError> {
|
async fn read_sidecar(&self, path: &str) -> Result<StructuredData, DomainError> {
|
||||||
self.data.lock().await.get(path).cloned()
|
self.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.get(path)
|
||||||
|
.cloned()
|
||||||
.ok_or_else(|| DomainError::NotFound(format!("Sidecar not found: {path}")))
|
.ok_or_else(|| DomainError::NotFound(format!("Sidecar not found: {path}")))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -168,9 +202,9 @@ impl TokenIssuer for StubTokenIssuer {
|
|||||||
Ok(format!("token:{user_id}"))
|
Ok(format!("token:{user_id}"))
|
||||||
}
|
}
|
||||||
async fn verify(&self, token: &str) -> Result<(SystemId, String), DomainError> {
|
async fn verify(&self, token: &str) -> Result<(SystemId, String), DomainError> {
|
||||||
let id_str = token.strip_prefix("token:").ok_or_else(|| {
|
let id_str = token
|
||||||
DomainError::Unauthorized("Invalid stub token".to_string())
|
.strip_prefix("token:")
|
||||||
})?;
|
.ok_or_else(|| DomainError::Unauthorized("Invalid stub token".to_string()))?;
|
||||||
let uuid = uuid::Uuid::parse_str(id_str)
|
let uuid = uuid::Uuid::parse_str(id_str)
|
||||||
.map_err(|_| DomainError::Unauthorized("Bad UUID in stub token".to_string()))?;
|
.map_err(|_| DomainError::Unauthorized("Bad UUID in stub token".to_string()))?;
|
||||||
Ok((SystemId::from_uuid(uuid), "user".to_string()))
|
Ok((SystemId::from_uuid(uuid), "user".to_string()))
|
||||||
|
|||||||
@@ -1,25 +1,23 @@
|
|||||||
use std::collections::HashMap;
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use tokio::sync::Mutex;
|
|
||||||
use domain::{
|
use domain::{
|
||||||
entities::{
|
entities::{
|
||||||
Album, Asset, AssetMetadata, AssetTag, DuplicateGroup, DuplicateStatus,
|
Album, Asset, AssetMetadata, AssetTag, DuplicateGroup, DuplicateStatus, Group,
|
||||||
Group, IngestSession, InviteCode, Job, JobBatch, JobStatus, LibraryPath,
|
IngestSession, InviteCode, Job, JobBatch, JobStatus, LibraryPath, MetadataSource, Plugin,
|
||||||
MetadataSource, Plugin, ProcessingPipeline, QuotaDefinition, Role,
|
ProcessingPipeline, QuotaDefinition, Role, ShareLink, ShareScope, ShareTarget,
|
||||||
ShareLink, ShareScope, ShareTarget, SidecarRecord, SyncStatus,
|
SidecarRecord, StorageVolume, SyncStatus, Tag, UsageLedgerEntry, UsageType, User,
|
||||||
StorageVolume, Tag, UsageLedgerEntry, UsageType, User,
|
|
||||||
},
|
},
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
ports::{
|
ports::{
|
||||||
AlbumRepository, AssetMetadataRepository, AssetRepository,
|
AlbumRepository, AssetMetadataRepository, AssetRepository, DuplicateRepository,
|
||||||
DuplicateRepository, GroupRepository, IngestSessionRepository,
|
GroupRepository, IngestSessionRepository, JobBatchRepository, JobRepository,
|
||||||
JobBatchRepository, JobRepository, LibraryPathRepository,
|
LibraryPathRepository, PipelineRepository, PluginRepository, QuotaRepository,
|
||||||
PipelineRepository, PluginRepository, QuotaRepository,
|
RoleRepository, ShareRepository, SidecarRepository, StorageVolumeRepository, TagRepository,
|
||||||
RoleRepository, ShareRepository, SidecarRepository, StorageVolumeRepository,
|
UsageLedgerRepository, UserRepository,
|
||||||
TagRepository, UsageLedgerRepository, UserRepository,
|
|
||||||
},
|
},
|
||||||
value_objects::{Checksum, DateTimeStamp, Email, SystemId},
|
value_objects::{Checksum, DateTimeStamp, Email, SystemId},
|
||||||
};
|
};
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
// --- InMemoryUserRepository ---
|
// --- InMemoryUserRepository ---
|
||||||
|
|
||||||
@@ -29,7 +27,9 @@ pub struct InMemoryUserRepository {
|
|||||||
|
|
||||||
impl InMemoryUserRepository {
|
impl InMemoryUserRepository {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self { users: Mutex::new(HashMap::new()) }
|
Self {
|
||||||
|
users: Mutex::new(HashMap::new()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn all(&self) -> Vec<User> {
|
pub async fn all(&self) -> Vec<User> {
|
||||||
@@ -38,7 +38,9 @@ impl InMemoryUserRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Default for InMemoryUserRepository {
|
impl Default for InMemoryUserRepository {
|
||||||
fn default() -> Self { Self::new() }
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -48,19 +50,30 @@ impl UserRepository for InMemoryUserRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn find_by_email(&self, email: &Email) -> Result<Option<User>, DomainError> {
|
async fn find_by_email(&self, email: &Email) -> Result<Option<User>, DomainError> {
|
||||||
Ok(self.users.lock().await.values()
|
Ok(self
|
||||||
|
.users
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.values()
|
||||||
.find(|u| u.email.as_str() == email.as_str())
|
.find(|u| u.email.as_str() == email.as_str())
|
||||||
.cloned())
|
.cloned())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn find_by_username(&self, username: &str) -> Result<Option<User>, DomainError> {
|
async fn find_by_username(&self, username: &str) -> Result<Option<User>, DomainError> {
|
||||||
Ok(self.users.lock().await.values()
|
Ok(self
|
||||||
|
.users
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.values()
|
||||||
.find(|u| u.username == username)
|
.find(|u| u.username == username)
|
||||||
.cloned())
|
.cloned())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn save(&self, user: &User) -> Result<(), DomainError> {
|
async fn save(&self, user: &User) -> Result<(), DomainError> {
|
||||||
self.users.lock().await.insert(user.id.to_string(), user.clone());
|
self.users
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.insert(user.id.to_string(), user.clone());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,12 +91,16 @@ pub struct InMemoryAssetRepository {
|
|||||||
|
|
||||||
impl InMemoryAssetRepository {
|
impl InMemoryAssetRepository {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self { data: Mutex::new(HashMap::new()) }
|
Self {
|
||||||
|
data: Mutex::new(HashMap::new()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for InMemoryAssetRepository {
|
impl Default for InMemoryAssetRepository {
|
||||||
fn default() -> Self { Self::new() }
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -93,22 +110,42 @@ impl AssetRepository for InMemoryAssetRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn find_by_checksum(&self, checksum: &Checksum) -> Result<Vec<Asset>, DomainError> {
|
async fn find_by_checksum(&self, checksum: &Checksum) -> Result<Vec<Asset>, DomainError> {
|
||||||
Ok(self.data.lock().await.values()
|
Ok(self
|
||||||
|
.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.values()
|
||||||
.filter(|a| &a.source_reference.checksum == checksum)
|
.filter(|a| &a.source_reference.checksum == checksum)
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn find_by_owner(&self, owner_id: &SystemId, limit: u32, offset: u32) -> Result<Vec<Asset>, DomainError> {
|
async fn find_by_owner(
|
||||||
let all: Vec<Asset> = self.data.lock().await.values()
|
&self,
|
||||||
|
owner_id: &SystemId,
|
||||||
|
limit: u32,
|
||||||
|
offset: u32,
|
||||||
|
) -> Result<Vec<Asset>, DomainError> {
|
||||||
|
let all: Vec<Asset> = self
|
||||||
|
.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.values()
|
||||||
.filter(|a| &a.owner_user_id == owner_id)
|
.filter(|a| &a.owner_user_id == owner_id)
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect();
|
.collect();
|
||||||
Ok(all.into_iter().skip(offset as usize).take(limit as usize).collect())
|
Ok(all
|
||||||
|
.into_iter()
|
||||||
|
.skip(offset as usize)
|
||||||
|
.take(limit as usize)
|
||||||
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn save(&self, asset: &Asset) -> Result<(), DomainError> {
|
async fn save(&self, asset: &Asset) -> Result<(), DomainError> {
|
||||||
self.data.lock().await.insert(asset.asset_id.to_string(), asset.clone());
|
self.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.insert(asset.asset_id.to_string(), asset.clone());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,12 +163,16 @@ pub struct InMemoryAlbumRepository {
|
|||||||
|
|
||||||
impl InMemoryAlbumRepository {
|
impl InMemoryAlbumRepository {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self { data: Mutex::new(HashMap::new()) }
|
Self {
|
||||||
|
data: Mutex::new(HashMap::new()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for InMemoryAlbumRepository {
|
impl Default for InMemoryAlbumRepository {
|
||||||
fn default() -> Self { Self::new() }
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -141,14 +182,21 @@ impl AlbumRepository for InMemoryAlbumRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn find_by_creator(&self, creator_id: &SystemId) -> Result<Vec<Album>, DomainError> {
|
async fn find_by_creator(&self, creator_id: &SystemId) -> Result<Vec<Album>, DomainError> {
|
||||||
Ok(self.data.lock().await.values()
|
Ok(self
|
||||||
|
.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.values()
|
||||||
.filter(|a| &a.creator_user_id == creator_id)
|
.filter(|a| &a.creator_user_id == creator_id)
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn save(&self, album: &Album) -> Result<(), DomainError> {
|
async fn save(&self, album: &Album) -> Result<(), DomainError> {
|
||||||
self.data.lock().await.insert(album.album_id.to_string(), album.clone());
|
self.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.insert(album.album_id.to_string(), album.clone());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,12 +214,16 @@ pub struct InMemoryJobRepository {
|
|||||||
|
|
||||||
impl InMemoryJobRepository {
|
impl InMemoryJobRepository {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self { data: Mutex::new(HashMap::new()) }
|
Self {
|
||||||
|
data: Mutex::new(HashMap::new()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for InMemoryJobRepository {
|
impl Default for InMemoryJobRepository {
|
||||||
fn default() -> Self { Self::new() }
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -182,21 +234,29 @@ impl JobRepository for InMemoryJobRepository {
|
|||||||
|
|
||||||
async fn find_next_queued(&self) -> Result<Option<Job>, DomainError> {
|
async fn find_next_queued(&self) -> Result<Option<Job>, DomainError> {
|
||||||
let data = self.data.lock().await;
|
let data = self.data.lock().await;
|
||||||
Ok(data.values()
|
Ok(data
|
||||||
|
.values()
|
||||||
.filter(|j| j.status == JobStatus::Queued)
|
.filter(|j| j.status == JobStatus::Queued)
|
||||||
.max_by_key(|j| j.priority)
|
.max_by_key(|j| j.priority)
|
||||||
.cloned())
|
.cloned())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn find_by_batch(&self, batch_id: &SystemId) -> Result<Vec<Job>, DomainError> {
|
async fn find_by_batch(&self, batch_id: &SystemId) -> Result<Vec<Job>, DomainError> {
|
||||||
Ok(self.data.lock().await.values()
|
Ok(self
|
||||||
|
.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.values()
|
||||||
.filter(|j| j.batch_id.as_ref() == Some(batch_id))
|
.filter(|j| j.batch_id.as_ref() == Some(batch_id))
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn save(&self, job: &Job) -> Result<(), DomainError> {
|
async fn save(&self, job: &Job) -> Result<(), DomainError> {
|
||||||
self.data.lock().await.insert(job.job_id.to_string(), job.clone());
|
self.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.insert(job.job_id.to_string(), job.clone());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -209,12 +269,16 @@ pub struct InMemoryRoleRepository {
|
|||||||
|
|
||||||
impl InMemoryRoleRepository {
|
impl InMemoryRoleRepository {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self { data: Mutex::new(HashMap::new()) }
|
Self {
|
||||||
|
data: Mutex::new(HashMap::new()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for InMemoryRoleRepository {
|
impl Default for InMemoryRoleRepository {
|
||||||
fn default() -> Self { Self::new() }
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -224,20 +288,31 @@ impl RoleRepository for InMemoryRoleRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn find_by_name(&self, name: &str) -> Result<Option<Role>, DomainError> {
|
async fn find_by_name(&self, name: &str) -> Result<Option<Role>, DomainError> {
|
||||||
Ok(self.data.lock().await.values()
|
Ok(self
|
||||||
|
.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.values()
|
||||||
.find(|r| r.name == name)
|
.find(|r| r.name == name)
|
||||||
.cloned())
|
.cloned())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn find_defaults(&self) -> Result<Vec<Role>, DomainError> {
|
async fn find_defaults(&self) -> Result<Vec<Role>, DomainError> {
|
||||||
Ok(self.data.lock().await.values()
|
Ok(self
|
||||||
|
.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.values()
|
||||||
.filter(|r| r.is_system_default)
|
.filter(|r| r.is_system_default)
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn save(&self, role: &Role) -> Result<(), DomainError> {
|
async fn save(&self, role: &Role) -> Result<(), DomainError> {
|
||||||
self.data.lock().await.insert(role.role_id.to_string(), role.clone());
|
self.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.insert(role.role_id.to_string(), role.clone());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,12 +330,16 @@ pub struct InMemoryGroupRepository {
|
|||||||
|
|
||||||
impl InMemoryGroupRepository {
|
impl InMemoryGroupRepository {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self { data: Mutex::new(HashMap::new()) }
|
Self {
|
||||||
|
data: Mutex::new(HashMap::new()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for InMemoryGroupRepository {
|
impl Default for InMemoryGroupRepository {
|
||||||
fn default() -> Self { Self::new() }
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -270,14 +349,21 @@ impl GroupRepository for InMemoryGroupRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn find_by_user(&self, user_id: &SystemId) -> Result<Vec<Group>, DomainError> {
|
async fn find_by_user(&self, user_id: &SystemId) -> Result<Vec<Group>, DomainError> {
|
||||||
Ok(self.data.lock().await.values()
|
Ok(self
|
||||||
|
.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.values()
|
||||||
.filter(|g| g.is_member(user_id))
|
.filter(|g| g.is_member(user_id))
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn save(&self, group: &Group) -> Result<(), DomainError> {
|
async fn save(&self, group: &Group) -> Result<(), DomainError> {
|
||||||
self.data.lock().await.insert(group.group_id.to_string(), group.clone());
|
self.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.insert(group.group_id.to_string(), group.clone());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -295,12 +381,16 @@ pub struct InMemoryStorageVolumeRepository {
|
|||||||
|
|
||||||
impl InMemoryStorageVolumeRepository {
|
impl InMemoryStorageVolumeRepository {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self { data: Mutex::new(HashMap::new()) }
|
Self {
|
||||||
|
data: Mutex::new(HashMap::new()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for InMemoryStorageVolumeRepository {
|
impl Default for InMemoryStorageVolumeRepository {
|
||||||
fn default() -> Self { Self::new() }
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -314,7 +404,10 @@ impl StorageVolumeRepository for InMemoryStorageVolumeRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn save(&self, volume: &StorageVolume) -> Result<(), DomainError> {
|
async fn save(&self, volume: &StorageVolume) -> Result<(), DomainError> {
|
||||||
self.data.lock().await.insert(volume.volume_id.to_string(), volume.clone());
|
self.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.insert(volume.volume_id.to_string(), volume.clone());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,12 +425,16 @@ pub struct InMemoryLibraryPathRepository {
|
|||||||
|
|
||||||
impl InMemoryLibraryPathRepository {
|
impl InMemoryLibraryPathRepository {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self { data: Mutex::new(HashMap::new()) }
|
Self {
|
||||||
|
data: Mutex::new(HashMap::new()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for InMemoryLibraryPathRepository {
|
impl Default for InMemoryLibraryPathRepository {
|
||||||
fn default() -> Self { Self::new() }
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -347,21 +444,35 @@ impl LibraryPathRepository for InMemoryLibraryPathRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn find_by_volume(&self, volume_id: &SystemId) -> Result<Vec<LibraryPath>, DomainError> {
|
async fn find_by_volume(&self, volume_id: &SystemId) -> Result<Vec<LibraryPath>, DomainError> {
|
||||||
Ok(self.data.lock().await.values()
|
Ok(self
|
||||||
|
.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.values()
|
||||||
.filter(|p| &p.volume_id == volume_id)
|
.filter(|p| &p.volume_id == volume_id)
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn find_ingest_destinations(&self, owner_id: &SystemId) -> Result<Vec<LibraryPath>, DomainError> {
|
async fn find_ingest_destinations(
|
||||||
Ok(self.data.lock().await.values()
|
&self,
|
||||||
|
owner_id: &SystemId,
|
||||||
|
) -> Result<Vec<LibraryPath>, DomainError> {
|
||||||
|
Ok(self
|
||||||
|
.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.values()
|
||||||
.filter(|p| p.is_ingest_destination && p.designated_owner_id.as_ref() == Some(owner_id))
|
.filter(|p| p.is_ingest_destination && p.designated_owner_id.as_ref() == Some(owner_id))
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn save(&self, path: &LibraryPath) -> Result<(), DomainError> {
|
async fn save(&self, path: &LibraryPath) -> Result<(), DomainError> {
|
||||||
self.data.lock().await.insert(path.path_id.to_string(), path.clone());
|
self.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.insert(path.path_id.to_string(), path.clone());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -379,12 +490,16 @@ pub struct InMemoryIngestSessionRepository {
|
|||||||
|
|
||||||
impl InMemoryIngestSessionRepository {
|
impl InMemoryIngestSessionRepository {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self { data: Mutex::new(HashMap::new()) }
|
Self {
|
||||||
|
data: Mutex::new(HashMap::new()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for InMemoryIngestSessionRepository {
|
impl Default for InMemoryIngestSessionRepository {
|
||||||
fn default() -> Self { Self::new() }
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -394,14 +509,21 @@ impl IngestSessionRepository for InMemoryIngestSessionRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn find_by_user(&self, user_id: &SystemId) -> Result<Vec<IngestSession>, DomainError> {
|
async fn find_by_user(&self, user_id: &SystemId) -> Result<Vec<IngestSession>, DomainError> {
|
||||||
Ok(self.data.lock().await.values()
|
Ok(self
|
||||||
|
.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.values()
|
||||||
.filter(|s| &s.uploader_user_id == user_id)
|
.filter(|s| &s.uploader_user_id == user_id)
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn save(&self, session: &IngestSession) -> Result<(), DomainError> {
|
async fn save(&self, session: &IngestSession) -> Result<(), DomainError> {
|
||||||
self.data.lock().await.insert(session.session_id.to_string(), session.clone());
|
self.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.insert(session.session_id.to_string(), session.clone());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -414,24 +536,38 @@ pub struct InMemoryQuotaRepository {
|
|||||||
|
|
||||||
impl InMemoryQuotaRepository {
|
impl InMemoryQuotaRepository {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self { data: Mutex::new(HashMap::new()) }
|
Self {
|
||||||
|
data: Mutex::new(HashMap::new()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for InMemoryQuotaRepository {
|
impl Default for InMemoryQuotaRepository {
|
||||||
fn default() -> Self { Self::new() }
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl QuotaRepository for InMemoryQuotaRepository {
|
impl QuotaRepository for InMemoryQuotaRepository {
|
||||||
async fn find_by_owner(&self, owner_id: &SystemId) -> Result<Option<QuotaDefinition>, DomainError> {
|
async fn find_by_owner(
|
||||||
Ok(self.data.lock().await.values()
|
&self,
|
||||||
|
owner_id: &SystemId,
|
||||||
|
) -> Result<Option<QuotaDefinition>, DomainError> {
|
||||||
|
Ok(self
|
||||||
|
.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.values()
|
||||||
.find(|q| &q.owner_scope == owner_id)
|
.find(|q| &q.owner_scope == owner_id)
|
||||||
.cloned())
|
.cloned())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn save(&self, quota: &QuotaDefinition) -> Result<(), DomainError> {
|
async fn save(&self, quota: &QuotaDefinition) -> Result<(), DomainError> {
|
||||||
self.data.lock().await.insert(quota.quota_id.to_string(), quota.clone());
|
self.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.insert(quota.quota_id.to_string(), quota.clone());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -449,12 +585,16 @@ pub struct InMemoryUsageLedgerRepository {
|
|||||||
|
|
||||||
impl InMemoryUsageLedgerRepository {
|
impl InMemoryUsageLedgerRepository {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self { entries: Mutex::new(Vec::new()) }
|
Self {
|
||||||
|
entries: Mutex::new(Vec::new()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for InMemoryUsageLedgerRepository {
|
impl Default for InMemoryUsageLedgerRepository {
|
||||||
fn default() -> Self { Self::new() }
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -471,7 +611,8 @@ impl UsageLedgerRepository for InMemoryUsageLedgerRepository {
|
|||||||
since: Option<DateTimeStamp>,
|
since: Option<DateTimeStamp>,
|
||||||
) -> Result<u64, DomainError> {
|
) -> Result<u64, DomainError> {
|
||||||
let entries = self.entries.lock().await;
|
let entries = self.entries.lock().await;
|
||||||
let total = entries.iter()
|
let total = entries
|
||||||
|
.iter()
|
||||||
.filter(|e| &e.user_id == user_id && e.usage_type == usage_type)
|
.filter(|e| &e.user_id == user_id && e.usage_type == usage_type)
|
||||||
.filter(|e| match &since {
|
.filter(|e| match &since {
|
||||||
Some(ts) => &e.timestamp >= ts,
|
Some(ts) => &e.timestamp >= ts,
|
||||||
@@ -491,7 +632,9 @@ pub struct InMemoryAssetMetadataRepository {
|
|||||||
|
|
||||||
impl InMemoryAssetMetadataRepository {
|
impl InMemoryAssetMetadataRepository {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self { data: Mutex::new(HashMap::new()) }
|
Self {
|
||||||
|
data: Mutex::new(HashMap::new()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn key(asset_id: &SystemId, source: MetadataSource) -> String {
|
fn key(asset_id: &SystemId, source: MetadataSource) -> String {
|
||||||
@@ -500,21 +643,36 @@ impl InMemoryAssetMetadataRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Default for InMemoryAssetMetadataRepository {
|
impl Default for InMemoryAssetMetadataRepository {
|
||||||
fn default() -> Self { Self::new() }
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl AssetMetadataRepository for InMemoryAssetMetadataRepository {
|
impl AssetMetadataRepository for InMemoryAssetMetadataRepository {
|
||||||
async fn find_by_asset(&self, asset_id: &SystemId) -> Result<Vec<AssetMetadata>, DomainError> {
|
async fn find_by_asset(&self, asset_id: &SystemId) -> Result<Vec<AssetMetadata>, DomainError> {
|
||||||
let prefix = format!("{asset_id}:");
|
let prefix = format!("{asset_id}:");
|
||||||
Ok(self.data.lock().await.iter()
|
Ok(self
|
||||||
|
.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.iter()
|
||||||
.filter(|(k, _)| k.starts_with(&prefix))
|
.filter(|(k, _)| k.starts_with(&prefix))
|
||||||
.map(|(_, v)| v.clone())
|
.map(|(_, v)| v.clone())
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn find_by_asset_and_source(&self, asset_id: &SystemId, source: MetadataSource) -> Result<Option<AssetMetadata>, DomainError> {
|
async fn find_by_asset_and_source(
|
||||||
Ok(self.data.lock().await.get(&Self::key(asset_id, source)).cloned())
|
&self,
|
||||||
|
asset_id: &SystemId,
|
||||||
|
source: MetadataSource,
|
||||||
|
) -> Result<Option<AssetMetadata>, DomainError> {
|
||||||
|
Ok(self
|
||||||
|
.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.get(&Self::key(asset_id, source))
|
||||||
|
.cloned())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn save(&self, metadata: &AssetMetadata) -> Result<(), DomainError> {
|
async fn save(&self, metadata: &AssetMetadata) -> Result<(), DomainError> {
|
||||||
@@ -523,7 +681,11 @@ impl AssetMetadataRepository for InMemoryAssetMetadataRepository {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn delete_by_asset_and_source(&self, asset_id: &SystemId, source: MetadataSource) -> Result<(), DomainError> {
|
async fn delete_by_asset_and_source(
|
||||||
|
&self,
|
||||||
|
asset_id: &SystemId,
|
||||||
|
source: MetadataSource,
|
||||||
|
) -> Result<(), DomainError> {
|
||||||
self.data.lock().await.remove(&Self::key(asset_id, source));
|
self.data.lock().await.remove(&Self::key(asset_id, source));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -550,13 +712,18 @@ impl InMemoryShareRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Default for InMemoryShareRepository {
|
impl Default for InMemoryShareRepository {
|
||||||
fn default() -> Self { Self::new() }
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ShareRepository for InMemoryShareRepository {
|
impl ShareRepository for InMemoryShareRepository {
|
||||||
async fn save_scope(&self, scope: &ShareScope) -> Result<(), DomainError> {
|
async fn save_scope(&self, scope: &ShareScope) -> Result<(), DomainError> {
|
||||||
self.scopes.lock().await.insert(scope.scope_id.to_string(), scope.clone());
|
self.scopes
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.insert(scope.scope_id.to_string(), scope.clone());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -564,8 +731,15 @@ impl ShareRepository for InMemoryShareRepository {
|
|||||||
Ok(self.scopes.lock().await.get(&id.to_string()).cloned())
|
Ok(self.scopes.lock().await.get(&id.to_string()).cloned())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn find_scopes_for_resource(&self, resource_id: &SystemId) -> Result<Vec<ShareScope>, DomainError> {
|
async fn find_scopes_for_resource(
|
||||||
Ok(self.scopes.lock().await.values()
|
&self,
|
||||||
|
resource_id: &SystemId,
|
||||||
|
) -> Result<Vec<ShareScope>, DomainError> {
|
||||||
|
Ok(self
|
||||||
|
.scopes
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.values()
|
||||||
.filter(|s| &s.shareable_id == resource_id)
|
.filter(|s| &s.shareable_id == resource_id)
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect())
|
.collect())
|
||||||
@@ -582,22 +756,39 @@ impl ShareRepository for InMemoryShareRepository {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn find_targets_for_scope(&self, scope_id: &SystemId) -> Result<Vec<ShareTarget>, DomainError> {
|
async fn find_targets_for_scope(
|
||||||
Ok(self.targets.lock().await.values()
|
&self,
|
||||||
|
scope_id: &SystemId,
|
||||||
|
) -> Result<Vec<ShareTarget>, DomainError> {
|
||||||
|
Ok(self
|
||||||
|
.targets
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.values()
|
||||||
.filter(|t| &t.scope_id == scope_id)
|
.filter(|t| &t.scope_id == scope_id)
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn find_targets_for_user(&self, user_id: &SystemId) -> Result<Vec<ShareTarget>, DomainError> {
|
async fn find_targets_for_user(
|
||||||
Ok(self.targets.lock().await.values()
|
&self,
|
||||||
|
user_id: &SystemId,
|
||||||
|
) -> Result<Vec<ShareTarget>, DomainError> {
|
||||||
|
Ok(self
|
||||||
|
.targets
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.values()
|
||||||
.filter(|t| &t.target_id == user_id)
|
.filter(|t| &t.target_id == user_id)
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn save_link(&self, link: &ShareLink) -> Result<(), DomainError> {
|
async fn save_link(&self, link: &ShareLink) -> Result<(), DomainError> {
|
||||||
self.links.lock().await.insert(link.token.clone(), link.clone());
|
self.links
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.insert(link.token.clone(), link.clone());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -606,7 +797,10 @@ impl ShareRepository for InMemoryShareRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn save_invite(&self, invite: &InviteCode) -> Result<(), DomainError> {
|
async fn save_invite(&self, invite: &InviteCode) -> Result<(), DomainError> {
|
||||||
self.invites.lock().await.insert(invite.code_id.to_string(), invite.clone());
|
self.invites
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.insert(invite.code_id.to_string(), invite.clone());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -632,7 +826,9 @@ impl InMemoryTagRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Default for InMemoryTagRepository {
|
impl Default for InMemoryTagRepository {
|
||||||
fn default() -> Self { Self::new() }
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -642,17 +838,26 @@ impl TagRepository for InMemoryTagRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn find_by_name(&self, name: &str) -> Result<Option<Tag>, DomainError> {
|
async fn find_by_name(&self, name: &str) -> Result<Option<Tag>, DomainError> {
|
||||||
Ok(self.tags.lock().await.values()
|
Ok(self
|
||||||
|
.tags
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.values()
|
||||||
.find(|t| t.name == name)
|
.find(|t| t.name == name)
|
||||||
.cloned())
|
.cloned())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn find_tags_for_asset(&self, asset_id: &SystemId) -> Result<Vec<(Tag, AssetTag)>, DomainError> {
|
async fn find_tags_for_asset(
|
||||||
|
&self,
|
||||||
|
asset_id: &SystemId,
|
||||||
|
) -> Result<Vec<(Tag, AssetTag)>, DomainError> {
|
||||||
let asset_tags = self.asset_tags.lock().await;
|
let asset_tags = self.asset_tags.lock().await;
|
||||||
let tags = self.tags.lock().await;
|
let tags = self.tags.lock().await;
|
||||||
let mut result = Vec::new();
|
let mut result = Vec::new();
|
||||||
for at in asset_tags.values() {
|
for at in asset_tags.values() {
|
||||||
if &at.asset_id == asset_id && let Some(tag) = tags.get(&at.tag_id.to_string()) {
|
if &at.asset_id == asset_id
|
||||||
|
&& let Some(tag) = tags.get(&at.tag_id.to_string())
|
||||||
|
{
|
||||||
result.push((tag.clone(), at.clone()));
|
result.push((tag.clone(), at.clone()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -660,7 +865,10 @@ impl TagRepository for InMemoryTagRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn save_tag(&self, tag: &Tag) -> Result<(), DomainError> {
|
async fn save_tag(&self, tag: &Tag) -> Result<(), DomainError> {
|
||||||
self.tags.lock().await.insert(tag.tag_id.to_string(), tag.clone());
|
self.tags
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.insert(tag.tag_id.to_string(), tag.clone());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -670,7 +878,11 @@ impl TagRepository for InMemoryTagRepository {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn remove_asset_tag(&self, asset_id: &SystemId, tag_id: &SystemId) -> Result<(), DomainError> {
|
async fn remove_asset_tag(
|
||||||
|
&self,
|
||||||
|
asset_id: &SystemId,
|
||||||
|
tag_id: &SystemId,
|
||||||
|
) -> Result<(), DomainError> {
|
||||||
let key = format!("{asset_id}:{tag_id}");
|
let key = format!("{asset_id}:{tag_id}");
|
||||||
self.asset_tags.lock().await.remove(&key);
|
self.asset_tags.lock().await.remove(&key);
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -685,12 +897,16 @@ pub struct InMemoryDuplicateRepository {
|
|||||||
|
|
||||||
impl InMemoryDuplicateRepository {
|
impl InMemoryDuplicateRepository {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self { data: Mutex::new(HashMap::new()) }
|
Self {
|
||||||
|
data: Mutex::new(HashMap::new()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for InMemoryDuplicateRepository {
|
impl Default for InMemoryDuplicateRepository {
|
||||||
fn default() -> Self { Self::new() }
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -700,21 +916,32 @@ impl DuplicateRepository for InMemoryDuplicateRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn find_unresolved(&self) -> Result<Vec<DuplicateGroup>, DomainError> {
|
async fn find_unresolved(&self) -> Result<Vec<DuplicateGroup>, DomainError> {
|
||||||
Ok(self.data.lock().await.values()
|
Ok(self
|
||||||
|
.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.values()
|
||||||
.filter(|g| g.status == DuplicateStatus::Unresolved)
|
.filter(|g| g.status == DuplicateStatus::Unresolved)
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn find_by_asset(&self, asset_id: &SystemId) -> Result<Vec<DuplicateGroup>, DomainError> {
|
async fn find_by_asset(&self, asset_id: &SystemId) -> Result<Vec<DuplicateGroup>, DomainError> {
|
||||||
Ok(self.data.lock().await.values()
|
Ok(self
|
||||||
|
.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.values()
|
||||||
.filter(|g| g.candidates.iter().any(|c| &c.asset_id == asset_id))
|
.filter(|g| g.candidates.iter().any(|c| &c.asset_id == asset_id))
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn save(&self, group: &DuplicateGroup) -> Result<(), DomainError> {
|
async fn save(&self, group: &DuplicateGroup) -> Result<(), DomainError> {
|
||||||
self.data.lock().await.insert(group.group_id.to_string(), group.clone());
|
self.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.insert(group.group_id.to_string(), group.clone());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -727,29 +954,43 @@ pub struct InMemorySidecarRepository {
|
|||||||
|
|
||||||
impl InMemorySidecarRepository {
|
impl InMemorySidecarRepository {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self { data: Mutex::new(HashMap::new()) }
|
Self {
|
||||||
|
data: Mutex::new(HashMap::new()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for InMemorySidecarRepository {
|
impl Default for InMemorySidecarRepository {
|
||||||
fn default() -> Self { Self::new() }
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl SidecarRepository for InMemorySidecarRepository {
|
impl SidecarRepository for InMemorySidecarRepository {
|
||||||
async fn find_by_asset(&self, asset_id: &SystemId) -> Result<Option<SidecarRecord>, DomainError> {
|
async fn find_by_asset(
|
||||||
|
&self,
|
||||||
|
asset_id: &SystemId,
|
||||||
|
) -> Result<Option<SidecarRecord>, DomainError> {
|
||||||
Ok(self.data.lock().await.get(&asset_id.to_string()).cloned())
|
Ok(self.data.lock().await.get(&asset_id.to_string()).cloned())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn find_by_status(&self, status: SyncStatus) -> Result<Vec<SidecarRecord>, DomainError> {
|
async fn find_by_status(&self, status: SyncStatus) -> Result<Vec<SidecarRecord>, DomainError> {
|
||||||
Ok(self.data.lock().await.values()
|
Ok(self
|
||||||
|
.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.values()
|
||||||
.filter(|r| r.sync_status == status)
|
.filter(|r| r.sync_status == status)
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn save(&self, record: &SidecarRecord) -> Result<(), DomainError> {
|
async fn save(&self, record: &SidecarRecord) -> Result<(), DomainError> {
|
||||||
self.data.lock().await.insert(record.asset_id.to_string(), record.clone());
|
self.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.insert(record.asset_id.to_string(), record.clone());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -767,12 +1008,16 @@ pub struct InMemoryJobBatchRepository {
|
|||||||
|
|
||||||
impl InMemoryJobBatchRepository {
|
impl InMemoryJobBatchRepository {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self { data: Mutex::new(HashMap::new()) }
|
Self {
|
||||||
|
data: Mutex::new(HashMap::new()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for InMemoryJobBatchRepository {
|
impl Default for InMemoryJobBatchRepository {
|
||||||
fn default() -> Self { Self::new() }
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -782,7 +1027,10 @@ impl JobBatchRepository for InMemoryJobBatchRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn save(&self, batch: &JobBatch) -> Result<(), DomainError> {
|
async fn save(&self, batch: &JobBatch) -> Result<(), DomainError> {
|
||||||
self.data.lock().await.insert(batch.batch_id.to_string(), batch.clone());
|
self.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.insert(batch.batch_id.to_string(), batch.clone());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -795,12 +1043,16 @@ pub struct InMemoryPluginRepository {
|
|||||||
|
|
||||||
impl InMemoryPluginRepository {
|
impl InMemoryPluginRepository {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self { data: Mutex::new(HashMap::new()) }
|
Self {
|
||||||
|
data: Mutex::new(HashMap::new()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for InMemoryPluginRepository {
|
impl Default for InMemoryPluginRepository {
|
||||||
fn default() -> Self { Self::new() }
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -810,14 +1062,21 @@ impl PluginRepository for InMemoryPluginRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn find_enabled(&self) -> Result<Vec<Plugin>, DomainError> {
|
async fn find_enabled(&self) -> Result<Vec<Plugin>, DomainError> {
|
||||||
Ok(self.data.lock().await.values()
|
Ok(self
|
||||||
|
.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.values()
|
||||||
.filter(|p| p.is_enabled)
|
.filter(|p| p.is_enabled)
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn save(&self, plugin: &Plugin) -> Result<(), DomainError> {
|
async fn save(&self, plugin: &Plugin) -> Result<(), DomainError> {
|
||||||
self.data.lock().await.insert(plugin.plugin_id.to_string(), plugin.clone());
|
self.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.insert(plugin.plugin_id.to_string(), plugin.clone());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -830,12 +1089,16 @@ pub struct InMemoryPipelineRepository {
|
|||||||
|
|
||||||
impl InMemoryPipelineRepository {
|
impl InMemoryPipelineRepository {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self { data: Mutex::new(HashMap::new()) }
|
Self {
|
||||||
|
data: Mutex::new(HashMap::new()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for InMemoryPipelineRepository {
|
impl Default for InMemoryPipelineRepository {
|
||||||
fn default() -> Self { Self::new() }
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -845,14 +1108,21 @@ impl PipelineRepository for InMemoryPipelineRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn find_by_trigger(&self, event: &str) -> Result<Vec<ProcessingPipeline>, DomainError> {
|
async fn find_by_trigger(&self, event: &str) -> Result<Vec<ProcessingPipeline>, DomainError> {
|
||||||
Ok(self.data.lock().await.values()
|
Ok(self
|
||||||
|
.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.values()
|
||||||
.filter(|p| p.trigger_event == event)
|
.filter(|p| p.trigger_event == event)
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn save(&self, pipeline: &ProcessingPipeline) -> Result<(), DomainError> {
|
async fn save(&self, pipeline: &ProcessingPipeline) -> Result<(), DomainError> {
|
||||||
self.data.lock().await.insert(pipeline.pipeline_id.to_string(), pipeline.clone());
|
self.data
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.insert(pipeline.pipeline_id.to_string(), pipeline.clone());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
mod catalog;
|
||||||
mod identity;
|
mod identity;
|
||||||
mod organization;
|
mod organization;
|
||||||
mod storage;
|
mod processing;
|
||||||
mod catalog;
|
|
||||||
mod sharing;
|
mod sharing;
|
||||||
mod sidecar;
|
mod sidecar;
|
||||||
mod processing;
|
mod storage;
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use application::catalog::{RegisterAssetCommand, RegisterAssetHandler};
|
use application::catalog::{RegisterAssetCommand, RegisterAssetHandler};
|
||||||
use application::testing::{InMemoryAssetRepository, InMemoryDuplicateRepository, StubEventPublisher};
|
use application::testing::{
|
||||||
|
InMemoryAssetRepository, InMemoryDuplicateRepository, StubEventPublisher,
|
||||||
|
};
|
||||||
use domain::catalog::entities::AssetType;
|
use domain::catalog::entities::AssetType;
|
||||||
use domain::value_objects::SystemId;
|
use domain::value_objects::SystemId;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
fn valid_checksum() -> String {
|
fn valid_checksum() -> String {
|
||||||
"a".repeat(64)
|
"a".repeat(64)
|
||||||
@@ -14,16 +16,13 @@ async fn registers_asset() {
|
|||||||
let dup_repo = Arc::new(InMemoryDuplicateRepository::new());
|
let dup_repo = Arc::new(InMemoryDuplicateRepository::new());
|
||||||
let events = Arc::new(StubEventPublisher::new());
|
let events = Arc::new(StubEventPublisher::new());
|
||||||
|
|
||||||
let handler = RegisterAssetHandler::new(
|
let handler = RegisterAssetHandler::new(asset_repo.clone(), dup_repo.clone(), events.clone());
|
||||||
asset_repo.clone(),
|
|
||||||
dup_repo.clone(),
|
|
||||||
events.clone(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let owner = SystemId::new();
|
let owner = SystemId::new();
|
||||||
let volume = SystemId::new();
|
let volume = SystemId::new();
|
||||||
|
|
||||||
let (asset, dup) = handler.execute(RegisterAssetCommand {
|
let (asset, dup) = handler
|
||||||
|
.execute(RegisterAssetCommand {
|
||||||
volume_id: volume,
|
volume_id: volume,
|
||||||
relative_path: "photos/img.jpg".into(),
|
relative_path: "photos/img.jpg".into(),
|
||||||
checksum: valid_checksum(),
|
checksum: valid_checksum(),
|
||||||
@@ -31,7 +30,9 @@ async fn registers_asset() {
|
|||||||
mime_type: "image/jpeg".into(),
|
mime_type: "image/jpeg".into(),
|
||||||
file_size: 1024,
|
file_size: 1024,
|
||||||
owner_id: owner,
|
owner_id: owner,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(asset.mime_type, "image/jpeg");
|
assert_eq!(asset.mime_type, "image/jpeg");
|
||||||
assert_eq!(asset.file_size, 1024);
|
assert_eq!(asset.file_size, 1024);
|
||||||
@@ -46,18 +47,15 @@ async fn flags_duplicate_when_checksum_exists() {
|
|||||||
let dup_repo = Arc::new(InMemoryDuplicateRepository::new());
|
let dup_repo = Arc::new(InMemoryDuplicateRepository::new());
|
||||||
let events = Arc::new(StubEventPublisher::new());
|
let events = Arc::new(StubEventPublisher::new());
|
||||||
|
|
||||||
let handler = RegisterAssetHandler::new(
|
let handler = RegisterAssetHandler::new(asset_repo.clone(), dup_repo.clone(), events.clone());
|
||||||
asset_repo.clone(),
|
|
||||||
dup_repo.clone(),
|
|
||||||
events.clone(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let owner = SystemId::new();
|
let owner = SystemId::new();
|
||||||
let volume = SystemId::new();
|
let volume = SystemId::new();
|
||||||
let checksum = valid_checksum();
|
let checksum = valid_checksum();
|
||||||
|
|
||||||
// First asset
|
// First asset
|
||||||
let (first, _) = handler.execute(RegisterAssetCommand {
|
let (first, _) = handler
|
||||||
|
.execute(RegisterAssetCommand {
|
||||||
volume_id: volume,
|
volume_id: volume,
|
||||||
relative_path: "photos/img1.jpg".into(),
|
relative_path: "photos/img1.jpg".into(),
|
||||||
checksum: checksum.clone(),
|
checksum: checksum.clone(),
|
||||||
@@ -65,10 +63,13 @@ async fn flags_duplicate_when_checksum_exists() {
|
|||||||
mime_type: "image/jpeg".into(),
|
mime_type: "image/jpeg".into(),
|
||||||
file_size: 1024,
|
file_size: 1024,
|
||||||
owner_id: owner,
|
owner_id: owner,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// Second asset with same checksum
|
// Second asset with same checksum
|
||||||
let (second, dup) = handler.execute(RegisterAssetCommand {
|
let (second, dup) = handler
|
||||||
|
.execute(RegisterAssetCommand {
|
||||||
volume_id: volume,
|
volume_id: volume,
|
||||||
relative_path: "photos/img2.jpg".into(),
|
relative_path: "photos/img2.jpg".into(),
|
||||||
checksum,
|
checksum,
|
||||||
@@ -76,7 +77,9 @@ async fn flags_duplicate_when_checksum_exists() {
|
|||||||
mime_type: "image/jpeg".into(),
|
mime_type: "image/jpeg".into(),
|
||||||
file_size: 1024,
|
file_size: 1024,
|
||||||
owner_id: owner,
|
owner_id: owner,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let group = dup.expect("should flag duplicate");
|
let group = dup.expect("should flag duplicate");
|
||||||
let candidate_ids: Vec<_> = group.candidates.iter().map(|c| c.asset_id).collect();
|
let candidate_ids: Vec<_> = group.candidates.iter().map(|c| c.asset_id).collect();
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use application::catalog::{UpdateMetadataCommand, UpdateMetadataHandler};
|
use application::catalog::{UpdateMetadataCommand, UpdateMetadataHandler};
|
||||||
use application::testing::{InMemoryAssetRepository, InMemoryAssetMetadataRepository, StubEventPublisher};
|
use application::testing::{
|
||||||
use domain::catalog::entities::{Asset, AssetType, SourceReference, MetadataSource};
|
InMemoryAssetMetadataRepository, InMemoryAssetRepository, StubEventPublisher,
|
||||||
|
};
|
||||||
|
use domain::catalog::entities::{Asset, AssetType, MetadataSource, SourceReference};
|
||||||
use domain::errors::DomainError;
|
use domain::errors::DomainError;
|
||||||
use domain::value_objects::{Checksum, MetadataValue, StructuredData, SystemId};
|
use domain::value_objects::{Checksum, MetadataValue, StructuredData, SystemId};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
async fn seed_asset(repo: &InMemoryAssetRepository) -> Asset {
|
async fn seed_asset(repo: &InMemoryAssetRepository) -> Asset {
|
||||||
let source = SourceReference {
|
let source = SourceReference {
|
||||||
@@ -11,7 +13,13 @@ async fn seed_asset(repo: &InMemoryAssetRepository) -> Asset {
|
|||||||
relative_path: "photos/img.jpg".into(),
|
relative_path: "photos/img.jpg".into(),
|
||||||
checksum: Checksum::new("a".repeat(64)).unwrap(),
|
checksum: Checksum::new("a".repeat(64)).unwrap(),
|
||||||
};
|
};
|
||||||
let asset = Asset::new(source, AssetType::Image, "image/jpeg", 1024, SystemId::new());
|
let asset = Asset::new(
|
||||||
|
source,
|
||||||
|
AssetType::Image,
|
||||||
|
"image/jpeg",
|
||||||
|
1024,
|
||||||
|
SystemId::new(),
|
||||||
|
);
|
||||||
repo.save(&asset).await.unwrap();
|
repo.save(&asset).await.unwrap();
|
||||||
asset
|
asset
|
||||||
}
|
}
|
||||||
@@ -26,20 +34,19 @@ async fn updates_metadata() {
|
|||||||
|
|
||||||
let asset = seed_asset(&asset_repo).await;
|
let asset = seed_asset(&asset_repo).await;
|
||||||
|
|
||||||
let handler = UpdateMetadataHandler::new(
|
let handler = UpdateMetadataHandler::new(asset_repo.clone(), meta_repo.clone(), events.clone());
|
||||||
asset_repo.clone(),
|
|
||||||
meta_repo.clone(),
|
|
||||||
events.clone(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut data = StructuredData::new();
|
let mut data = StructuredData::new();
|
||||||
data.insert("title", MetadataValue::String("Sunset".into()));
|
data.insert("title", MetadataValue::String("Sunset".into()));
|
||||||
|
|
||||||
let result = handler.execute(UpdateMetadataCommand {
|
let result = handler
|
||||||
|
.execute(UpdateMetadataCommand {
|
||||||
asset_id: asset.asset_id,
|
asset_id: asset.asset_id,
|
||||||
user_id: SystemId::new(),
|
user_id: SystemId::new(),
|
||||||
data,
|
data,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(result.metadata_source, MetadataSource::UserEdited);
|
assert_eq!(result.metadata_source, MetadataSource::UserEdited);
|
||||||
assert_eq!(result.data.get_string("title"), Some("Sunset"));
|
assert_eq!(result.data.get_string("title"), Some("Sunset"));
|
||||||
@@ -54,11 +61,13 @@ async fn rejects_nonexistent_asset() {
|
|||||||
|
|
||||||
let handler = UpdateMetadataHandler::new(asset_repo, meta_repo, events);
|
let handler = UpdateMetadataHandler::new(asset_repo, meta_repo, events);
|
||||||
|
|
||||||
let result = handler.execute(UpdateMetadataCommand {
|
let result = handler
|
||||||
|
.execute(UpdateMetadataCommand {
|
||||||
asset_id: SystemId::new(),
|
asset_id: SystemId::new(),
|
||||||
user_id: SystemId::new(),
|
user_id: SystemId::new(),
|
||||||
data: StructuredData::new(),
|
data: StructuredData::new(),
|
||||||
}).await;
|
})
|
||||||
|
.await;
|
||||||
|
|
||||||
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::sync::Arc;
|
use application::catalog::{GetAssetHandler, GetAssetQuery};
|
||||||
use application::catalog::{GetAssetQuery, GetAssetHandler};
|
use application::testing::{InMemoryAssetMetadataRepository, InMemoryAssetRepository};
|
||||||
use application::testing::{InMemoryAssetRepository, InMemoryAssetMetadataRepository};
|
|
||||||
use domain::catalog::entities::{Asset, AssetMetadata, AssetType, MetadataSource, SourceReference};
|
use domain::catalog::entities::{Asset, AssetMetadata, AssetType, MetadataSource, SourceReference};
|
||||||
use domain::errors::DomainError;
|
use domain::errors::DomainError;
|
||||||
use domain::ports::{AssetRepository, AssetMetadataRepository};
|
use domain::ports::{AssetMetadataRepository, AssetRepository};
|
||||||
use domain::value_objects::{Checksum, MetadataValue, StructuredData, SystemId};
|
use domain::value_objects::{Checksum, MetadataValue, StructuredData, SystemId};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn returns_asset_with_resolved_metadata() {
|
async fn returns_asset_with_resolved_metadata() {
|
||||||
@@ -16,7 +16,13 @@ async fn returns_asset_with_resolved_metadata() {
|
|||||||
relative_path: "photos/img.jpg".into(),
|
relative_path: "photos/img.jpg".into(),
|
||||||
checksum: Checksum::new("a".repeat(64)).unwrap(),
|
checksum: Checksum::new("a".repeat(64)).unwrap(),
|
||||||
};
|
};
|
||||||
let asset = Asset::new(source, AssetType::Image, "image/jpeg", 1024, SystemId::new());
|
let asset = Asset::new(
|
||||||
|
source,
|
||||||
|
AssetType::Image,
|
||||||
|
"image/jpeg",
|
||||||
|
1024,
|
||||||
|
SystemId::new(),
|
||||||
|
);
|
||||||
asset_repo.save(&asset).await.unwrap();
|
asset_repo.save(&asset).await.unwrap();
|
||||||
|
|
||||||
// Add exif layer
|
// Add exif layer
|
||||||
@@ -33,9 +39,12 @@ async fn returns_asset_with_resolved_metadata() {
|
|||||||
meta_repo.save(&user_meta).await.unwrap();
|
meta_repo.save(&user_meta).await.unwrap();
|
||||||
|
|
||||||
let handler = GetAssetHandler::new(asset_repo, meta_repo);
|
let handler = GetAssetHandler::new(asset_repo, meta_repo);
|
||||||
let (returned, resolved) = handler.execute(GetAssetQuery {
|
let (returned, resolved) = handler
|
||||||
|
.execute(GetAssetQuery {
|
||||||
asset_id: asset.asset_id,
|
asset_id: asset.asset_id,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(returned.asset_id, asset.asset_id);
|
assert_eq!(returned.asset_id, asset.asset_id);
|
||||||
// UserEdited overrides ExifExtracted
|
// UserEdited overrides ExifExtracted
|
||||||
@@ -50,9 +59,11 @@ async fn rejects_nonexistent() {
|
|||||||
let meta_repo = Arc::new(InMemoryAssetMetadataRepository::new());
|
let meta_repo = Arc::new(InMemoryAssetMetadataRepository::new());
|
||||||
|
|
||||||
let handler = GetAssetHandler::new(asset_repo, meta_repo);
|
let handler = GetAssetHandler::new(asset_repo, meta_repo);
|
||||||
let result = handler.execute(GetAssetQuery {
|
let result = handler
|
||||||
|
.execute(GetAssetQuery {
|
||||||
asset_id: SystemId::new(),
|
asset_id: SystemId::new(),
|
||||||
}).await;
|
})
|
||||||
|
.await;
|
||||||
|
|
||||||
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
use std::sync::Arc;
|
use application::catalog::{GetTimelineHandler, GetTimelineQuery};
|
||||||
use application::catalog::{GetTimelineQuery, GetTimelineHandler};
|
use application::testing::{InMemoryAssetMetadataRepository, InMemoryAssetRepository};
|
||||||
use application::testing::{InMemoryAssetRepository, InMemoryAssetMetadataRepository};
|
|
||||||
use domain::catalog::entities::{Asset, AssetType, SourceReference};
|
use domain::catalog::entities::{Asset, AssetType, SourceReference};
|
||||||
use domain::ports::AssetRepository;
|
use domain::ports::AssetRepository;
|
||||||
use domain::value_objects::{Checksum, SystemId};
|
use domain::value_objects::{Checksum, SystemId};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
async fn seed_assets(repo: &InMemoryAssetRepository, owner: SystemId, count: usize) {
|
async fn seed_assets(repo: &InMemoryAssetRepository, owner: SystemId, count: usize) {
|
||||||
for i in 0..count {
|
for i in 0..count {
|
||||||
@@ -28,11 +28,14 @@ async fn returns_paginated_assets() {
|
|||||||
|
|
||||||
let handler = GetTimelineHandler::new(asset_repo, meta_repo);
|
let handler = GetTimelineHandler::new(asset_repo, meta_repo);
|
||||||
|
|
||||||
let page = handler.execute(GetTimelineQuery {
|
let page = handler
|
||||||
|
.execute(GetTimelineQuery {
|
||||||
owner_id: owner,
|
owner_id: owner,
|
||||||
limit: 3,
|
limit: 3,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(page.len(), 3);
|
assert_eq!(page.len(), 3);
|
||||||
}
|
}
|
||||||
@@ -44,11 +47,14 @@ async fn returns_empty_for_no_assets() {
|
|||||||
|
|
||||||
let handler = GetTimelineHandler::new(asset_repo, meta_repo);
|
let handler = GetTimelineHandler::new(asset_repo, meta_repo);
|
||||||
|
|
||||||
let page = handler.execute(GetTimelineQuery {
|
let page = handler
|
||||||
|
.execute(GetTimelineQuery {
|
||||||
owner_id: SystemId::new(),
|
owner_id: SystemId::new(),
|
||||||
limit: 10,
|
limit: 10,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert!(page.is_empty());
|
assert!(page.is_empty());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
mod get_timeline;
|
|
||||||
mod get_asset;
|
mod get_asset;
|
||||||
|
mod get_timeline;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use application::testing::{InMemoryUserRepository, StubPasswordHasher};
|
|
||||||
use application::identity::{RegisterUserCommand, RegisterUserHandler};
|
use application::identity::{RegisterUserCommand, RegisterUserHandler};
|
||||||
|
use application::testing::{InMemoryUserRepository, StubPasswordHasher};
|
||||||
use domain::errors::DomainError;
|
use domain::errors::DomainError;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn registers_new_user() {
|
async fn registers_new_user() {
|
||||||
@@ -22,16 +22,21 @@ async fn registers_new_user() {
|
|||||||
async fn rejects_duplicate_email() {
|
async fn rejects_duplicate_email() {
|
||||||
let repo = Arc::new(InMemoryUserRepository::new());
|
let repo = Arc::new(InMemoryUserRepository::new());
|
||||||
let handler = RegisterUserHandler::new(repo.clone(), Arc::new(StubPasswordHasher));
|
let handler = RegisterUserHandler::new(repo.clone(), Arc::new(StubPasswordHasher));
|
||||||
handler.execute(RegisterUserCommand {
|
handler
|
||||||
|
.execute(RegisterUserCommand {
|
||||||
username: "user1".into(),
|
username: "user1".into(),
|
||||||
email: "test@example.com".into(),
|
email: "test@example.com".into(),
|
||||||
password: "password123".into(),
|
password: "password123".into(),
|
||||||
}).await.unwrap();
|
})
|
||||||
let result = handler.execute(RegisterUserCommand {
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let result = handler
|
||||||
|
.execute(RegisterUserCommand {
|
||||||
username: "user2".into(),
|
username: "user2".into(),
|
||||||
email: "test@example.com".into(),
|
email: "test@example.com".into(),
|
||||||
password: "different1".into(),
|
password: "different1".into(),
|
||||||
}).await;
|
})
|
||||||
|
.await;
|
||||||
assert!(matches!(result, Err(DomainError::Conflict(_))));
|
assert!(matches!(result, Err(DomainError::Conflict(_))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,16 +44,21 @@ async fn rejects_duplicate_email() {
|
|||||||
async fn rejects_duplicate_username() {
|
async fn rejects_duplicate_username() {
|
||||||
let repo = Arc::new(InMemoryUserRepository::new());
|
let repo = Arc::new(InMemoryUserRepository::new());
|
||||||
let handler = RegisterUserHandler::new(repo.clone(), Arc::new(StubPasswordHasher));
|
let handler = RegisterUserHandler::new(repo.clone(), Arc::new(StubPasswordHasher));
|
||||||
handler.execute(RegisterUserCommand {
|
handler
|
||||||
|
.execute(RegisterUserCommand {
|
||||||
username: "sameuser".into(),
|
username: "sameuser".into(),
|
||||||
email: "a@example.com".into(),
|
email: "a@example.com".into(),
|
||||||
password: "password123".into(),
|
password: "password123".into(),
|
||||||
}).await.unwrap();
|
})
|
||||||
let result = handler.execute(RegisterUserCommand {
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let result = handler
|
||||||
|
.execute(RegisterUserCommand {
|
||||||
username: "sameuser".into(),
|
username: "sameuser".into(),
|
||||||
email: "b@example.com".into(),
|
email: "b@example.com".into(),
|
||||||
password: "password123".into(),
|
password: "password123".into(),
|
||||||
}).await;
|
})
|
||||||
|
.await;
|
||||||
assert!(matches!(result, Err(DomainError::Conflict(_))));
|
assert!(matches!(result, Err(DomainError::Conflict(_))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,11 +66,13 @@ async fn rejects_duplicate_username() {
|
|||||||
async fn rejects_short_password() {
|
async fn rejects_short_password() {
|
||||||
let repo = Arc::new(InMemoryUserRepository::new());
|
let repo = Arc::new(InMemoryUserRepository::new());
|
||||||
let handler = RegisterUserHandler::new(repo, Arc::new(StubPasswordHasher));
|
let handler = RegisterUserHandler::new(repo, Arc::new(StubPasswordHasher));
|
||||||
let result = handler.execute(RegisterUserCommand {
|
let result = handler
|
||||||
|
.execute(RegisterUserCommand {
|
||||||
username: "user".into(),
|
username: "user".into(),
|
||||||
email: "test@example.com".into(),
|
email: "test@example.com".into(),
|
||||||
password: "short".into(),
|
password: "short".into(),
|
||||||
}).await;
|
})
|
||||||
|
.await;
|
||||||
assert!(matches!(result, Err(DomainError::Validation(_))));
|
assert!(matches!(result, Err(DomainError::Validation(_))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,10 +80,12 @@ async fn rejects_short_password() {
|
|||||||
async fn rejects_empty_username() {
|
async fn rejects_empty_username() {
|
||||||
let repo = Arc::new(InMemoryUserRepository::new());
|
let repo = Arc::new(InMemoryUserRepository::new());
|
||||||
let handler = RegisterUserHandler::new(repo, Arc::new(StubPasswordHasher));
|
let handler = RegisterUserHandler::new(repo, Arc::new(StubPasswordHasher));
|
||||||
let result = handler.execute(RegisterUserCommand {
|
let result = handler
|
||||||
|
.execute(RegisterUserCommand {
|
||||||
username: "".into(),
|
username: "".into(),
|
||||||
email: "test@example.com".into(),
|
email: "test@example.com".into(),
|
||||||
password: "password123".into(),
|
password: "password123".into(),
|
||||||
}).await;
|
})
|
||||||
|
.await;
|
||||||
assert!(matches!(result, Err(DomainError::Validation(_))));
|
assert!(matches!(result, Err(DomainError::Validation(_))));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,29 @@
|
|||||||
use std::sync::Arc;
|
use application::identity::{
|
||||||
|
GetProfileHandler, GetProfileQuery, RegisterUserCommand, RegisterUserHandler,
|
||||||
|
};
|
||||||
use application::testing::{InMemoryUserRepository, StubPasswordHasher};
|
use application::testing::{InMemoryUserRepository, StubPasswordHasher};
|
||||||
use application::identity::{RegisterUserCommand, RegisterUserHandler, GetProfileQuery, GetProfileHandler};
|
|
||||||
use domain::errors::DomainError;
|
use domain::errors::DomainError;
|
||||||
use domain::value_objects::SystemId;
|
use domain::value_objects::SystemId;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn returns_existing_user() {
|
async fn returns_existing_user() {
|
||||||
let repo = Arc::new(InMemoryUserRepository::new());
|
let repo = Arc::new(InMemoryUserRepository::new());
|
||||||
let reg = RegisterUserHandler::new(repo.clone(), Arc::new(StubPasswordHasher));
|
let reg = RegisterUserHandler::new(repo.clone(), Arc::new(StubPasswordHasher));
|
||||||
let user = reg.execute(RegisterUserCommand {
|
let user = reg
|
||||||
|
.execute(RegisterUserCommand {
|
||||||
username: "alice".into(),
|
username: "alice".into(),
|
||||||
email: "alice@example.com".into(),
|
email: "alice@example.com".into(),
|
||||||
password: "password123".into(),
|
password: "password123".into(),
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let handler = GetProfileHandler::new(repo);
|
let handler = GetProfileHandler::new(repo);
|
||||||
let found = handler.execute(GetProfileQuery { user_id: user.id }).await.unwrap();
|
let found = handler
|
||||||
|
.execute(GetProfileQuery { user_id: user.id })
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
assert_eq!(found.username, "alice");
|
assert_eq!(found.username, "alice");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,6 +31,10 @@ async fn returns_existing_user() {
|
|||||||
async fn returns_not_found_for_missing_user() {
|
async fn returns_not_found_for_missing_user() {
|
||||||
let repo = Arc::new(InMemoryUserRepository::new());
|
let repo = Arc::new(InMemoryUserRepository::new());
|
||||||
let handler = GetProfileHandler::new(repo);
|
let handler = GetProfileHandler::new(repo);
|
||||||
let result = handler.execute(GetProfileQuery { user_id: SystemId::new() }).await;
|
let result = handler
|
||||||
|
.execute(GetProfileQuery {
|
||||||
|
user_id: SystemId::new(),
|
||||||
|
})
|
||||||
|
.await;
|
||||||
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,21 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use application::testing::InMemoryAlbumRepository;
|
|
||||||
use application::organization::{CreateAlbumCommand, CreateAlbumHandler};
|
use application::organization::{CreateAlbumCommand, CreateAlbumHandler};
|
||||||
|
use application::testing::InMemoryAlbumRepository;
|
||||||
use domain::errors::DomainError;
|
use domain::errors::DomainError;
|
||||||
use domain::value_objects::SystemId;
|
use domain::value_objects::SystemId;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn creates_album() {
|
async fn creates_album() {
|
||||||
let repo = Arc::new(InMemoryAlbumRepository::new());
|
let repo = Arc::new(InMemoryAlbumRepository::new());
|
||||||
let handler = CreateAlbumHandler::new(repo);
|
let handler = CreateAlbumHandler::new(repo);
|
||||||
let creator = SystemId::new();
|
let creator = SystemId::new();
|
||||||
let album = handler.execute(CreateAlbumCommand {
|
let album = handler
|
||||||
|
.execute(CreateAlbumCommand {
|
||||||
title: "Vacation 2024".into(),
|
title: "Vacation 2024".into(),
|
||||||
creator_id: creator,
|
creator_id: creator,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
assert_eq!(album.title, "Vacation 2024");
|
assert_eq!(album.title, "Vacation 2024");
|
||||||
assert_eq!(album.creator_user_id, creator);
|
assert_eq!(album.creator_user_id, creator);
|
||||||
assert_eq!(album.asset_count(), 0);
|
assert_eq!(album.asset_count(), 0);
|
||||||
@@ -22,9 +25,11 @@ async fn creates_album() {
|
|||||||
async fn rejects_empty_title() {
|
async fn rejects_empty_title() {
|
||||||
let repo = Arc::new(InMemoryAlbumRepository::new());
|
let repo = Arc::new(InMemoryAlbumRepository::new());
|
||||||
let handler = CreateAlbumHandler::new(repo);
|
let handler = CreateAlbumHandler::new(repo);
|
||||||
let result = handler.execute(CreateAlbumCommand {
|
let result = handler
|
||||||
|
.execute(CreateAlbumCommand {
|
||||||
title: "".into(),
|
title: "".into(),
|
||||||
creator_id: SystemId::new(),
|
creator_id: SystemId::new(),
|
||||||
}).await;
|
})
|
||||||
|
.await;
|
||||||
assert!(matches!(result, Err(DomainError::Validation(_))));
|
assert!(matches!(result, Err(DomainError::Validation(_))));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,21 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use application::testing::InMemoryAlbumRepository;
|
|
||||||
use application::organization::{
|
use application::organization::{
|
||||||
AlbumAction, CreateAlbumCommand, CreateAlbumHandler,
|
AlbumAction, CreateAlbumCommand, CreateAlbumHandler, ManageAlbumEntriesCommand,
|
||||||
ManageAlbumEntriesCommand, ManageAlbumEntriesHandler,
|
ManageAlbumEntriesHandler,
|
||||||
};
|
};
|
||||||
|
use application::testing::InMemoryAlbumRepository;
|
||||||
use domain::errors::DomainError;
|
use domain::errors::DomainError;
|
||||||
use domain::value_objects::SystemId;
|
use domain::value_objects::SystemId;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
async fn setup_album(repo: &Arc<InMemoryAlbumRepository>, creator: SystemId) -> SystemId {
|
async fn setup_album(repo: &Arc<InMemoryAlbumRepository>, creator: SystemId) -> SystemId {
|
||||||
let handler = CreateAlbumHandler::new(repo.clone());
|
let handler = CreateAlbumHandler::new(repo.clone());
|
||||||
let album = handler.execute(CreateAlbumCommand {
|
let album = handler
|
||||||
|
.execute(CreateAlbumCommand {
|
||||||
title: "Test Album".into(),
|
title: "Test Album".into(),
|
||||||
creator_id: creator,
|
creator_id: creator,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
album.album_id
|
album.album_id
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,11 +27,14 @@ async fn adds_asset_to_album() {
|
|||||||
let asset_id = SystemId::new();
|
let asset_id = SystemId::new();
|
||||||
|
|
||||||
let handler = ManageAlbumEntriesHandler::new(repo.clone());
|
let handler = ManageAlbumEntriesHandler::new(repo.clone());
|
||||||
let album = handler.execute(ManageAlbumEntriesCommand {
|
let album = handler
|
||||||
|
.execute(ManageAlbumEntriesCommand {
|
||||||
album_id,
|
album_id,
|
||||||
action: AlbumAction::Add { asset_id },
|
action: AlbumAction::Add { asset_id },
|
||||||
user_id: user,
|
user_id: user,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(album.asset_count(), 1);
|
assert_eq!(album.asset_count(), 1);
|
||||||
assert_eq!(album.entries[0].asset_id, asset_id);
|
assert_eq!(album.entries[0].asset_id, asset_id);
|
||||||
@@ -42,17 +48,23 @@ async fn removes_asset_from_album() {
|
|||||||
let asset_id = SystemId::new();
|
let asset_id = SystemId::new();
|
||||||
|
|
||||||
let handler = ManageAlbumEntriesHandler::new(repo.clone());
|
let handler = ManageAlbumEntriesHandler::new(repo.clone());
|
||||||
handler.execute(ManageAlbumEntriesCommand {
|
handler
|
||||||
|
.execute(ManageAlbumEntriesCommand {
|
||||||
album_id,
|
album_id,
|
||||||
action: AlbumAction::Add { asset_id },
|
action: AlbumAction::Add { asset_id },
|
||||||
user_id: user,
|
user_id: user,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let album = handler.execute(ManageAlbumEntriesCommand {
|
let album = handler
|
||||||
|
.execute(ManageAlbumEntriesCommand {
|
||||||
album_id,
|
album_id,
|
||||||
action: AlbumAction::Remove { asset_id },
|
action: AlbumAction::Remove { asset_id },
|
||||||
user_id: user,
|
user_id: user,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(album.asset_count(), 0);
|
assert_eq!(album.asset_count(), 0);
|
||||||
}
|
}
|
||||||
@@ -61,11 +73,15 @@ async fn removes_asset_from_album() {
|
|||||||
async fn rejects_nonexistent_album() {
|
async fn rejects_nonexistent_album() {
|
||||||
let repo = Arc::new(InMemoryAlbumRepository::new());
|
let repo = Arc::new(InMemoryAlbumRepository::new());
|
||||||
let handler = ManageAlbumEntriesHandler::new(repo);
|
let handler = ManageAlbumEntriesHandler::new(repo);
|
||||||
let result = handler.execute(ManageAlbumEntriesCommand {
|
let result = handler
|
||||||
|
.execute(ManageAlbumEntriesCommand {
|
||||||
album_id: SystemId::new(),
|
album_id: SystemId::new(),
|
||||||
action: AlbumAction::Add { asset_id: SystemId::new() },
|
action: AlbumAction::Add {
|
||||||
|
asset_id: SystemId::new(),
|
||||||
|
},
|
||||||
user_id: SystemId::new(),
|
user_id: SystemId::new(),
|
||||||
}).await;
|
})
|
||||||
|
.await;
|
||||||
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,16 +93,21 @@ async fn rejects_duplicate_add() {
|
|||||||
let asset_id = SystemId::new();
|
let asset_id = SystemId::new();
|
||||||
|
|
||||||
let handler = ManageAlbumEntriesHandler::new(repo.clone());
|
let handler = ManageAlbumEntriesHandler::new(repo.clone());
|
||||||
handler.execute(ManageAlbumEntriesCommand {
|
handler
|
||||||
|
.execute(ManageAlbumEntriesCommand {
|
||||||
album_id,
|
album_id,
|
||||||
action: AlbumAction::Add { asset_id },
|
action: AlbumAction::Add { asset_id },
|
||||||
user_id: user,
|
user_id: user,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let result = handler.execute(ManageAlbumEntriesCommand {
|
let result = handler
|
||||||
|
.execute(ManageAlbumEntriesCommand {
|
||||||
album_id,
|
album_id,
|
||||||
action: AlbumAction::Add { asset_id },
|
action: AlbumAction::Add { asset_id },
|
||||||
user_id: user,
|
user_id: user,
|
||||||
}).await;
|
})
|
||||||
|
.await;
|
||||||
assert!(matches!(result, Err(DomainError::Conflict(_))));
|
assert!(matches!(result, Err(DomainError::Conflict(_))));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use application::testing::{InMemoryAssetRepository, InMemoryTagRepository};
|
|
||||||
use application::organization::{TagAssetCommand, TagAssetHandler};
|
use application::organization::{TagAssetCommand, TagAssetHandler};
|
||||||
|
use application::testing::{InMemoryAssetRepository, InMemoryTagRepository};
|
||||||
use domain::entities::{Asset, AssetType, SourceReference};
|
use domain::entities::{Asset, AssetType, SourceReference};
|
||||||
use domain::errors::DomainError;
|
use domain::errors::DomainError;
|
||||||
use domain::ports::{AssetRepository, TagRepository};
|
use domain::ports::{AssetRepository, TagRepository};
|
||||||
use domain::value_objects::{Checksum, SystemId};
|
use domain::value_objects::{Checksum, SystemId};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
async fn seed_asset(repo: &Arc<InMemoryAssetRepository>) -> SystemId {
|
async fn seed_asset(repo: &Arc<InMemoryAssetRepository>) -> SystemId {
|
||||||
let owner = SystemId::new();
|
let owner = SystemId::new();
|
||||||
@@ -32,11 +32,14 @@ async fn tags_asset_creates_new_tag() {
|
|||||||
let user = SystemId::new();
|
let user = SystemId::new();
|
||||||
|
|
||||||
let handler = TagAssetHandler::new(asset_repo, tag_repo);
|
let handler = TagAssetHandler::new(asset_repo, tag_repo);
|
||||||
let (tag, asset_tag) = handler.execute(TagAssetCommand {
|
let (tag, asset_tag) = handler
|
||||||
|
.execute(TagAssetCommand {
|
||||||
asset_id,
|
asset_id,
|
||||||
tag_name: "sunset".into(),
|
tag_name: "sunset".into(),
|
||||||
user_id: user,
|
user_id: user,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(tag.name, "sunset");
|
assert_eq!(tag.name, "sunset");
|
||||||
assert_eq!(asset_tag.asset_id, asset_id);
|
assert_eq!(asset_tag.asset_id, asset_id);
|
||||||
@@ -57,11 +60,14 @@ async fn reuses_existing_tag() {
|
|||||||
tag_repo.save_tag(&existing).await.unwrap();
|
tag_repo.save_tag(&existing).await.unwrap();
|
||||||
|
|
||||||
let handler = TagAssetHandler::new(asset_repo, tag_repo);
|
let handler = TagAssetHandler::new(asset_repo, tag_repo);
|
||||||
let (tag, _) = handler.execute(TagAssetCommand {
|
let (tag, _) = handler
|
||||||
|
.execute(TagAssetCommand {
|
||||||
asset_id,
|
asset_id,
|
||||||
tag_name: "sunset".into(),
|
tag_name: "sunset".into(),
|
||||||
user_id: user,
|
user_id: user,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(tag.tag_id, existing_id);
|
assert_eq!(tag.tag_id, existing_id);
|
||||||
}
|
}
|
||||||
@@ -72,10 +78,12 @@ async fn rejects_nonexistent_asset() {
|
|||||||
let tag_repo = Arc::new(InMemoryTagRepository::new());
|
let tag_repo = Arc::new(InMemoryTagRepository::new());
|
||||||
|
|
||||||
let handler = TagAssetHandler::new(asset_repo, tag_repo);
|
let handler = TagAssetHandler::new(asset_repo, tag_repo);
|
||||||
let result = handler.execute(TagAssetCommand {
|
let result = handler
|
||||||
|
.execute(TagAssetCommand {
|
||||||
asset_id: SystemId::new(),
|
asset_id: SystemId::new(),
|
||||||
tag_name: "sunset".into(),
|
tag_name: "sunset".into(),
|
||||||
user_id: SystemId::new(),
|
user_id: SystemId::new(),
|
||||||
}).await;
|
})
|
||||||
|
.await;
|
||||||
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use application::testing::InMemoryAlbumRepository;
|
|
||||||
use application::organization::{
|
use application::organization::{
|
||||||
CreateAlbumCommand, CreateAlbumHandler,
|
CreateAlbumCommand, CreateAlbumHandler, GetAlbumHandler, GetAlbumQuery,
|
||||||
GetAlbumQuery, GetAlbumHandler,
|
|
||||||
};
|
};
|
||||||
|
use application::testing::InMemoryAlbumRepository;
|
||||||
use domain::errors::DomainError;
|
use domain::errors::DomainError;
|
||||||
use domain::value_objects::SystemId;
|
use domain::value_objects::SystemId;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn returns_album() {
|
async fn returns_album() {
|
||||||
@@ -13,15 +12,21 @@ async fn returns_album() {
|
|||||||
let creator = SystemId::new();
|
let creator = SystemId::new();
|
||||||
|
|
||||||
let create_handler = CreateAlbumHandler::new(repo.clone());
|
let create_handler = CreateAlbumHandler::new(repo.clone());
|
||||||
let album = create_handler.execute(CreateAlbumCommand {
|
let album = create_handler
|
||||||
|
.execute(CreateAlbumCommand {
|
||||||
title: "My Album".into(),
|
title: "My Album".into(),
|
||||||
creator_id: creator,
|
creator_id: creator,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let query_handler = GetAlbumHandler::new(repo);
|
let query_handler = GetAlbumHandler::new(repo);
|
||||||
let found = query_handler.execute(GetAlbumQuery {
|
let found = query_handler
|
||||||
|
.execute(GetAlbumQuery {
|
||||||
album_id: album.album_id,
|
album_id: album.album_id,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(found.album_id, album.album_id);
|
assert_eq!(found.album_id, album.album_id);
|
||||||
assert_eq!(found.title, "My Album");
|
assert_eq!(found.title, "My Album");
|
||||||
@@ -31,8 +36,10 @@ async fn returns_album() {
|
|||||||
async fn rejects_nonexistent() {
|
async fn rejects_nonexistent() {
|
||||||
let repo = Arc::new(InMemoryAlbumRepository::new());
|
let repo = Arc::new(InMemoryAlbumRepository::new());
|
||||||
let handler = GetAlbumHandler::new(repo);
|
let handler = GetAlbumHandler::new(repo);
|
||||||
let result = handler.execute(GetAlbumQuery {
|
let result = handler
|
||||||
|
.execute(GetAlbumQuery {
|
||||||
album_id: SystemId::new(),
|
album_id: SystemId::new(),
|
||||||
}).await;
|
})
|
||||||
|
.await;
|
||||||
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use application::testing::{InMemoryJobBatchRepository, InMemoryJobRepository, StubEventPublisher};
|
|
||||||
use application::processing::{CompleteJobCommand, CompleteJobHandler};
|
use application::processing::{CompleteJobCommand, CompleteJobHandler};
|
||||||
|
use application::testing::{InMemoryJobBatchRepository, InMemoryJobRepository, StubEventPublisher};
|
||||||
use domain::entities::{Job, JobBatch, JobStatus, JobType};
|
use domain::entities::{Job, JobBatch, JobStatus, JobType};
|
||||||
use domain::events::DomainEvent;
|
use domain::events::DomainEvent;
|
||||||
use domain::ports::{JobBatchRepository, JobRepository};
|
use domain::ports::{JobBatchRepository, JobRepository};
|
||||||
use domain::value_objects::StructuredData;
|
use domain::value_objects::StructuredData;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn completes_job() {
|
async fn completes_job() {
|
||||||
@@ -18,10 +18,13 @@ async fn completes_job() {
|
|||||||
job_repo.save(&job).await.unwrap();
|
job_repo.save(&job).await.unwrap();
|
||||||
|
|
||||||
let handler = CompleteJobHandler::new(job_repo.clone(), batch_repo.clone(), event_pub.clone());
|
let handler = CompleteJobHandler::new(job_repo.clone(), batch_repo.clone(), event_pub.clone());
|
||||||
let result = handler.execute(CompleteJobCommand {
|
let result = handler
|
||||||
|
.execute(CompleteJobCommand {
|
||||||
job_id,
|
job_id,
|
||||||
result: StructuredData::new(),
|
result: StructuredData::new(),
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(result.status, JobStatus::Completed);
|
assert_eq!(result.status, JobStatus::Completed);
|
||||||
assert!(result.result_data.is_some());
|
assert!(result.result_data.is_some());
|
||||||
@@ -37,17 +40,19 @@ async fn completes_job_and_updates_batch() {
|
|||||||
let batch_id = batch.batch_id;
|
let batch_id = batch.batch_id;
|
||||||
batch_repo.save(&batch).await.unwrap();
|
batch_repo.save(&batch).await.unwrap();
|
||||||
|
|
||||||
let mut job = Job::new(JobType::ExtractMetadata, 5, StructuredData::new())
|
let mut job = Job::new(JobType::ExtractMetadata, 5, StructuredData::new()).with_batch(batch_id);
|
||||||
.with_batch(batch_id);
|
|
||||||
job.start().unwrap();
|
job.start().unwrap();
|
||||||
let job_id = job.job_id;
|
let job_id = job.job_id;
|
||||||
job_repo.save(&job).await.unwrap();
|
job_repo.save(&job).await.unwrap();
|
||||||
|
|
||||||
let handler = CompleteJobHandler::new(job_repo.clone(), batch_repo.clone(), event_pub.clone());
|
let handler = CompleteJobHandler::new(job_repo.clone(), batch_repo.clone(), event_pub.clone());
|
||||||
handler.execute(CompleteJobCommand {
|
handler
|
||||||
|
.execute(CompleteJobCommand {
|
||||||
job_id,
|
job_id,
|
||||||
result: StructuredData::new(),
|
result: StructuredData::new(),
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let updated_batch = batch_repo.find_by_id(&batch_id).await.unwrap().unwrap();
|
let updated_batch = batch_repo.find_by_id(&batch_id).await.unwrap().unwrap();
|
||||||
assert_eq!(updated_batch.completed_count, 1);
|
assert_eq!(updated_batch.completed_count, 1);
|
||||||
@@ -65,10 +70,13 @@ async fn publishes_event() {
|
|||||||
job_repo.save(&job).await.unwrap();
|
job_repo.save(&job).await.unwrap();
|
||||||
|
|
||||||
let handler = CompleteJobHandler::new(job_repo.clone(), batch_repo.clone(), event_pub.clone());
|
let handler = CompleteJobHandler::new(job_repo.clone(), batch_repo.clone(), event_pub.clone());
|
||||||
handler.execute(CompleteJobCommand {
|
handler
|
||||||
|
.execute(CompleteJobCommand {
|
||||||
job_id,
|
job_id,
|
||||||
result: StructuredData::new(),
|
result: StructuredData::new(),
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let events = event_pub.published().await;
|
let events = event_pub.published().await;
|
||||||
assert_eq!(events.len(), 1);
|
assert_eq!(events.len(), 1);
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
use std::sync::Arc;
|
use application::processing::{
|
||||||
|
ConfigurePipelineCommand, ConfigurePipelineHandler, PipelineStepConfig,
|
||||||
|
};
|
||||||
use application::testing::{InMemoryPipelineRepository, InMemoryPluginRepository};
|
use application::testing::{InMemoryPipelineRepository, InMemoryPluginRepository};
|
||||||
use application::processing::{ConfigurePipelineCommand, ConfigurePipelineHandler, PipelineStepConfig};
|
|
||||||
use domain::entities::{Plugin, PluginType};
|
use domain::entities::{Plugin, PluginType};
|
||||||
use domain::errors::DomainError;
|
use domain::errors::DomainError;
|
||||||
use domain::ports::PluginRepository;
|
use domain::ports::PluginRepository;
|
||||||
use domain::value_objects::{StructuredData, SystemId};
|
use domain::value_objects::{StructuredData, SystemId};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn creates_pipeline() {
|
async fn creates_pipeline() {
|
||||||
@@ -19,13 +21,22 @@ async fn creates_pipeline() {
|
|||||||
plugin_repo.save(&p2).await.unwrap();
|
plugin_repo.save(&p2).await.unwrap();
|
||||||
|
|
||||||
let handler = ConfigurePipelineHandler::new(pipeline_repo.clone(), plugin_repo.clone());
|
let handler = ConfigurePipelineHandler::new(pipeline_repo.clone(), plugin_repo.clone());
|
||||||
let pipeline = handler.execute(ConfigurePipelineCommand {
|
let pipeline = handler
|
||||||
|
.execute(ConfigurePipelineCommand {
|
||||||
trigger_event: "asset.ingested".into(),
|
trigger_event: "asset.ingested".into(),
|
||||||
steps: vec![
|
steps: vec![
|
||||||
PipelineStepConfig { plugin_id: p1_id, config: StructuredData::new() },
|
PipelineStepConfig {
|
||||||
PipelineStepConfig { plugin_id: p2_id, config: StructuredData::new() },
|
plugin_id: p1_id,
|
||||||
|
config: StructuredData::new(),
|
||||||
|
},
|
||||||
|
PipelineStepConfig {
|
||||||
|
plugin_id: p2_id,
|
||||||
|
config: StructuredData::new(),
|
||||||
|
},
|
||||||
],
|
],
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(pipeline.trigger_event, "asset.ingested");
|
assert_eq!(pipeline.trigger_event, "asset.ingested");
|
||||||
assert_eq!(pipeline.steps.len(), 2);
|
assert_eq!(pipeline.steps.len(), 2);
|
||||||
@@ -37,12 +48,15 @@ async fn rejects_nonexistent_plugin() {
|
|||||||
let plugin_repo = Arc::new(InMemoryPluginRepository::new());
|
let plugin_repo = Arc::new(InMemoryPluginRepository::new());
|
||||||
|
|
||||||
let handler = ConfigurePipelineHandler::new(pipeline_repo.clone(), plugin_repo.clone());
|
let handler = ConfigurePipelineHandler::new(pipeline_repo.clone(), plugin_repo.clone());
|
||||||
let result = handler.execute(ConfigurePipelineCommand {
|
let result = handler
|
||||||
|
.execute(ConfigurePipelineCommand {
|
||||||
trigger_event: "asset.ingested".into(),
|
trigger_event: "asset.ingested".into(),
|
||||||
steps: vec![
|
steps: vec![PipelineStepConfig {
|
||||||
PipelineStepConfig { plugin_id: SystemId::new(), config: StructuredData::new() },
|
plugin_id: SystemId::new(),
|
||||||
],
|
config: StructuredData::new(),
|
||||||
}).await;
|
}],
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
|
||||||
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use application::testing::{InMemoryJobRepository, StubEventPublisher};
|
|
||||||
use application::processing::{EnqueueJobCommand, EnqueueJobHandler};
|
use application::processing::{EnqueueJobCommand, EnqueueJobHandler};
|
||||||
|
use application::testing::{InMemoryJobRepository, StubEventPublisher};
|
||||||
use domain::entities::{JobStatus, JobType};
|
use domain::entities::{JobStatus, JobType};
|
||||||
use domain::events::DomainEvent;
|
use domain::events::DomainEvent;
|
||||||
use domain::value_objects::{StructuredData, SystemId};
|
use domain::value_objects::{StructuredData, SystemId};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn enqueues_job() {
|
async fn enqueues_job() {
|
||||||
@@ -11,13 +11,16 @@ async fn enqueues_job() {
|
|||||||
let event_pub = Arc::new(StubEventPublisher::new());
|
let event_pub = Arc::new(StubEventPublisher::new());
|
||||||
let handler = EnqueueJobHandler::new(job_repo.clone(), event_pub.clone());
|
let handler = EnqueueJobHandler::new(job_repo.clone(), event_pub.clone());
|
||||||
|
|
||||||
let job = handler.execute(EnqueueJobCommand {
|
let job = handler
|
||||||
|
.execute(EnqueueJobCommand {
|
||||||
job_type: JobType::ExtractMetadata,
|
job_type: JobType::ExtractMetadata,
|
||||||
priority: 5,
|
priority: 5,
|
||||||
payload: StructuredData::new(),
|
payload: StructuredData::new(),
|
||||||
target_asset_id: None,
|
target_asset_id: None,
|
||||||
batch_id: None,
|
batch_id: None,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(job.status, JobStatus::Queued);
|
assert_eq!(job.status, JobStatus::Queued);
|
||||||
assert_eq!(job.priority, 5);
|
assert_eq!(job.priority, 5);
|
||||||
@@ -33,13 +36,16 @@ async fn enqueues_with_target_and_batch() {
|
|||||||
|
|
||||||
let target = SystemId::new();
|
let target = SystemId::new();
|
||||||
let batch = SystemId::new();
|
let batch = SystemId::new();
|
||||||
let job = handler.execute(EnqueueJobCommand {
|
let job = handler
|
||||||
|
.execute(EnqueueJobCommand {
|
||||||
job_type: JobType::GenerateDerivative,
|
job_type: JobType::GenerateDerivative,
|
||||||
priority: 10,
|
priority: 10,
|
||||||
payload: StructuredData::new(),
|
payload: StructuredData::new(),
|
||||||
target_asset_id: Some(target),
|
target_asset_id: Some(target),
|
||||||
batch_id: Some(batch),
|
batch_id: Some(batch),
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(job.target_asset_id, Some(target));
|
assert_eq!(job.target_asset_id, Some(target));
|
||||||
assert_eq!(job.batch_id, Some(batch));
|
assert_eq!(job.batch_id, Some(batch));
|
||||||
@@ -51,13 +57,16 @@ async fn publishes_event() {
|
|||||||
let event_pub = Arc::new(StubEventPublisher::new());
|
let event_pub = Arc::new(StubEventPublisher::new());
|
||||||
let handler = EnqueueJobHandler::new(job_repo.clone(), event_pub.clone());
|
let handler = EnqueueJobHandler::new(job_repo.clone(), event_pub.clone());
|
||||||
|
|
||||||
let job = handler.execute(EnqueueJobCommand {
|
let job = handler
|
||||||
|
.execute(EnqueueJobCommand {
|
||||||
job_type: JobType::ScanDirectory,
|
job_type: JobType::ScanDirectory,
|
||||||
priority: 1,
|
priority: 1,
|
||||||
payload: StructuredData::new(),
|
payload: StructuredData::new(),
|
||||||
target_asset_id: None,
|
target_asset_id: None,
|
||||||
batch_id: None,
|
batch_id: None,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let events = event_pub.published().await;
|
let events = event_pub.published().await;
|
||||||
assert_eq!(events.len(), 1);
|
assert_eq!(events.len(), 1);
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use application::testing::{InMemoryJobBatchRepository, InMemoryJobRepository, StubEventPublisher};
|
|
||||||
use application::processing::{FailJobCommand, FailJobHandler};
|
use application::processing::{FailJobCommand, FailJobHandler};
|
||||||
|
use application::testing::{InMemoryJobBatchRepository, InMemoryJobRepository, StubEventPublisher};
|
||||||
use domain::entities::{Job, JobBatch, JobStatus, JobType};
|
use domain::entities::{Job, JobBatch, JobStatus, JobType};
|
||||||
use domain::events::DomainEvent;
|
use domain::events::DomainEvent;
|
||||||
use domain::ports::{JobBatchRepository, JobRepository};
|
use domain::ports::{JobBatchRepository, JobRepository};
|
||||||
use domain::value_objects::StructuredData;
|
use domain::value_objects::StructuredData;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
fn make_handler(
|
fn make_handler(
|
||||||
job_repo: Arc<InMemoryJobRepository>,
|
job_repo: Arc<InMemoryJobRepository>,
|
||||||
@@ -26,10 +26,13 @@ async fn retries_on_failure() {
|
|||||||
job_repo.save(&job).await.unwrap();
|
job_repo.save(&job).await.unwrap();
|
||||||
|
|
||||||
let handler = make_handler(job_repo.clone(), batch_repo.clone(), event_pub.clone());
|
let handler = make_handler(job_repo.clone(), batch_repo.clone(), event_pub.clone());
|
||||||
let result = handler.execute(FailJobCommand {
|
let result = handler
|
||||||
|
.execute(FailJobCommand {
|
||||||
job_id,
|
job_id,
|
||||||
error: "transient error".into(),
|
error: "transient error".into(),
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(result.status, JobStatus::Queued);
|
assert_eq!(result.status, JobStatus::Queued);
|
||||||
assert_eq!(result.retry_count, 1);
|
assert_eq!(result.retry_count, 1);
|
||||||
@@ -54,10 +57,13 @@ async fn fails_permanently_after_max_retries() {
|
|||||||
job_repo.save(&job).await.unwrap();
|
job_repo.save(&job).await.unwrap();
|
||||||
|
|
||||||
let handler = make_handler(job_repo.clone(), batch_repo.clone(), event_pub.clone());
|
let handler = make_handler(job_repo.clone(), batch_repo.clone(), event_pub.clone());
|
||||||
let result = handler.execute(FailJobCommand {
|
let result = handler
|
||||||
|
.execute(FailJobCommand {
|
||||||
job_id,
|
job_id,
|
||||||
error: "fatal".into(),
|
error: "fatal".into(),
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(result.status, JobStatus::Failed);
|
assert_eq!(result.status, JobStatus::Failed);
|
||||||
assert_eq!(result.retry_count, 3);
|
assert_eq!(result.retry_count, 3);
|
||||||
@@ -76,8 +82,7 @@ async fn updates_batch_on_permanent_failure() {
|
|||||||
let batch_id = batch.batch_id;
|
let batch_id = batch.batch_id;
|
||||||
batch_repo.save(&batch).await.unwrap();
|
batch_repo.save(&batch).await.unwrap();
|
||||||
|
|
||||||
let mut job = Job::new(JobType::ExtractMetadata, 5, StructuredData::new())
|
let mut job = Job::new(JobType::ExtractMetadata, 5, StructuredData::new()).with_batch(batch_id);
|
||||||
.with_batch(batch_id);
|
|
||||||
// Exhaust retries
|
// Exhaust retries
|
||||||
job.fail("err1");
|
job.fail("err1");
|
||||||
job.fail("err2");
|
job.fail("err2");
|
||||||
@@ -85,10 +90,13 @@ async fn updates_batch_on_permanent_failure() {
|
|||||||
job_repo.save(&job).await.unwrap();
|
job_repo.save(&job).await.unwrap();
|
||||||
|
|
||||||
let handler = make_handler(job_repo.clone(), batch_repo.clone(), event_pub.clone());
|
let handler = make_handler(job_repo.clone(), batch_repo.clone(), event_pub.clone());
|
||||||
handler.execute(FailJobCommand {
|
handler
|
||||||
|
.execute(FailJobCommand {
|
||||||
job_id,
|
job_id,
|
||||||
error: "permanent failure".into(),
|
error: "permanent failure".into(),
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let updated_batch = batch_repo.find_by_id(&batch_id).await.unwrap().unwrap();
|
let updated_batch = batch_repo.find_by_id(&batch_id).await.unwrap().unwrap();
|
||||||
assert_eq!(updated_batch.failed_count, 1);
|
assert_eq!(updated_batch.failed_count, 1);
|
||||||
|
|||||||
@@ -1,23 +1,26 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use application::testing::InMemoryPluginRepository;
|
|
||||||
use application::processing::{ManagePluginCommand, ManagePluginHandler, PluginAction};
|
use application::processing::{ManagePluginCommand, ManagePluginHandler, PluginAction};
|
||||||
|
use application::testing::InMemoryPluginRepository;
|
||||||
use domain::entities::{Plugin, PluginType};
|
use domain::entities::{Plugin, PluginType};
|
||||||
use domain::ports::PluginRepository;
|
use domain::ports::PluginRepository;
|
||||||
use domain::value_objects::StructuredData;
|
use domain::value_objects::StructuredData;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn creates_plugin() {
|
async fn creates_plugin() {
|
||||||
let plugin_repo = Arc::new(InMemoryPluginRepository::new());
|
let plugin_repo = Arc::new(InMemoryPluginRepository::new());
|
||||||
let handler = ManagePluginHandler::new(plugin_repo.clone());
|
let handler = ManagePluginHandler::new(plugin_repo.clone());
|
||||||
|
|
||||||
let plugin = handler.execute(ManagePluginCommand {
|
let plugin = handler
|
||||||
|
.execute(ManagePluginCommand {
|
||||||
plugin_id: None,
|
plugin_id: None,
|
||||||
action: PluginAction::Create {
|
action: PluginAction::Create {
|
||||||
name: "EXIF Extractor".into(),
|
name: "EXIF Extractor".into(),
|
||||||
plugin_type: PluginType::MediaProcessor,
|
plugin_type: PluginType::MediaProcessor,
|
||||||
config: StructuredData::new(),
|
config: StructuredData::new(),
|
||||||
},
|
},
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(plugin.name, "EXIF Extractor");
|
assert_eq!(plugin.name, "EXIF Extractor");
|
||||||
assert_eq!(plugin.plugin_type, PluginType::MediaProcessor);
|
assert_eq!(plugin.plugin_type, PluginType::MediaProcessor);
|
||||||
@@ -36,10 +39,13 @@ async fn enables_plugin() {
|
|||||||
plugin_repo.save(&plugin).await.unwrap();
|
plugin_repo.save(&plugin).await.unwrap();
|
||||||
|
|
||||||
let handler = ManagePluginHandler::new(plugin_repo.clone());
|
let handler = ManagePluginHandler::new(plugin_repo.clone());
|
||||||
let result = handler.execute(ManagePluginCommand {
|
let result = handler
|
||||||
|
.execute(ManagePluginCommand {
|
||||||
plugin_id: Some(plugin_id),
|
plugin_id: Some(plugin_id),
|
||||||
action: PluginAction::Enable,
|
action: PluginAction::Enable,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert!(result.is_enabled);
|
assert!(result.is_enabled);
|
||||||
}
|
}
|
||||||
@@ -52,10 +58,13 @@ async fn disables_plugin() {
|
|||||||
plugin_repo.save(&plugin).await.unwrap();
|
plugin_repo.save(&plugin).await.unwrap();
|
||||||
|
|
||||||
let handler = ManagePluginHandler::new(plugin_repo.clone());
|
let handler = ManagePluginHandler::new(plugin_repo.clone());
|
||||||
let result = handler.execute(ManagePluginCommand {
|
let result = handler
|
||||||
|
.execute(ManagePluginCommand {
|
||||||
plugin_id: Some(plugin_id),
|
plugin_id: Some(plugin_id),
|
||||||
action: PluginAction::Disable,
|
action: PluginAction::Disable,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert!(!result.is_enabled);
|
assert!(!result.is_enabled);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
mod enqueue_job;
|
|
||||||
mod start_job;
|
|
||||||
mod complete_job;
|
mod complete_job;
|
||||||
|
mod configure_pipeline;
|
||||||
|
mod enqueue_job;
|
||||||
mod fail_job;
|
mod fail_job;
|
||||||
mod manage_plugin;
|
mod manage_plugin;
|
||||||
mod configure_pipeline;
|
mod start_job;
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use application::testing::InMemoryJobRepository;
|
|
||||||
use application::processing::{StartJobCommand, StartJobHandler};
|
use application::processing::{StartJobCommand, StartJobHandler};
|
||||||
|
use application::testing::InMemoryJobRepository;
|
||||||
use domain::entities::{Job, JobStatus, JobType};
|
use domain::entities::{Job, JobStatus, JobType};
|
||||||
use domain::errors::DomainError;
|
use domain::errors::DomainError;
|
||||||
use domain::ports::JobRepository;
|
use domain::ports::JobRepository;
|
||||||
use domain::value_objects::StructuredData;
|
use domain::value_objects::StructuredData;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn starts_queued_job() {
|
async fn starts_queued_job() {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::sync::Arc;
|
use application::processing::{ReportBatchProgressHandler, ReportBatchProgressQuery};
|
||||||
use application::testing::{InMemoryJobBatchRepository, InMemoryJobRepository};
|
use application::testing::{InMemoryJobBatchRepository, InMemoryJobRepository};
|
||||||
use application::processing::{ReportBatchProgressQuery, ReportBatchProgressHandler};
|
|
||||||
use domain::entities::{Job, JobBatch, JobType};
|
use domain::entities::{Job, JobBatch, JobType};
|
||||||
use domain::errors::DomainError;
|
use domain::errors::DomainError;
|
||||||
use domain::ports::{JobBatchRepository, JobRepository};
|
use domain::ports::{JobBatchRepository, JobRepository};
|
||||||
use domain::value_objects::{StructuredData, SystemId};
|
use domain::value_objects::{StructuredData, SystemId};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn returns_progress() {
|
async fn returns_progress() {
|
||||||
@@ -21,7 +21,10 @@ async fn returns_progress() {
|
|||||||
job_repo.save(&j2).await.unwrap();
|
job_repo.save(&j2).await.unwrap();
|
||||||
|
|
||||||
let handler = ReportBatchProgressHandler::new(batch_repo.clone(), job_repo.clone());
|
let handler = ReportBatchProgressHandler::new(batch_repo.clone(), job_repo.clone());
|
||||||
let progress = handler.execute(ReportBatchProgressQuery { batch_id }).await.unwrap();
|
let progress = handler
|
||||||
|
.execute(ReportBatchProgressQuery { batch_id })
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(progress.batch.batch_id, batch_id);
|
assert_eq!(progress.batch.batch_id, batch_id);
|
||||||
assert_eq!(progress.jobs.len(), 2);
|
assert_eq!(progress.jobs.len(), 2);
|
||||||
@@ -33,9 +36,11 @@ async fn rejects_nonexistent_batch() {
|
|||||||
let job_repo = Arc::new(InMemoryJobRepository::new());
|
let job_repo = Arc::new(InMemoryJobRepository::new());
|
||||||
|
|
||||||
let handler = ReportBatchProgressHandler::new(batch_repo.clone(), job_repo.clone());
|
let handler = ReportBatchProgressHandler::new(batch_repo.clone(), job_repo.clone());
|
||||||
let result = handler.execute(ReportBatchProgressQuery {
|
let result = handler
|
||||||
|
.execute(ReportBatchProgressQuery {
|
||||||
batch_id: SystemId::new(),
|
batch_id: SystemId::new(),
|
||||||
}).await;
|
})
|
||||||
|
.await;
|
||||||
|
|
||||||
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,25 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use application::testing::InMemoryShareRepository;
|
|
||||||
use application::sharing::{GenerateShareLinkCommand, GenerateShareLinkHandler};
|
use application::sharing::{GenerateShareLinkCommand, GenerateShareLinkHandler};
|
||||||
|
use application::testing::InMemoryShareRepository;
|
||||||
use domain::entities::{LinkAccessLevel, ScopeType, ShareableType};
|
use domain::entities::{LinkAccessLevel, ScopeType, ShareableType};
|
||||||
use domain::value_objects::{DateTimeStamp, SystemId};
|
use domain::value_objects::{DateTimeStamp, SystemId};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn generates_link() {
|
async fn generates_link() {
|
||||||
let share_repo = Arc::new(InMemoryShareRepository::new());
|
let share_repo = Arc::new(InMemoryShareRepository::new());
|
||||||
let handler = GenerateShareLinkHandler::new(share_repo);
|
let handler = GenerateShareLinkHandler::new(share_repo);
|
||||||
|
|
||||||
let (scope, link) = handler.execute(GenerateShareLinkCommand {
|
let (scope, link) = handler
|
||||||
|
.execute(GenerateShareLinkCommand {
|
||||||
shareable_type: ShareableType::Album,
|
shareable_type: ShareableType::Album,
|
||||||
shareable_id: SystemId::new(),
|
shareable_id: SystemId::new(),
|
||||||
access_level: LinkAccessLevel::ViewOnly,
|
access_level: LinkAccessLevel::ViewOnly,
|
||||||
created_by: SystemId::new(),
|
created_by: SystemId::new(),
|
||||||
expires_at: None,
|
expires_at: None,
|
||||||
max_uses: None,
|
max_uses: None,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(scope.scope_type, ScopeType::Link);
|
assert_eq!(scope.scope_type, ScopeType::Link);
|
||||||
assert!(!link.token.is_empty());
|
assert!(!link.token.is_empty());
|
||||||
@@ -31,14 +34,17 @@ async fn generates_link_with_expiry_and_max_uses() {
|
|||||||
let handler = GenerateShareLinkHandler::new(share_repo);
|
let handler = GenerateShareLinkHandler::new(share_repo);
|
||||||
|
|
||||||
let expiry = DateTimeStamp::now();
|
let expiry = DateTimeStamp::now();
|
||||||
let (_, link) = handler.execute(GenerateShareLinkCommand {
|
let (_, link) = handler
|
||||||
|
.execute(GenerateShareLinkCommand {
|
||||||
shareable_type: ShareableType::Collection,
|
shareable_type: ShareableType::Collection,
|
||||||
shareable_id: SystemId::new(),
|
shareable_id: SystemId::new(),
|
||||||
access_level: LinkAccessLevel::LimitedSearch,
|
access_level: LinkAccessLevel::LimitedSearch,
|
||||||
created_by: SystemId::new(),
|
created_by: SystemId::new(),
|
||||||
expires_at: Some(expiry),
|
expires_at: Some(expiry),
|
||||||
max_uses: Some(10),
|
max_uses: Some(10),
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert!(link.expires_at.is_some());
|
assert!(link.expires_at.is_some());
|
||||||
assert_eq!(link.max_uses, Some(10));
|
assert_eq!(link.max_uses, Some(10));
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
mod share_resource;
|
|
||||||
mod generate_share_link;
|
mod generate_share_link;
|
||||||
mod revoke_share;
|
mod revoke_share;
|
||||||
|
mod share_resource;
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use application::testing::{InMemoryShareRepository, StubEventPublisher};
|
|
||||||
use application::sharing::{
|
use application::sharing::{
|
||||||
GenerateShareLinkCommand, GenerateShareLinkHandler,
|
GenerateShareLinkCommand, GenerateShareLinkHandler, RevokeShareCommand, RevokeShareHandler,
|
||||||
RevokeShareCommand, RevokeShareHandler,
|
|
||||||
};
|
};
|
||||||
|
use application::testing::{InMemoryShareRepository, StubEventPublisher};
|
||||||
use domain::entities::{LinkAccessLevel, ShareableType};
|
use domain::entities::{LinkAccessLevel, ShareableType};
|
||||||
use domain::errors::DomainError;
|
use domain::errors::DomainError;
|
||||||
use domain::value_objects::SystemId;
|
use domain::value_objects::SystemId;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn revokes_share() {
|
async fn revokes_share() {
|
||||||
@@ -15,20 +14,26 @@ async fn revokes_share() {
|
|||||||
|
|
||||||
// Create a scope first via generate_share_link
|
// Create a scope first via generate_share_link
|
||||||
let gen_handler = GenerateShareLinkHandler::new(share_repo.clone());
|
let gen_handler = GenerateShareLinkHandler::new(share_repo.clone());
|
||||||
let (scope, _) = gen_handler.execute(GenerateShareLinkCommand {
|
let (scope, _) = gen_handler
|
||||||
|
.execute(GenerateShareLinkCommand {
|
||||||
shareable_type: ShareableType::Album,
|
shareable_type: ShareableType::Album,
|
||||||
shareable_id: SystemId::new(),
|
shareable_id: SystemId::new(),
|
||||||
access_level: LinkAccessLevel::ViewOnly,
|
access_level: LinkAccessLevel::ViewOnly,
|
||||||
created_by: SystemId::new(),
|
created_by: SystemId::new(),
|
||||||
expires_at: None,
|
expires_at: None,
|
||||||
max_uses: None,
|
max_uses: None,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let handler = RevokeShareHandler::new(share_repo, event_pub.clone());
|
let handler = RevokeShareHandler::new(share_repo, event_pub.clone());
|
||||||
handler.execute(RevokeShareCommand {
|
handler
|
||||||
|
.execute(RevokeShareCommand {
|
||||||
scope_id: scope.scope_id,
|
scope_id: scope.scope_id,
|
||||||
revoked_by: SystemId::new(),
|
revoked_by: SystemId::new(),
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let events = event_pub.published().await;
|
let events = event_pub.published().await;
|
||||||
assert_eq!(events.len(), 1);
|
assert_eq!(events.len(), 1);
|
||||||
@@ -40,9 +45,11 @@ async fn rejects_nonexistent_scope() {
|
|||||||
let event_pub = Arc::new(StubEventPublisher::new());
|
let event_pub = Arc::new(StubEventPublisher::new());
|
||||||
let handler = RevokeShareHandler::new(share_repo, event_pub);
|
let handler = RevokeShareHandler::new(share_repo, event_pub);
|
||||||
|
|
||||||
let result = handler.execute(RevokeShareCommand {
|
let result = handler
|
||||||
|
.execute(RevokeShareCommand {
|
||||||
scope_id: SystemId::new(),
|
scope_id: SystemId::new(),
|
||||||
revoked_by: SystemId::new(),
|
revoked_by: SystemId::new(),
|
||||||
}).await;
|
})
|
||||||
|
.await;
|
||||||
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use application::testing::{InMemoryShareRepository, StubEventPublisher};
|
|
||||||
use application::sharing::{ShareResourceCommand, ShareResourceHandler};
|
use application::sharing::{ShareResourceCommand, ShareResourceHandler};
|
||||||
|
use application::testing::{InMemoryShareRepository, StubEventPublisher};
|
||||||
use domain::entities::{ScopeType, ShareableType, TargetType};
|
use domain::entities::{ScopeType, ShareableType, TargetType};
|
||||||
use domain::value_objects::SystemId;
|
use domain::value_objects::SystemId;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn shares_with_user() {
|
async fn shares_with_user() {
|
||||||
@@ -10,14 +10,17 @@ async fn shares_with_user() {
|
|||||||
let event_pub = Arc::new(StubEventPublisher::new());
|
let event_pub = Arc::new(StubEventPublisher::new());
|
||||||
|
|
||||||
let handler = ShareResourceHandler::new(share_repo, event_pub.clone());
|
let handler = ShareResourceHandler::new(share_repo, event_pub.clone());
|
||||||
let (scope, target) = handler.execute(ShareResourceCommand {
|
let (scope, target) = handler
|
||||||
|
.execute(ShareResourceCommand {
|
||||||
shareable_type: ShareableType::Album,
|
shareable_type: ShareableType::Album,
|
||||||
shareable_id: SystemId::new(),
|
shareable_id: SystemId::new(),
|
||||||
target_type: TargetType::User,
|
target_type: TargetType::User,
|
||||||
target_id: SystemId::new(),
|
target_id: SystemId::new(),
|
||||||
role_id: SystemId::new(),
|
role_id: SystemId::new(),
|
||||||
created_by: SystemId::new(),
|
created_by: SystemId::new(),
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(scope.scope_type, ScopeType::User);
|
assert_eq!(scope.scope_type, ScopeType::User);
|
||||||
assert_eq!(target.target_type, TargetType::User);
|
assert_eq!(target.target_type, TargetType::User);
|
||||||
@@ -33,14 +36,17 @@ async fn shares_with_group() {
|
|||||||
let event_pub = Arc::new(StubEventPublisher::new());
|
let event_pub = Arc::new(StubEventPublisher::new());
|
||||||
|
|
||||||
let handler = ShareResourceHandler::new(share_repo, event_pub.clone());
|
let handler = ShareResourceHandler::new(share_repo, event_pub.clone());
|
||||||
let (scope, target) = handler.execute(ShareResourceCommand {
|
let (scope, target) = handler
|
||||||
|
.execute(ShareResourceCommand {
|
||||||
shareable_type: ShareableType::Asset,
|
shareable_type: ShareableType::Asset,
|
||||||
shareable_id: SystemId::new(),
|
shareable_id: SystemId::new(),
|
||||||
target_type: TargetType::Group,
|
target_type: TargetType::Group,
|
||||||
target_id: SystemId::new(),
|
target_id: SystemId::new(),
|
||||||
role_id: SystemId::new(),
|
role_id: SystemId::new(),
|
||||||
created_by: SystemId::new(),
|
created_by: SystemId::new(),
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(scope.scope_type, ScopeType::Group);
|
assert_eq!(scope.scope_type, ScopeType::Group);
|
||||||
assert_eq!(target.target_type, TargetType::Group);
|
assert_eq!(target.target_type, TargetType::Group);
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use application::testing::InMemoryShareRepository;
|
|
||||||
use application::sharing::{
|
use application::sharing::{
|
||||||
AccessSharedResourceQuery, AccessSharedResourceHandler,
|
AccessSharedResourceHandler, AccessSharedResourceQuery, GenerateShareLinkCommand,
|
||||||
GenerateShareLinkCommand, GenerateShareLinkHandler,
|
GenerateShareLinkHandler,
|
||||||
};
|
};
|
||||||
|
use application::testing::InMemoryShareRepository;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use domain::entities::{LinkAccessLevel, ShareableType};
|
use domain::entities::{LinkAccessLevel, ShareableType};
|
||||||
use domain::errors::DomainError;
|
use domain::errors::DomainError;
|
||||||
use domain::value_objects::{DateTimeStamp, SystemId};
|
use domain::value_objects::{DateTimeStamp, SystemId};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
async fn create_link(
|
async fn create_link(
|
||||||
repo: &Arc<InMemoryShareRepository>,
|
repo: &Arc<InMemoryShareRepository>,
|
||||||
@@ -15,14 +15,17 @@ async fn create_link(
|
|||||||
max_uses: Option<u32>,
|
max_uses: Option<u32>,
|
||||||
) -> String {
|
) -> String {
|
||||||
let handler = GenerateShareLinkHandler::new(repo.clone());
|
let handler = GenerateShareLinkHandler::new(repo.clone());
|
||||||
let (_, link) = handler.execute(GenerateShareLinkCommand {
|
let (_, link) = handler
|
||||||
|
.execute(GenerateShareLinkCommand {
|
||||||
shareable_type: ShareableType::Album,
|
shareable_type: ShareableType::Album,
|
||||||
shareable_id: SystemId::new(),
|
shareable_id: SystemId::new(),
|
||||||
access_level: LinkAccessLevel::ViewOnly,
|
access_level: LinkAccessLevel::ViewOnly,
|
||||||
created_by: SystemId::new(),
|
created_by: SystemId::new(),
|
||||||
expires_at,
|
expires_at,
|
||||||
max_uses,
|
max_uses,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
link.token
|
link.token
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,9 +35,10 @@ async fn valid_link_returns_scope() {
|
|||||||
let token = create_link(&repo, None, None).await;
|
let token = create_link(&repo, None, None).await;
|
||||||
|
|
||||||
let handler = AccessSharedResourceHandler::new(repo);
|
let handler = AccessSharedResourceHandler::new(repo);
|
||||||
let (scope, access_level) = handler.execute(AccessSharedResourceQuery {
|
let (scope, access_level) = handler
|
||||||
token,
|
.execute(AccessSharedResourceQuery { token })
|
||||||
}).await.unwrap();
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(access_level, LinkAccessLevel::ViewOnly);
|
assert_eq!(access_level, LinkAccessLevel::ViewOnly);
|
||||||
assert_eq!(scope.shareable_type, ShareableType::Album);
|
assert_eq!(scope.shareable_type, ShareableType::Album);
|
||||||
@@ -59,7 +63,12 @@ async fn exhausted_link_rejected() {
|
|||||||
|
|
||||||
// Use it once
|
// Use it once
|
||||||
let handler = AccessSharedResourceHandler::new(repo.clone());
|
let handler = AccessSharedResourceHandler::new(repo.clone());
|
||||||
handler.execute(AccessSharedResourceQuery { token: token.clone() }).await.unwrap();
|
handler
|
||||||
|
.execute(AccessSharedResourceQuery {
|
||||||
|
token: token.clone(),
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// Second use should fail
|
// Second use should fail
|
||||||
let result = handler.execute(AccessSharedResourceQuery { token }).await;
|
let result = handler.execute(AccessSharedResourceQuery { token }).await;
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use application::sidecar::{DetectExternalChangesCommand, DetectExternalChangesHandler};
|
|
||||||
use application::sidecar::hash_helper::hash_structured_data;
|
use application::sidecar::hash_helper::hash_structured_data;
|
||||||
|
use application::sidecar::{DetectExternalChangesCommand, DetectExternalChangesHandler};
|
||||||
use application::testing::{InMemorySidecarRepository, InMemorySidecarWriter};
|
use application::testing::{InMemorySidecarRepository, InMemorySidecarWriter};
|
||||||
use domain::entities::{SidecarRecord, SyncStatus};
|
use domain::entities::{SidecarRecord, SyncStatus};
|
||||||
use domain::ports::{SidecarRepository, SidecarWriterPort};
|
use domain::ports::{SidecarRepository, SidecarWriterPort};
|
||||||
use domain::value_objects::{MetadataValue, StructuredData, SystemId};
|
use domain::value_objects::{MetadataValue, StructuredData, SystemId};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn detects_changed_sidecar() {
|
async fn detects_changed_sidecar() {
|
||||||
@@ -31,7 +31,11 @@ async fn detects_changed_sidecar() {
|
|||||||
let changed = handler.execute(DetectExternalChangesCommand).await.unwrap();
|
let changed = handler.execute(DetectExternalChangesCommand).await.unwrap();
|
||||||
|
|
||||||
assert_eq!(changed, 1);
|
assert_eq!(changed, 1);
|
||||||
let updated = sidecar_repo.find_by_asset(&asset_id).await.unwrap().unwrap();
|
let updated = sidecar_repo
|
||||||
|
.find_by_asset(&asset_id)
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
assert_eq!(updated.sync_status, SyncStatus::PendingRead);
|
assert_eq!(updated.sync_status, SyncStatus::PendingRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,6 +62,10 @@ async fn ignores_unchanged_sidecar() {
|
|||||||
let changed = handler.execute(DetectExternalChangesCommand).await.unwrap();
|
let changed = handler.execute(DetectExternalChangesCommand).await.unwrap();
|
||||||
|
|
||||||
assert_eq!(changed, 0);
|
assert_eq!(changed, 0);
|
||||||
let updated = sidecar_repo.find_by_asset(&asset_id).await.unwrap().unwrap();
|
let updated = sidecar_repo
|
||||||
|
.find_by_asset(&asset_id)
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
assert_eq!(updated.sync_status, SyncStatus::InSync);
|
assert_eq!(updated.sync_status, SyncStatus::InSync);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use application::sidecar::{ExportSidecarCommand, ExportSidecarHandler};
|
use application::sidecar::{ExportSidecarCommand, ExportSidecarHandler};
|
||||||
use application::testing::{InMemoryAssetMetadataRepository, InMemorySidecarRepository, InMemorySidecarWriter};
|
use application::testing::{
|
||||||
|
InMemoryAssetMetadataRepository, InMemorySidecarRepository, InMemorySidecarWriter,
|
||||||
|
};
|
||||||
use domain::catalog::entities::{AssetMetadata, MetadataSource};
|
use domain::catalog::entities::{AssetMetadata, MetadataSource};
|
||||||
use domain::entities::SyncStatus;
|
use domain::entities::SyncStatus;
|
||||||
use domain::ports::SidecarRepository;
|
use domain::ports::SidecarRepository;
|
||||||
use domain::value_objects::{MetadataValue, StructuredData, SystemId};
|
use domain::value_objects::{MetadataValue, StructuredData, SystemId};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn exports_sidecar_marks_in_sync() {
|
async fn exports_sidecar_marks_in_sync() {
|
||||||
@@ -20,7 +22,10 @@ async fn exports_sidecar_marks_in_sync() {
|
|||||||
meta_repo.save(&metadata).await.unwrap();
|
meta_repo.save(&metadata).await.unwrap();
|
||||||
|
|
||||||
let handler = ExportSidecarHandler::new(meta_repo, sidecar_repo.clone(), writer.clone());
|
let handler = ExportSidecarHandler::new(meta_repo, sidecar_repo.clone(), writer.clone());
|
||||||
let record = handler.execute(ExportSidecarCommand { asset_id }).await.unwrap();
|
let record = handler
|
||||||
|
.execute(ExportSidecarCommand { asset_id })
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(record.sync_status, SyncStatus::InSync);
|
assert_eq!(record.sync_status, SyncStatus::InSync);
|
||||||
assert!(record.last_known_file_hash.is_some());
|
assert!(record.last_known_file_hash.is_some());
|
||||||
@@ -39,7 +44,10 @@ async fn creates_new_record_if_none_exists() {
|
|||||||
let asset_id = SystemId::new();
|
let asset_id = SystemId::new();
|
||||||
|
|
||||||
let handler = ExportSidecarHandler::new(meta_repo, sidecar_repo.clone(), writer);
|
let handler = ExportSidecarHandler::new(meta_repo, sidecar_repo.clone(), writer);
|
||||||
let record = handler.execute(ExportSidecarCommand { asset_id }).await.unwrap();
|
let record = handler
|
||||||
|
.execute(ExportSidecarCommand { asset_id })
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(record.asset_id, asset_id);
|
assert_eq!(record.asset_id, asset_id);
|
||||||
assert_eq!(record.sync_status, SyncStatus::InSync);
|
assert_eq!(record.sync_status, SyncStatus::InSync);
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use application::sidecar::{FullExportCommand, FullExportHandler};
|
use application::sidecar::{FullExportCommand, FullExportHandler};
|
||||||
use application::testing::{
|
use application::testing::{
|
||||||
InMemoryAssetRepository, InMemoryAssetMetadataRepository,
|
InMemoryAssetMetadataRepository, InMemoryAssetRepository, InMemorySidecarRepository,
|
||||||
InMemorySidecarRepository, InMemorySidecarWriter,
|
InMemorySidecarWriter,
|
||||||
};
|
};
|
||||||
use domain::catalog::entities::{Asset, AssetMetadata, AssetType, MetadataSource, SourceReference};
|
use domain::catalog::entities::{Asset, AssetMetadata, AssetType, MetadataSource, SourceReference};
|
||||||
use domain::ports::AssetRepository;
|
use domain::ports::AssetRepository;
|
||||||
use domain::value_objects::{Checksum, MetadataValue, StructuredData, SystemId};
|
use domain::value_objects::{Checksum, MetadataValue, StructuredData, SystemId};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
fn make_asset(owner: SystemId) -> Asset {
|
fn make_asset(owner: SystemId) -> Asset {
|
||||||
let source = SourceReference {
|
let source = SourceReference {
|
||||||
@@ -33,10 +33,20 @@ async fn exports_all_user_assets() {
|
|||||||
let mut data = StructuredData::new();
|
let mut data = StructuredData::new();
|
||||||
data.insert("title", MetadataValue::String("Sunset".into()));
|
data.insert("title", MetadataValue::String("Sunset".into()));
|
||||||
use domain::ports::AssetMetadataRepository;
|
use domain::ports::AssetMetadataRepository;
|
||||||
meta_repo.save(&AssetMetadata::new(a1.asset_id, MetadataSource::UserEdited, data)).await.unwrap();
|
meta_repo
|
||||||
|
.save(&AssetMetadata::new(
|
||||||
|
a1.asset_id,
|
||||||
|
MetadataSource::UserEdited,
|
||||||
|
data,
|
||||||
|
))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let handler = FullExportHandler::new(asset_repo, meta_repo, sidecar_repo, writer.clone());
|
let handler = FullExportHandler::new(asset_repo, meta_repo, sidecar_repo, writer.clone());
|
||||||
let count = handler.execute(FullExportCommand { owner_id: owner }).await.unwrap();
|
let count = handler
|
||||||
|
.execute(FullExportCommand { owner_id: owner })
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(count, 2);
|
assert_eq!(count, 2);
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use application::sidecar::{FullImportCommand, FullImportHandler};
|
use application::sidecar::{FullImportCommand, FullImportHandler};
|
||||||
use application::testing::{
|
use application::testing::{
|
||||||
InMemoryAssetRepository, InMemoryAssetMetadataRepository,
|
InMemoryAssetMetadataRepository, InMemoryAssetRepository, InMemorySidecarRepository,
|
||||||
InMemorySidecarRepository, InMemorySidecarWriter,
|
InMemorySidecarWriter,
|
||||||
};
|
};
|
||||||
use domain::catalog::entities::{Asset, AssetType, MetadataSource, SourceReference};
|
use domain::catalog::entities::{Asset, AssetType, MetadataSource, SourceReference};
|
||||||
use domain::entities::SidecarRecord;
|
use domain::entities::SidecarRecord;
|
||||||
use domain::ports::{AssetMetadataRepository, AssetRepository, SidecarRepository, SidecarWriterPort};
|
use domain::ports::{
|
||||||
|
AssetMetadataRepository, AssetRepository, SidecarRepository, SidecarWriterPort,
|
||||||
|
};
|
||||||
use domain::value_objects::{Checksum, MetadataValue, StructuredData, SystemId};
|
use domain::value_objects::{Checksum, MetadataValue, StructuredData, SystemId};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
fn make_asset(owner: SystemId) -> Asset {
|
fn make_asset(owner: SystemId) -> Asset {
|
||||||
let source = SourceReference {
|
let source = SourceReference {
|
||||||
@@ -38,10 +40,16 @@ async fn imports_from_existing_sidecars() {
|
|||||||
writer.write_sidecar(&data, &path).await.unwrap();
|
writer.write_sidecar(&data, &path).await.unwrap();
|
||||||
|
|
||||||
let handler = FullImportHandler::new(asset_repo, meta_repo.clone(), sidecar_repo, writer);
|
let handler = FullImportHandler::new(asset_repo, meta_repo.clone(), sidecar_repo, writer);
|
||||||
let count = handler.execute(FullImportCommand { owner_id: owner }).await.unwrap();
|
let count = handler
|
||||||
|
.execute(FullImportCommand { owner_id: owner })
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(count, 1);
|
assert_eq!(count, 1);
|
||||||
let imported = meta_repo.find_by_asset_and_source(&asset.asset_id, MetadataSource::ExifExtracted).await.unwrap();
|
let imported = meta_repo
|
||||||
|
.find_by_asset_and_source(&asset.asset_id, MetadataSource::ExifExtracted)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
assert!(imported.is_some());
|
assert!(imported.is_some());
|
||||||
assert_eq!(imported.unwrap().data.get_string("lens"), Some("50mm"));
|
assert_eq!(imported.unwrap().data.get_string("lens"), Some("50mm"));
|
||||||
}
|
}
|
||||||
@@ -59,7 +67,10 @@ async fn skips_missing_sidecars() {
|
|||||||
// No sidecar record, no sidecar file
|
// No sidecar record, no sidecar file
|
||||||
|
|
||||||
let handler = FullImportHandler::new(asset_repo, meta_repo, sidecar_repo, writer);
|
let handler = FullImportHandler::new(asset_repo, meta_repo, sidecar_repo, writer);
|
||||||
let count = handler.execute(FullImportCommand { owner_id: owner }).await.unwrap();
|
let count = handler
|
||||||
|
.execute(FullImportCommand { owner_id: owner })
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(count, 0);
|
assert_eq!(count, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use application::sidecar::{ImportSidecarCommand, ImportSidecarHandler};
|
use application::sidecar::{ImportSidecarCommand, ImportSidecarHandler};
|
||||||
use application::testing::{InMemoryAssetMetadataRepository, InMemorySidecarRepository, InMemorySidecarWriter};
|
use application::testing::{
|
||||||
|
InMemoryAssetMetadataRepository, InMemorySidecarRepository, InMemorySidecarWriter,
|
||||||
|
};
|
||||||
use domain::catalog::entities::MetadataSource;
|
use domain::catalog::entities::MetadataSource;
|
||||||
use domain::entities::{SidecarRecord, SyncStatus};
|
use domain::entities::{SidecarRecord, SyncStatus};
|
||||||
use domain::errors::DomainError;
|
use domain::errors::DomainError;
|
||||||
use domain::ports::{SidecarRepository, SidecarWriterPort};
|
use domain::ports::{SidecarRepository, SidecarWriterPort};
|
||||||
use domain::value_objects::{MetadataValue, StructuredData, SystemId};
|
use domain::value_objects::{MetadataValue, StructuredData, SystemId};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn imports_pending_read_sidecar() {
|
async fn imports_pending_read_sidecar() {
|
||||||
@@ -27,12 +29,19 @@ async fn imports_pending_read_sidecar() {
|
|||||||
writer.write_sidecar(&data, &path).await.unwrap();
|
writer.write_sidecar(&data, &path).await.unwrap();
|
||||||
|
|
||||||
let handler = ImportSidecarHandler::new(sidecar_repo.clone(), writer, meta_repo);
|
let handler = ImportSidecarHandler::new(sidecar_repo.clone(), writer, meta_repo);
|
||||||
let metadata = handler.execute(ImportSidecarCommand { asset_id }).await.unwrap();
|
let metadata = handler
|
||||||
|
.execute(ImportSidecarCommand { asset_id })
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(metadata.metadata_source, MetadataSource::ExifExtracted);
|
assert_eq!(metadata.metadata_source, MetadataSource::ExifExtracted);
|
||||||
assert_eq!(metadata.data.get_string("camera"), Some("Canon"));
|
assert_eq!(metadata.data.get_string("camera"), Some("Canon"));
|
||||||
|
|
||||||
let updated = sidecar_repo.find_by_asset(&asset_id).await.unwrap().unwrap();
|
let updated = sidecar_repo
|
||||||
|
.find_by_asset(&asset_id)
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
assert_eq!(updated.sync_status, SyncStatus::InSync);
|
assert_eq!(updated.sync_status, SyncStatus::InSync);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
mod export_sidecar;
|
|
||||||
mod detect_external_changes;
|
mod detect_external_changes;
|
||||||
mod import_sidecar;
|
mod export_sidecar;
|
||||||
mod resolve_conflict;
|
|
||||||
mod full_export;
|
mod full_export;
|
||||||
mod full_import;
|
mod full_import;
|
||||||
|
mod import_sidecar;
|
||||||
|
mod resolve_conflict;
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use application::sidecar::{ResolveConflictCommand, ResolveConflictHandler};
|
use application::sidecar::{ResolveConflictCommand, ResolveConflictHandler};
|
||||||
use application::testing::{InMemoryAssetMetadataRepository, InMemorySidecarRepository, InMemorySidecarWriter};
|
use application::testing::{
|
||||||
|
InMemoryAssetMetadataRepository, InMemorySidecarRepository, InMemorySidecarWriter,
|
||||||
|
};
|
||||||
use domain::catalog::entities::{AssetMetadata, MetadataSource};
|
use domain::catalog::entities::{AssetMetadata, MetadataSource};
|
||||||
use domain::entities::{ConflictPolicy, SidecarRecord, SyncStatus};
|
use domain::entities::{ConflictPolicy, SidecarRecord, SyncStatus};
|
||||||
use domain::errors::DomainError;
|
use domain::errors::DomainError;
|
||||||
use domain::ports::{AssetMetadataRepository, SidecarRepository, SidecarWriterPort};
|
use domain::ports::{AssetMetadataRepository, SidecarRepository, SidecarWriterPort};
|
||||||
use domain::value_objects::{MetadataValue, StructuredData, SystemId};
|
use domain::value_objects::{MetadataValue, StructuredData, SystemId};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
fn conflict_record(asset_id: SystemId, path: &str) -> SidecarRecord {
|
fn conflict_record(asset_id: SystemId, path: &str) -> SidecarRecord {
|
||||||
let mut r = SidecarRecord::new(asset_id, path);
|
let mut r = SidecarRecord::new(asset_id, path);
|
||||||
@@ -22,17 +24,30 @@ async fn db_wins_re_exports() {
|
|||||||
let asset_id = SystemId::new();
|
let asset_id = SystemId::new();
|
||||||
let path = format!("sidecars/{}.xmp", asset_id);
|
let path = format!("sidecars/{}.xmp", asset_id);
|
||||||
|
|
||||||
sidecar_repo.save(&conflict_record(asset_id, &path)).await.unwrap();
|
sidecar_repo
|
||||||
|
.save(&conflict_record(asset_id, &path))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let mut data = StructuredData::new();
|
let mut data = StructuredData::new();
|
||||||
data.insert("title", MetadataValue::String("DB Value".into()));
|
data.insert("title", MetadataValue::String("DB Value".into()));
|
||||||
meta_repo.save(&AssetMetadata::new(asset_id, MetadataSource::UserEdited, data)).await.unwrap();
|
meta_repo
|
||||||
|
.save(&AssetMetadata::new(
|
||||||
|
asset_id,
|
||||||
|
MetadataSource::UserEdited,
|
||||||
|
data,
|
||||||
|
))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let handler = ResolveConflictHandler::new(sidecar_repo.clone(), writer.clone(), meta_repo);
|
let handler = ResolveConflictHandler::new(sidecar_repo.clone(), writer.clone(), meta_repo);
|
||||||
let record = handler.execute(ResolveConflictCommand {
|
let record = handler
|
||||||
|
.execute(ResolveConflictCommand {
|
||||||
asset_id,
|
asset_id,
|
||||||
policy: ConflictPolicy::DbWins,
|
policy: ConflictPolicy::DbWins,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(record.sync_status, SyncStatus::InSync);
|
assert_eq!(record.sync_status, SyncStatus::InSync);
|
||||||
let written = writer.get(&path).await.unwrap();
|
let written = writer.get(&path).await.unwrap();
|
||||||
@@ -48,22 +63,34 @@ async fn file_wins_re_imports() {
|
|||||||
let asset_id = SystemId::new();
|
let asset_id = SystemId::new();
|
||||||
let path = format!("sidecars/{}.xmp", asset_id);
|
let path = format!("sidecars/{}.xmp", asset_id);
|
||||||
|
|
||||||
sidecar_repo.save(&conflict_record(asset_id, &path)).await.unwrap();
|
sidecar_repo
|
||||||
|
.save(&conflict_record(asset_id, &path))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let mut file_data = StructuredData::new();
|
let mut file_data = StructuredData::new();
|
||||||
file_data.insert("title", MetadataValue::String("File Value".into()));
|
file_data.insert("title", MetadataValue::String("File Value".into()));
|
||||||
writer.write_sidecar(&file_data, &path).await.unwrap();
|
writer.write_sidecar(&file_data, &path).await.unwrap();
|
||||||
|
|
||||||
let handler = ResolveConflictHandler::new(sidecar_repo.clone(), writer, meta_repo.clone());
|
let handler = ResolveConflictHandler::new(sidecar_repo.clone(), writer, meta_repo.clone());
|
||||||
let record = handler.execute(ResolveConflictCommand {
|
let record = handler
|
||||||
|
.execute(ResolveConflictCommand {
|
||||||
asset_id,
|
asset_id,
|
||||||
policy: ConflictPolicy::FileWins,
|
policy: ConflictPolicy::FileWins,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(record.sync_status, SyncStatus::InSync);
|
assert_eq!(record.sync_status, SyncStatus::InSync);
|
||||||
let imported = meta_repo.find_by_asset_and_source(&asset_id, MetadataSource::ExifExtracted).await.unwrap();
|
let imported = meta_repo
|
||||||
|
.find_by_asset_and_source(&asset_id, MetadataSource::ExifExtracted)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
assert!(imported.is_some());
|
assert!(imported.is_some());
|
||||||
assert_eq!(imported.unwrap().data.get_string("title"), Some("File Value"));
|
assert_eq!(
|
||||||
|
imported.unwrap().data.get_string("title"),
|
||||||
|
Some("File Value")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -73,13 +100,18 @@ async fn user_decision_returns_error() {
|
|||||||
let meta_repo = Arc::new(InMemoryAssetMetadataRepository::new());
|
let meta_repo = Arc::new(InMemoryAssetMetadataRepository::new());
|
||||||
|
|
||||||
let asset_id = SystemId::new();
|
let asset_id = SystemId::new();
|
||||||
sidecar_repo.save(&conflict_record(asset_id, "sidecars/x.xmp")).await.unwrap();
|
sidecar_repo
|
||||||
|
.save(&conflict_record(asset_id, "sidecars/x.xmp"))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let handler = ResolveConflictHandler::new(sidecar_repo, writer, meta_repo);
|
let handler = ResolveConflictHandler::new(sidecar_repo, writer, meta_repo);
|
||||||
let result = handler.execute(ResolveConflictCommand {
|
let result = handler
|
||||||
|
.execute(ResolveConflictCommand {
|
||||||
asset_id,
|
asset_id,
|
||||||
policy: ConflictPolicy::RequireUserDecision,
|
policy: ConflictPolicy::RequireUserDecision,
|
||||||
}).await;
|
})
|
||||||
|
.await;
|
||||||
|
|
||||||
assert!(matches!(result, Err(DomainError::Validation(msg)) if msg.contains("Manual")));
|
assert!(matches!(result, Err(DomainError::Validation(msg)) if msg.contains("Manual")));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,18 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use bytes::Bytes;
|
|
||||||
use application::testing::{
|
|
||||||
InMemoryAssetRepository, InMemoryIngestSessionRepository,
|
|
||||||
InMemoryLibraryPathRepository, InMemoryQuotaRepository,
|
|
||||||
InMemoryStorageVolumeRepository, InMemoryUsageLedgerRepository,
|
|
||||||
InMemoryFileStorage, StubEventPublisher,
|
|
||||||
};
|
|
||||||
use application::storage::{
|
use application::storage::{
|
||||||
IngestAssetCommand, IngestAssetHandler,
|
IngestAssetCommand, IngestAssetHandler, RegisterLibraryPathCommand, RegisterLibraryPathHandler,
|
||||||
RegisterVolumeCommand, RegisterVolumeHandler,
|
RegisterVolumeCommand, RegisterVolumeHandler,
|
||||||
RegisterLibraryPathCommand, RegisterLibraryPathHandler,
|
|
||||||
};
|
};
|
||||||
|
use application::testing::{
|
||||||
|
InMemoryAssetRepository, InMemoryFileStorage, InMemoryIngestSessionRepository,
|
||||||
|
InMemoryLibraryPathRepository, InMemoryQuotaRepository, InMemoryStorageVolumeRepository,
|
||||||
|
InMemoryUsageLedgerRepository, StubEventPublisher,
|
||||||
|
};
|
||||||
|
use bytes::Bytes;
|
||||||
use domain::entities::{IngestStatus, QuotaDefinition, TimePeriod, UsageType};
|
use domain::entities::{IngestStatus, QuotaDefinition, TimePeriod, UsageType};
|
||||||
use domain::errors::DomainError;
|
use domain::errors::DomainError;
|
||||||
use domain::ports::QuotaRepository;
|
use domain::ports::QuotaRepository;
|
||||||
use domain::value_objects::SystemId;
|
use domain::value_objects::SystemId;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
struct Harness {
|
struct Harness {
|
||||||
ingest_repo: Arc<InMemoryIngestSessionRepository>,
|
ingest_repo: Arc<InMemoryIngestSessionRepository>,
|
||||||
@@ -55,19 +53,26 @@ impl Harness {
|
|||||||
|
|
||||||
async fn setup_volume_and_path(&self, owner: SystemId) -> SystemId {
|
async fn setup_volume_and_path(&self, owner: SystemId) -> SystemId {
|
||||||
let vol_handler = RegisterVolumeHandler::new(self.vol_repo.clone());
|
let vol_handler = RegisterVolumeHandler::new(self.vol_repo.clone());
|
||||||
let vol = vol_handler.execute(RegisterVolumeCommand {
|
let vol = vol_handler
|
||||||
|
.execute(RegisterVolumeCommand {
|
||||||
volume_name: "main".into(),
|
volume_name: "main".into(),
|
||||||
uri_prefix: "file:///data".into(),
|
uri_prefix: "file:///data".into(),
|
||||||
is_writable: true,
|
is_writable: true,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let path_handler = RegisterLibraryPathHandler::new(self.vol_repo.clone(), self.path_repo.clone());
|
let path_handler =
|
||||||
let path = path_handler.execute(RegisterLibraryPathCommand {
|
RegisterLibraryPathHandler::new(self.vol_repo.clone(), self.path_repo.clone());
|
||||||
|
let path = path_handler
|
||||||
|
.execute(RegisterLibraryPathCommand {
|
||||||
volume_id: vol.volume_id,
|
volume_id: vol.volume_id,
|
||||||
relative_path: "photos/inbox".into(),
|
relative_path: "photos/inbox".into(),
|
||||||
owner_id: owner,
|
owner_id: owner,
|
||||||
is_ingest_destination: true,
|
is_ingest_destination: true,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
path.path_id
|
path.path_id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,7 +88,8 @@ async fn ingests_successfully() {
|
|||||||
let path_id = h.setup_volume_and_path(user).await;
|
let path_id = h.setup_volume_and_path(user).await;
|
||||||
|
|
||||||
let handler = h.ingest_handler();
|
let handler = h.ingest_handler();
|
||||||
let (asset, session) = handler.execute(IngestAssetCommand {
|
let (asset, session) = handler
|
||||||
|
.execute(IngestAssetCommand {
|
||||||
uploader_id: user,
|
uploader_id: user,
|
||||||
client_device_id: "iphone-1".into(),
|
client_device_id: "iphone-1".into(),
|
||||||
filename: "photo.jpg".into(),
|
filename: "photo.jpg".into(),
|
||||||
@@ -91,7 +97,9 @@ async fn ingests_successfully() {
|
|||||||
target_path_id: path_id,
|
target_path_id: path_id,
|
||||||
file_size: 1024,
|
file_size: 1024,
|
||||||
data: Bytes::from(vec![0u8; 1024]),
|
data: Bytes::from(vec![0u8; 1024]),
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(asset.mime_type, "image/jpeg");
|
assert_eq!(asset.mime_type, "image/jpeg");
|
||||||
assert_eq!(asset.file_size, 1024);
|
assert_eq!(asset.file_size, 1024);
|
||||||
@@ -111,7 +119,8 @@ async fn rejects_quota_exceeded() {
|
|||||||
h.quota_repo.save("a).await.unwrap();
|
h.quota_repo.save("a).await.unwrap();
|
||||||
|
|
||||||
let handler = h.ingest_handler();
|
let handler = h.ingest_handler();
|
||||||
let result = handler.execute(IngestAssetCommand {
|
let result = handler
|
||||||
|
.execute(IngestAssetCommand {
|
||||||
uploader_id: user,
|
uploader_id: user,
|
||||||
client_device_id: "iphone-1".into(),
|
client_device_id: "iphone-1".into(),
|
||||||
filename: "big.jpg".into(),
|
filename: "big.jpg".into(),
|
||||||
@@ -119,7 +128,8 @@ async fn rejects_quota_exceeded() {
|
|||||||
target_path_id: path_id,
|
target_path_id: path_id,
|
||||||
file_size: 1024,
|
file_size: 1024,
|
||||||
data: Bytes::from(vec![0u8; 1024]),
|
data: Bytes::from(vec![0u8; 1024]),
|
||||||
}).await;
|
})
|
||||||
|
.await;
|
||||||
|
|
||||||
assert!(matches!(result, Err(DomainError::QuotaExceeded(_))));
|
assert!(matches!(result, Err(DomainError::QuotaExceeded(_))));
|
||||||
}
|
}
|
||||||
@@ -131,7 +141,8 @@ async fn rejects_invalid_checksum() {
|
|||||||
let path_id = h.setup_volume_and_path(user).await;
|
let path_id = h.setup_volume_and_path(user).await;
|
||||||
|
|
||||||
let handler = h.ingest_handler();
|
let handler = h.ingest_handler();
|
||||||
let result = handler.execute(IngestAssetCommand {
|
let result = handler
|
||||||
|
.execute(IngestAssetCommand {
|
||||||
uploader_id: user,
|
uploader_id: user,
|
||||||
client_device_id: "iphone-1".into(),
|
client_device_id: "iphone-1".into(),
|
||||||
filename: "photo.jpg".into(),
|
filename: "photo.jpg".into(),
|
||||||
@@ -139,7 +150,8 @@ async fn rejects_invalid_checksum() {
|
|||||||
target_path_id: path_id,
|
target_path_id: path_id,
|
||||||
file_size: 1024,
|
file_size: 1024,
|
||||||
data: Bytes::from(vec![0u8; 1024]),
|
data: Bytes::from(vec![0u8; 1024]),
|
||||||
}).await;
|
})
|
||||||
|
.await;
|
||||||
|
|
||||||
assert!(matches!(result, Err(DomainError::Validation(_))));
|
assert!(matches!(result, Err(DomainError::Validation(_))));
|
||||||
}
|
}
|
||||||
@@ -151,11 +163,14 @@ async fn rejects_non_ingest_path() {
|
|||||||
|
|
||||||
// Create volume + non-ingest path directly
|
// Create volume + non-ingest path directly
|
||||||
let vol_handler = RegisterVolumeHandler::new(h.vol_repo.clone());
|
let vol_handler = RegisterVolumeHandler::new(h.vol_repo.clone());
|
||||||
let vol = vol_handler.execute(RegisterVolumeCommand {
|
let vol = vol_handler
|
||||||
|
.execute(RegisterVolumeCommand {
|
||||||
volume_name: "main".into(),
|
volume_name: "main".into(),
|
||||||
uri_prefix: "file:///data".into(),
|
uri_prefix: "file:///data".into(),
|
||||||
is_writable: true,
|
is_writable: true,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let path = domain::entities::LibraryPath::new_user_owned(
|
let path = domain::entities::LibraryPath::new_user_owned(
|
||||||
vol.volume_id,
|
vol.volume_id,
|
||||||
@@ -167,7 +182,8 @@ async fn rejects_non_ingest_path() {
|
|||||||
h.path_repo.save(&path).await.unwrap();
|
h.path_repo.save(&path).await.unwrap();
|
||||||
|
|
||||||
let handler = h.ingest_handler();
|
let handler = h.ingest_handler();
|
||||||
let result = handler.execute(IngestAssetCommand {
|
let result = handler
|
||||||
|
.execute(IngestAssetCommand {
|
||||||
uploader_id: user,
|
uploader_id: user,
|
||||||
client_device_id: "iphone-1".into(),
|
client_device_id: "iphone-1".into(),
|
||||||
filename: "photo.jpg".into(),
|
filename: "photo.jpg".into(),
|
||||||
@@ -175,7 +191,8 @@ async fn rejects_non_ingest_path() {
|
|||||||
target_path_id: path.path_id,
|
target_path_id: path.path_id,
|
||||||
file_size: 1024,
|
file_size: 1024,
|
||||||
data: Bytes::from(vec![0u8; 1024]),
|
data: Bytes::from(vec![0u8; 1024]),
|
||||||
}).await;
|
})
|
||||||
|
.await;
|
||||||
|
|
||||||
assert!(matches!(result, Err(DomainError::Validation(_))));
|
assert!(matches!(result, Err(DomainError::Validation(_))));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
mod register_volume;
|
|
||||||
mod register_library_path;
|
|
||||||
mod ingest_asset;
|
mod ingest_asset;
|
||||||
|
mod register_library_path;
|
||||||
|
mod register_volume;
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
use std::sync::Arc;
|
use application::storage::{
|
||||||
use application::testing::{InMemoryStorageVolumeRepository, InMemoryLibraryPathRepository};
|
RegisterLibraryPathCommand, RegisterLibraryPathHandler, RegisterVolumeCommand,
|
||||||
use application::storage::{RegisterVolumeCommand, RegisterVolumeHandler, RegisterLibraryPathCommand, RegisterLibraryPathHandler};
|
RegisterVolumeHandler,
|
||||||
|
};
|
||||||
|
use application::testing::{InMemoryLibraryPathRepository, InMemoryStorageVolumeRepository};
|
||||||
use domain::errors::DomainError;
|
use domain::errors::DomainError;
|
||||||
use domain::value_objects::SystemId;
|
use domain::value_objects::SystemId;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn creates_path() {
|
async fn creates_path() {
|
||||||
@@ -10,20 +13,26 @@ async fn creates_path() {
|
|||||||
let path_repo = Arc::new(InMemoryLibraryPathRepository::new());
|
let path_repo = Arc::new(InMemoryLibraryPathRepository::new());
|
||||||
|
|
||||||
let vol_handler = RegisterVolumeHandler::new(vol_repo.clone());
|
let vol_handler = RegisterVolumeHandler::new(vol_repo.clone());
|
||||||
let vol = vol_handler.execute(RegisterVolumeCommand {
|
let vol = vol_handler
|
||||||
|
.execute(RegisterVolumeCommand {
|
||||||
volume_name: "main".into(),
|
volume_name: "main".into(),
|
||||||
uri_prefix: "file:///data".into(),
|
uri_prefix: "file:///data".into(),
|
||||||
is_writable: true,
|
is_writable: true,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let handler = RegisterLibraryPathHandler::new(vol_repo, path_repo);
|
let handler = RegisterLibraryPathHandler::new(vol_repo, path_repo);
|
||||||
let owner = SystemId::new();
|
let owner = SystemId::new();
|
||||||
let path = handler.execute(RegisterLibraryPathCommand {
|
let path = handler
|
||||||
|
.execute(RegisterLibraryPathCommand {
|
||||||
volume_id: vol.volume_id,
|
volume_id: vol.volume_id,
|
||||||
relative_path: "photos/inbox".into(),
|
relative_path: "photos/inbox".into(),
|
||||||
owner_id: owner,
|
owner_id: owner,
|
||||||
is_ingest_destination: true,
|
is_ingest_destination: true,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(path.volume_id, vol.volume_id);
|
assert_eq!(path.volume_id, vol.volume_id);
|
||||||
assert_eq!(path.relative_path, "photos/inbox");
|
assert_eq!(path.relative_path, "photos/inbox");
|
||||||
@@ -37,11 +46,13 @@ async fn rejects_nonexistent_volume() {
|
|||||||
let path_repo = Arc::new(InMemoryLibraryPathRepository::new());
|
let path_repo = Arc::new(InMemoryLibraryPathRepository::new());
|
||||||
let handler = RegisterLibraryPathHandler::new(vol_repo, path_repo);
|
let handler = RegisterLibraryPathHandler::new(vol_repo, path_repo);
|
||||||
|
|
||||||
let result = handler.execute(RegisterLibraryPathCommand {
|
let result = handler
|
||||||
|
.execute(RegisterLibraryPathCommand {
|
||||||
volume_id: SystemId::new(),
|
volume_id: SystemId::new(),
|
||||||
relative_path: "photos/inbox".into(),
|
relative_path: "photos/inbox".into(),
|
||||||
owner_id: SystemId::new(),
|
owner_id: SystemId::new(),
|
||||||
is_ingest_destination: true,
|
is_ingest_destination: true,
|
||||||
}).await;
|
})
|
||||||
|
.await;
|
||||||
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,20 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use application::testing::InMemoryStorageVolumeRepository;
|
|
||||||
use application::storage::{RegisterVolumeCommand, RegisterVolumeHandler};
|
use application::storage::{RegisterVolumeCommand, RegisterVolumeHandler};
|
||||||
|
use application::testing::InMemoryStorageVolumeRepository;
|
||||||
use domain::errors::DomainError;
|
use domain::errors::DomainError;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn creates_volume() {
|
async fn creates_volume() {
|
||||||
let repo = Arc::new(InMemoryStorageVolumeRepository::new());
|
let repo = Arc::new(InMemoryStorageVolumeRepository::new());
|
||||||
let handler = RegisterVolumeHandler::new(repo);
|
let handler = RegisterVolumeHandler::new(repo);
|
||||||
let vol = handler.execute(RegisterVolumeCommand {
|
let vol = handler
|
||||||
|
.execute(RegisterVolumeCommand {
|
||||||
volume_name: "primary".into(),
|
volume_name: "primary".into(),
|
||||||
uri_prefix: "file:///data".into(),
|
uri_prefix: "file:///data".into(),
|
||||||
is_writable: true,
|
is_writable: true,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
assert_eq!(vol.volume_name, "primary");
|
assert_eq!(vol.volume_name, "primary");
|
||||||
assert_eq!(vol.uri_prefix, "file:///data");
|
assert_eq!(vol.uri_prefix, "file:///data");
|
||||||
assert!(vol.is_writable);
|
assert!(vol.is_writable);
|
||||||
@@ -21,10 +24,12 @@ async fn creates_volume() {
|
|||||||
async fn rejects_empty_name() {
|
async fn rejects_empty_name() {
|
||||||
let repo = Arc::new(InMemoryStorageVolumeRepository::new());
|
let repo = Arc::new(InMemoryStorageVolumeRepository::new());
|
||||||
let handler = RegisterVolumeHandler::new(repo);
|
let handler = RegisterVolumeHandler::new(repo);
|
||||||
let result = handler.execute(RegisterVolumeCommand {
|
let result = handler
|
||||||
|
.execute(RegisterVolumeCommand {
|
||||||
volume_name: "".into(),
|
volume_name: "".into(),
|
||||||
uri_prefix: "file:///data".into(),
|
uri_prefix: "file:///data".into(),
|
||||||
is_writable: true,
|
is_writable: true,
|
||||||
}).await;
|
})
|
||||||
|
.await;
|
||||||
assert!(matches!(result, Err(DomainError::Validation(_))));
|
assert!(matches!(result, Err(DomainError::Validation(_))));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
use std::sync::Arc;
|
use application::storage::{CheckQuotaHandler, CheckQuotaQuery};
|
||||||
use application::testing::{InMemoryQuotaRepository, InMemoryUsageLedgerRepository};
|
use application::testing::{InMemoryQuotaRepository, InMemoryUsageLedgerRepository};
|
||||||
use application::storage::{CheckQuotaQuery, CheckQuotaHandler};
|
|
||||||
use domain::entities::{QuotaDefinition, TimePeriod, UsageLedgerEntry, UsageType};
|
use domain::entities::{QuotaDefinition, TimePeriod, UsageLedgerEntry, UsageType};
|
||||||
use domain::ports::UsageLedgerRepository;
|
use domain::ports::UsageLedgerRepository;
|
||||||
use domain::value_objects::SystemId;
|
use domain::value_objects::SystemId;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn returns_allowed() {
|
async fn returns_allowed() {
|
||||||
@@ -17,11 +17,14 @@ async fn returns_allowed() {
|
|||||||
quota_repo.save("a).await.unwrap();
|
quota_repo.save("a).await.unwrap();
|
||||||
|
|
||||||
let handler = CheckQuotaHandler::new(quota_repo, ledger_repo);
|
let handler = CheckQuotaHandler::new(quota_repo, ledger_repo);
|
||||||
let result = handler.execute(CheckQuotaQuery {
|
let result = handler
|
||||||
|
.execute(CheckQuotaQuery {
|
||||||
user_id: user,
|
user_id: user,
|
||||||
usage_type: UsageType::StorageBytes,
|
usage_type: UsageType::StorageBytes,
|
||||||
requested_amount: 5_000,
|
requested_amount: 5_000,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert!(result.allowed);
|
assert!(result.allowed);
|
||||||
assert_eq!(result.limit, 10_000);
|
assert_eq!(result.limit, 10_000);
|
||||||
@@ -44,11 +47,14 @@ async fn returns_denied() {
|
|||||||
ledger_repo.record(&entry).await.unwrap();
|
ledger_repo.record(&entry).await.unwrap();
|
||||||
|
|
||||||
let handler = CheckQuotaHandler::new(quota_repo, ledger_repo);
|
let handler = CheckQuotaHandler::new(quota_repo, ledger_repo);
|
||||||
let result = handler.execute(CheckQuotaQuery {
|
let result = handler
|
||||||
|
.execute(CheckQuotaQuery {
|
||||||
user_id: user,
|
user_id: user,
|
||||||
usage_type: UsageType::StorageBytes,
|
usage_type: UsageType::StorageBytes,
|
||||||
requested_amount: 200,
|
requested_amount: 200,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert!(!result.allowed);
|
assert!(!result.allowed);
|
||||||
assert_eq!(result.current_usage, 900);
|
assert_eq!(result.current_usage, 900);
|
||||||
@@ -60,11 +66,14 @@ async fn returns_unlimited_when_no_quota() {
|
|||||||
let ledger_repo = Arc::new(InMemoryUsageLedgerRepository::new());
|
let ledger_repo = Arc::new(InMemoryUsageLedgerRepository::new());
|
||||||
|
|
||||||
let handler = CheckQuotaHandler::new(quota_repo, ledger_repo);
|
let handler = CheckQuotaHandler::new(quota_repo, ledger_repo);
|
||||||
let result = handler.execute(CheckQuotaQuery {
|
let result = handler
|
||||||
|
.execute(CheckQuotaQuery {
|
||||||
user_id: SystemId::new(),
|
user_id: SystemId::new(),
|
||||||
usage_type: UsageType::StorageBytes,
|
usage_type: UsageType::StorageBytes,
|
||||||
requested_amount: 999_999,
|
requested_amount: 999_999,
|
||||||
}).await.unwrap();
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert!(result.allowed);
|
assert!(result.allowed);
|
||||||
assert!(result.is_unlimited);
|
assert!(result.is_unlimited);
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use axum::Router;
|
use axum::Router;
|
||||||
use axum::http::HeaderValue;
|
use axum::http::HeaderValue;
|
||||||
use tower_http::{cors::{Any, CorsLayer}, trace::TraceLayer};
|
use std::sync::Arc;
|
||||||
|
use tower_http::{
|
||||||
|
cors::{Any, CorsLayer},
|
||||||
|
trace::TraceLayer,
|
||||||
|
};
|
||||||
|
|
||||||
use adapters_auth::{BcryptPasswordHasher, JwtTokenIssuer};
|
use adapters_auth::{BcryptPasswordHasher, JwtTokenIssuer};
|
||||||
|
|
||||||
|
use adapters_postgres::{PostgresUserRepository, connect, run_migrations};
|
||||||
use adapters_postgres::{connect, run_migrations, PostgresUserRepository};
|
|
||||||
|
|
||||||
|
|
||||||
use adapters_storage::{ObjectStorageAdapter, StorageConfig, build_store};
|
use adapters_storage::{ObjectStorageAdapter, StorageConfig, build_store};
|
||||||
|
|
||||||
use application::identity::{RegisterUserHandler, LoginUserHandler, GetProfileHandler};
|
use application::identity::{GetProfileHandler, LoginUserHandler, RegisterUserHandler};
|
||||||
use presentation::{routes::app_router, state::AppState};
|
use presentation::{routes::app_router, state::AppState};
|
||||||
|
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
@@ -21,28 +22,36 @@ pub async fn build_app(config: &Config) -> Result<Router> {
|
|||||||
let pool = connect(&config.database_url).await?;
|
let pool = connect(&config.database_url).await?;
|
||||||
run_migrations(&pool).await?;
|
run_migrations(&pool).await?;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let user_repo = Arc::new(PostgresUserRepository::new(pool));
|
let user_repo = Arc::new(PostgresUserRepository::new(pool));
|
||||||
|
|
||||||
let hasher = Arc::new(BcryptPasswordHasher);
|
let hasher = Arc::new(BcryptPasswordHasher);
|
||||||
let issuer = Arc::new(JwtTokenIssuer::new(&config.jwt_secret));
|
let issuer = Arc::new(JwtTokenIssuer::new(&config.jwt_secret));
|
||||||
|
|
||||||
let register_handler = Arc::new(RegisterUserHandler::new(user_repo.clone(), hasher.clone()));
|
let register_handler = Arc::new(RegisterUserHandler::new(user_repo.clone(), hasher.clone()));
|
||||||
let login_handler = Arc::new(LoginUserHandler::new(user_repo.clone(), hasher, issuer.clone()));
|
let login_handler = Arc::new(LoginUserHandler::new(
|
||||||
|
user_repo.clone(),
|
||||||
|
hasher,
|
||||||
|
issuer.clone(),
|
||||||
|
));
|
||||||
let get_profile_handler = Arc::new(GetProfileHandler::new(user_repo));
|
let get_profile_handler = Arc::new(GetProfileHandler::new(user_repo));
|
||||||
|
|
||||||
|
|
||||||
let storage_cfg = StorageConfig::from_env()?;
|
let storage_cfg = StorageConfig::from_env()?;
|
||||||
let store = build_store(&storage_cfg)?;
|
let store = build_store(&storage_cfg)?;
|
||||||
let storage = Arc::new(ObjectStorageAdapter::new(store, &storage_cfg.prefix)?);
|
let storage = Arc::new(ObjectStorageAdapter::new(store, &storage_cfg.prefix)?);
|
||||||
|
|
||||||
|
let state = AppState::new(
|
||||||
let state = AppState::new(register_handler, login_handler, get_profile_handler, issuer, storage);
|
register_handler,
|
||||||
|
login_handler,
|
||||||
|
get_profile_handler,
|
||||||
|
issuer,
|
||||||
|
storage,
|
||||||
|
);
|
||||||
|
|
||||||
let cors = CorsLayer::new()
|
let cors = CorsLayer::new()
|
||||||
.allow_origin(
|
.allow_origin(
|
||||||
config.cors_allowed_origins.iter()
|
config
|
||||||
|
.cors_allowed_origins
|
||||||
|
.iter()
|
||||||
.filter_map(|o| o.parse::<HeaderValue>().ok())
|
.filter_map(|o| o.parse::<HeaderValue>().ok())
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,9 @@ impl Asset {
|
|||||||
|
|
||||||
// --- AssetMetadata ---
|
// --- AssetMetadata ---
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize)]
|
#[derive(
|
||||||
|
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize,
|
||||||
|
)]
|
||||||
pub enum MetadataSource {
|
pub enum MetadataSource {
|
||||||
ExifExtracted,
|
ExifExtracted,
|
||||||
AiGenerated,
|
AiGenerated,
|
||||||
@@ -133,7 +135,11 @@ impl AssetStack {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_member(&mut self, asset_id: SystemId, role: StackMemberRole) -> Result<(), DomainError> {
|
pub fn add_member(
|
||||||
|
&mut self,
|
||||||
|
asset_id: SystemId,
|
||||||
|
role: StackMemberRole,
|
||||||
|
) -> Result<(), DomainError> {
|
||||||
if self.members.iter().any(|m| m.asset_id == asset_id) {
|
if self.members.iter().any(|m| m.asset_id == asset_id) {
|
||||||
return Err(DomainError::Conflict(
|
return Err(DomainError::Conflict(
|
||||||
"Asset already exists in stack".to_string(),
|
"Asset already exists in stack".to_string(),
|
||||||
@@ -179,7 +185,11 @@ pub struct DerivativeAsset {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl DerivativeAsset {
|
impl DerivativeAsset {
|
||||||
pub fn new_pending(parent: SystemId, profile: DerivativeProfile, path: impl Into<String>) -> Self {
|
pub fn new_pending(
|
||||||
|
parent: SystemId,
|
||||||
|
profile: DerivativeProfile,
|
||||||
|
path: impl Into<String>,
|
||||||
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
derivative_id: SystemId::new(),
|
derivative_id: SystemId::new(),
|
||||||
parent_asset_id: parent,
|
parent_asset_id: parent,
|
||||||
@@ -239,8 +249,14 @@ impl DuplicateGroup {
|
|||||||
detection_method: DetectionMethod::ExactHash,
|
detection_method: DetectionMethod::ExactHash,
|
||||||
status: DuplicateStatus::Unresolved,
|
status: DuplicateStatus::Unresolved,
|
||||||
candidates: vec![
|
candidates: vec![
|
||||||
DuplicateCandidate { asset_id: asset_a, similarity_score: 1.0 },
|
DuplicateCandidate {
|
||||||
DuplicateCandidate { asset_id: asset_b, similarity_score: 1.0 },
|
asset_id: asset_a,
|
||||||
|
similarity_score: 1.0,
|
||||||
|
},
|
||||||
|
DuplicateCandidate {
|
||||||
|
asset_id: asset_b,
|
||||||
|
similarity_score: 1.0,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use async_trait::async_trait;
|
use super::entities::{
|
||||||
|
Asset, AssetMetadata, AssetStack, DerivativeAsset, DerivativeProfile, DuplicateGroup,
|
||||||
|
MetadataSource,
|
||||||
|
};
|
||||||
use crate::common::errors::DomainError;
|
use crate::common::errors::DomainError;
|
||||||
use crate::common::value_objects::{Checksum, SystemId};
|
use crate::common::value_objects::{Checksum, SystemId};
|
||||||
use super::entities::{
|
use async_trait::async_trait;
|
||||||
Asset, AssetMetadata, AssetStack, DerivativeAsset, DerivativeProfile,
|
|
||||||
DuplicateGroup, MetadataSource,
|
|
||||||
};
|
|
||||||
|
|
||||||
// --- AssetRepository ---
|
// --- AssetRepository ---
|
||||||
|
|
||||||
@@ -12,7 +12,12 @@ use super::entities::{
|
|||||||
pub trait AssetRepository: Send + Sync {
|
pub trait AssetRepository: Send + Sync {
|
||||||
async fn find_by_id(&self, id: &SystemId) -> Result<Option<Asset>, DomainError>;
|
async fn find_by_id(&self, id: &SystemId) -> Result<Option<Asset>, DomainError>;
|
||||||
async fn find_by_checksum(&self, checksum: &Checksum) -> Result<Vec<Asset>, DomainError>;
|
async fn find_by_checksum(&self, checksum: &Checksum) -> Result<Vec<Asset>, DomainError>;
|
||||||
async fn find_by_owner(&self, owner_id: &SystemId, limit: u32, offset: u32) -> Result<Vec<Asset>, DomainError>;
|
async fn find_by_owner(
|
||||||
|
&self,
|
||||||
|
owner_id: &SystemId,
|
||||||
|
limit: u32,
|
||||||
|
offset: u32,
|
||||||
|
) -> Result<Vec<Asset>, DomainError>;
|
||||||
async fn save(&self, asset: &Asset) -> Result<(), DomainError>;
|
async fn save(&self, asset: &Asset) -> Result<(), DomainError>;
|
||||||
async fn delete(&self, id: &SystemId) -> Result<(), DomainError>;
|
async fn delete(&self, id: &SystemId) -> Result<(), DomainError>;
|
||||||
}
|
}
|
||||||
@@ -22,9 +27,17 @@ pub trait AssetRepository: Send + Sync {
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait AssetMetadataRepository: Send + Sync {
|
pub trait AssetMetadataRepository: Send + Sync {
|
||||||
async fn find_by_asset(&self, asset_id: &SystemId) -> Result<Vec<AssetMetadata>, DomainError>;
|
async fn find_by_asset(&self, asset_id: &SystemId) -> Result<Vec<AssetMetadata>, DomainError>;
|
||||||
async fn find_by_asset_and_source(&self, asset_id: &SystemId, source: MetadataSource) -> Result<Option<AssetMetadata>, DomainError>;
|
async fn find_by_asset_and_source(
|
||||||
|
&self,
|
||||||
|
asset_id: &SystemId,
|
||||||
|
source: MetadataSource,
|
||||||
|
) -> Result<Option<AssetMetadata>, DomainError>;
|
||||||
async fn save(&self, metadata: &AssetMetadata) -> Result<(), DomainError>;
|
async fn save(&self, metadata: &AssetMetadata) -> Result<(), DomainError>;
|
||||||
async fn delete_by_asset_and_source(&self, asset_id: &SystemId, source: MetadataSource) -> Result<(), DomainError>;
|
async fn delete_by_asset_and_source(
|
||||||
|
&self,
|
||||||
|
asset_id: &SystemId,
|
||||||
|
source: MetadataSource,
|
||||||
|
) -> Result<(), DomainError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- AssetStackRepository ---
|
// --- AssetStackRepository ---
|
||||||
@@ -41,8 +54,13 @@ pub trait AssetStackRepository: Send + Sync {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait DerivativeRepository: Send + Sync {
|
pub trait DerivativeRepository: Send + Sync {
|
||||||
async fn find_by_asset(&self, asset_id: &SystemId) -> Result<Vec<DerivativeAsset>, DomainError>;
|
async fn find_by_asset(&self, asset_id: &SystemId)
|
||||||
async fn find_by_asset_and_profile(&self, asset_id: &SystemId, profile: DerivativeProfile) -> Result<Option<DerivativeAsset>, DomainError>;
|
-> Result<Vec<DerivativeAsset>, DomainError>;
|
||||||
|
async fn find_by_asset_and_profile(
|
||||||
|
&self,
|
||||||
|
asset_id: &SystemId,
|
||||||
|
profile: DerivativeProfile,
|
||||||
|
) -> Result<Option<DerivativeAsset>, DomainError>;
|
||||||
async fn save(&self, derivative: &DerivativeAsset) -> Result<(), DomainError>;
|
async fn save(&self, derivative: &DerivativeAsset) -> Result<(), DomainError>;
|
||||||
async fn delete(&self, id: &SystemId) -> Result<(), DomainError>;
|
async fn delete(&self, id: &SystemId) -> Result<(), DomainError>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use async_trait::async_trait;
|
|
||||||
use crate::common::errors::DomainError;
|
use crate::common::errors::DomainError;
|
||||||
use crate::common::events::DomainEvent;
|
use crate::common::events::DomainEvent;
|
||||||
|
use async_trait::async_trait;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait EventPublisher: Send + Sync {
|
pub trait EventPublisher: Send + Sync {
|
||||||
|
|||||||
@@ -7,9 +7,10 @@ impl Checksum {
|
|||||||
pub fn new(hex: impl Into<String>) -> Result<Self, DomainError> {
|
pub fn new(hex: impl Into<String>) -> Result<Self, DomainError> {
|
||||||
let hex = hex.into().to_lowercase();
|
let hex = hex.into().to_lowercase();
|
||||||
if hex.len() != 64 {
|
if hex.len() != 64 {
|
||||||
return Err(DomainError::Validation(
|
return Err(DomainError::Validation(format!(
|
||||||
format!("Checksum must be 64 hex characters, got {}", hex.len()),
|
"Checksum must be 64 hex characters, got {}",
|
||||||
));
|
hex.len()
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
if !hex.chars().all(|c| c.is_ascii_hexdigit()) {
|
if !hex.chars().all(|c| c.is_ascii_hexdigit()) {
|
||||||
return Err(DomainError::Validation(
|
return Err(DomainError::Validation(
|
||||||
@@ -19,7 +20,9 @@ impl Checksum {
|
|||||||
Ok(Self(hex))
|
Ok(Self(hex))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_str(&self) -> &str { &self.0 }
|
pub fn as_str(&self) -> &str {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for Checksum {
|
impl std::fmt::Display for Checksum {
|
||||||
|
|||||||
@@ -1,12 +1,20 @@
|
|||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize)]
|
#[derive(
|
||||||
|
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize,
|
||||||
|
)]
|
||||||
pub struct DateTimeStamp(DateTime<Utc>);
|
pub struct DateTimeStamp(DateTime<Utc>);
|
||||||
|
|
||||||
impl DateTimeStamp {
|
impl DateTimeStamp {
|
||||||
pub fn now() -> Self { Self(Utc::now()) }
|
pub fn now() -> Self {
|
||||||
pub fn from_datetime(dt: DateTime<Utc>) -> Self { Self(dt) }
|
Self(Utc::now())
|
||||||
pub fn as_datetime(&self) -> &DateTime<Utc> { &self.0 }
|
}
|
||||||
|
pub fn from_datetime(dt: DateTime<Utc>) -> Self {
|
||||||
|
Self(dt)
|
||||||
|
}
|
||||||
|
pub fn as_datetime(&self) -> &DateTime<Utc> {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for DateTimeStamp {
|
impl std::fmt::Display for DateTimeStamp {
|
||||||
@@ -16,5 +24,7 @@ impl std::fmt::Display for DateTimeStamp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl From<DateTime<Utc>> for DateTimeStamp {
|
impl From<DateTime<Utc>> for DateTimeStamp {
|
||||||
fn from(dt: DateTime<Utc>) -> Self { Self(dt) }
|
fn from(dt: DateTime<Utc>) -> Self {
|
||||||
|
Self(dt)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user