diff --git a/src/api/v1/meta.rs b/src/api/v1/meta.rs new file mode 100644 index 0000000..f01839a --- /dev/null +++ b/src/api/v1/meta.rs @@ -0,0 +1,63 @@ +use actix_web::{web, HttpResponse, Responder}; +use serde::{Deserialize, Serialize}; + +use crate::{GIT_COMMIT_HASH, VERSION}; + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct BuildDetails { + pub version: &'static str, + pub git_commit_hash: &'static str, +} + +pub mod routes { + pub struct Meta { + pub build_details: &'static str, + pub health: &'static str, + } + + impl Meta { + pub const fn new() -> Self { + Self { + build_details: "/api/v1/meta/build", + health: "/api/v1/meta/health", + } + } + } +} + +pub const META: routes::Meta = routes::Meta::new(); + +/// emmits build details of the bninary +#[actix_web_codegen_const_routes::get(path = "META.build_details")] +async fn build_details() -> impl Responder { + let build = BuildDetails { + version: VERSION, + git_commit_hash: GIT_COMMIT_HASH, + }; + HttpResponse::Ok().json(build) +} + +pub fn services(cfg: &mut web::ServiceConfig) { + cfg.service(build_details); +} + +#[cfg(test)] +mod tests { + use actix_web::{http::StatusCode, test, App}; + + use super::services; + + #[actix_rt::test] + async fn build_details_works() { + let app = test::init_service(App::new().configure(services)).await; + + let resp = test::call_service( + &app, + test::TestRequest::get() + .uri(super::META.build_details) + .to_request(), + ) + .await; + assert_eq!(resp.status(), StatusCode::OK); + } +} diff --git a/src/api/v1/mod.rs b/src/api/v1/mod.rs index d0b1439..4f25df7 100644 --- a/src/api/v1/mod.rs +++ b/src/api/v1/mod.rs @@ -2,8 +2,10 @@ // // SPDX-License-Identifier: AGPL-3.0-or-later +pub mod meta; pub mod webhooks; pub fn services(cfg: &mut actix_web::web::ServiceConfig) { webhooks::services(cfg); + meta::services(cfg); }