Initial commit
This commit is contained in:
commit
f1e6c68aac
31 changed files with 3297 additions and 0 deletions
50
src/http/novels/list.rs
Normal file
50
src/http/novels/list.rs
Normal file
|
@ -0,0 +1,50 @@
|
|||
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<jiff::Zoned>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Default)]
|
||||
struct Output {
|
||||
pub novels: HashMap<String, FullNovel>,
|
||||
pub errors: Vec<String>,
|
||||
}
|
||||
|
||||
async fn list(state: State, FromJson(args): FromJson<Args>) -> ApiResult<Output> {
|
||||
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))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue