Add a dashboard

This commit is contained in:
Bat
2018-06-10 18:55:08 +01:00
parent 7a3215edaa
commit edbeeef640
6 changed files with 53 additions and 3 deletions
+9 -1
View File
@@ -7,7 +7,7 @@ use reqwest::{
use serde_json;
use url::Url;
use chrono::NaiveDateTime;
use diesel::{self, QueryDsl, RunQueryDsl, ExpressionMethods, PgConnection};
use diesel::{self, QueryDsl, RunQueryDsl, ExpressionMethods, PgConnection, dsl::any};
use openssl::{
hash::MessageDigest,
pkey::{PKey, Private},
@@ -71,6 +71,14 @@ impl Blog {
.into_iter().nth(0)
}
pub fn find_for_author(conn: &PgConnection, author_id: i32) -> Vec<Blog> {
use schema::blog_authors;
let author_ids = blog_authors::table.filter(blog_authors::author_id.eq(author_id)).select(blog_authors::blog_id);
blogs::table.filter(blogs::id.eq(any(author_ids)))
.load::<Blog>(conn)
.expect("Couldn't load blogs ")
}
pub fn find_by_name(conn: &PgConnection, name: String, instance_id: i32) -> Option<Blog> {
blogs::table.filter(blogs::actor_id.eq(name))
.filter(blogs::instance_id.eq(instance_id))