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:
@@ -4,7 +4,7 @@ use domain::{
|
||||
errors::DomainError,
|
||||
events::DomainEvent,
|
||||
models::{Goal, GoalType, GoalWithProgress},
|
||||
ports::{EventPublisher, GoalRepository},
|
||||
ports::{EventPublisher, GoalRepository, StatsRepository},
|
||||
value_objects::UserId,
|
||||
};
|
||||
|
||||
@@ -12,6 +12,7 @@ use super::commands::CreateGoalCommand;
|
||||
|
||||
pub async fn execute(
|
||||
goal: Arc<dyn GoalRepository>,
|
||||
stats: Arc<dyn StatsRepository>,
|
||||
event_publisher: Arc<dyn EventPublisher>,
|
||||
cmd: CreateGoalCommand,
|
||||
) -> Result<GoalWithProgress, DomainError> {
|
||||
@@ -32,7 +33,7 @@ pub async fn execute(
|
||||
)?;
|
||||
goal.save(&g).await?;
|
||||
|
||||
let current_count = goal.count_reviews_in_year(&user_id, cmd.year).await?;
|
||||
let current_count = stats.count_reviews_in_year(&user_id, cmd.year).await?;
|
||||
|
||||
event_publisher
|
||||
.publish(&DomainEvent::GoalCreated {
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use domain::{
|
||||
errors::DomainError, models::GoalWithProgress, ports::GoalRepository, value_objects::UserId,
|
||||
errors::DomainError,
|
||||
models::GoalWithProgress,
|
||||
ports::{GoalRepository, StatsRepository},
|
||||
value_objects::UserId,
|
||||
};
|
||||
|
||||
use super::queries::GetGoalQuery;
|
||||
|
||||
pub async fn execute(
|
||||
goal: Arc<dyn GoalRepository>,
|
||||
stats: Arc<dyn StatsRepository>,
|
||||
query: GetGoalQuery,
|
||||
) -> Result<Option<GoalWithProgress>, DomainError> {
|
||||
let user_id = UserId::from_uuid(query.user_id);
|
||||
@@ -16,7 +20,7 @@ pub async fn execute(
|
||||
|
||||
let Some(g) = found else { return Ok(None) };
|
||||
|
||||
let current_count = goal.count_reviews_in_year(&user_id, query.year).await?;
|
||||
let current_count = stats.count_reviews_in_year(&user_id, query.year).await?;
|
||||
|
||||
Ok(Some(GoalWithProgress {
|
||||
goal: g,
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use domain::{
|
||||
errors::DomainError, models::GoalWithProgress, ports::GoalRepository, value_objects::UserId,
|
||||
errors::DomainError,
|
||||
models::GoalWithProgress,
|
||||
ports::{GoalRepository, StatsRepository},
|
||||
value_objects::UserId,
|
||||
};
|
||||
|
||||
use super::queries::ListGoalsQuery;
|
||||
|
||||
pub async fn execute(
|
||||
goal: Arc<dyn GoalRepository>,
|
||||
stats: Arc<dyn StatsRepository>,
|
||||
query: ListGoalsQuery,
|
||||
) -> Result<Vec<GoalWithProgress>, DomainError> {
|
||||
let user_id = UserId::from_uuid(query.user_id);
|
||||
@@ -15,7 +19,7 @@ pub async fn execute(
|
||||
|
||||
let mut result = Vec::with_capacity(goals.len());
|
||||
for g in goals {
|
||||
let current_count = goal.count_reviews_in_year(&user_id, g.year()).await?;
|
||||
let current_count = stats.count_reviews_in_year(&user_id, g.year()).await?;
|
||||
result.push(GoalWithProgress {
|
||||
goal: g,
|
||||
current_count,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use domain::events::DomainEvent;
|
||||
use domain::testing::{InMemoryGoalRepository, NoopEventPublisher};
|
||||
use domain::testing::{FakeStatsRepository, InMemoryGoalRepository, NoopEventPublisher};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::goals::{commands::CreateGoalCommand, create};
|
||||
@@ -10,10 +10,12 @@ use crate::test_helpers::TestContextBuilder;
|
||||
#[tokio::test]
|
||||
async fn creates_goal_and_returns_progress() {
|
||||
let goals = InMemoryGoalRepository::new();
|
||||
let stats = FakeStatsRepository::new();
|
||||
let events = NoopEventPublisher::new();
|
||||
|
||||
let result = create::execute(
|
||||
Arc::clone(&goals) as _,
|
||||
Arc::clone(&stats) as _,
|
||||
Arc::clone(&events) as _,
|
||||
CreateGoalCommand {
|
||||
user_id: Uuid::nil(),
|
||||
@@ -33,11 +35,13 @@ async fn creates_goal_and_returns_progress() {
|
||||
#[tokio::test]
|
||||
async fn creates_goal_with_review_count() {
|
||||
let goals = InMemoryGoalRepository::new();
|
||||
goals.set_review_count(Uuid::nil(), 2025, 5);
|
||||
let stats = FakeStatsRepository::new();
|
||||
stats.set_review_count(Uuid::nil(), 2025, 5);
|
||||
let events = NoopEventPublisher::new();
|
||||
|
||||
let result = create::execute(
|
||||
Arc::clone(&goals) as _,
|
||||
Arc::clone(&stats) as _,
|
||||
Arc::clone(&events) as _,
|
||||
CreateGoalCommand {
|
||||
user_id: Uuid::nil(),
|
||||
@@ -59,6 +63,7 @@ async fn emits_goal_created_event() {
|
||||
|
||||
create::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
Arc::clone(&events) as _,
|
||||
CreateGoalCommand {
|
||||
user_id: Uuid::nil(),
|
||||
@@ -86,12 +91,18 @@ async fn rejects_duplicate_year() {
|
||||
target_count: 10,
|
||||
};
|
||||
|
||||
create::execute(b.goal_repo.clone(), b.event_publisher.clone(), cmd)
|
||||
.await
|
||||
.unwrap();
|
||||
create::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
b.event_publisher.clone(),
|
||||
cmd,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let result = create::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
b.event_publisher.clone(),
|
||||
CreateGoalCommand {
|
||||
user_id: Uuid::nil(),
|
||||
@@ -109,6 +120,7 @@ async fn rejects_year_before_2020() {
|
||||
let b = TestContextBuilder::new();
|
||||
let result = create::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
b.event_publisher.clone(),
|
||||
CreateGoalCommand {
|
||||
user_id: Uuid::nil(),
|
||||
@@ -126,6 +138,7 @@ async fn rejects_zero_target() {
|
||||
let b = TestContextBuilder::new();
|
||||
let result = create::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
b.event_publisher.clone(),
|
||||
CreateGoalCommand {
|
||||
user_id: Uuid::nil(),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use domain::testing::{InMemoryGoalRepository, NoopEventPublisher};
|
||||
use domain::testing::{FakeStatsRepository, InMemoryGoalRepository, NoopEventPublisher};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::goals::{
|
||||
@@ -12,10 +12,12 @@ use crate::test_helpers::TestContextBuilder;
|
||||
#[tokio::test]
|
||||
async fn deletes_existing_goal() {
|
||||
let goals = InMemoryGoalRepository::new();
|
||||
let stats = FakeStatsRepository::new();
|
||||
let events = NoopEventPublisher::new();
|
||||
|
||||
create::execute(
|
||||
Arc::clone(&goals) as _,
|
||||
Arc::clone(&stats) as _,
|
||||
Arc::clone(&events) as _,
|
||||
CreateGoalCommand {
|
||||
user_id: Uuid::nil(),
|
||||
|
||||
@@ -8,6 +8,7 @@ async fn returns_goal_when_exists() {
|
||||
let b = TestContextBuilder::new();
|
||||
create::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
b.event_publisher.clone(),
|
||||
CreateGoalCommand {
|
||||
user_id: Uuid::nil(),
|
||||
@@ -20,6 +21,7 @@ async fn returns_goal_when_exists() {
|
||||
|
||||
let result = get::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
GetGoalQuery {
|
||||
user_id: Uuid::nil(),
|
||||
year: 2025,
|
||||
@@ -37,6 +39,7 @@ async fn returns_none_when_missing() {
|
||||
let b = TestContextBuilder::new();
|
||||
let result = get::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
GetGoalQuery {
|
||||
user_id: Uuid::nil(),
|
||||
year: 2025,
|
||||
|
||||
@@ -8,6 +8,7 @@ async fn returns_empty_when_no_goals() {
|
||||
let b = TestContextBuilder::new();
|
||||
let result = list::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
ListGoalsQuery {
|
||||
user_id: Uuid::nil(),
|
||||
},
|
||||
@@ -24,6 +25,7 @@ async fn returns_all_goals_for_user() {
|
||||
for year in [2023, 2024, 2025] {
|
||||
create::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
b.event_publisher.clone(),
|
||||
CreateGoalCommand {
|
||||
user_id: Uuid::nil(),
|
||||
@@ -37,6 +39,7 @@ async fn returns_all_goals_for_user() {
|
||||
|
||||
let result = list::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
ListGoalsQuery {
|
||||
user_id: Uuid::nil(),
|
||||
},
|
||||
|
||||
@@ -11,6 +11,7 @@ async fn updates_target_count() {
|
||||
let b = TestContextBuilder::new();
|
||||
create::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
b.event_publisher.clone(),
|
||||
CreateGoalCommand {
|
||||
user_id: Uuid::nil(),
|
||||
@@ -23,6 +24,7 @@ async fn updates_target_count() {
|
||||
|
||||
let result = update::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
b.event_publisher.clone(),
|
||||
UpdateGoalCommand {
|
||||
user_id: Uuid::nil(),
|
||||
@@ -41,6 +43,7 @@ async fn fails_when_goal_not_found() {
|
||||
let b = TestContextBuilder::new();
|
||||
let result = update::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
b.event_publisher.clone(),
|
||||
UpdateGoalCommand {
|
||||
user_id: Uuid::nil(),
|
||||
@@ -58,6 +61,7 @@ async fn rejects_zero_target() {
|
||||
let b = TestContextBuilder::new();
|
||||
create::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
b.event_publisher.clone(),
|
||||
CreateGoalCommand {
|
||||
user_id: Uuid::nil(),
|
||||
@@ -70,6 +74,7 @@ async fn rejects_zero_target() {
|
||||
|
||||
let result = update::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
b.event_publisher.clone(),
|
||||
UpdateGoalCommand {
|
||||
user_id: Uuid::nil(),
|
||||
|
||||
@@ -4,7 +4,7 @@ use domain::{
|
||||
errors::DomainError,
|
||||
events::DomainEvent,
|
||||
models::GoalWithProgress,
|
||||
ports::{EventPublisher, GoalRepository},
|
||||
ports::{EventPublisher, GoalRepository, StatsRepository},
|
||||
value_objects::UserId,
|
||||
};
|
||||
|
||||
@@ -12,6 +12,7 @@ use super::commands::UpdateGoalCommand;
|
||||
|
||||
pub async fn execute(
|
||||
goal: Arc<dyn GoalRepository>,
|
||||
stats: Arc<dyn StatsRepository>,
|
||||
event_publisher: Arc<dyn EventPublisher>,
|
||||
cmd: UpdateGoalCommand,
|
||||
) -> Result<GoalWithProgress, DomainError> {
|
||||
@@ -25,7 +26,7 @@ pub async fn execute(
|
||||
g.update_target(cmd.target_count)?;
|
||||
goal.update(&g).await?;
|
||||
|
||||
let current_count = goal.count_reviews_in_year(&user_id, cmd.year).await?;
|
||||
let current_count = stats.count_reviews_in_year(&user_id, cmd.year).await?;
|
||||
|
||||
event_publisher
|
||||
.publish(&DomainEvent::GoalUpdated {
|
||||
|
||||
Reference in New Issue
Block a user