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:
2026-07-12 04:02:12 +02:00
parent d650e2ba07
commit 98a54245b1
54 changed files with 1190 additions and 1942 deletions

View File

@@ -1,13 +1,7 @@
use crate::value_objects::ContentType;
// ============================================================================
// LibraryItem
// ============================================================================
const SYNC_STATUS_RUNNING: &str = "running";
/// A media item stored in the local library cache, synced from a provider.
///
/// The `id` format is `"{provider_id}::{external_id}"` -- this composite key
/// allows items from multiple providers to coexist in the same table.
#[derive(Debug, Clone)]
pub struct LibraryItem {
id: String,
@@ -30,7 +24,6 @@ pub struct LibraryItem {
}
impl LibraryItem {
/// Create a new library item with required fields; optional fields default to None/empty.
pub fn new(
provider_id: impl Into<String>,
external_id: impl Into<String>,
@@ -63,8 +56,6 @@ impl LibraryItem {
}
}
/// Hydrate from persistence -- no validation, accepts all fields.
#[allow(clippy::too_many_arguments)]
pub fn from_persistence(
id: String,
provider_id: String,
@@ -105,8 +96,6 @@ impl LibraryItem {
}
}
// -- Getters --
pub fn id(&self) -> &str {
&self.id
}
@@ -176,11 +165,6 @@ impl LibraryItem {
}
}
// ============================================================================
// LibraryCollection
// ============================================================================
/// A collection summary derived from synced library items.
#[derive(Debug, Clone)]
pub struct LibraryCollection {
id: String,
@@ -209,8 +193,6 @@ impl LibraryCollection {
}
}
// -- Getters --
pub fn id(&self) -> &str {
&self.id
}
@@ -224,11 +206,6 @@ impl LibraryCollection {
}
}
// ============================================================================
// LibrarySyncResult
// ============================================================================
/// Result of a single provider sync run.
#[derive(Debug, Clone)]
pub struct LibrarySyncResult {
provider_id: String,
@@ -278,8 +255,6 @@ impl LibrarySyncResult {
}
}
// -- Getters --
pub fn provider_id(&self) -> &str {
&self.provider_id
}
@@ -297,11 +272,6 @@ impl LibrarySyncResult {
}
}
// ============================================================================
// LibrarySyncLogEntry
// ============================================================================
/// Log entry from the library_sync_log table.
#[derive(Debug, Clone)]
pub struct LibrarySyncLogEntry {
id: i64,
@@ -321,7 +291,7 @@ impl LibrarySyncLogEntry {
started_at: started_at.into(),
finished_at: None,
items_found: 0,
status: "running".to_string(),
status: SYNC_STATUS_RUNNING.to_string(),
error_msg: None,
}
}
@@ -346,8 +316,6 @@ impl LibrarySyncLogEntry {
}
}
// -- Getters --
pub fn id(&self) -> i64 {
self.id
}
@@ -377,11 +345,6 @@ impl LibrarySyncLogEntry {
}
}
// ============================================================================
// ShowSummary
// ============================================================================
/// Aggregated summary of a TV show derived from synced episodes.
#[derive(Debug, Clone)]
pub struct ShowSummary {
series_name: String,
@@ -422,8 +385,6 @@ impl ShowSummary {
}
}
// -- Getters --
pub fn series_name(&self) -> &str {
&self.series_name
}
@@ -445,11 +406,6 @@ impl ShowSummary {
}
}
// ============================================================================
// SeasonSummary
// ============================================================================
/// Aggregated summary of one season of a TV show.
#[derive(Debug, Clone)]
pub struct SeasonSummary {
season_number: u32,
@@ -478,8 +434,6 @@ impl SeasonSummary {
}
}
// -- Getters --
pub fn season_number(&self) -> u32 {
self.season_number
}
@@ -493,132 +447,6 @@ impl SeasonSummary {
}
}
// ============================================================================
// Tests
// ============================================================================
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn library_item_new_generates_composite_id() {
let item = LibraryItem::new("jellyfin", "abc123", "Test Movie", ContentType::Movie, 7200, "2026-03-19T00:00:00Z");
assert_eq!(item.id(), "jellyfin::abc123");
assert_eq!(item.provider_id(), "jellyfin");
assert_eq!(item.external_id(), "abc123");
}
#[test]
fn library_item_new_defaults_optional_fields() {
let item = LibraryItem::new("jf", "1", "Movie", ContentType::Movie, 3600, "2026-01-01");
assert!(item.series_name().is_none());
assert!(item.season_number().is_none());
assert!(item.genres().is_empty());
assert!(item.tags().is_empty());
assert!(item.collection_id().is_none());
assert!(item.thumbnail_url().is_none());
}
#[test]
fn library_item_from_persistence_all_fields() {
let item = LibraryItem::from_persistence(
"jf::abc".into(),
"jf".into(),
"abc".into(),
"Breaking Bad S01E01".into(),
ContentType::Episode,
2700,
Some("Breaking Bad".into()),
Some(1),
Some(1),
Some(2008),
vec!["Drama".into()],
vec!["tv".into()],
Some("col-1".into()),
Some("TV Shows".into()),
Some("tvshows".into()),
Some("http://thumb.jpg".into()),
"2026-03-19T00:00:00Z".into(),
);
assert_eq!(item.series_name(), Some("Breaking Bad"));
assert_eq!(item.season_number(), Some(1));
assert_eq!(item.year(), Some(2008));
assert_eq!(item.collection_name(), Some("TV Shows"));
}
#[test]
fn library_collection_new_and_getters() {
let col = LibraryCollection::new("col-1", "Movies");
assert_eq!(col.id(), "col-1");
assert_eq!(col.name(), "Movies");
assert!(col.collection_type().is_none());
}
#[test]
fn library_collection_from_persistence() {
let col = LibraryCollection::from_persistence(
"col-2".into(),
"TV Shows".into(),
Some("tvshows".into()),
);
assert_eq!(col.collection_type(), Some("tvshows"));
}
#[test]
fn sync_result_success() {
let r = LibrarySyncResult::new("jellyfin", 150, 1200);
assert_eq!(r.provider_id(), "jellyfin");
assert_eq!(r.items_found(), 150);
assert_eq!(r.duration_ms(), 1200);
assert!(r.error().is_none());
}
#[test]
fn sync_result_with_error() {
let r = LibrarySyncResult::with_error("jellyfin", 500, "connection refused");
assert_eq!(r.items_found(), 0);
assert_eq!(r.error(), Some("connection refused"));
}
#[test]
fn sync_log_entry_new_defaults() {
let entry = LibrarySyncLogEntry::new(1, "jellyfin", "2026-03-19T00:00:00Z");
assert_eq!(entry.id(), 1);
assert_eq!(entry.status(), "running");
assert_eq!(entry.items_found(), 0);
assert!(entry.finished_at().is_none());
assert!(entry.error_msg().is_none());
}
#[test]
fn show_summary_getters() {
let show = ShowSummary::from_persistence(
"Breaking Bad".into(),
62,
5,
Some("http://thumb.jpg".into()),
vec!["Drama".into(), "Crime".into()],
);
assert_eq!(show.series_name(), "Breaking Bad");
assert_eq!(show.episode_count(), 62);
assert_eq!(show.season_count(), 5);
assert_eq!(show.genres().len(), 2);
}
#[test]
fn season_summary_getters() {
let season = SeasonSummary::from_persistence(1, 7, Some("http://s1.jpg".into()));
assert_eq!(season.season_number(), 1);
assert_eq!(season.episode_count(), 7);
assert_eq!(season.thumbnail_url(), Some("http://s1.jpg"));
}
#[test]
fn season_summary_new_defaults() {
let season = SeasonSummary::new(3, 13);
assert_eq!(season.season_number(), 3);
assert_eq!(season.episode_count(), 13);
assert!(season.thumbnail_url().is_none());
}
}
#[path = "tests/library.rs"]
mod tests;