feat(search): offset & limit options for search

This commit is contained in:
RafayAhmad7548 2026-09-01 19:58:14 +05:00
parent 10e3ca2efb
commit 4c6daf1fb7
Signed by: RafayAhmad
SSH key fingerprint: SHA256:WURX8viobA1uawb4dWM3LqYrY+XPcZcXhAXAlrYdhtE
3 changed files with 18 additions and 8 deletions

View file

@ -18,13 +18,19 @@ struct SearchQueryParams {
pub struct Search {
query: String,
offset: Option<u32>,
limit: Option<u32>,
}
impl Search {
const BASE_URL: &str = "https://api.modrinth.com/v2";
pub fn new(query: String) -> Self {
Search { query }
pub fn new(
query: String,
offset: Option<u32>,
limit: Option<u32>,
) -> Self {
Search { query, offset, limit }
}
pub async fn run(&self) -> Result<(), Box<dyn Error>> {
@ -49,8 +55,8 @@ impl Search {
let params = SearchQueryParams {
query: self.query.clone(),
facets: facets.into(),
offset: None,
limit: None,
offset: self.offset,
limit: self.limit,
};
let res: SearchResult = client

View file

@ -56,6 +56,12 @@ enum Commands {
Search {
query: String,
#[arg(long)]
offset: Option<u32>,
#[arg(long, value_parser = clap::value_parser!(u32).range(1..=100))]
limit: Option<u32>,
},
}
@ -90,8 +96,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
let config = create.download_server().await?;
create.save_config(config).await?;
}
Commands::Search { query } => {
let search = Search::new(query);
Commands::Search { query, offset, limit } => {
let search = Search::new(query, offset, limit);
search.run().await?;
}
}

View file

@ -3,8 +3,6 @@ use serde::Deserialize;
#[derive(Deserialize)]
pub struct SearchResult {
pub hits: Vec<SearchHit>,
pub offset: u32,
pub limit: u32,
pub total_hits: u32,
}