use axum::{
Router,
extract::{Path, State},
routing::get,
};
use ocre::{ApiResult, Ctx, Json, OptionExt, Page, PageLinks};
use crate::models::<%= singular %>::{self, <%= model %>};
pub fn routes() -> Router<Ctx> {
Router::new()
.route("/api/<%= plural %>", get(index))
.route("/api/<%= plural %>/{id}", get(show))
}
async fn index(State(ctx): State<Ctx>, page: Page) -> ApiResult<(PageLinks, Json<Vec<<%= model %>>>)> {
let <%= plural %> = <%= singular %>::all(&ctx, page).await?;
Ok((page.links("/api/<%= plural %>", <%= plural %>.len()), Json(<%= plural %>)))
}
async fn show(State(ctx): State<Ctx>, Path(id): Path<i64>) -> ApiResult<Json<<%= model %>>> {
Ok(Json(<%= singular %>::find(&ctx, id).await?.or_404()?))
}