Skip to content

Commit 285fcc7

Browse files
committed
fix: response error
1 parent 6b6712f commit 285fcc7

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

src/deserializers/question.rs

+38
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,43 @@ mod tests {
9292

9393
#[test]
9494
fn test_json_deserialization() {
95+
let json2 = r#"
96+
{
97+
"data": {
98+
"problemsetQuestionList": {
99+
"total": 2781,
100+
"questions": [
101+
{
102+
"acRate": 50.21369744908346,
103+
"difficulty": "Easy",
104+
"freqBar": null,
105+
"frontendQuestionId": "1",
106+
"isFavor": false,
107+
"paidOnly": false,
108+
"status": "ac",
109+
"title": "Two Sum",
110+
"titleSlug": "two-sum",
111+
"topicTags": [
112+
{
113+
"name": "Array",
114+
"id": "VG9waWNUYWdOb2RlOjU=",
115+
"slug": "array"
116+
},
117+
{
118+
"name": "Hash Table",
119+
"id": "VG9waWNUYWdOb2RlOjY=",
120+
"slug": "hash-table"
121+
}
122+
],
123+
"hasSolution": true,
124+
"hasVideoSolution": true
125+
}
126+
]
127+
}
128+
}
129+
}
130+
"#;
131+
95132
let json = r#"{
96133
"data": {
97134
"problemsetQuestionList": {
@@ -123,6 +160,7 @@ mod tests {
123160
}"#;
124161

125162
let root: ProblemSetQuestionListQuery = serde_json::from_str(json).unwrap();
163+
let root2: ProblemSetQuestionListQuery = serde_json::from_str(json2).unwrap();
126164

127165
// Validate the deserialized struct fields
128166
assert_eq!(root.data.problemset_question_list.total, 2777);

src/graphql/problemset_question_list.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use serde::Serialize;
2+
use serde_json::{json, Value};
23

34
use super::GQLLeetcodeQuery;
45

@@ -34,7 +35,7 @@ query problemsetQuestionList($categorySlug: String, $limit: Int, $skip: Int, $fi
3435

3536
#[derive(Serialize)]
3637
#[serde(rename_all = "camelCase")]
37-
struct Filters;
38+
struct Filters(Value);
3839

3940
#[derive(Serialize)]
4041
#[serde(rename_all = "camelCase")]
@@ -58,9 +59,9 @@ impl Default for Query {
5859
query: QUERY,
5960
variables: Variables {
6061
category_slug: "".to_string(),
61-
limit: 50,
62+
limit: 1,
6263
skip: 0,
63-
filters: Filters,
64+
filters: Filters(json!({})),
6465
},
6566
}
6667
}

src/main.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
use deserializers::question::ProblemSetQuestionList;
21
use leetcode_tui_rs::app_ui::list::StatefulList;
32
use leetcode_tui_rs::config::{self, Config};
43
use leetcode_tui_rs::db_ops::ModelUtils;
5-
use leetcode_tui_rs::deserializers;
6-
use leetcode_tui_rs::deserializers::question::Question;
4+
use leetcode_tui_rs::deserializers::question::{ProblemSetQuestionListQuery, Question};
75
use leetcode_tui_rs::entities::QuestionModel;
86
use leetcode_tui_rs::graphql::problemset_question_list::Query;
97
use leetcode_tui_rs::graphql::GQLLeetcodeQuery;
@@ -50,8 +48,8 @@ async fn main() -> AppResult<()> {
5048
let DATABASE_CLIENT = Database::connect(CONFIG.db.url.as_str()).await.unwrap();
5149

5250
let query = Query::default();
53-
let questions: ProblemSetQuestionList = query.post(&CLIENT).await;
54-
Question::multi_insert(&DATABASE_CLIENT, questions.questions).await;
51+
let query_response: ProblemSetQuestionListQuery = query.post(&CLIENT).await;
52+
Question::multi_insert(&DATABASE_CLIENT, query_response.get_questions()).await;
5553

5654
// Create an application.
5755
let (send, recv) = tokio::sync::mpsc::channel(300);

0 commit comments

Comments
 (0)