feat(search): offset & limit options for search
This commit is contained in:
parent
10e3ca2efb
commit
4c6daf1fb7
3 changed files with 18 additions and 8 deletions
|
|
@ -18,13 +18,19 @@ struct SearchQueryParams {
|
||||||
|
|
||||||
pub struct Search {
|
pub struct Search {
|
||||||
query: String,
|
query: String,
|
||||||
|
offset: Option<u32>,
|
||||||
|
limit: Option<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Search {
|
impl Search {
|
||||||
const BASE_URL: &str = "https://api.modrinth.com/v2";
|
const BASE_URL: &str = "https://api.modrinth.com/v2";
|
||||||
|
|
||||||
pub fn new(query: String) -> Self {
|
pub fn new(
|
||||||
Search { query }
|
query: String,
|
||||||
|
offset: Option<u32>,
|
||||||
|
limit: Option<u32>,
|
||||||
|
) -> Self {
|
||||||
|
Search { query, offset, limit }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn run(&self) -> Result<(), Box<dyn Error>> {
|
pub async fn run(&self) -> Result<(), Box<dyn Error>> {
|
||||||
|
|
@ -49,8 +55,8 @@ impl Search {
|
||||||
let params = SearchQueryParams {
|
let params = SearchQueryParams {
|
||||||
query: self.query.clone(),
|
query: self.query.clone(),
|
||||||
facets: facets.into(),
|
facets: facets.into(),
|
||||||
offset: None,
|
offset: self.offset,
|
||||||
limit: None,
|
limit: self.limit,
|
||||||
};
|
};
|
||||||
|
|
||||||
let res: SearchResult = client
|
let res: SearchResult = client
|
||||||
|
|
|
||||||
10
src/main.rs
10
src/main.rs
|
|
@ -56,6 +56,12 @@ enum Commands {
|
||||||
|
|
||||||
Search {
|
Search {
|
||||||
query: String,
|
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?;
|
let config = create.download_server().await?;
|
||||||
create.save_config(config).await?;
|
create.save_config(config).await?;
|
||||||
}
|
}
|
||||||
Commands::Search { query } => {
|
Commands::Search { query, offset, limit } => {
|
||||||
let search = Search::new(query);
|
let search = Search::new(query, offset, limit);
|
||||||
search.run().await?;
|
search.run().await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@ use serde::Deserialize;
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct SearchResult {
|
pub struct SearchResult {
|
||||||
pub hits: Vec<SearchHit>,
|
pub hits: Vec<SearchHit>,
|
||||||
pub offset: u32,
|
|
||||||
pub limit: u32,
|
|
||||||
pub total_hits: u32,
|
pub total_hits: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue