refactor: split domain models, move presentation logic out of app layer
Some checks failed
CI / Check / Test (push) Failing after 47s

Split domain/models/mod.rs (630 lines) into focused files:
movie.rs, review.rs, user.rs, stats.rs, enrichment.rs, feed.rs.

Move URL/date formatting from application use cases to
presentation mappers — use cases now return raw domain data.

Delete watchlist/get_page.rs (was pure presentation logic),
replace with presentation/mappers/watchlist.rs.

Document signature conventions in CONTRIBUTING.md.
This commit is contained in:
2026-06-09 02:29:11 +02:00
parent ac03182aa6
commit 70b3ca0f5c
23 changed files with 761 additions and 1150 deletions

View File

@@ -3,3 +3,4 @@ pub mod import;
pub mod integrations;
pub mod movies;
pub mod users;
pub mod watchlist;

View File

@@ -1,5 +1,6 @@
use application::users::get_profile::PendingFollowerView;
use domain::models::UserSummary;
use chrono::Datelike;
use domain::models::{DiaryEntry, MonthActivity, UserSummary};
use domain::ports::RemoteActorInfo;
use template_askama::{RemoteActorData, RemoteActorDisplay, UserSummaryView};
@@ -43,3 +44,49 @@ pub fn pending_follower_data(p: &PendingFollowerView) -> RemoteActorData {
avatar_url: p.avatar_url.clone(),
}
}
pub fn group_by_month(entries: Vec<DiaryEntry>) -> Vec<MonthActivity> {
use std::collections::BTreeMap;
let mut map: BTreeMap<(i32, u32), Vec<DiaryEntry>> = BTreeMap::new();
for entry in entries {
let watched_at = entry.review().watched_at();
let year = watched_at.year();
let month = watched_at.month();
map.entry((year, month)).or_default().push(entry);
}
map.into_iter()
.rev()
.map(|((year, month), entries)| {
let year_month = format!("{:04}-{:02}", year, month);
MonthActivity {
month_label: format_year_month_long(&year_month),
count: entries.len() as i64,
entries,
year_month,
}
})
.collect()
}
fn format_year_month_long(ym: &str) -> String {
let parts: Vec<&str> = ym.splitn(2, '-').collect();
if parts.len() != 2 {
return ym.to_string();
}
let month = match parts[1] {
"01" => "January",
"02" => "February",
"03" => "March",
"04" => "April",
"05" => "May",
"06" => "June",
"07" => "July",
"08" => "August",
"09" => "September",
"10" => "October",
"11" => "November",
"12" => "December",
_ => parts[1],
};
format!("{} {}", month, parts[0])
}

View File

@@ -0,0 +1,65 @@
use domain::models::{RemoteWatchlistEntry, WatchlistWithMovie, collections::Paginated};
use template_askama::WatchlistDisplayEntry;
pub struct WatchlistPageResult {
pub display_entries: Vec<WatchlistDisplayEntry>,
pub has_more: bool,
pub current_offset: u32,
pub limit: u32,
}
pub fn build_watchlist_page(
page: Paginated<WatchlistWithMovie>,
is_owner: bool,
) -> WatchlistPageResult {
let has_more = page.offset + page.limit < page.total_count as u32;
let display_entries = page
.items
.iter()
.map(|w| {
let remove_url = if is_owner {
Some(format!("/watchlist/{}/remove", w.movie.id().value()))
} else {
None
};
WatchlistDisplayEntry {
poster_url: w
.movie
.poster_path()
.map(|p| format!("/images/{}", p.value())),
movie_title: w.movie.title().value().to_string(),
release_year: w.movie.release_year().value(),
movie_url: Some(format!("/movies/{}", w.movie.id().value())),
added_at: w.entry.added_at.format("%b %-d, %Y").to_string(),
remove_url,
}
})
.collect();
WatchlistPageResult {
display_entries,
has_more,
current_offset: page.offset,
limit: page.limit,
}
}
pub fn build_remote_watchlist_page(entries: Vec<RemoteWatchlistEntry>) -> WatchlistPageResult {
let len = entries.len() as u32;
let display_entries = entries
.into_iter()
.map(|e| WatchlistDisplayEntry {
poster_url: e.poster_url,
movie_title: e.movie_title,
release_year: e.release_year,
movie_url: None,
added_at: e.added_at.format("%b %-d, %Y").to_string(),
remove_url: None,
})
.collect();
WatchlistPageResult {
display_entries,
has_more: false,
current_offset: 0,
limit: len,
}
}