refactor: split domain models, move presentation logic out of app layer
Some checks failed
CI / Check / Test (push) Failing after 47s
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:
@@ -58,12 +58,13 @@ pub async fn get_profile(
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
let base_url = &state.app_ctx.config.base_url;
|
||||
Ok(Json(ProfileResponse {
|
||||
username: profile.username,
|
||||
display_name: profile.display_name,
|
||||
bio: profile.bio,
|
||||
avatar_url: profile.avatar_url,
|
||||
banner_url: profile.banner_url,
|
||||
avatar_url: profile.avatar_path.map(|p| format!("{}/images/{}", base_url, p)),
|
||||
banner_url: profile.banner_path.map(|p| format!("{}/images/{}", base_url, p)),
|
||||
also_known_as: profile.also_known_as,
|
||||
fields: profile
|
||||
.fields
|
||||
@@ -286,8 +287,8 @@ pub async fn get_user_profile(
|
||||
offset: p.offset,
|
||||
});
|
||||
|
||||
let history = profile.history.map(|months| {
|
||||
months
|
||||
let history = profile.history.map(|entries| {
|
||||
crate::mappers::users::group_by_month(entries)
|
||||
.into_iter()
|
||||
.map(|m| MonthActivityDto {
|
||||
year_month: m.year_month,
|
||||
@@ -542,8 +543,10 @@ pub async fn get_user_profile_html(
|
||||
.most_active_month
|
||||
.clone()
|
||||
.unwrap_or_else(|| "\u{2014}".to_string());
|
||||
let heatmap = profile
|
||||
let history = profile
|
||||
.history
|
||||
.map(crate::mappers::users::group_by_month);
|
||||
let heatmap = history
|
||||
.as_deref()
|
||||
.map(build_heatmap)
|
||||
.unwrap_or_default();
|
||||
@@ -594,7 +597,7 @@ pub async fn get_user_profile_html(
|
||||
current_offset: offset,
|
||||
has_more,
|
||||
limit,
|
||||
history: profile.history.as_ref(),
|
||||
history: history.as_ref(),
|
||||
trends: profile.trends.as_ref(),
|
||||
monthly_rating_rows,
|
||||
heatmap,
|
||||
@@ -618,7 +621,7 @@ pub async fn get_user_profile_html(
|
||||
current_offset: offset,
|
||||
has_more,
|
||||
limit,
|
||||
history: profile.history.as_ref(),
|
||||
history: history.as_ref(),
|
||||
trends: profile.trends.as_ref(),
|
||||
monthly_rating_rows,
|
||||
heatmap,
|
||||
|
||||
@@ -178,19 +178,39 @@ pub async fn get_watchlist_page(
|
||||
let ctx = build_page_context(&state, viewer_id.clone(), csrf.0).await;
|
||||
let is_owner = viewer_id.map(|u| u.value() == owner_id).unwrap_or(false);
|
||||
|
||||
let result = match application::watchlist::get_page::execute(
|
||||
&state.app_ctx,
|
||||
application::watchlist::queries::GetWatchlistQuery {
|
||||
user_id: owner_id,
|
||||
limit: params.limit.or(Some(20)),
|
||||
offset: params.offset.or(Some(0)),
|
||||
},
|
||||
is_owner,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(r) => r,
|
||||
Err(e) => return crate::errors::domain_error_response(e),
|
||||
let user_id = domain::value_objects::UserId::from_uuid(owner_id);
|
||||
let is_local = state
|
||||
.app_ctx
|
||||
.repos
|
||||
.user
|
||||
.find_by_id(&user_id)
|
||||
.await
|
||||
.map(|u| u.is_some())
|
||||
.unwrap_or(false);
|
||||
|
||||
let result = if is_local {
|
||||
match get_watchlist::execute(
|
||||
&state.app_ctx,
|
||||
application::watchlist::queries::GetWatchlistQuery {
|
||||
user_id: owner_id,
|
||||
limit: params.limit.or(Some(20)),
|
||||
offset: params.offset.or(Some(0)),
|
||||
},
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(page) => crate::mappers::watchlist::build_watchlist_page(page, is_owner),
|
||||
Err(e) => return crate::errors::domain_error_response(e),
|
||||
}
|
||||
} else {
|
||||
let remote_entries = state
|
||||
.app_ctx
|
||||
.repos
|
||||
.remote_watchlist
|
||||
.get_by_derived_uuid(owner_id)
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
crate::mappers::watchlist::build_remote_watchlist_page(remote_entries)
|
||||
};
|
||||
|
||||
render_page(WatchlistTemplate {
|
||||
|
||||
Reference in New Issue
Block a user