From 351c01f71c384594625f9a34f4e1159e33aaf72e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Sat, 25 May 2019 23:35:00 +0200 Subject: [PATCH] list custom_domains thanks a lot to @fdb-hiroshima and @BaptisteGelez for helping with the code. --- plume-models/src/blogs.rs | 11 ++++++++++- src/main.rs | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/plume-models/src/blogs.rs b/plume-models/src/blogs.rs index 6c5a449d..2a64d886 100644 --- a/plume-models/src/blogs.rs +++ b/plume-models/src/blogs.rs @@ -81,7 +81,7 @@ pub struct NewBlog { pub summary_html: SafeString, pub icon_id: Option, pub banner_id: Option, - pub custom_domain: Option, + pub custom_domain: Option, } const BLOG_PREFIX: &str = "~"; @@ -311,6 +311,15 @@ impl Blog { .map(|_| ()) .map_err(Error::from) } + + pub fn list_custom_domains(conn: &Connection) -> Result> { + blogs::table + .filter(blogs::custom_domain.is_not_null()) + .select(blogs::custom_domain) + .load::>(conn) + .map_err(Error::from) + .map(|res| res.into_iter().map(|s| s.unwrap()).collect::>()) + } } impl<'a, 'r> FromRequest<'a, 'r> for Host { diff --git a/src/main.rs b/src/main.rs index 0bdfaddc..6c466777 100644 --- a/src/main.rs +++ b/src/main.rs @@ -175,6 +175,9 @@ Then try to restart Plume println!("Please refer to the documentation to see how to configure it."); } + let custom_domains = plume_models::blogs::Blog::list_custom_domains(&dbpool.get().unwrap()).unwrap(); + dbg!(custom_domains); + let rocket = rocket::custom(CONFIG.rocket.clone().unwrap()) .mount( "/",