Restore codebase deleted by bad auto-commit e4227cf
Commit e4227cf (a story creation auto-commit) erroneously deleted 175
files from master's tree, likely due to a race condition between
concurrent git operations. This commit re-adds all files from the
working directory.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
66
server/src/http/health.rs
Normal file
66
server/src/http/health.rs
Normal file
@@ -0,0 +1,66 @@
|
||||
use poem::handler;
|
||||
use poem_openapi::{Object, OpenApi, Tags, payload::Json};
|
||||
use serde::Serialize;
|
||||
|
||||
/// Health check endpoint.
|
||||
///
|
||||
/// Returns a static "ok" response to indicate the server is running.
|
||||
#[handler]
|
||||
pub fn health() -> &'static str {
|
||||
"ok"
|
||||
}
|
||||
|
||||
#[derive(Tags)]
|
||||
enum HealthTags {
|
||||
Health,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Object)]
|
||||
pub struct HealthStatus {
|
||||
status: String,
|
||||
}
|
||||
|
||||
pub struct HealthApi;
|
||||
|
||||
#[OpenApi(tag = "HealthTags::Health")]
|
||||
impl HealthApi {
|
||||
/// Health check endpoint.
|
||||
///
|
||||
/// Returns a JSON status object to confirm the server is running.
|
||||
#[oai(path = "/health", method = "get")]
|
||||
async fn health(&self) -> Json<HealthStatus> {
|
||||
Json(HealthStatus {
|
||||
status: "ok".to_string(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[tokio::test]
|
||||
async fn handler_health_returns_ok() {
|
||||
let app = poem::Route::new().at("/health", poem::get(health));
|
||||
let cli = poem::test::TestClient::new(app);
|
||||
let resp = cli.get("/health").send().await;
|
||||
resp.assert_status_is_ok();
|
||||
resp.assert_text("ok").await;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn health_status_serializes_to_json() {
|
||||
let status = HealthStatus {
|
||||
status: "ok".to_string(),
|
||||
};
|
||||
let json = serde_json::to_value(&status).unwrap();
|
||||
assert_eq!(json["status"], "ok");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn api_health_returns_ok_status() {
|
||||
let api = HealthApi;
|
||||
let response = api.health().await;
|
||||
assert_eq!(response.0.status, "ok");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user