Add some to_json functions to models for serialization in templates
This commit is contained in:
@@ -99,6 +99,12 @@ impl Comment {
|
||||
.expect("Couldn't load local comments")
|
||||
.len()
|
||||
}
|
||||
|
||||
pub fn to_json(&self, conn: &PgConnection) -> serde_json::Value {
|
||||
let mut json = serde_json::to_value(self).unwrap();
|
||||
json["author"] = self.get_author(conn).to_json(conn);
|
||||
json
|
||||
}
|
||||
}
|
||||
|
||||
impl FromActivity<Note> for Comment {
|
||||
|
||||
@@ -168,6 +168,15 @@ impl Post {
|
||||
act.create_props.set_object_object(self.into_activity(conn)).unwrap();
|
||||
act
|
||||
}
|
||||
|
||||
pub fn to_json(&self, conn: &PgConnection) -> serde_json::Value {
|
||||
json!({
|
||||
"post": self,
|
||||
"author": self.get_authors(conn)[0].to_json(conn),
|
||||
"url": format!("/~/{}/{}/", self.get_blog(conn).actor_id, self.slug),
|
||||
"date": self.creation_date.timestamp()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl FromActivity<Article> for Post {
|
||||
|
||||
@@ -330,6 +330,12 @@ impl User {
|
||||
};
|
||||
actor
|
||||
}
|
||||
|
||||
pub fn to_json(&self, conn: &PgConnection) -> serde_json::Value {
|
||||
let mut json = serde_json::to_value(self).unwrap();
|
||||
json["fqn"] = serde_json::Value::String(self.get_fqn(conn));
|
||||
json
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'r> FromRequest<'a, 'r> for User {
|
||||
|
||||
Reference in New Issue
Block a user