diff --git a/src/wrapper/service.rs b/src/wrapper/service.rs index d2ed66e..f85998e 100644 --- a/src/wrapper/service.rs +++ b/src/wrapper/service.rs @@ -6,6 +6,7 @@ use crate::api_core::access_management::{ }; use crate::error::Error; +use crate::wrapper::builders::search_builder::SearchBuilder; use crate::Client; use std::collections::HashMap; use std::convert::TryFrom; @@ -103,6 +104,22 @@ pub struct Service { pub service_type: ServiceType, } +impl Service { + pub fn search(&self) -> SearchBuilder { + let builder = SearchBuilder::new(self.client.clone()); + match self.service_type { + ServiceType::LocalTags | ServiceType::TagRepositories | ServiceType::AllKnownTags => { + builder.tag_service_key(&self.key) + } + ServiceType::LocalFiles + | ServiceType::FileRepositories + | ServiceType::AllLocalFiles + | ServiceType::AllKnownFiles + | ServiceType::Trash => builder.file_service_key(&self.key), + } + } +} + #[derive(Clone)] pub struct Services { inner: HashMap>, diff --git a/tests/wrapper/mod.rs b/tests/wrapper/mod.rs index 9102ce3..dc843f3 100644 --- a/tests/wrapper/mod.rs +++ b/tests/wrapper/mod.rs @@ -1,7 +1,8 @@ +mod test_address; mod test_files; mod test_hydrus; mod test_import; -mod test_url; mod test_page; -mod test_address; +mod test_service; mod test_tags; +mod test_url; diff --git a/tests/wrapper/test_service.rs b/tests/wrapper/test_service.rs new file mode 100644 index 0000000..8949675 --- /dev/null +++ b/tests/wrapper/test_service.rs @@ -0,0 +1,27 @@ +use super::super::common; +use hydrus_api::wrapper::service::{Service, ServiceType, Services}; + +async fn get_services() -> Services { + let hydrus = common::get_hydrus(); + hydrus.services().await.unwrap() +} + +async fn get_file_service() -> Service { + let services = get_services().await; + services + .get_services(ServiceType::LocalFiles) + .pop() + .unwrap() + .clone() +} + +#[tokio::test] +async fn it_searches_for_files() { + let service = get_file_service().await; + service + .search() + .add_tag("character:rimuru tempest".into()) + .run() + .await + .unwrap(); +}