fix: honest review update rollback test, goal delete NotFound fake, read before write

This commit is contained in:
2026-10-26 00:52:45 +01:00
parent 62ad9f4017
commit 2f133afb96
4 changed files with 20 additions and 7 deletions

View File

@@ -29,6 +29,8 @@ pub async fn execute(
cmd.target_count,
GoalType::Movies,
)?;
// Reads that can fail happen before the write, so an error never follows a commit.
let current_count = deps.stats.count_reviews_in_year(&user_id, cmd.year).await?;
let event = DomainEvent::GoalCreated {
goal_id: g.id().clone(),
user_id: user_id.clone(),
@@ -37,8 +39,6 @@ pub async fn execute(
};
deps.goal_command.save(&g, &[event]).await?;
let current_count = deps.stats.count_reviews_in_year(&user_id, cmd.year).await?;
Ok(GoalWithProgress {
goal: g,
current_count,

View File

@@ -17,6 +17,8 @@ pub async fn execute(
.ok_or_else(|| DomainError::NotFound(format!("Goal for year {}", cmd.year)))?;
g.update_target(cmd.target_count)?;
// Reads that can fail happen before the write, so an error never follows a commit.
let current_count = deps.stats.count_reviews_in_year(&user_id, cmd.year).await?;
let event = DomainEvent::GoalUpdated {
goal_id: g.id().clone(),
user_id: user_id.clone(),
@@ -25,8 +27,6 @@ pub async fn execute(
};
deps.goal_command.update(&g, &[event]).await?;
let current_count = deps.stats.count_reviews_in_year(&user_id, cmd.year).await?;
Ok(GoalWithProgress {
goal: g,
current_count,