Kould
kould
commited on
Commit
·
95c6cbb
1
Parent(s):
57a709c
fix: created_at & updated_at (#5)
Browse filesCo-authored-by: kould <[email protected]>
- Cargo.toml +1 -0
- src/api/tag.rs +1 -1
- src/entity/dialog_info.rs +2 -0
- src/entity/doc_info.rs +2 -2
- src/entity/kb_info.rs +2 -0
- src/entity/tag_info.rs +2 -0
- src/entity/user_info.rs +4 -2
- src/service/tag_info.rs +6 -5
Cargo.toml
CHANGED
@@ -16,6 +16,7 @@ serde_json = "1.0"
|
|
16 |
tracing-subscriber = "0.3.18"
|
17 |
dotenvy = "0.15.7"
|
18 |
listenfd = "1.0.1"
|
|
|
19 |
migration = { path = "./migration" }
|
20 |
|
21 |
[[bin]]
|
|
|
16 |
tracing-subscriber = "0.3.18"
|
17 |
dotenvy = "0.15.7"
|
18 |
listenfd = "1.0.1"
|
19 |
+
chrono = "0.4.31"
|
20 |
migration = { path = "./migration" }
|
21 |
|
22 |
[[bin]]
|
src/api/tag.rs
CHANGED
@@ -11,7 +11,7 @@ async fn create(model: web::Json<tag_info::Model>, data: web::Data<AppState>) ->
|
|
11 |
let model = Mutation::create_tag(&data.conn, model.into_inner()).await.unwrap();
|
12 |
|
13 |
let mut result = HashMap::new();
|
14 |
-
result.insert("tid", model.
|
15 |
|
16 |
let json_response = JsonResponse {
|
17 |
code: 200,
|
|
|
11 |
let model = Mutation::create_tag(&data.conn, model.into_inner()).await.unwrap();
|
12 |
|
13 |
let mut result = HashMap::new();
|
14 |
+
result.insert("tid", model.tid.unwrap());
|
15 |
|
16 |
let json_response = JsonResponse {
|
17 |
code: 200,
|
src/entity/dialog_info.rs
CHANGED
@@ -11,7 +11,9 @@ pub struct Model {
|
|
11 |
pub dialog_name: String,
|
12 |
pub history: String,
|
13 |
|
|
|
14 |
pub created_at: Date,
|
|
|
15 |
pub updated_at: Date,
|
16 |
}
|
17 |
|
|
|
11 |
pub dialog_name: String,
|
12 |
pub history: String,
|
13 |
|
14 |
+
#[serde(skip_deserializing)]
|
15 |
pub created_at: Date,
|
16 |
+
#[serde(skip_deserializing)]
|
17 |
pub updated_at: Date,
|
18 |
}
|
19 |
|
src/entity/doc_info.rs
CHANGED
@@ -14,10 +14,10 @@ pub struct Model {
|
|
14 |
pub r#type: String,
|
15 |
pub kb_progress: f64,
|
16 |
|
|
|
17 |
pub created_at: Date,
|
|
|
18 |
pub updated_at: Date,
|
19 |
-
#[sea_orm(soft_delete_column)]
|
20 |
-
pub is_deleted: bool,
|
21 |
}
|
22 |
|
23 |
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
|
|
14 |
pub r#type: String,
|
15 |
pub kb_progress: f64,
|
16 |
|
17 |
+
#[serde(skip_deserializing)]
|
18 |
pub created_at: Date,
|
19 |
+
#[serde(skip_deserializing)]
|
20 |
pub updated_at: Date,
|
|
|
|
|
21 |
}
|
22 |
|
23 |
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
src/entity/kb_info.rs
CHANGED
@@ -11,7 +11,9 @@ pub struct Model {
|
|
11 |
pub kn_name: String,
|
12 |
pub icon: i64,
|
13 |
|
|
|
14 |
pub created_at: Date,
|
|
|
15 |
pub updated_at: Date,
|
16 |
}
|
17 |
|
|
|
11 |
pub kn_name: String,
|
12 |
pub icon: i64,
|
13 |
|
14 |
+
#[serde(skip_deserializing)]
|
15 |
pub created_at: Date,
|
16 |
+
#[serde(skip_deserializing)]
|
17 |
pub updated_at: Date,
|
18 |
}
|
19 |
|
src/entity/tag_info.rs
CHANGED
@@ -14,7 +14,9 @@ pub struct Model {
|
|
14 |
pub icon: i64,
|
15 |
pub dir: String,
|
16 |
|
|
|
17 |
pub created_at: Date,
|
|
|
18 |
pub updated_at: Date,
|
19 |
}
|
20 |
|
|
|
14 |
pub icon: i64,
|
15 |
pub dir: String,
|
16 |
|
17 |
+
#[serde(skip_deserializing)]
|
18 |
pub created_at: Date,
|
19 |
+
#[serde(skip_deserializing)]
|
20 |
pub updated_at: Date,
|
21 |
}
|
22 |
|
src/entity/user_info.rs
CHANGED
@@ -14,8 +14,10 @@ pub struct Model {
|
|
14 |
pub list_style: String,
|
15 |
pub language: String,
|
16 |
|
17 |
-
|
18 |
-
pub
|
|
|
|
|
19 |
}
|
20 |
|
21 |
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
|
|
14 |
pub list_style: String,
|
15 |
pub language: String,
|
16 |
|
17 |
+
#[serde(skip_deserializing)]
|
18 |
+
pub created_at: Date,
|
19 |
+
#[serde(skip_deserializing)]
|
20 |
+
pub updated_at: Date,
|
21 |
}
|
22 |
|
23 |
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
src/service/tag_info.rs
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
use sea_orm::{ActiveModelTrait, DbConn, DbErr, DeleteResult, EntityTrait, PaginatorTrait, QueryOrder};
|
2 |
use sea_orm::ActiveValue::Set;
|
3 |
use crate::entity::tag_info;
|
@@ -38,15 +39,15 @@ impl Mutation {
|
|
38 |
form_data: tag_info::Model,
|
39 |
) -> Result<tag_info::ActiveModel, DbErr> {
|
40 |
tag_info::ActiveModel {
|
41 |
-
tid:
|
42 |
uid: Set(form_data.uid.to_owned()),
|
43 |
tag_name: Set(form_data.tag_name.to_owned()),
|
44 |
regx: Set(form_data.regx.to_owned()),
|
45 |
color: Set(form_data.color.to_owned()),
|
46 |
icon: Set(form_data.icon.to_owned()),
|
47 |
dir: Set(form_data.dir.to_owned()),
|
48 |
-
created_at:
|
49 |
-
updated_at:
|
50 |
}
|
51 |
.save(db)
|
52 |
.await
|
@@ -60,7 +61,7 @@ impl Mutation {
|
|
60 |
let tag: tag_info::ActiveModel = Entity::find_by_id(id)
|
61 |
.one(db)
|
62 |
.await?
|
63 |
-
.ok_or(DbErr::Custom("Cannot find
|
64 |
.map(Into::into)?;
|
65 |
|
66 |
tag_info::ActiveModel {
|
@@ -72,7 +73,7 @@ impl Mutation {
|
|
72 |
icon: Set(form_data.icon.to_owned()),
|
73 |
dir: Set(form_data.dir.to_owned()),
|
74 |
created_at: Default::default(),
|
75 |
-
updated_at:
|
76 |
}
|
77 |
.update(db)
|
78 |
.await
|
|
|
1 |
+
use chrono::{Local, NaiveDate};
|
2 |
use sea_orm::{ActiveModelTrait, DbConn, DbErr, DeleteResult, EntityTrait, PaginatorTrait, QueryOrder};
|
3 |
use sea_orm::ActiveValue::Set;
|
4 |
use crate::entity::tag_info;
|
|
|
39 |
form_data: tag_info::Model,
|
40 |
) -> Result<tag_info::ActiveModel, DbErr> {
|
41 |
tag_info::ActiveModel {
|
42 |
+
tid: Default::default(),
|
43 |
uid: Set(form_data.uid.to_owned()),
|
44 |
tag_name: Set(form_data.tag_name.to_owned()),
|
45 |
regx: Set(form_data.regx.to_owned()),
|
46 |
color: Set(form_data.color.to_owned()),
|
47 |
icon: Set(form_data.icon.to_owned()),
|
48 |
dir: Set(form_data.dir.to_owned()),
|
49 |
+
created_at: Set(Local::now().date_naive()),
|
50 |
+
updated_at: Set(Local::now().date_naive()),
|
51 |
}
|
52 |
.save(db)
|
53 |
.await
|
|
|
61 |
let tag: tag_info::ActiveModel = Entity::find_by_id(id)
|
62 |
.one(db)
|
63 |
.await?
|
64 |
+
.ok_or(DbErr::Custom("Cannot find tag.".to_owned()))
|
65 |
.map(Into::into)?;
|
66 |
|
67 |
tag_info::ActiveModel {
|
|
|
73 |
icon: Set(form_data.icon.to_owned()),
|
74 |
dir: Set(form_data.dir.to_owned()),
|
75 |
created_at: Default::default(),
|
76 |
+
updated_at: Set(Local::now().date_naive()),
|
77 |
}
|
78 |
.update(db)
|
79 |
.await
|