use smol_str::SmolStr;
use super::*;
#[derive(Deserialize)]
pub struct GetHostStatus {
pub hostname: SmolStr,
}
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GetHostStatusOutput {
#[serde(skip_serializing_if = "Option::is_none")]
pub account_count: Option<i64>,
pub hostname: SmolStr,
#[serde(skip_serializing_if = "Option::is_none")]
pub seq: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<&'static str>,
}
pub async fn handle(
State(hydrant): State<Hydrant>,
ExtractXrpc(req): ExtractXrpc<GetHostStatus>,
) -> XrpcResult<Json<GetHostStatusOutput>> {
let Some(host) = hydrant
.get_host_status(&req.hostname)
.await
.map_err(internal_error)?
else {
return Err(bad_request("host does not exist"));
};
Ok(Json(GetHostStatusOutput {
account_count: Some(host.account_count as i64),
hostname: host.name,
seq: Some(host.seq),
status: Some(host.status.as_str()),
}))
}