pickcat_api_collection/
reading_session.rs1use crate::dto::reading_session::{ReadingBatchDTO, ReadingBatchResponseDTO, VisiblePostDTO};
6use crate::{Error, PickcatAccound};
7
8pub trait ReadingSessionBehavior {
11 fn report_reading_batch(
16 &self,
17 session_id: &str,
18 batch_no: u32,
19 topic_id: &str,
20 elapsed_ms: u64,
21 visible_posts: Vec<VisiblePostDTO>,
22 ) -> impl std::future::Future<Output = Result<ReadingBatchResponseDTO, Error>> + Send;
23}
24
25impl ReadingSessionBehavior for PickcatAccound {
26 async fn report_reading_batch(
27 &self,
28 session_id: &str,
29 batch_no: u32,
30 topic_id: &str,
31 elapsed_ms: u64,
32 visible_posts: Vec<VisiblePostDTO>,
33 ) -> Result<ReadingBatchResponseDTO, Error> {
34 let dto = ReadingBatchDTO {
35 topic_id: topic_id.to_string(),
36 elapsed_ms,
37 visible_posts,
38 };
39 Ok(self
40 .client
41 .put(format!(
42 "{}/api/v1/reading-sessions/{}/batches/{}",
43 self.base_url, session_id, batch_no
44 ))
45 .json(&dto)
46 .send()
47 .await?
48 .json::<ReadingBatchResponseDTO>()
49 .await?)
50 }
51}