plc_control/crates/app_feeder_distributor/src/router.rs

87 lines
2.8 KiB
Rust

use axum::{
routing::{get, post},
Router,
};
use crate::{handler, AppState};
pub fn build_router(state: AppState) -> Router {
// Platform routes (source, point, equipment, tag, page, logs) from core.
let platform = plc_platform_core::handler::platform_routes::<AppState>();
// Feeder-specific routes.
let feeder_routes = Router::new()
// Unit / control routes (feeder-specific).
.route(
"/api/unit",
get(handler::control::get_unit_list).post(handler::control::create_unit),
)
.route(
"/api/unit/{unit_id}",
get(handler::control::get_unit)
.put(handler::control::update_unit)
.delete(handler::control::delete_unit),
)
.route("/api/event", get(handler::control::get_event_list))
.route(
"/api/control/equipment/{equipment_id}/start",
post(handler::control::start_equipment),
)
.route(
"/api/control/equipment/{equipment_id}/stop",
post(handler::control::stop_equipment),
)
.route(
"/api/control/unit/{unit_id}/start-auto",
post(handler::control::start_auto_unit),
)
.route(
"/api/control/unit/{unit_id}/stop-auto",
post(handler::control::stop_auto_unit),
)
.route(
"/api/control/unit/batch-start-auto",
post(handler::control::batch_start_auto),
)
.route(
"/api/control/unit/batch-stop-auto",
post(handler::control::batch_stop_auto),
)
.route(
"/api/control/unit/{unit_id}/ack-fault",
post(handler::control::ack_fault_unit),
)
.route(
"/api/unit/{unit_id}/runtime",
get(handler::control::get_unit_runtime),
)
.route(
"/api/unit/{unit_id}/detail",
get(handler::control::get_unit_detail),
)
// Doc routes (feeder-specific doc paths).
.route("/api/docs/api-md", get(handler::doc::get_api_md))
.route("/api/docs/readme-md", get(handler::doc::get_readme_md));
Router::new()
.merge(platform)
.merge(feeder_routes)
.nest(
"/ui",
plc_platform_core::http::static_ui_routes("web/feeder", "web/core"),
)
.route(
"/ws/public",
get(plc_platform_core::websocket::public_websocket_handler::<AppState>),
)
.route(
"/ws/client/{client_id}",
get(plc_platform_core::websocket::client_websocket_handler::<AppState>),
)
.layer(axum::middleware::from_fn(
plc_platform_core::http::simple_logger,
))
.layer(plc_platform_core::http::permissive_cors())
.with_state(state)
}