Only add params if user adds params

This commit is contained in:
Leon Grünewald 2024-01-01 21:50:57 +01:00
parent 6ea49fc36a
commit 46911f17ad

View file

@ -41,15 +41,15 @@ impl<'a> Client<'a> {
pub async fn list_posts(&mut self, limit: Option<u16>, tags: Option<Vec<String>>, page: Option<u32>) -> Result<Vec<Post>> {
let mut url = url::Url::parse(format!("{}/posts.json", self.host).as_str())?;
let limit = limit.unwrap_or(320);
let page = page.unwrap_or(0);
let mut query_params = String::new();
query_params.push_str("limit=");
query_params.push_str(limit.to_string().as_str());
let mut query_params = Vec::new();
if let Some(limit) = limit {
query_params.push(format!("limit={limit}"));
}
query_params.push_str("page=");
query_params.push_str(page.to_string().as_str());
if let Some(page) = page {
query_params.push(format!("page={page}"));
}
if let Some(tags) = tags {
if tags.len() > 0 {