Skip to content

Commit 19503f0

Browse files
committed
fix: post search
1 parent 35fd0d4 commit 19503f0

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/api/post/search.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use crate::infra::http::{body_or_err, RequestBuilderExt, VecExt};
44
use crate::infra::json;
55
use crate::infra::result::IntoResult;
66
use anyhow::Result;
7-
use serde::{Deserialize, Serialize};
87
use serde_json::Value;
98
use std::collections::HashSet;
9+
use std::iter;
1010

1111
impl Post {
1212
pub async fn search(
@@ -35,14 +35,9 @@ impl Post {
3535

3636
// total_count
3737
{
38-
#[derive(Serialize, Deserialize, Debug)]
39-
struct Body {
40-
#[serde(rename = "postsCount")]
41-
pub total_count: usize,
42-
}
4338
let body = body_or_err(resp).await?;
44-
let body = json::deserialize::<Body>(&body)?;
45-
body.total_count
39+
let json = json::deserialize::<Value>(&body)?;
40+
json["postsCount"].as_u64().unwrap() as usize
4641
}
4742
};
4843

@@ -64,18 +59,19 @@ impl Post {
6459
let id_list = {
6560
let body = body_or_err(resp).await?;
6661
let mut json = json::deserialize::<Value>(&body)?;
67-
let post_id_list = {
62+
let post_id = {
6863
let json = json["postList"].take();
69-
serde_json::from_value::<Vec<usize>>(json)
70-
}?;
64+
let [post, ..] = serde_json::from_value::<[Value; 1]>(json)?;
65+
post["id"].as_u64().unwrap() as usize
66+
};
7167
let zzk_post_id_list = {
7268
let json = json["zzkSearchResult"]["postIds"].take();
7369
serde_json::from_value::<Vec<usize>>(json)
7470
}?;
7571

76-
post_id_list
72+
zzk_post_id_list
7773
.into_iter()
78-
.chain(zzk_post_id_list.into_iter())
74+
.chain(iter::once(post_id))
7975
.collect::<Vec<usize>>()
8076
};
8177

0 commit comments

Comments
 (0)