domain crate code quality cleanup
strip all comments, extract tests to tests/ dirs, remove #[allow(clippy::...)], extract magic numbers to constants, refactor schedule engine private methods to use param structs, add Default impls, clippy.toml for persistence constructors
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
//! Library persistence ports (CQRS split) and sync adapter.
|
||||
|
||||
use async_trait::async_trait;
|
||||
|
||||
use crate::errors::DomainResult;
|
||||
@@ -11,58 +9,43 @@ use crate::value_objects::{ContentType, LibrarySearchFilter};
|
||||
|
||||
use super::media::IMediaProvider;
|
||||
|
||||
/// Write-side port for library persistence.
|
||||
#[async_trait]
|
||||
pub trait LibraryCommand: Send + Sync {
|
||||
/// Upsert a batch of library items for a given provider.
|
||||
async fn upsert_items(&self, provider_id: &str, items: Vec<LibraryItem>) -> DomainResult<()>;
|
||||
|
||||
/// Remove all items belonging to a provider (used before full re-sync).
|
||||
async fn clear_provider(&self, provider_id: &str) -> DomainResult<()>;
|
||||
|
||||
/// Create a sync log entry marking the start of a sync run.
|
||||
/// Returns the log entry ID for later completion.
|
||||
async fn log_sync_start(&self, provider_id: &str) -> DomainResult<i64>;
|
||||
|
||||
/// Mark a sync log entry as finished with the given result.
|
||||
async fn log_sync_finish(&self, log_id: i64, result: &LibrarySyncResult) -> DomainResult<()>;
|
||||
}
|
||||
|
||||
/// Read-side port for library persistence.
|
||||
#[async_trait]
|
||||
pub trait LibraryQuery: Send + Sync {
|
||||
/// Search the library with the given filter. Returns (items, total_count).
|
||||
async fn search(
|
||||
&self,
|
||||
filter: &LibrarySearchFilter,
|
||||
) -> DomainResult<(Vec<LibraryItem>, u32)>;
|
||||
|
||||
/// Get a single library item by its composite ID.
|
||||
async fn get_by_id(&self, id: &str) -> DomainResult<Option<LibraryItem>>;
|
||||
|
||||
/// List all collections, optionally filtered by provider.
|
||||
async fn list_collections(
|
||||
&self,
|
||||
provider_id: Option<&str>,
|
||||
) -> DomainResult<Vec<LibraryCollection>>;
|
||||
|
||||
/// List all unique series names, optionally filtered by provider.
|
||||
async fn list_series(&self, provider_id: Option<&str>) -> DomainResult<Vec<String>>;
|
||||
|
||||
/// List all genres, optionally filtered by content type and provider.
|
||||
async fn list_genres(
|
||||
&self,
|
||||
content_type: Option<&ContentType>,
|
||||
provider_id: Option<&str>,
|
||||
) -> DomainResult<Vec<String>>;
|
||||
|
||||
/// Get the latest sync log entries (one per provider).
|
||||
async fn latest_sync_status(&self) -> DomainResult<Vec<LibrarySyncLogEntry>>;
|
||||
|
||||
/// Check whether a sync is currently running for a provider.
|
||||
async fn is_sync_running(&self, provider_id: &str) -> DomainResult<bool>;
|
||||
|
||||
/// List TV show summaries, optionally filtered by provider, search term, and genres.
|
||||
async fn list_shows(
|
||||
&self,
|
||||
provider_id: Option<&str>,
|
||||
@@ -70,7 +53,6 @@ pub trait LibraryQuery: Send + Sync {
|
||||
genres: &[String],
|
||||
) -> DomainResult<Vec<ShowSummary>>;
|
||||
|
||||
/// List season summaries for a specific series.
|
||||
async fn list_seasons(
|
||||
&self,
|
||||
series_name: &str,
|
||||
@@ -78,9 +60,6 @@ pub trait LibraryQuery: Send + Sync {
|
||||
) -> DomainResult<Vec<SeasonSummary>>;
|
||||
}
|
||||
|
||||
/// Port: sync one provider's items into the library.
|
||||
///
|
||||
/// DB writes are handled entirely inside implementations — no pool in the trait.
|
||||
#[async_trait]
|
||||
pub trait LibrarySyncAdapter: Send + Sync {
|
||||
async fn sync_provider(
|
||||
|
||||
Reference in New Issue
Block a user