From ab5edbc6a58fba931e535624dbd9b5666a1bca9a Mon Sep 17 00:00:00 2001 From: Baptiste Gelez Date: Tue, 30 Oct 2018 19:13:25 +0100 Subject: [PATCH] Add a cover field to posts Referencing the media to use to illustrate the article --- .../postgres/2018-10-30-151529_add_post_cover/down.sql | 2 ++ migrations/postgres/2018-10-30-151529_add_post_cover/up.sql | 2 ++ migrations/sqlite/2018-10-30-151545_add_post_cover/down.sql | 2 ++ migrations/sqlite/2018-10-30-151545_add_post_cover/up.sql | 2 ++ plume-models/src/posts.rs | 5 ++++- plume-models/src/schema.rs | 2 ++ src/routes/posts.rs | 1 + 7 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 migrations/postgres/2018-10-30-151529_add_post_cover/down.sql create mode 100644 migrations/postgres/2018-10-30-151529_add_post_cover/up.sql create mode 100644 migrations/sqlite/2018-10-30-151545_add_post_cover/down.sql create mode 100644 migrations/sqlite/2018-10-30-151545_add_post_cover/up.sql diff --git a/migrations/postgres/2018-10-30-151529_add_post_cover/down.sql b/migrations/postgres/2018-10-30-151529_add_post_cover/down.sql new file mode 100644 index 00000000..15321a9b --- /dev/null +++ b/migrations/postgres/2018-10-30-151529_add_post_cover/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE posts DROP COLUMN cover_id; diff --git a/migrations/postgres/2018-10-30-151529_add_post_cover/up.sql b/migrations/postgres/2018-10-30-151529_add_post_cover/up.sql new file mode 100644 index 00000000..d3239a25 --- /dev/null +++ b/migrations/postgres/2018-10-30-151529_add_post_cover/up.sql @@ -0,0 +1,2 @@ +-- Your SQL goes here +ALTER TABLE posts ADD COLUMN cover_id INTEGER REFERENCES medias(id) DEFAULT NULL; diff --git a/migrations/sqlite/2018-10-30-151545_add_post_cover/down.sql b/migrations/sqlite/2018-10-30-151545_add_post_cover/down.sql new file mode 100644 index 00000000..15321a9b --- /dev/null +++ b/migrations/sqlite/2018-10-30-151545_add_post_cover/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE posts DROP COLUMN cover_id; diff --git a/migrations/sqlite/2018-10-30-151545_add_post_cover/up.sql b/migrations/sqlite/2018-10-30-151545_add_post_cover/up.sql new file mode 100644 index 00000000..d3239a25 --- /dev/null +++ b/migrations/sqlite/2018-10-30-151545_add_post_cover/up.sql @@ -0,0 +1,2 @@ +-- Your SQL goes here +ALTER TABLE posts ADD COLUMN cover_id INTEGER REFERENCES medias(id) DEFAULT NULL; diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index 91c8c17c..e63d6420 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -44,6 +44,7 @@ pub struct Post { pub ap_url: String, pub subtitle: String, pub source: String, + pub cover_id: Option, } #[derive(Insertable)] @@ -59,6 +60,7 @@ pub struct NewPost { pub ap_url: String, pub subtitle: String, pub source: String, + pub cover_id: Option, } impl<'a> Provider<(&'a Connection, Option)> for Post { @@ -547,7 +549,8 @@ impl FromActivity for Post { ap_url: article.object_props.url_string().unwrap_or(article.object_props.id_string().expect("Post::from_activity: url + id error")), creation_date: Some(article.object_props.published_utctime().expect("Post::from_activity: published error").naive_utc()), subtitle: article.object_props.summary_string().expect("Post::from_activity: summary error"), - source: article.ap_object_props.source_object::().expect("Post::from_activity: source error").content + source: article.ap_object_props.source_object::().expect("Post::from_activity: source error").content, + cover_id: None, // TODO }); for author in authors.into_iter() { diff --git a/plume-models/src/schema.rs b/plume-models/src/schema.rs index 5be393f3..7d9e39eb 100644 --- a/plume-models/src/schema.rs +++ b/plume-models/src/schema.rs @@ -150,6 +150,7 @@ table! { ap_url -> Varchar, subtitle -> Text, source -> Text, + cover_id -> Nullable, } } @@ -211,6 +212,7 @@ joinable!(notifications -> users (user_id)); joinable!(post_authors -> posts (post_id)); joinable!(post_authors -> users (author_id)); joinable!(posts -> blogs (blog_id)); +joinable!(posts -> medias (cover_id)); joinable!(reshares -> posts (post_id)); joinable!(reshares -> users (user_id)); joinable!(tags -> posts (post_id)); diff --git a/src/routes/posts.rs b/src/routes/posts.rs index 48486a5e..4b41a1b6 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -309,6 +309,7 @@ fn create(blog_name: String, data: LenientForm, user: User, conn: D creation_date: None, subtitle: form.subtitle.clone(), source: form.content.clone(), + cover_id: None, // TODO }); let post = post.update_ap_url(&*conn); PostAuthor::insert(&*conn, NewPostAuthor {