Add search function to hydrus service

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/5/head
trivernis 3 years ago
parent 2a297c0636
commit 9d80486662
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -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<ServiceType, Vec<Service>>,

@ -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;

@ -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();
}
Loading…
Cancel
Save