summaryrefslogtreecommitdiff
path: root/makima/src/server
diff options
context:
space:
mode:
Diffstat (limited to 'makima/src/server')
-rw-r--r--makima/src/server/handlers/directives.rs45
1 files changed, 24 insertions, 21 deletions
diff --git a/makima/src/server/handlers/directives.rs b/makima/src/server/handlers/directives.rs
index 929769c..6060171 100644
--- a/makima/src/server/handlers/directives.rs
+++ b/makima/src/server/handlers/directives.rs
@@ -823,29 +823,32 @@ pub async fn update_goal(
.into_response();
};
- match repository::update_directive_goal(pool, auth.owner_id, id, &req.goal).await {
- Ok(Some(directive)) => {
- // Clear non-started steps so replanning starts fresh
- match repository::clear_pending_directive_steps(pool, id).await {
- Ok(count) => {
- if count > 0 {
- tracing::info!(
- directive_id = %id,
- removed_steps = count,
- "Cleared pending steps after goal update — replanning will generate new steps"
- );
- }
- }
- Err(e) => {
- tracing::warn!(
- directive_id = %id,
- error = %e,
- "Failed to clear pending steps after goal update"
- );
- }
+ // Save old goal to history before overwriting (best-effort)
+ match repository::get_directive_for_owner(pool, auth.owner_id, id).await {
+ Ok(Some(current)) => {
+ if let Err(e) = repository::save_directive_goal_history(pool, id, &current.goal).await
+ {
+ tracing::warn!(
+ directive_id = %id,
+ error = %e,
+ "Failed to save goal history before update — continuing with goal update"
+ );
}
- Json(directive).into_response()
}
+ Ok(None) => {
+ // Directive not found — update_directive_goal will handle this
+ }
+ Err(e) => {
+ tracing::warn!(
+ directive_id = %id,
+ error = %e,
+ "Failed to fetch current directive for goal history — continuing with goal update"
+ );
+ }
+ }
+
+ match repository::update_directive_goal(pool, auth.owner_id, id, &req.goal).await {
+ Ok(Some(directive)) => Json(directive).into_response(),
Ok(None) => (
StatusCode::NOT_FOUND,
Json(ApiError::new("NOT_FOUND", "Directive not found")),