Add a cover field to posts

Referencing the media to use to illustrate the article
This commit is contained in:
Baptiste Gelez 2018-10-30 19:13:25 +01:00
parent 9f1b37648e
commit ab5edbc6a5
7 changed files with 15 additions and 1 deletions

View File

@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
ALTER TABLE posts DROP COLUMN cover_id;

View File

@ -0,0 +1,2 @@
-- Your SQL goes here
ALTER TABLE posts ADD COLUMN cover_id INTEGER REFERENCES medias(id) DEFAULT NULL;

View File

@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
ALTER TABLE posts DROP COLUMN cover_id;

View File

@ -0,0 +1,2 @@
-- Your SQL goes here
ALTER TABLE posts ADD COLUMN cover_id INTEGER REFERENCES medias(id) DEFAULT NULL;

View File

@ -44,6 +44,7 @@ pub struct Post {
pub ap_url: String,
pub subtitle: String,
pub source: String,
pub cover_id: Option<i32>,
}
#[derive(Insertable)]
@ -59,6 +60,7 @@ pub struct NewPost {
pub ap_url: String,
pub subtitle: String,
pub source: String,
pub cover_id: Option<i32>,
}
impl<'a> Provider<(&'a Connection, Option<i32>)> for Post {
@ -547,7 +549,8 @@ impl FromActivity<Article, Connection> 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::<Source>().expect("Post::from_activity: source error").content
source: article.ap_object_props.source_object::<Source>().expect("Post::from_activity: source error").content,
cover_id: None, // TODO
});
for author in authors.into_iter() {

View File

@ -150,6 +150,7 @@ table! {
ap_url -> Varchar,
subtitle -> Text,
source -> Text,
cover_id -> Nullable<Int4>,
}
}
@ -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));

View File

@ -309,6 +309,7 @@ fn create(blog_name: String, data: LenientForm<NewPostForm>, 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 {