Skip to content

Commit 4aa42f3

Browse files
committed
fix: clippy warnings
1 parent 285fcc7 commit 4aa42f3

File tree

7 files changed

+40
-73
lines changed

7 files changed

+40
-73
lines changed

src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub struct Config {
1010
}
1111

1212
impl Config {
13-
pub fn from_file(path: &str) -> Self {
13+
pub fn from_file(_path: &str) -> Self {
1414
let f = File::open("config.toml").unwrap();
1515
let contents = read_to_string(f).unwrap();
1616
toml::from_str(contents.as_str()).unwrap()

src/db_ops.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub trait ModelUtils: Serialize + std::marker::Sized {
2828
.unwrap();
2929
}
3030

31-
async fn post_multi_insert(db: &DatabaseConnection, objects: Vec<Self>) {}
31+
async fn post_multi_insert(_db: &DatabaseConnection, _objects: Vec<Self>) {}
3232

3333
async fn multi_insert(db: &DatabaseConnection, objects: Vec<Self>) {
3434
let mut v = vec![];

src/db_ops/question.rs

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ impl ModelUtils for Question {
7878
}
7979
}
8080

81+
#[cfg(test)]
8182
mod tests {
8283

8384
use super::*;

src/deserializers/question.rs

-67
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::entities::{question::Model as QuestionModel, topic_tag::Model as TopicTagModel};
21
use serde::Deserialize;
32
use serde::{self, Serialize};
43

@@ -26,34 +25,6 @@ pub struct Question {
2625
pub has_video_solution: Option<bool>,
2726
pub topic_tags: Option<Vec<TopicTag>>,
2827
}
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-
// }
5728

5829
#[derive(Debug, Deserialize)]
5930
#[serde(rename_all = "camelCase")]
@@ -92,43 +63,6 @@ mod tests {
9263

9364
#[test]
9465
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-
13266
let json = r#"{
13367
"data": {
13468
"problemsetQuestionList": {
@@ -160,7 +94,6 @@ mod tests {
16094
}"#;
16195

16296
let root: ProblemSetQuestionListQuery = serde_json::from_str(json).unwrap();
163-
let root2: ProblemSetQuestionListQuery = serde_json::from_str(json2).unwrap();
16497

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

src/deserializers/topic_tag.rs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ pub struct Question {
1010
#[derive(Debug, Deserialize)]
1111
#[serde(rename_all = "camelCase")]
1212
struct ProblemSetQuestionList {
13-
total: i32,
1413
questions: Vec<Question>,
1514
}
1615

src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@ async fn main() -> AppResult<()> {
4545
.with_test_writer()
4646
.init();
4747

48-
let DATABASE_CLIENT = Database::connect(CONFIG.db.url.as_str()).await.unwrap();
48+
let database_client = Database::connect(CONFIG.db.url.as_str()).await.unwrap();
4949

5050
let query = Query::default();
5151
let query_response: ProblemSetQuestionListQuery = query.post(&CLIENT).await;
52-
Question::multi_insert(&DATABASE_CLIENT, query_response.get_questions()).await;
52+
Question::multi_insert(&database_client, query_response.get_questions()).await;
5353

5454
// Create an application.
5555
let (send, recv) = tokio::sync::mpsc::channel(300);
5656

5757
let mut q =
58-
leetcode_tui_rs::db_ops::topic_tag::query::get_questions_by_topic(&DATABASE_CLIENT, "")
58+
leetcode_tui_rs::db_ops::topic_tag::query::get_questions_by_topic(&database_client, "")
5959
.await;
6060

6161
while !q.is_empty() {

temp.json

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"data": {
3+
"problemsetQuestionList": {
4+
"total": 2781,
5+
"questions": [
6+
{
7+
"acRate": 50.21369744908346,
8+
"difficulty": "Easy",
9+
"freqBar": null,
10+
"frontendQuestionId": "1",
11+
"isFavor": false,
12+
"paidOnly": false,
13+
"status": "ac",
14+
"title": "Two Sum",
15+
"titleSlug": "two-sum",
16+
"topicTags": [
17+
{
18+
"name": "Array",
19+
"id": "VG9waWNUYWdOb2RlOjU=",
20+
"slug": "array"
21+
},
22+
{
23+
"name": "Hash Table",
24+
"id": "VG9waWNUYWdOb2RlOjY=",
25+
"slug": "hash-table"
26+
}
27+
],
28+
"hasSolution": true,
29+
"hasVideoSolution": true
30+
}
31+
]
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)