use {
futures::StreamExt,
log::error,
reqwest::Client,
serde::Deserialize,
time::OffsetDateTime,
crate::RqResult,
super::{
supplement::IdType,
datetimeformat,
traits::List,
post::{Posts, PostWrapper},
},
};
pub const POOLS_URL: &'static str = "pools.json";
#[derive(Debug, PartialEq, Eq, Deserialize)]
#[serde(rename_all="lowercase")]
pub enum Category {
Series,
Collection
}
#[derive(Debug, Deserialize)]
pub struct Pool {
pub id: IdType,
pub name: String,
#[serde(with = "datetimeformat")]
pub created_at: OffsetDateTime,
#[serde(with = "datetimeformat")]
pub updated_at: OffsetDateTime,
pub creator_id: IdType,
pub description: String,
pub is_active: bool,
pub category: Category,
pub post_ids: Vec<IdType>,
pub creator_name: String,
pub post_count: u16 }
impl List for Pool {
const ENDPOINT: &'static str = "pools";
}
impl Pool {
pub async fn by_search_first(&self, id: IdType) {
}
pub async fn by_search() {
}
pub async fn get_all_posts(self, client: Client)
-> RqResult<Posts> {
Ok(futures::stream::iter(
self.post_ids.into_iter().map(|id| {
let cc = client.clone();
async move {
match PostWrapper::new_by_id(cc, id).await {
Ok(PostWrapper::Post(x)) => x,
Err(e) => {
error!("Error while getting all posts: {:#?}", e);
panic!();
}
}
}
}
)).buffer_unordered(20).collect::<Vec<_>>().await)
}
}