refactor: remaining MEDIUM — CQRS splits, DI Deps, profile dedup, event Value, response enum

M1: MovieRepository→MovieCommand/MovieQuery, WatchEventRepository→
WatchEventCommand/WatchEventQuery
M2: goals/ and import/ use Deps structs
M7: extract upload_image helper in update_profile
M8: FederationDeliveryRequested activity_json String→serde_json::Value
M11: UserProfileResponse uses ProfileViewData enum
This commit is contained in:
2026-07-10 03:50:43 +02:00
parent 12da356a40
commit dee013c7eb
99 changed files with 1262 additions and 896 deletions

View File

@@ -4,6 +4,7 @@ use domain::events::DomainEvent;
use domain::testing::{FakeStatsRepository, InMemoryGoalRepository, NoopEventPublisher};
use uuid::Uuid;
use crate::goals::deps::GoalCommandDeps;
use crate::goals::{commands::CreateGoalCommand, create};
use crate::test_helpers::TestContextBuilder;
@@ -12,11 +13,14 @@ async fn creates_goal_and_returns_progress() {
let goals = InMemoryGoalRepository::new();
let stats = FakeStatsRepository::new();
let events = NoopEventPublisher::new();
let deps = GoalCommandDeps {
goal: Arc::clone(&goals) as _,
stats: Arc::clone(&stats) as _,
event_publisher: Arc::clone(&events) as _,
};
let result = create::execute(
Arc::clone(&goals) as _,
Arc::clone(&stats) as _,
Arc::clone(&events) as _,
&deps,
CreateGoalCommand {
user_id: Uuid::nil(),
year: 2025,
@@ -38,11 +42,14 @@ async fn creates_goal_with_review_count() {
let stats = FakeStatsRepository::new();
stats.set_review_count(Uuid::nil(), 2025, 5);
let events = NoopEventPublisher::new();
let deps = GoalCommandDeps {
goal: Arc::clone(&goals) as _,
stats: Arc::clone(&stats) as _,
event_publisher: Arc::clone(&events) as _,
};
let result = create::execute(
Arc::clone(&goals) as _,
Arc::clone(&stats) as _,
Arc::clone(&events) as _,
&deps,
CreateGoalCommand {
user_id: Uuid::nil(),
year: 2025,
@@ -60,11 +67,14 @@ async fn creates_goal_with_review_count() {
async fn emits_goal_created_event() {
let b = TestContextBuilder::new();
let events = NoopEventPublisher::new();
let deps = GoalCommandDeps {
goal: b.goal_repo.clone(),
stats: b.stats_repo.clone(),
event_publisher: Arc::clone(&events) as _,
};
create::execute(
b.goal_repo.clone(),
b.stats_repo.clone(),
Arc::clone(&events) as _,
&deps,
CreateGoalCommand {
user_id: Uuid::nil(),
year: 2025,
@@ -85,25 +95,21 @@ async fn emits_goal_created_event() {
#[tokio::test]
async fn rejects_duplicate_year() {
let b = TestContextBuilder::new();
let deps = GoalCommandDeps {
goal: b.goal_repo.clone(),
stats: b.stats_repo.clone(),
event_publisher: b.event_publisher.clone(),
};
let cmd = CreateGoalCommand {
user_id: Uuid::nil(),
year: 2025,
target_count: 10,
};
create::execute(
b.goal_repo.clone(),
b.stats_repo.clone(),
b.event_publisher.clone(),
cmd,
)
.await
.unwrap();
create::execute(&deps, cmd).await.unwrap();
let result = create::execute(
b.goal_repo.clone(),
b.stats_repo.clone(),
b.event_publisher.clone(),
&deps,
CreateGoalCommand {
user_id: Uuid::nil(),
year: 2025,
@@ -118,10 +124,13 @@ async fn rejects_duplicate_year() {
#[tokio::test]
async fn rejects_year_before_2020() {
let b = TestContextBuilder::new();
let deps = GoalCommandDeps {
goal: b.goal_repo.clone(),
stats: b.stats_repo.clone(),
event_publisher: b.event_publisher.clone(),
};
let result = create::execute(
b.goal_repo.clone(),
b.stats_repo.clone(),
b.event_publisher.clone(),
&deps,
CreateGoalCommand {
user_id: Uuid::nil(),
year: 2019,
@@ -136,10 +145,13 @@ async fn rejects_year_before_2020() {
#[tokio::test]
async fn rejects_zero_target() {
let b = TestContextBuilder::new();
let deps = GoalCommandDeps {
goal: b.goal_repo.clone(),
stats: b.stats_repo.clone(),
event_publisher: b.event_publisher.clone(),
};
let result = create::execute(
b.goal_repo.clone(),
b.stats_repo.clone(),
b.event_publisher.clone(),
&deps,
CreateGoalCommand {
user_id: Uuid::nil(),
year: 2025,

View File

@@ -3,6 +3,7 @@ use std::sync::Arc;
use domain::testing::{FakeStatsRepository, InMemoryGoalRepository, NoopEventPublisher};
use uuid::Uuid;
use crate::goals::deps::GoalCommandDeps;
use crate::goals::{
commands::{CreateGoalCommand, DeleteGoalCommand},
create, delete,
@@ -14,11 +15,14 @@ async fn deletes_existing_goal() {
let goals = InMemoryGoalRepository::new();
let stats = FakeStatsRepository::new();
let events = NoopEventPublisher::new();
let deps = GoalCommandDeps {
goal: Arc::clone(&goals) as _,
stats: Arc::clone(&stats) as _,
event_publisher: Arc::clone(&events) as _,
};
create::execute(
Arc::clone(&goals) as _,
Arc::clone(&stats) as _,
Arc::clone(&events) as _,
&deps,
CreateGoalCommand {
user_id: Uuid::nil(),
year: 2025,
@@ -30,8 +34,7 @@ async fn deletes_existing_goal() {
assert_eq!(goals.count(), 1);
delete::execute(
Arc::clone(&goals) as _,
Arc::clone(&events) as _,
&deps,
DeleteGoalCommand {
user_id: Uuid::nil(),
year: 2025,
@@ -46,9 +49,13 @@ async fn deletes_existing_goal() {
#[tokio::test]
async fn fails_when_not_found() {
let b = TestContextBuilder::new();
let deps = GoalCommandDeps {
goal: b.goal_repo.clone(),
stats: b.stats_repo.clone(),
event_publisher: b.event_publisher.clone(),
};
let result = delete::execute(
b.goal_repo.clone(),
b.event_publisher.clone(),
&deps,
DeleteGoalCommand {
user_id: Uuid::nil(),
year: 2025,

View File

@@ -1,15 +1,24 @@
use uuid::Uuid;
use crate::goals::deps::{GoalCommandDeps, GoalQueryDeps};
use crate::goals::{commands::CreateGoalCommand, create, get, queries::GetGoalQuery};
use crate::test_helpers::TestContextBuilder;
#[tokio::test]
async fn returns_goal_when_exists() {
let b = TestContextBuilder::new();
let cmd_deps = GoalCommandDeps {
goal: b.goal_repo.clone(),
stats: b.stats_repo.clone(),
event_publisher: b.event_publisher.clone(),
};
let query_deps = GoalQueryDeps {
goal: b.goal_repo.clone(),
stats: b.stats_repo.clone(),
};
create::execute(
b.goal_repo.clone(),
b.stats_repo.clone(),
b.event_publisher.clone(),
&cmd_deps,
CreateGoalCommand {
user_id: Uuid::nil(),
year: 2025,
@@ -20,8 +29,7 @@ async fn returns_goal_when_exists() {
.unwrap();
let result = get::execute(
b.goal_repo.clone(),
b.stats_repo.clone(),
&query_deps,
GetGoalQuery {
user_id: Uuid::nil(),
year: 2025,
@@ -37,9 +45,12 @@ async fn returns_goal_when_exists() {
#[tokio::test]
async fn returns_none_when_missing() {
let b = TestContextBuilder::new();
let query_deps = GoalQueryDeps {
goal: b.goal_repo.clone(),
stats: b.stats_repo.clone(),
};
let result = get::execute(
b.goal_repo.clone(),
b.stats_repo.clone(),
&query_deps,
GetGoalQuery {
user_id: Uuid::nil(),
year: 2025,

View File

@@ -1,14 +1,18 @@
use uuid::Uuid;
use crate::goals::deps::{GoalCommandDeps, GoalQueryDeps};
use crate::goals::{commands::CreateGoalCommand, create, list, queries::ListGoalsQuery};
use crate::test_helpers::TestContextBuilder;
#[tokio::test]
async fn returns_empty_when_no_goals() {
let b = TestContextBuilder::new();
let query_deps = GoalQueryDeps {
goal: b.goal_repo.clone(),
stats: b.stats_repo.clone(),
};
let result = list::execute(
b.goal_repo.clone(),
b.stats_repo.clone(),
&query_deps,
ListGoalsQuery {
user_id: Uuid::nil(),
},
@@ -22,11 +26,19 @@ async fn returns_empty_when_no_goals() {
#[tokio::test]
async fn returns_all_goals_for_user() {
let b = TestContextBuilder::new();
let cmd_deps = GoalCommandDeps {
goal: b.goal_repo.clone(),
stats: b.stats_repo.clone(),
event_publisher: b.event_publisher.clone(),
};
let query_deps = GoalQueryDeps {
goal: b.goal_repo.clone(),
stats: b.stats_repo.clone(),
};
for year in [2023, 2024, 2025] {
create::execute(
b.goal_repo.clone(),
b.stats_repo.clone(),
b.event_publisher.clone(),
&cmd_deps,
CreateGoalCommand {
user_id: Uuid::nil(),
year,
@@ -38,8 +50,7 @@ async fn returns_all_goals_for_user() {
}
let result = list::execute(
b.goal_repo.clone(),
b.stats_repo.clone(),
&query_deps,
ListGoalsQuery {
user_id: Uuid::nil(),
},

View File

@@ -1,5 +1,6 @@
use uuid::Uuid;
use crate::goals::deps::GoalCommandDeps;
use crate::goals::{
commands::{CreateGoalCommand, UpdateGoalCommand},
create, update,
@@ -9,10 +10,14 @@ use crate::test_helpers::TestContextBuilder;
#[tokio::test]
async fn updates_target_count() {
let b = TestContextBuilder::new();
let deps = GoalCommandDeps {
goal: b.goal_repo.clone(),
stats: b.stats_repo.clone(),
event_publisher: b.event_publisher.clone(),
};
create::execute(
b.goal_repo.clone(),
b.stats_repo.clone(),
b.event_publisher.clone(),
&deps,
CreateGoalCommand {
user_id: Uuid::nil(),
year: 2025,
@@ -23,9 +28,7 @@ async fn updates_target_count() {
.unwrap();
let result = update::execute(
b.goal_repo.clone(),
b.stats_repo.clone(),
b.event_publisher.clone(),
&deps,
UpdateGoalCommand {
user_id: Uuid::nil(),
year: 2025,
@@ -41,10 +44,13 @@ async fn updates_target_count() {
#[tokio::test]
async fn fails_when_goal_not_found() {
let b = TestContextBuilder::new();
let deps = GoalCommandDeps {
goal: b.goal_repo.clone(),
stats: b.stats_repo.clone(),
event_publisher: b.event_publisher.clone(),
};
let result = update::execute(
b.goal_repo.clone(),
b.stats_repo.clone(),
b.event_publisher.clone(),
&deps,
UpdateGoalCommand {
user_id: Uuid::nil(),
year: 2025,
@@ -59,10 +65,14 @@ async fn fails_when_goal_not_found() {
#[tokio::test]
async fn rejects_zero_target() {
let b = TestContextBuilder::new();
let deps = GoalCommandDeps {
goal: b.goal_repo.clone(),
stats: b.stats_repo.clone(),
event_publisher: b.event_publisher.clone(),
};
create::execute(
b.goal_repo.clone(),
b.stats_repo.clone(),
b.event_publisher.clone(),
&deps,
CreateGoalCommand {
user_id: Uuid::nil(),
year: 2025,
@@ -73,9 +83,7 @@ async fn rejects_zero_target() {
.unwrap();
let result = update::execute(
b.goal_repo.clone(),
b.stats_repo.clone(),
b.event_publisher.clone(),
&deps,
UpdateGoalCommand {
user_id: Uuid::nil(),
year: 2025,