Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: created_at & updated_at #5

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ serde_json = "1.0"
tracing-subscriber = "0.3.18"
dotenvy = "0.15.7"
listenfd = "1.0.1"
chrono = "0.4.31"
migration = { path = "./migration" }

[[bin]]
Expand Down
2 changes: 1 addition & 1 deletion src/api/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async fn create(model: web::Json<tag_info::Model>, data: web::Data<AppState>) ->
let model = Mutation::create_tag(&data.conn, model.into_inner()).await.unwrap();

let mut result = HashMap::new();
result.insert("tid", model.uid.unwrap());
result.insert("tid", model.tid.unwrap());

let json_response = JsonResponse {
code: 200,
Expand Down
2 changes: 2 additions & 0 deletions src/entity/dialog_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ pub struct Model {
pub dialog_name: String,
pub history: String,

#[serde(skip_deserializing)]
pub created_at: Date,
#[serde(skip_deserializing)]
pub updated_at: Date,
}

Expand Down
4 changes: 2 additions & 2 deletions src/entity/doc_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ pub struct Model {
pub r#type: String,
pub kb_progress: f64,

#[serde(skip_deserializing)]
pub created_at: Date,
#[serde(skip_deserializing)]
pub updated_at: Date,
#[sea_orm(soft_delete_column)]
pub is_deleted: bool,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down
2 changes: 2 additions & 0 deletions src/entity/kb_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ pub struct Model {
pub kn_name: String,
pub icon: i64,

#[serde(skip_deserializing)]
pub created_at: Date,
#[serde(skip_deserializing)]
pub updated_at: Date,
}

Expand Down
2 changes: 2 additions & 0 deletions src/entity/tag_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ pub struct Model {
pub icon: i64,
pub dir: String,

#[serde(skip_deserializing)]
pub created_at: Date,
#[serde(skip_deserializing)]
pub updated_at: Date,
}

Expand Down
6 changes: 4 additions & 2 deletions src/entity/user_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ pub struct Model {
pub list_style: String,
pub language: String,

pub created_at: DateTimeWithTimeZone,
pub updated_at: DateTimeWithTimeZone,
#[serde(skip_deserializing)]
pub created_at: Date,
#[serde(skip_deserializing)]
pub updated_at: Date,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down
11 changes: 6 additions & 5 deletions src/service/tag_info.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use chrono::{Local, NaiveDate};
use sea_orm::{ActiveModelTrait, DbConn, DbErr, DeleteResult, EntityTrait, PaginatorTrait, QueryOrder};
use sea_orm::ActiveValue::Set;
use crate::entity::tag_info;
Expand Down Expand Up @@ -38,15 +39,15 @@ impl Mutation {
form_data: tag_info::Model,
) -> Result<tag_info::ActiveModel, DbErr> {
tag_info::ActiveModel {
tid: Set(form_data.tid.to_owned()),
tid: Default::default(),
uid: Set(form_data.uid.to_owned()),
tag_name: Set(form_data.tag_name.to_owned()),
regx: Set(form_data.regx.to_owned()),
color: Set(form_data.color.to_owned()),
icon: Set(form_data.icon.to_owned()),
dir: Set(form_data.dir.to_owned()),
created_at: Default::default(),
updated_at: Default::default(),
created_at: Set(Local::now().date_naive()),
updated_at: Set(Local::now().date_naive()),
}
.save(db)
.await
Expand All @@ -60,7 +61,7 @@ impl Mutation {
let tag: tag_info::ActiveModel = Entity::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.ok_or(DbErr::Custom("Cannot find tag.".to_owned()))
.map(Into::into)?;

tag_info::ActiveModel {
Expand All @@ -72,7 +73,7 @@ impl Mutation {
icon: Set(form_data.icon.to_owned()),
dir: Set(form_data.dir.to_owned()),
created_at: Default::default(),
updated_at: Default::default(),
updated_at: Set(Local::now().date_naive()),
}
.update(db)
.await
Expand Down