38 lines
1010 B
Rust
38 lines
1010 B
Rust
use super::AppState;
|
|
use crate::{domain::PokemonInfo, error::AppError};
|
|
use axum::{
|
|
Json,
|
|
extract::{Path, State},
|
|
http::header,
|
|
response::IntoResponse,
|
|
};
|
|
use serde::Serialize;
|
|
|
|
pub(super) async fn health() -> Json<HealthResponse> {
|
|
Json(HealthResponse { status: "ok" })
|
|
}
|
|
|
|
pub(super) async fn metrics(State(state): State<AppState>) -> Result<impl IntoResponse, AppError> {
|
|
let body = state.telemetry.render_prometheus()?;
|
|
Ok(([(header::CONTENT_TYPE, "text/plain; version=0.0.4")], body))
|
|
}
|
|
|
|
pub(super) async fn get_pokemon(
|
|
State(state): State<AppState>,
|
|
Path(name): Path<String>,
|
|
) -> Result<Json<PokemonInfo>, AppError> {
|
|
state.service.get_basic(&name).await.map(Json)
|
|
}
|
|
|
|
pub(super) async fn get_translated_pokemon(
|
|
State(state): State<AppState>,
|
|
Path(name): Path<String>,
|
|
) -> Result<Json<PokemonInfo>, AppError> {
|
|
state.service.get_translated(&name).await.map(Json)
|
|
}
|
|
|
|
#[derive(Serialize)]
|
|
pub(super) struct HealthResponse {
|
|
status: &'static str,
|
|
}
|