strava_wrapper/filters/
comments.rs1use crate::models::Comment;
2use crate::query::{
3 get_with_query_and_path, AfterCursor, Endpoint, ErrorWrapper, Page, PageSize, PathQuery, Query,
4 Sendable, ID,
5};
6use async_trait::async_trait;
7use std::collections::HashMap;
8
9#[derive(Debug, Clone)]
10pub struct CommentFilter {
11 url: String,
12 token: String,
13 path: String,
14 query: Vec<(String, String)>,
15 path_params: Vec<(String, String)>,
16}
17
18impl CommentFilter {
19 pub fn new(url: impl Into<String>, token: impl Into<String>, path: impl Into<String>) -> Self {
20 Self {
21 url: url.into(),
22 token: token.into(),
23 path: path.into(),
24 query: Vec::new(),
25 path_params: Vec::new(),
26 }
27 }
28}
29
30impl ID for CommentFilter {
31 fn id(mut self, id: u64) -> Self {
32 self.path_params.push(("id".to_string(), id.to_string()));
33 self
34 }
35}
36
37impl Endpoint for CommentFilter {
38 fn endpoint(&self) -> String {
39 format!("{}/{}", self.url, self.path)
40 }
41}
42
43#[async_trait]
44impl Sendable<CommentFilter, Vec<Comment>> for CommentFilter {
45 async fn send(mut self) -> Result<Vec<Comment>, ErrorWrapper> {
46 get_with_query_and_path(self.clone(), &self.token).await
47 }
48}
49
50impl Query for CommentFilter {
51 fn get_query_params(self) -> Vec<(String, String)> {
52 self.query
53 }
54}
55
56impl Page for CommentFilter {
57 fn page(mut self, number: u32) -> Self {
58 self.path_params
59 .push(("page".to_string(), number.to_string()));
60 self
61 }
62}
63
64impl PathQuery for CommentFilter {
65 fn get_path_params(&self) -> HashMap<String, String> {
66 self.path_params.iter().cloned().collect()
67 }
68}
69
70impl PageSize for CommentFilter {
71 fn page_size(mut self, size: u32) -> Self {
72 self.query.push(("per_page".to_string(), size.to_string()));
73 self
74 }
75}
76
77impl AfterCursor for CommentFilter {
78 fn after_cursor(mut self, cursor: String) -> Self {
79 self.query
80 .push(("after_cursor".to_string(), cursor.to_string()));
81 self
82 }
83}