style: cargo fmt --all
This commit is contained in:
@@ -1,25 +1,23 @@
|
||||
use std::collections::HashMap;
|
||||
use async_trait::async_trait;
|
||||
use tokio::sync::Mutex;
|
||||
use domain::{
|
||||
entities::{
|
||||
Album, Asset, AssetMetadata, AssetTag, DuplicateGroup, DuplicateStatus,
|
||||
Group, IngestSession, InviteCode, Job, JobBatch, JobStatus, LibraryPath,
|
||||
MetadataSource, Plugin, ProcessingPipeline, QuotaDefinition, Role,
|
||||
ShareLink, ShareScope, ShareTarget, SidecarRecord, SyncStatus,
|
||||
StorageVolume, Tag, UsageLedgerEntry, UsageType, User,
|
||||
Album, Asset, AssetMetadata, AssetTag, DuplicateGroup, DuplicateStatus, Group,
|
||||
IngestSession, InviteCode, Job, JobBatch, JobStatus, LibraryPath, MetadataSource, Plugin,
|
||||
ProcessingPipeline, QuotaDefinition, Role, ShareLink, ShareScope, ShareTarget,
|
||||
SidecarRecord, StorageVolume, SyncStatus, Tag, UsageLedgerEntry, UsageType, User,
|
||||
},
|
||||
errors::DomainError,
|
||||
ports::{
|
||||
AlbumRepository, AssetMetadataRepository, AssetRepository,
|
||||
DuplicateRepository, GroupRepository, IngestSessionRepository,
|
||||
JobBatchRepository, JobRepository, LibraryPathRepository,
|
||||
PipelineRepository, PluginRepository, QuotaRepository,
|
||||
RoleRepository, ShareRepository, SidecarRepository, StorageVolumeRepository,
|
||||
TagRepository, UsageLedgerRepository, UserRepository,
|
||||
AlbumRepository, AssetMetadataRepository, AssetRepository, DuplicateRepository,
|
||||
GroupRepository, IngestSessionRepository, JobBatchRepository, JobRepository,
|
||||
LibraryPathRepository, PipelineRepository, PluginRepository, QuotaRepository,
|
||||
RoleRepository, ShareRepository, SidecarRepository, StorageVolumeRepository, TagRepository,
|
||||
UsageLedgerRepository, UserRepository,
|
||||
},
|
||||
value_objects::{Checksum, DateTimeStamp, Email, SystemId},
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
// --- InMemoryUserRepository ---
|
||||
|
||||
@@ -29,7 +27,9 @@ pub struct InMemoryUserRepository {
|
||||
|
||||
impl InMemoryUserRepository {
|
||||
pub fn new() -> Self {
|
||||
Self { users: Mutex::new(HashMap::new()) }
|
||||
Self {
|
||||
users: Mutex::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn all(&self) -> Vec<User> {
|
||||
@@ -38,7 +38,9 @@ impl InMemoryUserRepository {
|
||||
}
|
||||
|
||||
impl Default for InMemoryUserRepository {
|
||||
fn default() -> Self { Self::new() }
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -48,19 +50,30 @@ impl UserRepository for InMemoryUserRepository {
|
||||
}
|
||||
|
||||
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())
|
||||
.cloned())
|
||||
}
|
||||
|
||||
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)
|
||||
.cloned())
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
|
||||
@@ -78,12 +91,16 @@ pub struct InMemoryAssetRepository {
|
||||
|
||||
impl InMemoryAssetRepository {
|
||||
pub fn new() -> Self {
|
||||
Self { data: Mutex::new(HashMap::new()) }
|
||||
Self {
|
||||
data: Mutex::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for InMemoryAssetRepository {
|
||||
fn default() -> Self { Self::new() }
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -93,22 +110,42 @@ impl AssetRepository for InMemoryAssetRepository {
|
||||
}
|
||||
|
||||
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)
|
||||
.cloned()
|
||||
.collect())
|
||||
}
|
||||
|
||||
async fn find_by_owner(&self, owner_id: &SystemId, limit: u32, offset: u32) -> Result<Vec<Asset>, DomainError> {
|
||||
let all: Vec<Asset> = self.data.lock().await.values()
|
||||
async fn find_by_owner(
|
||||
&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)
|
||||
.cloned()
|
||||
.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> {
|
||||
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(())
|
||||
}
|
||||
|
||||
@@ -126,12 +163,16 @@ pub struct InMemoryAlbumRepository {
|
||||
|
||||
impl InMemoryAlbumRepository {
|
||||
pub fn new() -> Self {
|
||||
Self { data: Mutex::new(HashMap::new()) }
|
||||
Self {
|
||||
data: Mutex::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for InMemoryAlbumRepository {
|
||||
fn default() -> Self { Self::new() }
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -141,14 +182,21 @@ impl AlbumRepository for InMemoryAlbumRepository {
|
||||
}
|
||||
|
||||
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)
|
||||
.cloned()
|
||||
.collect())
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
|
||||
@@ -166,12 +214,16 @@ pub struct InMemoryJobRepository {
|
||||
|
||||
impl InMemoryJobRepository {
|
||||
pub fn new() -> Self {
|
||||
Self { data: Mutex::new(HashMap::new()) }
|
||||
Self {
|
||||
data: Mutex::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for InMemoryJobRepository {
|
||||
fn default() -> Self { Self::new() }
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -182,21 +234,29 @@ impl JobRepository for InMemoryJobRepository {
|
||||
|
||||
async fn find_next_queued(&self) -> Result<Option<Job>, DomainError> {
|
||||
let data = self.data.lock().await;
|
||||
Ok(data.values()
|
||||
Ok(data
|
||||
.values()
|
||||
.filter(|j| j.status == JobStatus::Queued)
|
||||
.max_by_key(|j| j.priority)
|
||||
.cloned())
|
||||
}
|
||||
|
||||
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))
|
||||
.cloned()
|
||||
.collect())
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
}
|
||||
@@ -209,12 +269,16 @@ pub struct InMemoryRoleRepository {
|
||||
|
||||
impl InMemoryRoleRepository {
|
||||
pub fn new() -> Self {
|
||||
Self { data: Mutex::new(HashMap::new()) }
|
||||
Self {
|
||||
data: Mutex::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for InMemoryRoleRepository {
|
||||
fn default() -> Self { Self::new() }
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -224,20 +288,31 @@ impl RoleRepository for InMemoryRoleRepository {
|
||||
}
|
||||
|
||||
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)
|
||||
.cloned())
|
||||
}
|
||||
|
||||
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)
|
||||
.cloned()
|
||||
.collect())
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
|
||||
@@ -255,12 +330,16 @@ pub struct InMemoryGroupRepository {
|
||||
|
||||
impl InMemoryGroupRepository {
|
||||
pub fn new() -> Self {
|
||||
Self { data: Mutex::new(HashMap::new()) }
|
||||
Self {
|
||||
data: Mutex::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for InMemoryGroupRepository {
|
||||
fn default() -> Self { Self::new() }
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -270,14 +349,21 @@ impl GroupRepository for InMemoryGroupRepository {
|
||||
}
|
||||
|
||||
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))
|
||||
.cloned()
|
||||
.collect())
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
|
||||
@@ -295,12 +381,16 @@ pub struct InMemoryStorageVolumeRepository {
|
||||
|
||||
impl InMemoryStorageVolumeRepository {
|
||||
pub fn new() -> Self {
|
||||
Self { data: Mutex::new(HashMap::new()) }
|
||||
Self {
|
||||
data: Mutex::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for InMemoryStorageVolumeRepository {
|
||||
fn default() -> Self { Self::new() }
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -314,7 +404,10 @@ impl StorageVolumeRepository for InMemoryStorageVolumeRepository {
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
|
||||
@@ -332,12 +425,16 @@ pub struct InMemoryLibraryPathRepository {
|
||||
|
||||
impl InMemoryLibraryPathRepository {
|
||||
pub fn new() -> Self {
|
||||
Self { data: Mutex::new(HashMap::new()) }
|
||||
Self {
|
||||
data: Mutex::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for InMemoryLibraryPathRepository {
|
||||
fn default() -> Self { Self::new() }
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -347,21 +444,35 @@ impl LibraryPathRepository for InMemoryLibraryPathRepository {
|
||||
}
|
||||
|
||||
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)
|
||||
.cloned()
|
||||
.collect())
|
||||
}
|
||||
|
||||
async fn find_ingest_destinations(&self, owner_id: &SystemId) -> Result<Vec<LibraryPath>, DomainError> {
|
||||
Ok(self.data.lock().await.values()
|
||||
async fn find_ingest_destinations(
|
||||
&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))
|
||||
.cloned()
|
||||
.collect())
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
|
||||
@@ -379,12 +490,16 @@ pub struct InMemoryIngestSessionRepository {
|
||||
|
||||
impl InMemoryIngestSessionRepository {
|
||||
pub fn new() -> Self {
|
||||
Self { data: Mutex::new(HashMap::new()) }
|
||||
Self {
|
||||
data: Mutex::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for InMemoryIngestSessionRepository {
|
||||
fn default() -> Self { Self::new() }
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -394,14 +509,21 @@ impl IngestSessionRepository for InMemoryIngestSessionRepository {
|
||||
}
|
||||
|
||||
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)
|
||||
.cloned()
|
||||
.collect())
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
}
|
||||
@@ -414,24 +536,38 @@ pub struct InMemoryQuotaRepository {
|
||||
|
||||
impl InMemoryQuotaRepository {
|
||||
pub fn new() -> Self {
|
||||
Self { data: Mutex::new(HashMap::new()) }
|
||||
Self {
|
||||
data: Mutex::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for InMemoryQuotaRepository {
|
||||
fn default() -> Self { Self::new() }
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl QuotaRepository for InMemoryQuotaRepository {
|
||||
async fn find_by_owner(&self, owner_id: &SystemId) -> Result<Option<QuotaDefinition>, DomainError> {
|
||||
Ok(self.data.lock().await.values()
|
||||
async fn find_by_owner(
|
||||
&self,
|
||||
owner_id: &SystemId,
|
||||
) -> Result<Option<QuotaDefinition>, DomainError> {
|
||||
Ok(self
|
||||
.data
|
||||
.lock()
|
||||
.await
|
||||
.values()
|
||||
.find(|q| &q.owner_scope == owner_id)
|
||||
.cloned())
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
|
||||
@@ -449,12 +585,16 @@ pub struct InMemoryUsageLedgerRepository {
|
||||
|
||||
impl InMemoryUsageLedgerRepository {
|
||||
pub fn new() -> Self {
|
||||
Self { entries: Mutex::new(Vec::new()) }
|
||||
Self {
|
||||
entries: Mutex::new(Vec::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for InMemoryUsageLedgerRepository {
|
||||
fn default() -> Self { Self::new() }
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -471,7 +611,8 @@ impl UsageLedgerRepository for InMemoryUsageLedgerRepository {
|
||||
since: Option<DateTimeStamp>,
|
||||
) -> Result<u64, DomainError> {
|
||||
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| match &since {
|
||||
Some(ts) => &e.timestamp >= ts,
|
||||
@@ -491,7 +632,9 @@ pub struct InMemoryAssetMetadataRepository {
|
||||
|
||||
impl InMemoryAssetMetadataRepository {
|
||||
pub fn new() -> Self {
|
||||
Self { data: Mutex::new(HashMap::new()) }
|
||||
Self {
|
||||
data: Mutex::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
|
||||
fn key(asset_id: &SystemId, source: MetadataSource) -> String {
|
||||
@@ -500,21 +643,36 @@ impl InMemoryAssetMetadataRepository {
|
||||
}
|
||||
|
||||
impl Default for InMemoryAssetMetadataRepository {
|
||||
fn default() -> Self { Self::new() }
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl AssetMetadataRepository for InMemoryAssetMetadataRepository {
|
||||
async fn find_by_asset(&self, asset_id: &SystemId) -> Result<Vec<AssetMetadata>, DomainError> {
|
||||
let prefix = format!("{asset_id}:");
|
||||
Ok(self.data.lock().await.iter()
|
||||
Ok(self
|
||||
.data
|
||||
.lock()
|
||||
.await
|
||||
.iter()
|
||||
.filter(|(k, _)| k.starts_with(&prefix))
|
||||
.map(|(_, v)| v.clone())
|
||||
.collect())
|
||||
}
|
||||
|
||||
async fn find_by_asset_and_source(&self, asset_id: &SystemId, source: MetadataSource) -> Result<Option<AssetMetadata>, DomainError> {
|
||||
Ok(self.data.lock().await.get(&Self::key(asset_id, source)).cloned())
|
||||
async fn find_by_asset_and_source(
|
||||
&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> {
|
||||
@@ -523,7 +681,11 @@ impl AssetMetadataRepository for InMemoryAssetMetadataRepository {
|
||||
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));
|
||||
Ok(())
|
||||
}
|
||||
@@ -550,13 +712,18 @@ impl InMemoryShareRepository {
|
||||
}
|
||||
|
||||
impl Default for InMemoryShareRepository {
|
||||
fn default() -> Self { Self::new() }
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl ShareRepository for InMemoryShareRepository {
|
||||
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(())
|
||||
}
|
||||
|
||||
@@ -564,8 +731,15 @@ impl ShareRepository for InMemoryShareRepository {
|
||||
Ok(self.scopes.lock().await.get(&id.to_string()).cloned())
|
||||
}
|
||||
|
||||
async fn find_scopes_for_resource(&self, resource_id: &SystemId) -> Result<Vec<ShareScope>, DomainError> {
|
||||
Ok(self.scopes.lock().await.values()
|
||||
async fn find_scopes_for_resource(
|
||||
&self,
|
||||
resource_id: &SystemId,
|
||||
) -> Result<Vec<ShareScope>, DomainError> {
|
||||
Ok(self
|
||||
.scopes
|
||||
.lock()
|
||||
.await
|
||||
.values()
|
||||
.filter(|s| &s.shareable_id == resource_id)
|
||||
.cloned()
|
||||
.collect())
|
||||
@@ -582,22 +756,39 @@ impl ShareRepository for InMemoryShareRepository {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn find_targets_for_scope(&self, scope_id: &SystemId) -> Result<Vec<ShareTarget>, DomainError> {
|
||||
Ok(self.targets.lock().await.values()
|
||||
async fn find_targets_for_scope(
|
||||
&self,
|
||||
scope_id: &SystemId,
|
||||
) -> Result<Vec<ShareTarget>, DomainError> {
|
||||
Ok(self
|
||||
.targets
|
||||
.lock()
|
||||
.await
|
||||
.values()
|
||||
.filter(|t| &t.scope_id == scope_id)
|
||||
.cloned()
|
||||
.collect())
|
||||
}
|
||||
|
||||
async fn find_targets_for_user(&self, user_id: &SystemId) -> Result<Vec<ShareTarget>, DomainError> {
|
||||
Ok(self.targets.lock().await.values()
|
||||
async fn find_targets_for_user(
|
||||
&self,
|
||||
user_id: &SystemId,
|
||||
) -> Result<Vec<ShareTarget>, DomainError> {
|
||||
Ok(self
|
||||
.targets
|
||||
.lock()
|
||||
.await
|
||||
.values()
|
||||
.filter(|t| &t.target_id == user_id)
|
||||
.cloned()
|
||||
.collect())
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
|
||||
@@ -606,7 +797,10 @@ impl ShareRepository for InMemoryShareRepository {
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
|
||||
@@ -632,7 +826,9 @@ impl InMemoryTagRepository {
|
||||
}
|
||||
|
||||
impl Default for InMemoryTagRepository {
|
||||
fn default() -> Self { Self::new() }
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -642,17 +838,26 @@ impl TagRepository for InMemoryTagRepository {
|
||||
}
|
||||
|
||||
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)
|
||||
.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 tags = self.tags.lock().await;
|
||||
let mut result = Vec::new();
|
||||
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()));
|
||||
}
|
||||
}
|
||||
@@ -660,7 +865,10 @@ impl TagRepository for InMemoryTagRepository {
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
|
||||
@@ -670,7 +878,11 @@ impl TagRepository for InMemoryTagRepository {
|
||||
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}");
|
||||
self.asset_tags.lock().await.remove(&key);
|
||||
Ok(())
|
||||
@@ -685,12 +897,16 @@ pub struct InMemoryDuplicateRepository {
|
||||
|
||||
impl InMemoryDuplicateRepository {
|
||||
pub fn new() -> Self {
|
||||
Self { data: Mutex::new(HashMap::new()) }
|
||||
Self {
|
||||
data: Mutex::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for InMemoryDuplicateRepository {
|
||||
fn default() -> Self { Self::new() }
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -700,21 +916,32 @@ impl DuplicateRepository for InMemoryDuplicateRepository {
|
||||
}
|
||||
|
||||
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)
|
||||
.cloned()
|
||||
.collect())
|
||||
}
|
||||
|
||||
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))
|
||||
.cloned()
|
||||
.collect())
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
}
|
||||
@@ -727,29 +954,43 @@ pub struct InMemorySidecarRepository {
|
||||
|
||||
impl InMemorySidecarRepository {
|
||||
pub fn new() -> Self {
|
||||
Self { data: Mutex::new(HashMap::new()) }
|
||||
Self {
|
||||
data: Mutex::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for InMemorySidecarRepository {
|
||||
fn default() -> Self { Self::new() }
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
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())
|
||||
}
|
||||
|
||||
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)
|
||||
.cloned()
|
||||
.collect())
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
|
||||
@@ -767,12 +1008,16 @@ pub struct InMemoryJobBatchRepository {
|
||||
|
||||
impl InMemoryJobBatchRepository {
|
||||
pub fn new() -> Self {
|
||||
Self { data: Mutex::new(HashMap::new()) }
|
||||
Self {
|
||||
data: Mutex::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for InMemoryJobBatchRepository {
|
||||
fn default() -> Self { Self::new() }
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -782,7 +1027,10 @@ impl JobBatchRepository for InMemoryJobBatchRepository {
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
}
|
||||
@@ -795,12 +1043,16 @@ pub struct InMemoryPluginRepository {
|
||||
|
||||
impl InMemoryPluginRepository {
|
||||
pub fn new() -> Self {
|
||||
Self { data: Mutex::new(HashMap::new()) }
|
||||
Self {
|
||||
data: Mutex::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for InMemoryPluginRepository {
|
||||
fn default() -> Self { Self::new() }
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -810,14 +1062,21 @@ impl PluginRepository for InMemoryPluginRepository {
|
||||
}
|
||||
|
||||
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)
|
||||
.cloned()
|
||||
.collect())
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
}
|
||||
@@ -830,12 +1089,16 @@ pub struct InMemoryPipelineRepository {
|
||||
|
||||
impl InMemoryPipelineRepository {
|
||||
pub fn new() -> Self {
|
||||
Self { data: Mutex::new(HashMap::new()) }
|
||||
Self {
|
||||
data: Mutex::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for InMemoryPipelineRepository {
|
||||
fn default() -> Self { Self::new() }
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -845,14 +1108,21 @@ impl PipelineRepository for InMemoryPipelineRepository {
|
||||
}
|
||||
|
||||
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)
|
||||
.cloned()
|
||||
.collect())
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user