use crate::dto::reading_session::{ReadingBatchDTO, ReadingBatchResponseDTO, VisiblePostDTO};
use crate::{Error, PickcatAccound};
pub trait ReadingSessionBehavior {
fn report_reading_batch(
&self,
session_id: &str,
batch_no: u32,
topic_id: &str,
elapsed_ms: u64,
visible_posts: Vec<VisiblePostDTO>,
) -> impl std::future::Future<Output = Result<ReadingBatchResponseDTO, Error>> + Send;
}
impl ReadingSessionBehavior for PickcatAccound {
async fn report_reading_batch(
&self,
session_id: &str,
batch_no: u32,
topic_id: &str,
elapsed_ms: u64,
visible_posts: Vec<VisiblePostDTO>,
) -> Result<ReadingBatchResponseDTO, Error> {
let dto = ReadingBatchDTO {
topic_id: topic_id.to_string(),
elapsed_ms,
visible_posts,
};
Ok(self
.client
.put(format!(
"{}/api/v1/reading-sessions/{}/batches/{}",
self.base_url, session_id, batch_no
))
.json(&dto)
.send()
.await?
.json::<ReadingBatchResponseDTO>()
.await?)
}
}