refactor: fix HIGH+MEDIUM architectural violations from code review

HIGH: fix watch_medium data-loss bug, standardize error handling on
ApiError, fix dep direction (rss/template-askama no longer dep on
application), extract ImageFetcher port (remove reqwest from app layer),
move event construction from save_review to use case, extract
infra-wiring crate (DbPool/EventBusBackend dedup), deduplicate
presentation helpers (encode_error, export streaming, multipart parsing)

MEDIUM: split LocalApContentQuery god-trait 10→3 methods, dedup movie
resolution orchestration, add RemoteActorDto/PersonDto mappers, move
AppConfig to infra-wiring, fix SocialQueryPort Uuid→UserId, replace
stringly-typed api-types with domain enums, move count_reviews_in_year
to StatsRepository, dedup event publisher cfg blocks, extract
should_enrich, move group_by_month to application, dedup
count_local_posts, add FederationFlags Default, TUI input helper +
ShowError rename + typed auth errors, api-types cleanup
(UserSettingsDto/UserProfileBase/PreviewRowData)

102 files changed, -681 lines net
This commit is contained in:
2026-07-10 02:08:39 +02:00
parent 26152660bb
commit 12da356a40
110 changed files with 1399 additions and 1867 deletions

View File

@@ -1,12 +1,9 @@
use domain::{
errors::DomainError,
events::DomainEvent,
models::WatchlistEntry,
value_objects::{MovieId, UserId},
errors::DomainError, events::DomainEvent, models::WatchlistEntry, value_objects::UserId,
};
use crate::{
diary::movie_resolver::{MovieResolver, MovieResolverDeps},
movies::resolve::resolve_and_persist_movie,
watchlist::{commands::AddToWatchlistCommand, deps::WatchlistAddDeps},
};
@@ -16,34 +13,13 @@ pub async fn execute(
) -> Result<(), DomainError> {
let user_id = UserId::from_uuid(cmd.user_id);
let movie = if let Some(id) = cmd.input.movie_id {
let movie_id = MovieId::from_uuid(id);
deps.movie
.get_movie_by_id(&movie_id)
.await?
.ok_or_else(|| DomainError::NotFound(format!("Movie {id}")))?
} else {
let resolver_deps = MovieResolverDeps {
repository: deps.movie.as_ref(),
metadata_client: deps.metadata.as_ref(),
};
let (movie, is_new) = MovieResolver::default_pipeline()
.resolve(&cmd.input, &resolver_deps)
.await?;
if is_new {
deps.movie.upsert_movie(&movie).await?;
if let Some(ext_id) = movie.external_metadata_id() {
let _ = deps
.event_publisher
.publish(&DomainEvent::MovieDiscovered {
movie_id: movie.id().clone(),
external_metadata_id: ext_id.clone(),
})
.await;
}
}
movie
};
let (movie, _is_new) = resolve_and_persist_movie(
&cmd.input,
deps.movie.as_ref(),
deps.metadata.as_ref(),
deps.event_publisher.as_ref(),
)
.await?;
let entry = WatchlistEntry::new(user_id.clone(), movie.id().clone());
deps.watchlist.add(&entry).await?;