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
use crate::api_core::common::FileIdentifier;
use crate::api_core::endpoints::Endpoint;
use std::collections::HashMap;

pub struct SetNotes;

impl Endpoint for SetNotes {
    type Request = SetNotesRequest;
    type Response = ();

    fn path() -> String {
        String::from("add_notes/set_notes")
    }
}

#[derive(Serialize, Clone, Debug, Default)]
pub struct SetNotesRequest {
    notes: HashMap<String, String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    hash: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    file_id: Option<u64>,
}

impl SetNotesRequest {
    pub fn new(id: FileIdentifier, notes: HashMap<String, String>) -> Self {
        let mut request = Self {
            notes,
            ..Default::default()
        };
        match id {
            FileIdentifier::ID(id) => request.file_id = Some(id),
            FileIdentifier::Hash(hash) => request.hash = Some(hash),
        }

        request
    }
}

pub struct DeleteNotes;

impl Endpoint for DeleteNotes {
    type Request = DeleteNotesRequest;
    type Response = ();

    fn path() -> String {
        String::from("add_notes/delete_notes")
    }
}

#[derive(Serialize, Clone, Debug, Default)]
pub struct DeleteNotesRequest {
    note_names: Vec<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    hash: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    file_id: Option<u64>,
}

impl DeleteNotesRequest {
    pub fn new(id: FileIdentifier, note_names: Vec<String>) -> Self {
        let mut request = Self {
            note_names,
            ..Default::default()
        };
        match id {
            FileIdentifier::ID(id) => request.file_id = Some(id),
            FileIdentifier::Hash(hash) => request.hash = Some(hash),
        }

        request
    }
}