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

@@ -191,7 +191,24 @@ impl DiaryRepository for FakeDiaryRepository {
// ── FakeStatsRepository ─────────────────────────────────────────────────────
pub struct FakeStatsRepository;
pub struct FakeStatsRepository {
review_counts: Mutex<HashMap<(Uuid, u16), u32>>,
}
impl FakeStatsRepository {
pub fn new() -> Arc<Self> {
Arc::new(Self {
review_counts: Mutex::new(HashMap::new()),
})
}
pub fn set_review_count(&self, user_id: Uuid, year: u16, count: u32) {
self.review_counts
.lock()
.unwrap()
.insert((user_id, year), count);
}
}
#[async_trait]
impl StatsRepository for FakeStatsRepository {
@@ -211,6 +228,11 @@ impl StatsRepository for FakeStatsRepository {
max_director_count: 0,
})
}
async fn count_reviews_in_year(&self, user_id: &UserId, year: u16) -> Result<u32, DomainError> {
let counts = self.review_counts.lock().unwrap();
Ok(counts.get(&(user_id.value(), year)).copied().unwrap_or(0))
}
}
// ── FakePersonQuery ─────────────────────────────────────────────────────────

View File

@@ -10,7 +10,6 @@ use chrono::Utc;
use crate::{
errors::DomainError,
events::DomainEvent,
models::{
FederationFlags, Goal, ImportProfile, ImportSession, Movie, MovieFilter, MovieProfile,
MovieSummary, ProfileField, RefreshSession, Review, User, UserSettings, UserSummary,
@@ -171,18 +170,12 @@ impl InMemoryReviewRepository {
#[async_trait]
impl ReviewRepository for InMemoryReviewRepository {
async fn save_review(&self, review: &Review) -> Result<DomainEvent, DomainError> {
async fn save_review(&self, review: &Review) -> Result<(), DomainError> {
self.store
.lock()
.unwrap()
.insert(review.id().value(), review.clone());
Ok(DomainEvent::ReviewLogged {
review_id: review.id().clone(),
movie_id: review.movie_id().clone(),
user_id: review.user_id().clone(),
rating: review.rating().clone(),
watched_at: *review.watched_at(),
})
Ok(())
}
async fn get_review_by_id(&self, review_id: &ReviewId) -> Result<Option<Review>, DomainError> {
@@ -345,27 +338,18 @@ impl WatchlistRepository for InMemoryWatchlistRepository {
pub struct InMemoryGoalRepository {
store: Mutex<HashMap<Uuid, Goal>>,
review_counts: Mutex<HashMap<(Uuid, u16), u32>>,
}
impl InMemoryGoalRepository {
pub fn new() -> Arc<Self> {
Arc::new(Self {
store: Mutex::new(HashMap::new()),
review_counts: Mutex::new(HashMap::new()),
})
}
pub fn count(&self) -> usize {
self.store.lock().unwrap().len()
}
pub fn set_review_count(&self, user_id: Uuid, year: u16, count: u32) {
self.review_counts
.lock()
.unwrap()
.insert((user_id, year), count);
}
}
#[async_trait]
@@ -416,11 +400,6 @@ impl GoalRepository for InMemoryGoalRepository {
.cloned()
.collect())
}
async fn count_reviews_in_year(&self, user_id: &UserId, year: u16) -> Result<u32, DomainError> {
let counts = self.review_counts.lock().unwrap();
Ok(counts.get(&(user_id.value(), year)).copied().unwrap_or(0))
}
}
// ── InMemoryUserSettingsRepository ──────────────────────────────────────────

View File

@@ -97,7 +97,10 @@ pub struct NoopSocialQueryPort;
#[async_trait]
impl crate::ports::SocialQueryPort for NoopSocialQueryPort {
async fn get_accepted_following_urls(&self, _: uuid::Uuid) -> Result<Vec<String>, DomainError> {
async fn get_accepted_following_urls(
&self,
_: &crate::value_objects::UserId,
) -> Result<Vec<String>, DomainError> {
Ok(vec![])
}
async fn list_all_followed_remote_actors(
@@ -105,15 +108,21 @@ impl crate::ports::SocialQueryPort for NoopSocialQueryPort {
) -> Result<Vec<crate::models::RemoteActorInfo>, DomainError> {
Ok(vec![])
}
async fn count_following(&self, _: uuid::Uuid) -> Result<usize, DomainError> {
async fn count_following(
&self,
_: &crate::value_objects::UserId,
) -> Result<usize, DomainError> {
Ok(0)
}
async fn count_accepted_followers(&self, _: uuid::Uuid) -> Result<usize, DomainError> {
async fn count_accepted_followers(
&self,
_: &crate::value_objects::UserId,
) -> Result<usize, DomainError> {
Ok(0)
}
async fn get_pending_followers(
&self,
_: uuid::Uuid,
_: &crate::value_objects::UserId,
) -> Result<Vec<crate::models::PendingFollowerInfo>, DomainError> {
Ok(vec![])
}
@@ -148,9 +157,6 @@ impl crate::ports::GoalRepository for NoopGoalRepository {
async fn list_for_user(&self, _: &UserId) -> Result<Vec<crate::models::Goal>, DomainError> {
Ok(vec![])
}
async fn count_reviews_in_year(&self, _: &UserId, _: u16) -> Result<u32, DomainError> {
Ok(0)
}
}
// ── NoopUserSettingsRepository ────────────────────────────────────────────────

View File

@@ -80,6 +80,9 @@ impl StatsRepository for PanicStatsRepository {
async fn get_user_trends(&self, _: &UserId) -> Result<UserTrends, DomainError> {
panic!("PanicStatsRepository called")
}
async fn count_reviews_in_year(&self, _: &UserId, _: u16) -> Result<u32, DomainError> {
panic!("PanicStatsRepository called")
}
}
pub struct PanicImportSessionRepository;
@@ -327,21 +330,30 @@ pub struct PanicSocialQueryPort;
#[async_trait]
impl crate::ports::SocialQueryPort for PanicSocialQueryPort {
async fn get_accepted_following_urls(&self, _: uuid::Uuid) -> Result<Vec<String>, DomainError> {
async fn get_accepted_following_urls(
&self,
_: &crate::value_objects::UserId,
) -> Result<Vec<String>, DomainError> {
panic!("PanicSocialQueryPort called")
}
async fn list_all_followed_remote_actors(&self) -> Result<Vec<RemoteActorInfo>, DomainError> {
panic!("PanicSocialQueryPort called")
}
async fn count_following(&self, _: uuid::Uuid) -> Result<usize, DomainError> {
async fn count_following(
&self,
_: &crate::value_objects::UserId,
) -> Result<usize, DomainError> {
panic!("PanicSocialQueryPort called")
}
async fn count_accepted_followers(&self, _: uuid::Uuid) -> Result<usize, DomainError> {
async fn count_accepted_followers(
&self,
_: &crate::value_objects::UserId,
) -> Result<usize, DomainError> {
panic!("PanicSocialQueryPort called")
}
async fn get_pending_followers(
&self,
_: uuid::Uuid,
_: &crate::value_objects::UserId,
) -> Result<Vec<PendingFollowerInfo>, DomainError> {
panic!("PanicSocialQueryPort called")
}