hydrus_api/api_core/endpoints/
adding_notes.rs1use crate::api_core::common::FileIdentifier;
2use crate::api_core::endpoints::Endpoint;
3use std::collections::HashMap;
4
5pub struct SetNotes;
6
7impl Endpoint for SetNotes {
8 type Request = SetNotesRequest;
9 type Response = ();
10
11 fn path() -> String {
12 String::from("add_notes/set_notes")
13 }
14}
15
16#[derive(Serialize, Clone, Debug, Default)]
17pub struct SetNotesRequest {
18 notes: HashMap<String, String>,
19 #[serde(skip_serializing_if = "Option::is_none")]
20 hash: Option<String>,
21 #[serde(skip_serializing_if = "Option::is_none")]
22 file_id: Option<u64>,
23}
24
25impl SetNotesRequest {
26 pub fn new(id: FileIdentifier, notes: HashMap<String, String>) -> Self {
27 let mut request = Self {
28 notes,
29 ..Default::default()
30 };
31 match id {
32 FileIdentifier::ID(id) => request.file_id = Some(id),
33 FileIdentifier::Hash(hash) => request.hash = Some(hash),
34 }
35
36 request
37 }
38}
39
40pub struct DeleteNotes;
41
42impl Endpoint for DeleteNotes {
43 type Request = DeleteNotesRequest;
44 type Response = ();
45
46 fn path() -> String {
47 String::from("add_notes/delete_notes")
48 }
49}
50
51#[derive(Serialize, Clone, Debug, Default)]
52pub struct DeleteNotesRequest {
53 note_names: Vec<String>,
54 #[serde(skip_serializing_if = "Option::is_none")]
55 hash: Option<String>,
56 #[serde(skip_serializing_if = "Option::is_none")]
57 file_id: Option<u64>,
58}
59
60impl DeleteNotesRequest {
61 pub fn new(id: FileIdentifier, note_names: Vec<String>) -> Self {
62 let mut request = Self {
63 note_names,
64 ..Default::default()
65 };
66 match id {
67 FileIdentifier::ID(id) => request.file_id = Some(id),
68 FileIdentifier::Hash(hash) => request.hash = Some(hash),
69 }
70
71 request
72 }
73}