Skip to content

Commit

Permalink
refactor: use reqwest query fn
Browse files Browse the repository at this point in the history
  • Loading branch information
Thaumy committed Sep 27, 2023
1 parent 6b34b02 commit 8df09d1
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 38 deletions.
8 changes: 4 additions & 4 deletions src/api/fav/get_list.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::api::fav::Fav;
use crate::infra::http::{body_or_err, RequestBuilderExt, VecExt as HttpVecExt};
use crate::infra::http::{body_or_err, RequestBuilderExt};
use crate::infra::iter::IntoIteratorExt;
use crate::infra::json;
use crate::infra::result::IntoResult;
Expand Down Expand Up @@ -31,9 +31,9 @@ impl Fav {
let cf = range
.map(|i| async move {
let req = {
let query = vec![("pageIndex", i), ("pageSize", 1)].into_query_string();
let url = openapi!("/Bookmarks?{}", query);
client.get(url).pat_auth(&self.pat)
let url = openapi!("/bookmarks");
let query = [("pageIndex", i), ("pageSize", 1)];
client.get(url).query(&query).pat_auth(&self.pat)
};

let resp = req.send().await?;
Expand Down
2 changes: 1 addition & 1 deletion src/api/ing/get_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Ing {
.map(|i| async move {
let req = {
let url = openapi!("/statuses/@{}", ing_type.clone() as usize);
let query = vec![("pageIndex", i), ("pageSize", 1)];
let query = [("pageIndex", i), ("pageSize", 1)];
client.get(url).query(&query).pat_auth(&self.pat)
};

Expand Down
10 changes: 4 additions & 6 deletions src/api/news/get_list.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::api::news::News;
use crate::infra::http::{body_or_err, RequestBuilderExt, VecExt};
use crate::infra::http::{body_or_err, RequestBuilderExt};
use crate::infra::iter::IntoIteratorExt;
use crate::infra::json;
use crate::infra::result::IntoResult;
Expand Down Expand Up @@ -37,11 +37,9 @@ impl News {
range
.map(|i| async move {
let req = {
let url = {
let query = vec![("pageIndex", i), ("pageSize", 1)].into_query_string();
openapi!("/newsitems/?{}", query)
};
client.get(url).pat_auth(&self.pat)
let url = openapi!("/newsitems");
let query = [("pageIndex", i), ("pageSize", 1)];
client.get(url).query(&query).pat_auth(&self.pat)
};

let resp = req.send().await?;
Expand Down
11 changes: 4 additions & 7 deletions src/api/post/get_count.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::api::post::Post;
use crate::blog_backend;
use crate::infra::http::{body_or_err, RequestBuilderExt, VecExt};
use crate::infra::http::{body_or_err, RequestBuilderExt};
use crate::infra::json;
use crate::infra::result::IntoResult;
use anyhow::Result;
Expand All @@ -11,12 +11,9 @@ impl Post {
let client = reqwest::Client::new();

let req = {
let url = {
let query = vec![('t', 1), ('p', 1), ('s', 1)].into_query_string();
blog_backend!("/posts/list?{}", query)
};

client.get(url).pat_auth(&self.pat)
let url = blog_backend!("/posts/list");
let query = [('t', 1), ('p', 1), ('s', 1)];
client.get(url).query(&query).pat_auth(&self.pat)
};

let resp = req.send().await?;
Expand Down
11 changes: 4 additions & 7 deletions src/api/post/get_meta_list.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::api::post::get_one::PostEntry;
use crate::api::post::Post;
use crate::blog_backend;
use crate::infra::http::{body_or_err, RequestBuilderExt, VecExt};
use crate::infra::http::{body_or_err, RequestBuilderExt};
use crate::infra::iter::IntoIteratorExt;
use crate::infra::json;
use crate::infra::result::IntoResult;
Expand Down Expand Up @@ -35,12 +35,9 @@ impl Post {
let vec = range
.map(|i| async move {
let req = {
let url = {
let query = vec![('t', 1), ('p', i), ('s', 1)].into_query_string();
blog_backend!("/posts/list?{}", query)
};

client.get(url).pat_auth(&self.pat)
let url = blog_backend!("/posts/list");
let query = [('t', 1), ('p', i), ('s', 1)];
client.get(url).query(&query).pat_auth(&self.pat)
};

let resp = req.send().await?;
Expand Down
24 changes: 11 additions & 13 deletions src/api/post/search.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::api::post::Post;
use crate::blog_backend;
use crate::infra::http::{body_or_err, RequestBuilderExt, VecExt};
use crate::infra::http::{body_or_err, RequestBuilderExt};
use crate::infra::iter::IntoIteratorExt;
use crate::infra::json;
use crate::infra::result::IntoResult;
Expand All @@ -22,15 +22,14 @@ impl Post {
// If index is greater than the max page index, API will still return the last page
let total_count = {
let req = {
let query = vec![
("t", "1".to_string()),
let url = blog_backend!("/posts/list");
let query = [
("t", 1.to_string()),
("p", 1.to_string()),
("s", 1.to_string()),
("search", keyword.to_string()),
]
.into_query_string();
let url = blog_backend!("/posts/list?{}", query);
client.get(url).pat_auth(&self.pat)
];
client.get(url).query(&query).pat_auth(&self.pat)
};
let resp = req.send().await?;

Expand All @@ -48,15 +47,14 @@ impl Post {
let id_list = range
.map(|i| async move {
let req = {
let query = vec![
("t", "1".to_string()),
let url = blog_backend!("/posts/list");
let query = [
("t", 1.to_string()),
("p", i.to_string()),
("s", 1.to_string()),
("search", keyword.to_string()),
]
.into_query_string();
let url = blog_backend!("/posts/list?{}", query);
client.get(url).pat_auth(&self.pat)
];
client.get(url).query(&query).pat_auth(&self.pat)
};
let resp = req.send().await?;

Expand Down

0 comments on commit 8df09d1

Please sign in to comment.