refactor: split http layer

This commit is contained in:
2026-06-13 06:32:31 +02:00
parent a6dd497e8a
commit da910a88c7
7 changed files with 180 additions and 161 deletions

37
src/http/handlers.rs Normal file
View File

@@ -0,0 +1,37 @@
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,
}