From 7b2bab0f9dae039f9a5db7d51bc5b6c533715722 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Fri, 9 Apr 2021 10:55:09 +0900 Subject: [PATCH] Extract Post::ap_url() --- plume-models/src/posts.rs | 11 +++++------ src/routes/posts.rs | 8 +------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index 21470cb2..1048fb12 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -73,12 +73,7 @@ impl Post { .execute(conn)?; let mut post = Self::last(conn)?; if post.ap_url.is_empty() { - post.ap_url = ap_url(&format!( - "{}/~/{}/{}/", - CONFIG.base_url, - post.get_blog(conn)?.fqn, - post.slug - )); + post.ap_url = Self::ap_url(post.get_blog(conn)?, &post.slug); let _: Post = post.save_changes(conn)?; } @@ -254,6 +249,10 @@ impl Post { .map_err(Error::from) } + pub fn ap_url(blog: Blog, slug: &str) -> String { + ap_url(&format!("{}/~/{}/{}/", CONFIG.base_url, blog.fqn, slug)) + } + pub fn get_authors(&self, conn: &Connection) -> Result> { use crate::schema::post_authors; use crate::schema::users; diff --git a/src/routes/posts.rs b/src/routes/posts.rs index 78854006..7cf01a6b 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -290,13 +290,7 @@ pub fn update( let newly_published = if !post.published && !form.draft { post.published = true; post.creation_date = Utc::now().naive_utc(); - // TODO: share code with Post::insert() - post.ap_url = plume_models::ap_url(&format!( - "{}/~/{}/{}/", - CONFIG.base_url, - post.get_blog(&conn).unwrap().fqn, - new_slug - )); + post.ap_url = Post::ap_url(post.get_blog(&conn).unwrap(), &new_slug); true } else { false