Implement new function to Blog for the view

Added Blog::to_json and Blog::get_fqn
This commit is contained in:
Kevin "Ilphrin" Pellet
2018-07-25 21:22:42 +02:00
parent 390d694cac
commit aaae786fb7
2 changed files with 16 additions and 2 deletions
+15
View File
@@ -248,6 +248,21 @@ impl Blog {
}
})
}
pub fn get_fqn(&self, conn: &PgConnection) -> String {
if self.instance_id == Instance::local_id(conn) {
self.actor_id.clone()
} else {
format!("{}@{}", self.actor_id, self.get_instance(conn).public_domain)
}
}
pub fn to_json(&self, conn: &PgConnection) -> serde_json::Value {
let mut json = serde_json::to_value(self).unwrap();
let formatted = serde_json::Value::String(format!("/~/{}",self.get_fqn(conn)));
json["fqn"] = formatted;
json
}
}
impl IntoId for Blog {