use std::collections::HashMap; use axum::routing::post; use serde::Serialize; use crate::{ result::{ApiResult, FromJson}, schemas::novel::FullNovel, state::{Router, State}, }; #[derive(Debug, serde::Deserialize)] struct Args { pub start_from: Option, } #[derive(Debug, Serialize, Default)] struct Output { pub novels: HashMap, pub errors: Vec, } async fn list(state: State, FromJson(args): FromJson) -> ApiResult { let mut out = Output::default(); let novels = state.app.read().enumerate_novels(); for (slug, entry) in novels { let novel = match entry.get_full_info() { Ok(n) => n, Err(e) => { out.errors.push(e.to_string()); continue; } }; if let Some(ref start_from) = args.start_from { if &novel.data.post_at < start_from { continue; } } out.novels.insert(slug, novel); } Ok(out.into()) } pub fn make() -> Router { Router::new().route("/", post(list)) }