Skip to main content

conduit_cli/modrinth/
search.rs

1use super::client::ModrinthAPI;
2use super::models::SearchResult;
3use reqwest::Url;
4
5impl ModrinthAPI {
6    pub async fn search(
7        &self,
8        query: &str,
9        limit: i32,
10        offset: i32,
11        index: &str,
12        facets: Option<String>,
13    ) -> Result<SearchResult, reqwest::Error> {
14        let mut params = vec![
15            ("query", query.to_string()),
16            ("limit", limit.to_string()),
17            ("offset", offset.to_string()),
18            ("index", index.to_string()),
19        ];
20        if let Some(f) = facets {
21            params.push(("facets", f));
22        }
23        let url = Url::parse_with_params(&format!("{}/search", self.base_url), &params)
24            .expect("Critical: Failed to build Modrinth search URL");
25
26        self.client
27            .get(url)
28            .send()
29            .await?
30            .error_for_status()?
31            .json::<SearchResult>()
32            .await
33    }
34}