From a0aef506744db3385d9ab7d2d3398ab48a4aef50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Tue, 28 May 2019 12:37:27 +0200 Subject: [PATCH] extract common routing code into private "_guts()" functions --- po/plume/plume.pot | 18 +++++++++--------- src/routes/blogs.rs | 42 +++++++++++++++++++++++++++--------------- 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/po/plume/plume.pot b/po/plume/plume.pot index 751273b7..b362a602 100644 --- a/po/plume/plume.pot +++ b/po/plume/plume.pot @@ -36,39 +36,39 @@ msgstr "" msgid "{0}'s avatar" msgstr "" -# src/routes/blogs.rs:84 +# src/routes/blogs.rs:96 msgid "To create a new blog, you need to be logged in" msgstr "" -# src/routes/blogs.rs:126 +# src/routes/blogs.rs:138 msgid "A blog with the same name already exists." msgstr "" -# src/routes/blogs.rs:161 +# src/routes/blogs.rs:173 msgid "Your blog was successfully created!" msgstr "" -# src/routes/blogs.rs:183 +# src/routes/blogs.rs:195 msgid "Your blog was deleted." msgstr "" -# src/routes/blogs.rs:190 +# src/routes/blogs.rs:202 msgid "You are not allowed to delete this blog." msgstr "" -# src/routes/blogs.rs:238 +# src/routes/blogs.rs:250 msgid "You are not allowed to edit this blog." msgstr "" -# src/routes/blogs.rs:283 +# src/routes/blogs.rs:295 msgid "You can't use this media as a blog icon." msgstr "" -# src/routes/blogs.rs:301 +# src/routes/blogs.rs:313 msgid "You can't use this media as a blog banner." msgstr "" -# src/routes/blogs.rs:334 +# src/routes/blogs.rs:346 msgid "Your blog information have been updated." msgstr "" diff --git a/src/routes/blogs.rs b/src/routes/blogs.rs index 86f387ab..60c57783 100644 --- a/src/routes/blogs.rs +++ b/src/routes/blogs.rs @@ -19,21 +19,9 @@ use plume_models::{ use routes::{errors::ErrorPage, Page, RespondOrRedirect}; use template_utils::{IntoContext, Ructe}; -#[get("/?", rank = 2)] -pub fn custom_details( - custom_domain: String, - page: Option, - rockets: PlumeRocket, -) -> Result { - let blog = Blog::find_by_host(&rockets, Host::new(custom_domain))?; - details(blog.fqn, page, rockets) -} - -#[get("/~/?", rank = 2)] -pub fn details(name: String, page: Option, rockets: PlumeRocket) -> Result { +fn detail_guts(blog: Blog, page: Option, rockets: PlumeRocket) -> Result { let page = page.unwrap_or_default(); let conn = &*rockets.conn; - let blog = Blog::find_by_fqn(&rockets, &name)?; let posts = Post::blog_page(conn, &blog, page.limits())?; let articles_count = Post::count_for_blog(conn, &blog)?; let authors = &blog.list_authors(conn)?; @@ -48,6 +36,30 @@ pub fn details(name: String, page: Option, rockets: PlumeRocket) -> Result ))) } +#[get("/?", rank = 2)] +pub fn custom_details( + custom_domain: String, + page: Option, + rockets: PlumeRocket, +) -> Result { + let blog = Blog::find_by_host(&rockets, Host::new(custom_domain))?; + detail_guts(blog, page, rockets) +} + +#[get("/~/?", rank = 2)] +pub fn details(name: String, page: Option, rockets: PlumeRocket) -> Result { + let blog = Blog::find_by_fqn(&rockets, &name)?; + detail_guts(blog, page, rockets) +} + +pub fn activity_detail_guts( + blog: Blog, + rockets: PlumeRocket, + _ap: ApRequest, +) -> Option> { + Some(ActivityStream::new(blog.to_activity(&*rockets.conn).ok()?)) +} + #[get("/", rank = 1)] pub fn custom_activity_details( custom_domain: String, @@ -55,7 +67,7 @@ pub fn custom_activity_details( _ap: ApRequest, ) -> Option> { let blog = Blog::find_by_host(&rockets, Host::new(custom_domain)).ok()?; - activity_details(blog.fqn, rockets, _ap) + activity_detail_guts(blog, rockets, _ap) } #[get("/~/", rank = 1)] @@ -65,7 +77,7 @@ pub fn activity_details( _ap: ApRequest, ) -> Option> { let blog = Blog::find_by_fqn(&rockets, &name).ok()?; - Some(ActivityStream::new(blog.to_activity(&*rockets.conn).ok()?)) + activity_detail_guts(blog, rockets, _ap) } #[get("/blogs/new")]