diff options
| author | soryu <soryu@soryu.co> | 2026-02-16 19:01:56 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-16 19:01:56 +0000 |
| commit | 4bd40f047a6f4703945c6db2811d8feda27241d6 (patch) | |
| tree | b53feed7931309520c0886585487d143fc2957f4 /makima/src/server/handlers | |
| parent | b3de779d87450033f1e0361144c621a1d5f1dbf8 (diff) | |
| download | soryu-4bd40f047a6f4703945c6db2811d8feda27241d6.tar.gz soryu-4bd40f047a6f4703945c6db2811d8feda27241d6.zip | |
soryu-co/soryu - makima (#66)
* feat: soryu-co/soryu - makima: Fix contracts page scrolling overflow
* WIP: heartbeat checkpoint
* WIP: heartbeat checkpoint
* WIP: heartbeat checkpoint
* WIP: heartbeat checkpoint
Diffstat (limited to 'makima/src/server/handlers')
| -rw-r--r-- | makima/src/server/handlers/directives.rs | 13 | ||||
| -rw-r--r-- | makima/src/server/handlers/orders.rs | 26 |
2 files changed, 35 insertions, 4 deletions
diff --git a/makima/src/server/handlers/directives.rs b/makima/src/server/handlers/directives.rs index 960da94..15df6d5 100644 --- a/makima/src/server/handlers/directives.rs +++ b/makima/src/server/handlers/directives.rs @@ -1063,7 +1063,7 @@ pub async fn pick_up_orders( }; // Fetch available orders - let orders = match repository::get_available_orders_for_pickup(pool, auth.owner_id).await { + let orders = match repository::get_available_orders_for_pickup(pool, auth.owner_id, id).await { Ok(o) => o, Err(e) => { tracing::error!("Failed to fetch available orders: {}", e); @@ -1078,7 +1078,7 @@ pub async fn pick_up_orders( // If no orders available, return early if orders.is_empty() { return Json(PickUpOrdersResponse { - message: "No orders available to pick up".to_string(), + message: "No orders available to plan".to_string(), order_count: 0, task_id: None, }) @@ -1125,6 +1125,13 @@ pub async fn pick_up_orders( .into_response(); } + // Mark picked-up orders as in_progress + if let Err(e) = + repository::bulk_update_order_status(pool, auth.owner_id, &order_ids, "in_progress").await + { + tracing::warn!("Failed to update order status to in_progress: {}", e); + } + // Create the planning task let req = CreateTaskRequest { contract_id: None, @@ -1199,7 +1206,7 @@ pub async fn pick_up_orders( let _ = repository::advance_directive_ready_steps(pool, id).await; Json(PickUpOrdersResponse { - message: format!("Picked up {} orders", order_count), + message: format!("Planning {} orders", order_count), order_count, task_id: Some(task.id), }) diff --git a/makima/src/server/handlers/orders.rs b/makima/src/server/handlers/orders.rs index cddf6a6..1251f79 100644 --- a/makima/src/server/handlers/orders.rs +++ b/makima/src/server/handlers/orders.rs @@ -81,13 +81,14 @@ pub async fn list_orders( } } -/// Create a new order. +/// Create a new order. A valid directive_id is required. #[utoipa::path( post, path = "/api/v1/orders", request_body = CreateOrderRequest, responses( (status = 201, description = "Order created", body = Order), + (status = 400, description = "Invalid directive_id", body = ApiError), (status = 401, description = "Unauthorized", body = ApiError), (status = 503, description = "Database not configured", body = ApiError), ), @@ -107,6 +108,29 @@ pub async fn create_order( .into_response(); }; + // Validate the directive exists and belongs to this owner. + // directive_id is required by the CreateOrderRequest struct (Uuid, not Option<Uuid>). + match repository::get_directive_for_owner(pool, auth.owner_id, req.directive_id).await { + Ok(Some(_)) => {} + Ok(None) => { + return ( + StatusCode::BAD_REQUEST, + Json(ApiError::new( + "INVALID_DIRECTIVE", + "directive_id is required and must reference a valid directive owned by you", + )), + ) + .into_response(); + } + Err(e) => { + return ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(ApiError::new("VALIDATION_FAILED", &e.to_string())), + ) + .into_response(); + } + } + match repository::create_order(pool, auth.owner_id, req).await { Ok(order) => (StatusCode::CREATED, Json(order)).into_response(), Err(e) => { |
