fix: cannot add new article
This commit is contained in:
parent
b6bf29f6ee
commit
aa53b573c1
@ -92,10 +92,11 @@ impl Article {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn form_article_edit_form(article: &ArticleEditForm, current_user_id: i32) -> NewArticle {
|
pub fn form_article_edit_form(article: &ArticleEditForm, current_user_id: i32) -> NewArticle {
|
||||||
|
println!("{:?}", article);
|
||||||
let timestamp = if article.publish_at.eq("") {
|
let timestamp = if article.publish_at.eq("") {
|
||||||
Utc::now().timestamp()
|
Utc::now().timestamp()
|
||||||
} else {
|
} 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 {
|
let article_id = match article.id {
|
||||||
|
@ -101,11 +101,11 @@ pub fn article_edit(_admin: Admin, conn: DbConn, article_id: i32) -> Result<Temp
|
|||||||
pub fn save_article(admin: Admin, conn: DbConn, article: Form<ArticleEditForm>) -> Result<Flash<Redirect>, Status> {
|
pub fn save_article(admin: Admin, conn: DbConn, article: Form<ArticleEditForm>) -> Result<Flash<Redirect>, Status> {
|
||||||
use crate::schema::{articles};
|
use crate::schema::{articles};
|
||||||
|
|
||||||
let article = Article::form_article_edit_form(&article, admin.id);
|
let new_article = Article::form_article_edit_form(&article, admin.id);
|
||||||
let _fetched_article: QueryResult<Article> = match article.id {
|
let _fetched_article: QueryResult<Article> = match new_article.id {
|
||||||
Some(article_id) => diesel::update(articles::table.find(article_id)).set(&article).get_result(&*conn),
|
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"))
|
Ok(Flash::new(Redirect::to("/admin"), "success", "created"))
|
||||||
|
Loading…
Reference in New Issue
Block a user