Make it possible to tag articles and display them

This commit is contained in:
Bat
2018-09-05 21:18:27 +01:00
parent 2b7a5bee93
commit 5b3eca63e0
6 changed files with 44 additions and 6 deletions
+3 -1
View File
@@ -19,6 +19,7 @@ use likes::Like;
use mentions::Mention;
use post_authors::*;
use reshares::Reshare;
use tags::Tag;
use users::User;
use schema::posts;
use safe_string::SafeString;
@@ -244,7 +245,8 @@ impl Post {
"author": self.get_authors(conn)[0].to_json(conn),
"url": format!("/~/{}/{}/", blog.get_fqn(conn), self.slug),
"date": self.creation_date.timestamp(),
"blog": blog.to_json(conn)
"blog": blog.to_json(conn),
"tags": Tag::for_post(&*conn, self.id)
})
}
+2 -1
View File
@@ -1,7 +1,7 @@
use diesel::{self, PgConnection, ExpressionMethods, RunQueryDsl, QueryDsl};
use schema::tags;
#[derive(Queryable)]
#[derive(Serialize, Queryable)]
pub struct Tag {
pub id: i32,
pub tag: String,
@@ -20,4 +20,5 @@ pub struct NewTag {
impl Tag {
insert!(tags, NewTag);
get!(tags);
list_by!(tags, for_post, post_id as i32);
}