Skip to content

Commit

Permalink
Added ping endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
amigin committed Nov 11, 2024
1 parent 826fcc7 commit f2cab37
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ use super::models::IsAliveResponse;
{status_code: 200, description: "Monitoring result", model: "IsAliveResponse"},
]
)]
pub struct ApiController {}
pub struct IsAliveAction {}

impl ApiController {
impl IsAliveAction {
pub fn new() -> Self {
Self {}
}
}

async fn handle_request(
_: &ApiController,
_: &IsAliveAction,
_ctx: &mut HttpContext,
) -> Result<HttpOkResult, HttpFailResult> {
let version = env!("CARGO_PKG_VERSION");
Expand All @@ -41,5 +41,5 @@ async fn handle_request(
env_info,
};

HttpOutput::as_json(response).into_ok_result(true).into()
HttpOutput::as_json(response).into_ok_result(false).into()
}
6 changes: 4 additions & 2 deletions src/http/controllers/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod api_controller;
mod is_alive_action;
mod models;
pub use api_controller::ApiController;
pub use is_alive_action::*;
mod ping_action;
pub use ping_action::*;
20 changes: 20 additions & 0 deletions src/http/controllers/api/ping_action.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use my_http_server::{macros::http_route, HttpContext, HttpFailResult, HttpOkResult, HttpOutput};

#[http_route(
method: "GET",
route: "/api/Ping",
controller: "Monitoring",
description: "Endpoint to ping the service",
summary: "Endpoint to ping the service",
result:[
{status_code: 204, description: "Ok result"},
]
)]
pub struct PingAction;

async fn handle_request(
_: &PingAction,
_ctx: &mut HttpContext,
) -> Result<HttpOkResult, HttpFailResult> {
HttpOutput::Empty.into_ok_result(false).into()
}
2 changes: 1 addition & 1 deletion src/http/controllers/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::app::AppContext;
pub fn build(app: &Arc<AppContext>) -> ControllersMiddleware {
let mut result = ControllersMiddleware::new(None, None);

let api_controller = super::api::ApiController::new();
let api_controller = super::api::IsAliveAction::new();
result.register_get_action(Arc::new(api_controller));

result.register_get_action(Arc::new(super::tables_controller::GetListAction::new(
Expand Down

0 comments on commit f2cab37

Please sign in to comment.