#[cfg(feature = "actix")]
use std::sync::Arc;
#[cfg(feature = "actix")]
use actix_web::{web, App, HttpResponse, HttpServer};
#[cfg(feature = "actix")]
use rust_viewflow::{
create_actix_scope, migrate_sqlite, DefaultWorkflowApi, DefaultWorkflowEngine,
LeaveRequestWorkflow, SqliteDatabase,
};
#[cfg(feature = "actix")]
use sqlx::SqlitePool;
#[cfg(feature = "actix")]
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let pool = SqlitePool::connect("sqlite::memory:")
.await
.map_err(|e| std::io::Error::other(e.to_string()))?;
migrate_sqlite(&pool)
.await
.map_err(|e| std::io::Error::other(e.to_string()))?;
let db = Arc::new(SqliteDatabase::new(pool));
let engine = Arc::new(DefaultWorkflowEngine::new(db.clone()));
engine.register_workflow(Arc::new(LeaveRequestWorkflow::new(db)));
let api = Arc::new(DefaultWorkflowApi::new(engine));
HttpServer::new(move || {
App::new()
.route(
"/",
web::get().to(|| async { HttpResponse::Ok().body("Rust Viewflow Actix Example") }),
)
.service(create_actix_scope(api.clone()))
})
.bind(("0.0.0.0", 3001))?
.run()
.await
}
#[cfg(not(feature = "actix"))]
fn main() {
eprintln!("This example requires the `actix` feature. Run with: cargo run --example leave_request_actix --features actix");
}