@@ -4,9 +4,9 @@ use crate::infra::http::{body_or_err, RequestBuilderExt, VecExt};
4
4
use crate :: infra:: json;
5
5
use crate :: infra:: result:: IntoResult ;
6
6
use anyhow:: Result ;
7
- use serde:: { Deserialize , Serialize } ;
8
7
use serde_json:: Value ;
9
8
use std:: collections:: HashSet ;
9
+ use std:: iter;
10
10
11
11
impl Post {
12
12
pub async fn search (
@@ -35,14 +35,9 @@ impl Post {
35
35
36
36
// total_count
37
37
{
38
- #[ derive( Serialize , Deserialize , Debug ) ]
39
- struct Body {
40
- #[ serde( rename = "postsCount" ) ]
41
- pub total_count : usize ,
42
- }
43
38
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
46
41
}
47
42
} ;
48
43
@@ -64,18 +59,19 @@ impl Post {
64
59
let id_list = {
65
60
let body = body_or_err ( resp) . await ?;
66
61
let mut json = json:: deserialize :: < Value > ( & body) ?;
67
- let post_id_list = {
62
+ let post_id = {
68
63
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
+ } ;
71
67
let zzk_post_id_list = {
72
68
let json = json[ "zzkSearchResult" ] [ "postIds" ] . take ( ) ;
73
69
serde_json:: from_value :: < Vec < usize > > ( json)
74
70
} ?;
75
71
76
- post_id_list
72
+ zzk_post_id_list
77
73
. into_iter ( )
78
- . chain ( zzk_post_id_list . into_iter ( ) )
74
+ . chain ( iter :: once ( post_id ) )
79
75
. collect :: < Vec < usize > > ( )
80
76
} ;
81
77
0 commit comments