Skip to content

Commit

Permalink
fix: post search
Browse files Browse the repository at this point in the history
  • Loading branch information
Thaumy committed Sep 14, 2023
1 parent 35fd0d4 commit 19503f0
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/api/post/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use crate::infra::http::{body_or_err, RequestBuilderExt, VecExt};
use crate::infra::json;
use crate::infra::result::IntoResult;
use anyhow::Result;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashSet;
use std::iter;

impl Post {
pub async fn search(
Expand Down Expand Up @@ -35,14 +35,9 @@ impl Post {

// total_count
{
#[derive(Serialize, Deserialize, Debug)]
struct Body {
#[serde(rename = "postsCount")]
pub total_count: usize,
}
let body = body_or_err(resp).await?;
let body = json::deserialize::<Body>(&body)?;
body.total_count
let json = json::deserialize::<Value>(&body)?;
json["postsCount"].as_u64().unwrap() as usize
}
};

Expand All @@ -64,18 +59,19 @@ impl Post {
let id_list = {
let body = body_or_err(resp).await?;
let mut json = json::deserialize::<Value>(&body)?;
let post_id_list = {
let post_id = {
let json = json["postList"].take();
serde_json::from_value::<Vec<usize>>(json)
}?;
let [post, ..] = serde_json::from_value::<[Value; 1]>(json)?;
post["id"].as_u64().unwrap() as usize
};
let zzk_post_id_list = {
let json = json["zzkSearchResult"]["postIds"].take();
serde_json::from_value::<Vec<usize>>(json)
}?;

post_id_list
zzk_post_id_list
.into_iter()
.chain(zzk_post_id_list.into_iter())
.chain(iter::once(post_id))
.collect::<Vec<usize>>()
};

Expand Down

0 comments on commit 19503f0

Please sign in to comment.