Only add params if user adds params
This commit is contained in:
parent
6ea49fc36a
commit
46911f17ad
1 changed files with 7 additions and 7 deletions
|
@ -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>> {
|
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 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();
|
let mut query_params = Vec::new();
|
||||||
query_params.push_str("limit=");
|
if let Some(limit) = limit {
|
||||||
query_params.push_str(limit.to_string().as_str());
|
query_params.push(format!("limit={limit}"));
|
||||||
|
}
|
||||||
|
|
||||||
query_params.push_str("page=");
|
if let Some(page) = page {
|
||||||
query_params.push_str(page.to_string().as_str());
|
query_params.push(format!("page={page}"));
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(tags) = tags {
|
if let Some(tags) = tags {
|
||||||
if tags.len() > 0 {
|
if tags.len() > 0 {
|
||||||
|
|
Loading…
Reference in a new issue