feat: build details route

This commit is contained in:
Aravinth Manivannan 2023-10-04 19:20:06 +05:30
parent a63979af76
commit d6a5853d34
Signed by: realaravinth
GPG Key ID: F8F50389936984FF
2 changed files with 65 additions and 0 deletions

63
src/api/v1/meta.rs Normal file
View File

@ -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);
}
}

View File

@ -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);
}