Add low level notes api
Signed-off-by: trivernis <trivernis@protonmail.com>pull/13/head
parent
7ef1ec6c59
commit
a0eea94340
@ -0,0 +1,73 @@
|
|||||||
|
use crate::api_core::common::FileIdentifier;
|
||||||
|
use crate::api_core::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
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
use super::super::common;
|
||||||
|
use crate::common::test_data::TEST_HASH_1;
|
||||||
|
use hydrus_api::api_core::common::FileIdentifier;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn it_sets_notes() {
|
||||||
|
let client = common::get_client();
|
||||||
|
common::create_testdata(&client).await;
|
||||||
|
let mut test_notes = HashMap::new();
|
||||||
|
test_notes.insert("test".to_string(), "value".to_string());
|
||||||
|
test_notes.insert("test2".to_string(), "value".to_string());
|
||||||
|
|
||||||
|
client
|
||||||
|
.set_notes(FileIdentifier::hash(TEST_HASH_1), test_notes)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn it_deletes_notes() {
|
||||||
|
let client = common::get_client();
|
||||||
|
client
|
||||||
|
.delete_notes(FileIdentifier::hash(TEST_HASH_1), vec!["test".to_string()])
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
}
|
Loading…
Reference in New Issue