From 9eb1b987b2b3f00d2ca2642fc4ce0ae990feeda7 Mon Sep 17 00:00:00 2001 From: Bat Date: Mon, 23 Apr 2018 15:39:06 +0100 Subject: [PATCH] Save post author --- src/routes/posts.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/routes/posts.rs b/src/routes/posts.rs index d61f5968..2451f38f 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -8,6 +8,7 @@ use utils; use db_conn::DbConn; use models::blogs::*; use models::post::*; +use models::post_authors::*; use models::user::User; #[get("/~//", rank = 3)] @@ -35,11 +36,11 @@ struct NewPostForm { } #[post("/~//new", data = "")] -fn create(blog_name: String, data: Form, _user: User, conn: DbConn) -> Redirect { +fn create(blog_name: String, data: Form, user: User, conn: DbConn) -> Redirect { let blog = Blog::find_by_actor_id(&*conn, blog_name.to_string()).unwrap(); let form = data.get(); let slug = form.title.to_string().to_kebab_case(); - Post::insert(&*conn, NewPost { + let post = Post::insert(&*conn, NewPost { blog_id: blog.id, slug: slug.to_string(), title: form.title.to_string(), @@ -47,5 +48,9 @@ fn create(blog_name: String, data: Form, _user: User, conn: DbConn) published: true, license: form.license.to_string() }); + PostAuthor::insert(&*conn, NewPostAuthor { + post_id: post.id, + author_id: user.id + }); Redirect::to(format!("/~/{}/{}", blog_name, slug).as_str()) }