1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
pub mod models;

pub const BASE_URL: &'static str = "https://api.todoist.com/rest/v1";

pub mod task {
    use std::borrow::Cow;

    use korero::http::{Method, Query, QueryParams, Strategy};
    use serde::{Deserialize, Serialize};

    use crate::models::task::Task;

    #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
    pub struct Get {
        pub id: usize,
        pub params: GetQueryParams,
    }

    impl Get {
        pub fn new(id: usize) -> Self {
            Self {
                id,
                params: GetQueryParams::default(),
            }
        }
    }

    /** In order of precedence when processed by Todoist. */
    #[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
    pub struct GetQueryParams {
        #[serde(skip_serializing_if = "Option::is_none")]
        filter: Option<String>,
        #[serde(skip_serializing_if = "Option::is_none")]
        project_id: Option<usize>,
        #[serde(skip_serializing_if = "Option::is_none")]
        label_id: Option<usize>,
    }

    impl GetQueryParams {
        /** Set the get query params's filter. */
        pub fn set_filter(&mut self, filter: Option<String>) -> &mut Self {
            self.filter = filter;
            self
        }

        /** Set the get query params's project id. */
        pub fn set_project_id(&mut self, project_id: Option<usize>) -> &mut Self {
            self.project_id = project_id;
            self
        }

        /** Set the get query params's label id. */
        pub fn set_label_id(&mut self, label_id: Option<usize>) -> &mut Self {
            self.label_id = label_id;
            self
        }
    }

    impl Query for Get {
        fn endpoint(&self) -> Cow<'static, str> {
            format!("{}/tasks/{}", super::BASE_URL, self.id).into()
        }

        fn params(&self) -> QueryParams {
            // turn self.params into a QueryParams obj
            todo!()
        }
    }

    impl Strategy for Get {
        type Type = Task;

        fn method(&self) -> Method {
            Method::GET
        }

        fn execute(&self) -> Self::Type {
            todo!()
        }
    }
}

#[cfg(test)]
mod tests {}