moadim 1.6.1

Loop engine for AI agents — routines over REST, MCP, and a built-in web UI
//! `POST /routines` HTTP handler.

use super::logic;
use crate::error::{run_blocking, AppError};
use axum::{extract::State, http::StatusCode, Json};
use logic::{CreateRoutineRequest, RoutineResponse, RoutineStore};

/// `POST /routines` — create a new routine.
#[utoipa::path(post, path = "/routines",
    request_body = CreateRoutineRequest,
    responses((status = 201, body = RoutineResponse), (status = 400, description = "Invalid cron expression")))]
pub async fn create_routine(
    State(store): State<RoutineStore>,
    Json(body): Json<CreateRoutineRequest>,
) -> Result<(StatusCode, Json<RoutineResponse>), AppError> {
    // `svc_create` syncs the crontab, which shells out to `crontab`(1) (#360) — keep that
    // off the async worker thread.
    let resp = run_blocking(move || logic::build(&store, body)).await?;
    Ok((StatusCode::CREATED, Json(resp)))
}

#[cfg(test)]
#[path = "http_tests.rs"]
mod http_tests;