diff --git a/todored/src/main.rs b/todored/src/main.rs index 2e1bee5..407f7cc 100644 --- a/todored/src/main.rs +++ b/todored/src/main.rs @@ -17,10 +17,10 @@ async fn main() { .expect("to be able to connect to Redis"); let router = axum::Router::new() - .route("/", get(routes::root::version)) - .route("/version", get(routes::root::version)) - .route("/", post(routes::root::healthcheck)) - .route("/healthcheck", post(routes::root::healthcheck)) + .route("/", get(routes::version_route)) + .route("/version", get(routes::version_route)) + .route("/", post(routes::healthcheck_route)) + .route("/healthcheck", post(routes::healthcheck_route)) .route("/board/:board/ws", get(routes::board::board_websocket)) .layer(axum::Extension(rclient)) .layer(tower_http::cors::CorsLayer::new() diff --git a/todored/src/routes/mod.rs b/todored/src/routes/mod.rs index 0de7e88..cf9096e 100644 --- a/todored/src/routes/mod.rs +++ b/todored/src/routes/mod.rs @@ -1,2 +1,6 @@ -pub(crate) mod root; -pub(crate) mod board; +pub mod board; +pub mod structs; +pub(self) mod root; + +pub(crate) use root::version as version_route; +pub(crate) use root::healthcheck as healthcheck_route; diff --git a/todored/src/routes/root.rs b/todored/src/routes/root.rs index 2189170..b35d7cb 100644 --- a/todored/src/routes/root.rs +++ b/todored/src/routes/root.rs @@ -2,23 +2,26 @@ use axum::{Extension, Json}; use axum::http::StatusCode; use crate::outcome::{Response, LoggableOutcome}; +use crate::routes::structs::VersionInfo; const MAJOR: u32 = pkg_version::pkg_version_major!(); const MINOR: u32 = pkg_version::pkg_version_minor!(); const PATCH: u32 = pkg_version::pkg_version_patch!(); -fn compose_version() -> String { - format!("{}.{}.{}", MAJOR, MINOR, PATCH) +fn compose_version() -> VersionInfo { + VersionInfo { + version: format!("{}.{}.{}", MAJOR, MINOR, PATCH) + } } -pub async fn version() -> Response> { +pub async fn version() -> Response> { Ok(Json(compose_version())) } pub async fn healthcheck( Extension(rclient): Extension -) -> Response> { +) -> Response> { let mut rconn = rclient.get_async_connection().await .log_err_to_error("Failed to connect to Redis") .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; diff --git a/todored/src/routes/structs.rs b/todored/src/routes/structs.rs new file mode 100644 index 0000000..80d1116 --- /dev/null +++ b/todored/src/routes/structs.rs @@ -0,0 +1,6 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct VersionInfo { + pub version: String, +}