ruwebframe 0.1.8

a simple webframe for rust actix-web, based on rudi and rbatis.
Documentation
use crate::rubase::ruconst::ruconst;
use crate::rubase::{BaseEntity, ruresult};
use crate::rucfg;
use crate::rucfg::find_bean_ru_config;
use crate::rudomain::rudb::dbentity::dbexample::find_bean_person;
use crate::rulog::ru_log;
use actix_web::{HttpResponse, Responder, web};

pub async fn manual_hello() -> impl Responder {
    ru_log::info("manual_hello there");
    HttpResponse::Ok().body("manual_hello there!")
}
pub async fn home() -> impl Responder {
    ru_log::info2("home", ruresult::find_bean_ru_result().unwrap());

    HttpResponse::Ok()
        .content_type("application/json; charset=utf-8")
        .json(ruresult::find_bean_ru_result().unwrap())
}
pub async fn health() -> impl Responder {
    ru_log::info2("hello", ruresult::find_bean_ru_result().unwrap());

    HttpResponse::Ok()
        .content_type("application/json; charset=utf-8")
        .json(ruresult::find_bean_ru_result().unwrap())
}
pub async fn config() -> impl Responder {
    ru_log::info("/conf handler called");
    match rucfg::find_bean_ru_config() {
        Some(arc) => {
            ru_log::info("find_bean_ru_config returned Some");
            match arc.lock() {
                Ok(conf) => HttpResponse::Ok().json(conf.config.clone()),
                Err(e) => {
                    let msg = format!("config lock failed: {}", e);
                    ru_log::info2("config error:", &msg);
                    HttpResponse::InternalServerError().body(msg)
                }
            }
        }
        None => {
            ru_log::info("config bean not found - returning empty json");
            HttpResponse::Ok().json(serde_json::json!({"error": "config bean not found"}))
        }
    }
}

// 使用示例
pub fn config_routes(cfg: &mut web::ServiceConfig) {
    cfg.route("/hey", web::get().to(manual_hello));
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::rulog;
    #[test]
    fn test_01_cfg() {
        let cfg = rucfg::find_bean_ru_config()
            .unwrap()
            .lock()
            .unwrap()
            .read_clone();
        ru_log::info2("config:", &cfg);
    }
}

pub async fn person() -> impl Responder {
    let mut p = find_bean_person().unwrap().lock().unwrap().clone();
    p.name = "协调员".to_string();

    HttpResponse::Ok()
        .content_type("application/json; charset=utf-8")
        .body(p.to_json().unwrap())
}
pub async fn conf() -> impl Responder {
    ru_log::info("/conf handler called");
    let c = find_bean_ru_config().unwrap().lock().unwrap().read_clone();
    ru_log::info2("/conf handler called",&c);
    //let json_str = serde_json::to_string_pretty(&c).unwrap();

    HttpResponse::Ok()
        .content_type("application/json; charset=utf-8")
        .body(c.to_json().unwrap())
}