refactor: restructure domain crate by bounded context
This commit is contained in:
92
crates/domain/src/sidecar/entities.rs
Normal file
92
crates/domain/src/sidecar/entities.rs
Normal file
@@ -0,0 +1,92 @@
|
||||
use crate::common::value_objects::{Checksum, DateTimeStamp, SystemId};
|
||||
|
||||
// --- SidecarRecord ---
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
pub enum SyncStatus {
|
||||
InSync,
|
||||
PendingWrite,
|
||||
PendingRead,
|
||||
Conflict,
|
||||
Error,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct SidecarRecord {
|
||||
pub asset_id: SystemId,
|
||||
pub sync_status: SyncStatus,
|
||||
pub sidecar_storage_path: String,
|
||||
pub last_synced_at: Option<DateTimeStamp>,
|
||||
pub last_known_file_hash: Option<Checksum>,
|
||||
pub error_message: Option<String>,
|
||||
}
|
||||
|
||||
impl SidecarRecord {
|
||||
pub fn new(asset_id: SystemId, path: impl Into<String>) -> Self {
|
||||
Self {
|
||||
asset_id,
|
||||
sync_status: SyncStatus::PendingWrite,
|
||||
sidecar_storage_path: path.into(),
|
||||
last_synced_at: None,
|
||||
last_known_file_hash: None,
|
||||
error_message: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mark_synced(&mut self, file_hash: Checksum) {
|
||||
self.sync_status = SyncStatus::InSync;
|
||||
self.last_synced_at = Some(DateTimeStamp::now());
|
||||
self.last_known_file_hash = Some(file_hash);
|
||||
self.error_message = None;
|
||||
}
|
||||
|
||||
pub fn mark_pending_write(&mut self) {
|
||||
self.sync_status = SyncStatus::PendingWrite;
|
||||
}
|
||||
|
||||
pub fn mark_pending_read(&mut self) {
|
||||
self.sync_status = SyncStatus::PendingRead;
|
||||
}
|
||||
|
||||
pub fn mark_conflict(&mut self) {
|
||||
self.sync_status = SyncStatus::Conflict;
|
||||
}
|
||||
|
||||
pub fn mark_error(&mut self, message: impl Into<String>) {
|
||||
self.sync_status = SyncStatus::Error;
|
||||
self.error_message = Some(message.into());
|
||||
}
|
||||
}
|
||||
|
||||
// --- SidecarConfig ---
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
pub enum SyncMode {
|
||||
Auto,
|
||||
Scheduled,
|
||||
Manual,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
pub enum ConflictPolicy {
|
||||
DbWins,
|
||||
FileWins,
|
||||
RequireUserDecision,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct SidecarConfig {
|
||||
pub export_base_path: String,
|
||||
pub sync_mode: SyncMode,
|
||||
pub conflict_resolution_policy: ConflictPolicy,
|
||||
}
|
||||
|
||||
impl Default for SidecarConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
export_base_path: "/kphotos/sidecars".to_string(),
|
||||
sync_mode: SyncMode::Auto,
|
||||
conflict_resolution_policy: ConflictPolicy::DbWins,
|
||||
}
|
||||
}
|
||||
}
|
||||
5
crates/domain/src/sidecar/mod.rs
Normal file
5
crates/domain/src/sidecar/mod.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
pub mod entities;
|
||||
pub mod ports;
|
||||
|
||||
pub use entities::*;
|
||||
pub use ports::*;
|
||||
23
crates/domain/src/sidecar/ports.rs
Normal file
23
crates/domain/src/sidecar/ports.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use async_trait::async_trait;
|
||||
use crate::common::errors::DomainError;
|
||||
use crate::common::value_objects::{StructuredData, SystemId};
|
||||
use super::entities::{SidecarRecord, SyncStatus};
|
||||
|
||||
// --- SidecarRepository ---
|
||||
|
||||
#[async_trait]
|
||||
pub trait SidecarRepository: Send + Sync {
|
||||
async fn find_by_asset(&self, asset_id: &SystemId) -> Result<Option<SidecarRecord>, DomainError>;
|
||||
async fn find_by_status(&self, status: SyncStatus) -> Result<Vec<SidecarRecord>, DomainError>;
|
||||
async fn save(&self, record: &SidecarRecord) -> Result<(), DomainError>;
|
||||
async fn delete(&self, asset_id: &SystemId) -> Result<(), DomainError>;
|
||||
}
|
||||
|
||||
// --- SidecarWriterPort ---
|
||||
|
||||
#[async_trait]
|
||||
pub trait SidecarWriterPort: Send + Sync {
|
||||
fn format_name(&self) -> &str;
|
||||
async fn write_sidecar(&self, data: &StructuredData, path: &str) -> Result<(), DomainError>;
|
||||
async fn read_sidecar(&self, path: &str) -> Result<StructuredData, DomainError>;
|
||||
}
|
||||
Reference in New Issue
Block a user