Adding a way to GetComments for a community given its name only.

This commit is contained in:
Dessalines 2020-09-08 13:46:49 -05:00
parent bd0e69b2bb
commit 8dd3c9e429
4 changed files with 15 additions and 1 deletions

View file

@ -68,6 +68,7 @@ pub struct GetComments {
pub page: Option<i64>,
pub limit: Option<i64>,
pub community_id: Option<i32>,
pub community_name: Option<String>,
pub auth: Option<String>,
}

View file

@ -132,6 +132,7 @@ pub struct CommentQueryBuilder<'a> {
listing_type: ListingType,
sort: &'a SortType,
for_community_id: Option<i32>,
for_community_name: Option<String>,
for_post_id: Option<i32>,
for_creator_id: Option<i32>,
search_term: Option<String>,
@ -153,6 +154,7 @@ impl<'a> CommentQueryBuilder<'a> {
listing_type: ListingType::All,
sort: &SortType::New,
for_community_id: None,
for_community_name: None,
for_post_id: None,
for_creator_id: None,
search_term: None,
@ -188,6 +190,11 @@ impl<'a> CommentQueryBuilder<'a> {
self
}
pub fn for_community_name<T: MaybeOptional<String>>(mut self, for_community_name: T) -> Self {
self.for_community_name = for_community_name.get_optional();
self
}
pub fn search_term<T: MaybeOptional<String>>(mut self, search_term: T) -> Self {
self.search_term = search_term.get_optional();
self
@ -233,6 +240,10 @@ impl<'a> CommentQueryBuilder<'a> {
query = query.filter(community_id.eq(for_community_id));
}
if let Some(for_community_name) = self.for_community_name {
query = query.filter(community_name.eq(for_community_name));
}
if let Some(for_post_id) = self.for_post_id {
query = query.filter(post_id.eq(for_post_id));
};

View file

@ -1,7 +1,7 @@
use super::post_view::post_fast_view::BoxedQuery;
use crate::{fuzzy_search, limit_and_offset, ListingType, MaybeOptional, SortType};
use diesel::{dsl::*, pg::Pg, result::Error, *};
use serde::{Serialize};
use serde::Serialize;
// The faked schema since diesel doesn't do views
table! {

View file

@ -674,6 +674,7 @@ impl Perform for GetComments {
let sort = SortType::from_str(&data.sort)?;
let community_id = data.community_id;
let community_name = data.community_name.to_owned();
let page = data.page;
let limit = data.limit;
let comments = blocking(context.pool(), move |conn| {
@ -681,6 +682,7 @@ impl Perform for GetComments {
.listing_type(type_)
.sort(&sort)
.for_community_id(community_id)
.for_community_name(community_name)
.my_user_id(user_id)
.page(page)
.limit(limit)