|
1 |
| -use crate::entities::{question::Model as QuestionModel, topic_tag::Model as TopicTagModel}; |
2 | 1 | use serde::Deserialize;
|
3 | 2 | use serde::{self, Serialize};
|
4 | 3 |
|
@@ -26,34 +25,6 @@ pub struct Question {
|
26 | 25 | pub has_video_solution: Option<bool>,
|
27 | 26 | pub topic_tags: Option<Vec<TopicTag>>,
|
28 | 27 | }
|
29 |
| -// impl Question { |
30 |
| -// pub fn get_question_active_model(&self) -> QuestionActiveModel { |
31 |
| -// let p = serde_json::to_string(self).unwrap(); |
32 |
| -// let j: QuestionModel = serde_json::from_str(p.as_str()).unwrap(); |
33 |
| -// j.into_active_model() |
34 |
| -// } |
35 |
| - |
36 |
| -// pub fn get_topic_tags_active_model(&self) -> Vec<TopicTagActiveModel> { |
37 |
| -// let p = serde_json::to_string(&self.topic_tags).unwrap(); |
38 |
| -// let j: Vec<TopicTagModel> = serde_json::from_str(p.as_str()).unwrap(); |
39 |
| -// j.into_iter() |
40 |
| -// .map(|v| v.into_active_model()) |
41 |
| -// .collect::<Vec<_>>() |
42 |
| -// } |
43 |
| - |
44 |
| -// pub fn get_question_topics_relation(&self) -> Vec<QuestionTopicActiveModel> { |
45 |
| -// let mut v = vec![]; |
46 |
| -// if let Some(tts) = &self.topic_tags { |
47 |
| -// for topic_tag in tts { |
48 |
| -// v.push(QuestionTopicActiveModel { |
49 |
| -// question_id: sea_orm::ActiveValue::Set(self.frontend_question_id.clone()), |
50 |
| -// tag_id: ActiveValue::Set(topic_tag.id.clone()), |
51 |
| -// }) |
52 |
| -// } |
53 |
| -// } |
54 |
| -// v |
55 |
| -// } |
56 |
| -// } |
57 | 28 |
|
58 | 29 | #[derive(Debug, Deserialize)]
|
59 | 30 | #[serde(rename_all = "camelCase")]
|
@@ -92,43 +63,6 @@ mod tests {
|
92 | 63 |
|
93 | 64 | #[test]
|
94 | 65 | 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 |
| - |
132 | 66 | let json = r#"{
|
133 | 67 | "data": {
|
134 | 68 | "problemsetQuestionList": {
|
@@ -160,7 +94,6 @@ mod tests {
|
160 | 94 | }"#;
|
161 | 95 |
|
162 | 96 | let root: ProblemSetQuestionListQuery = serde_json::from_str(json).unwrap();
|
163 |
| - let root2: ProblemSetQuestionListQuery = serde_json::from_str(json2).unwrap(); |
164 | 97 |
|
165 | 98 | // Validate the deserialized struct fields
|
166 | 99 | assert_eq!(root.data.problemset_question_list.total, 2777);
|
|
0 commit comments