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

@@ -2,7 +2,6 @@ use async_trait::async_trait;
use crate::{
errors::DomainError,
events::DomainEvent,
models::{
DiaryEntry, DiaryFilter, ExportFormat, FeedEntry, FeedSortBy, FollowingFilter, MovieStats,
Review, ReviewHistory, UserStats, UserTrends,
@@ -43,7 +42,7 @@ pub trait DiaryRepository: Send + Sync {
#[async_trait]
pub trait ReviewRepository: Send + Sync {
async fn save_review(&self, review: &Review) -> Result<DomainEvent, DomainError>;
async fn save_review(&self, review: &Review) -> Result<(), DomainError>;
async fn get_review_by_id(&self, review_id: &ReviewId) -> Result<Option<Review>, DomainError>;
async fn update_review(&self, review: &Review) -> Result<(), DomainError>;
async fn delete_review(&self, review_id: &ReviewId) -> Result<(), DomainError>;
@@ -54,6 +53,7 @@ pub trait ReviewRepository: Send + Sync {
pub trait StatsRepository: Send + Sync {
async fn get_user_stats(&self, user_id: &UserId) -> Result<UserStats, DomainError>;
async fn get_user_trends(&self, user_id: &UserId) -> Result<UserTrends, DomainError>;
async fn count_reviews_in_year(&self, user_id: &UserId, year: u16) -> Result<u32, DomainError>;
}
pub trait DiaryExporter: Send + Sync {

View File

@@ -17,5 +17,4 @@ pub trait GoalRepository: Send + Sync {
year: u16,
) -> Result<Option<Goal>, DomainError>;
async fn list_for_user(&self, user_id: &UserId) -> Result<Vec<Goal>, DomainError>;
async fn count_reviews_in_year(&self, user_id: &UserId, year: u16) -> Result<u32, DomainError>;
}

View File

@@ -0,0 +1,8 @@
use async_trait::async_trait;
use crate::errors::DomainError;
#[async_trait]
pub trait ImageFetcher: Send + Sync {
async fn fetch_image(&self, url: &str) -> Result<Vec<u8>, DomainError>;
}

View File

@@ -3,12 +3,14 @@ pub mod diary;
pub mod events;
pub mod federated_profile;
pub mod goals;
pub mod image_fetcher;
pub mod images;
pub mod import;
pub mod jobs;
pub mod media_server;
pub mod movie;
pub mod person;
pub mod rss;
pub mod search;
pub mod social;
pub mod watchlist;
@@ -19,12 +21,14 @@ pub use diary::*;
pub use events::*;
pub use federated_profile::*;
pub use goals::*;
pub use image_fetcher::*;
pub use images::*;
pub use import::*;
pub use jobs::*;
pub use media_server::*;
pub use movie::*;
pub use person::*;
pub use rss::*;
pub use search::*;
pub use social::*;
pub use watchlist::*;

View File

@@ -0,0 +1,5 @@
use crate::models::DiaryEntry;
pub trait RssFeedRenderer: Send + Sync {
fn render_feed(&self, entries: &[DiaryEntry], title: &str) -> Result<String, String>;
}

View File

@@ -4,24 +4,24 @@ use chrono::NaiveDateTime;
use crate::{
errors::DomainError,
models::{
DiaryEntry, FederationFlags, Goal, Movie, PendingFollowerInfo, RemoteActorInfo,
RemoteGoalEntry, RemoteWatchlistEntry, Review, WatchlistWithMovie,
DiaryEntry, FederationFlags, PendingFollowerInfo, RemoteActorInfo, RemoteGoalEntry,
RemoteWatchlistEntry, WatchlistWithMovie,
},
value_objects::{MovieId, ReviewId, UserId},
value_objects::{MovieId, UserId},
};
#[async_trait]
pub trait SocialQueryPort: Send + Sync {
async fn get_accepted_following_urls(
&self,
user_id: uuid::Uuid,
user_id: &UserId,
) -> Result<Vec<String>, DomainError>;
async fn list_all_followed_remote_actors(&self) -> Result<Vec<RemoteActorInfo>, DomainError>;
async fn count_following(&self, user_id: uuid::Uuid) -> Result<usize, DomainError>;
async fn count_accepted_followers(&self, user_id: uuid::Uuid) -> Result<usize, DomainError>;
async fn count_following(&self, user_id: &UserId) -> Result<usize, DomainError>;
async fn count_accepted_followers(&self, user_id: &UserId) -> Result<usize, DomainError>;
async fn get_pending_followers(
&self,
user_id: uuid::Uuid,
user_id: &UserId,
) -> Result<Vec<PendingFollowerInfo>, DomainError>;
}
@@ -60,25 +60,16 @@ pub trait RemoteGoalRepository: Send + Sync {
async fn get_by_actor_url(&self, actor_url: &str) -> Result<Vec<RemoteGoalEntry>, DomainError>;
}
/// Read-only query port used exclusively by the ActivityPub adapter.
/// Consolidates all reads the AP adapter needs so it never touches write repositories.
/// Federation-specific read-only queries that have no equivalent on the
/// standard domain ports (e.g. unpaginated watchlist, local-only review
/// listings). Generic lookups (get_movie_by_id, get_review_by_id, etc.)
/// live on MovieRepository, ReviewRepository, and the other domain ports.
#[async_trait]
pub trait LocalApContentQuery: Send + Sync {
async fn get_local_reviews_for_user(
&self,
user_id: &UserId,
) -> Result<Vec<DiaryEntry>, DomainError>;
async fn get_local_watchlist_for_user(
&self,
user_id: &UserId,
) -> Result<Vec<WatchlistWithMovie>, DomainError>;
async fn get_review_by_id(&self, review_id: &ReviewId) -> Result<Option<Review>, DomainError>;
async fn get_movie_by_id(&self, movie_id: &MovieId) -> Result<Option<Movie>, DomainError>;
async fn get_movie_by_external_metadata_id(
&self,
external_id: &str,
) -> Result<Option<Movie>, DomainError>;
async fn count_local_posts(&self) -> Result<u64, DomainError>;
async fn get_local_reviews_for_movie(
&self,
movie_id: &MovieId,
@@ -89,10 +80,4 @@ pub trait LocalApContentQuery: Send + Sync {
before: Option<NaiveDateTime>,
limit: usize,
) -> Result<Vec<DiaryEntry>, DomainError>;
async fn get_goal_with_progress(
&self,
user_id: &UserId,
year: u16,
) -> Result<Option<(Goal, u32)>, DomainError>;
async fn list_goals_for_user(&self, user_id: &UserId) -> Result<Vec<Goal>, DomainError>;
}