dynasty_api/search/
suggestion.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{directory::DirectoryKind, DynastyReaderRoute, DYNASTY_READER_BASE};
4
5/// A configuration to get a [SearchSuggestion]
6#[allow(missing_docs)]
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub struct SearchSuggestionConfig {
9    pub query: String,
10}
11
12impl From<String> for SearchSuggestionConfig {
13    fn from(s: String) -> Self {
14        SearchSuggestionConfig { query: s }
15    }
16}
17
18impl DynastyReaderRoute for SearchSuggestionConfig {
19    fn request_builder(
20        &self,
21        client: &reqwest::Client,
22        url: reqwest::Url,
23    ) -> reqwest::RequestBuilder {
24        client.post(url).form(&[("query", &self.query)])
25    }
26
27    fn request_url(&self) -> reqwest::Url {
28        DYNASTY_READER_BASE.join("tags/suggest").unwrap()
29    }
30}
31
32/// A Dynasty Reader's search suggestion
33///
34/// You can convert this into a [super::SearchTag]
35#[allow(missing_docs)]
36#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
37pub struct SearchSuggestion {
38    pub id: u64,
39    pub name: String,
40    #[serde(alias = "type")]
41    pub kind: DirectoryKind,
42}
43
44#[cfg(test)]
45mod tests {
46    use anyhow::Result;
47
48    use crate::test_utils::tryhard_configs;
49
50    #[tokio::test]
51    #[ignore = "requires internet"]
52    async fn response_structure() -> Result<()> {
53        let configs = ["hin", "nio", "yagat", "ayano", "scum"].map(|s| s.to_string().into());
54
55        tryhard_configs(configs, |client, config| client.search_suggestions(config)).await?;
56
57        Ok(())
58    }
59}