From 472da486e9944f217f316e2e10eb53f143e27126 Mon Sep 17 00:00:00 2001 From: Bat Date: Tue, 25 Sep 2018 20:10:18 +0100 Subject: [PATCH] Fix the canapi::Provider impl for Post --- plume-models/src/comments.rs | 1 - plume-models/src/likes.rs | 1 - plume-models/src/posts.rs | 30 ++++++++++++++---------------- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/plume-models/src/comments.rs b/plume-models/src/comments.rs index 33c20555..040193e0 100644 --- a/plume-models/src/comments.rs +++ b/plume-models/src/comments.rs @@ -3,7 +3,6 @@ use activitypub::{ link, object::{Note} }; -use canapi::Provider; use chrono; use diesel::{self, PgConnection, RunQueryDsl, QueryDsl, ExpressionMethods, dsl::any}; use serde_json; diff --git a/plume-models/src/likes.rs b/plume-models/src/likes.rs index e072a7b5..9bf1bec3 100644 --- a/plume-models/src/likes.rs +++ b/plume-models/src/likes.rs @@ -1,5 +1,4 @@ use activitypub::activity; -use canapi::Provider; use chrono; use diesel::{self, PgConnection, QueryDsl, RunQueryDsl, ExpressionMethods}; diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index 58e93d84..0e1b2c58 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -5,7 +5,7 @@ use activitypub::{ }; use canapi::{Error, Provider}; use chrono::{NaiveDateTime, TimeZone, Utc}; -use diesel::{self, PgConnection, RunQueryDsl, QueryDsl, ExpressionMethods, BelongingToDsl, dsl::any, Expression, BoolExpressionMethods}; +use diesel::{self, PgConnection, RunQueryDsl, QueryDsl, ExpressionMethods, BelongingToDsl, dsl::any}; use heck::KebabCase; use serde_json; @@ -70,20 +70,18 @@ impl Provider for Post { } fn list(conn: &PgConnection, filter: PostEndpoint) -> Vec { - let mut filters = Vec::new(); + let mut query = posts::table.into_boxed(); if let Some(title) = filter.title { - filters.push(posts::title.eq(title)); + query = query.filter(posts::title.eq(title)); + } + if let Some(subtitle) = filter.subtitle { + query = query.filter(posts::subtitle.eq(subtitle)); + } + if let Some(content) = filter.content { + query = query.filter(posts::content.eq(content)); } - let filters = filters.into_iter(); - let res = if let Some(first_filter) = filters.next() { - posts::table.filter(filters.fold(first_filter, |q, f| q.and(f))) - .get_results::(conn) - } else { - posts::table.get_results::(conn) - }; - - res.map(|ps| ps.into_iter() + query.get_results::(conn).map(|ps| ps.into_iter() .map(|p| PostEndpoint { id: Some(p.id), title: Some(p.title.clone()), @@ -94,12 +92,12 @@ impl Provider for Post { ).unwrap_or(vec![]) } - fn create(conn: &PgConnection, query: PostEndpoint) -> Result { - + fn create(_conn: &PgConnection, _query: PostEndpoint) -> Result { + unimplemented!() } - fn update(conn: &PgConnection, id: i32, new_data: PostEndpoint) -> Result { - + fn update(_conn: &PgConnection, _id: i32, _new_data: PostEndpoint) -> Result { + unimplemented!() } fn delete(conn: &PgConnection, id: i32) {