use std::collections::HashMap; use axum::{ extract::{Path, Query, State}, Json, Router, }; use axum_extra::routing::Resource; use serde::{Deserialize, Serialize}; use crate::{service::Services, Error, Status}; #[derive(Debug, Clone, Default, Serialize, Deserialize)] pub struct ServiceQuery { pub name: Option, pub state: Option, } pub fn router() -> Router { Resource::named("services").index(index).show(show).into() } pub async fn index( Query(query): Query, State(services): State, ) -> Result>, Error> { services .check_filtered(|name| (!query.name.as_ref().is_some_and(|s| s != name))) .await .map(Json) } pub async fn show( Path(name): Path, State(services): State, ) -> Result { services .check_one(&name) .await .ok_or_else(|| Error::ServiceNotFound(name))? }