Files
movies-diary/crates/application/src/goals/update.rs
Gabriel Kaszewski d867a14b28
Some checks failed
CI / Check / Test (push) Has been cancelled
add 400+ unit tests for domain and application layers
Extract ReviewLogger trait to decouple import/integrations
from diary::log_review (cross-module coupling smell).

Add in-memory fakes for all repository ports, enabling
isolated testing of every use case module without a database.

Coverage: domain+application 22% → 80%, 427 tests.
2026-06-09 02:07:26 +02:00

49 lines
1.1 KiB
Rust

use domain::{
errors::DomainError, events::DomainEvent, models::GoalWithProgress, value_objects::UserId,
};
use super::commands::UpdateGoalCommand;
use crate::context::AppContext;
pub async fn execute(
ctx: &AppContext,
cmd: UpdateGoalCommand,
) -> Result<GoalWithProgress, DomainError> {
let user_id = UserId::from_uuid(cmd.user_id);
let mut goal = ctx
.repos
.goal
.find_by_user_and_year(&user_id, cmd.year)
.await?
.ok_or_else(|| DomainError::NotFound(format!("Goal for year {}", cmd.year)))?;
goal.update_target(cmd.target_count)?;
ctx.repos.goal.update(&goal).await?;
let current_count = ctx
.repos
.goal
.count_reviews_in_year(&user_id, cmd.year)
.await?;
ctx.services
.event_publisher
.publish(&DomainEvent::GoalUpdated {
goal_id: goal.id().clone(),
user_id,
year: cmd.year,
target_count: cmd.target_count,
})
.await?;
Ok(GoalWithProgress {
goal,
current_count,
})
}
#[cfg(test)]
#[path = "tests/update.rs"]
mod tests;