From aa53b573c1d3c060346fbae2e934f7da6894e80d Mon Sep 17 00:00:00 2001 From: Kilerd Chan Date: Tue, 1 Jan 2019 22:37:48 +0800 Subject: [PATCH] fix: cannot add new article --- src/models.rs | 3 ++- src/routers/admin.rs | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/models.rs b/src/models.rs index 7e387f5..dc902fe 100644 --- a/src/models.rs +++ b/src/models.rs @@ -92,10 +92,11 @@ impl Article { } pub fn form_article_edit_form(article: &ArticleEditForm, current_user_id: i32) -> NewArticle { + println!("{:?}", article); let timestamp = if article.publish_at.eq("") { Utc::now().timestamp() } else { - NaiveDateTime::parse_from_str(&article.publish_at, "%Y-%m-%dT%H:%M").unwrap().timestamp() + NaiveDateTime::parse_from_str(&article.publish_at, "%Y-%m-%dT%H:%M:%S").unwrap().timestamp() }; let article_id = match article.id { diff --git a/src/routers/admin.rs b/src/routers/admin.rs index f89ab1f..9feffff 100644 --- a/src/routers/admin.rs +++ b/src/routers/admin.rs @@ -101,11 +101,11 @@ pub fn article_edit(_admin: Admin, conn: DbConn, article_id: i32) -> Result) -> Result, Status> { use crate::schema::{articles}; - let article = Article::form_article_edit_form(&article, admin.id); - let _fetched_article: QueryResult
= match article.id { - Some(article_id) => diesel::update(articles::table.find(article_id)).set(&article).get_result(&*conn), + let new_article = Article::form_article_edit_form(&article, admin.id); + let _fetched_article: QueryResult
= match new_article.id { + Some(article_id) => diesel::update(articles::table.find(article_id)).set(&new_article).get_result(&*conn), - None => diesel::insert_into(articles::table).values(&article).get_result(&*conn), + None => diesel::insert_into(articles::table).values(&new_article).get_result(&*conn), }; Ok(Flash::new(Redirect::to("/admin"), "success", "created"))