Adding listing_type to search.

This commit is contained in:
Dessalines 2021-04-09 16:35:51 -04:00
parent a42ac3e58a
commit c86f5472fb
4 changed files with 23 additions and 10 deletions

View File

@ -13,7 +13,7 @@ use lemmy_api_common::{
user_show_nsfw,
};
use lemmy_apub::fetcher::search::search_by_apub_id;
use lemmy_db_queries::{source::site::Site_, Crud, SearchType, SortType};
use lemmy_db_queries::{source::site::Site_, Crud, ListingType, SearchType, SortType};
use lemmy_db_schema::source::{moderator::*, site::Site};
use lemmy_db_views::{
comment_view::CommentQueryBuilder,
@ -144,8 +144,6 @@ impl Perform for Search {
let person_id = local_user_view.map(|u| u.person.id);
let type_ = SearchType::from_str(&data.type_)?;
let mut posts = Vec::new();
let mut comments = Vec::new();
let mut communities = Vec::new();
@ -157,9 +155,10 @@ impl Perform for Search {
let page = data.page;
let limit = data.limit;
let sort = SortType::from_str(&data.sort)?;
let type_ = SearchType::from_str(&data.type_)?;
let listing_type = ListingType::from_str(&data.listing_type)?;
let community_id = data.community_id;
let community_name = data.community_name.to_owned();
let community_name_2 = data.community_name.to_owned();
let creator_id = data.creator_id;
match type_ {
SearchType::Posts => {
@ -168,6 +167,8 @@ impl Perform for Search {
.sort(&sort)
.show_nsfw(show_nsfw)
.show_bot_accounts(show_bot_accounts)
.listing_type(&listing_type)
.show_nsfw(true)
.community_id(community_id)
.community_name(community_name)
.creator_id(creator_id)
@ -183,6 +184,7 @@ impl Perform for Search {
comments = blocking(context.pool(), move |conn| {
CommentQueryBuilder::create(&conn)
.sort(&sort)
.listing_type(&listing_type)
.search_term(q)
.show_bot_accounts(show_bot_accounts)
.community_id(community_id)
@ -199,6 +201,7 @@ impl Perform for Search {
communities = blocking(context.pool(), move |conn| {
CommunityQueryBuilder::create(conn)
.sort(&sort)
.listing_type(&listing_type)
.search_term(q)
.my_person_id(person_id)
.page(page)
@ -224,6 +227,8 @@ impl Perform for Search {
.sort(&sort)
.show_nsfw(show_nsfw)
.show_bot_accounts(show_bot_accounts)
.listing_type(&listing_type)
.show_nsfw(true)
.community_id(community_id)
.community_name(community_name)
.creator_id(creator_id)
@ -237,14 +242,17 @@ impl Perform for Search {
let q = data.q.to_owned();
let sort = SortType::from_str(&data.sort)?;
let listing_type = ListingType::from_str(&data.listing_type)?;
let community_name = data.community_name.to_owned();
comments = blocking(context.pool(), move |conn| {
CommentQueryBuilder::create(conn)
.sort(&sort)
.listing_type(&listing_type)
.search_term(q)
.show_bot_accounts(show_bot_accounts)
.community_id(community_id)
.community_name(community_name_2)
.community_name(community_name)
.creator_id(creator_id)
.my_person_id(person_id)
.page(page)
@ -255,10 +263,12 @@ impl Perform for Search {
let q = data.q.to_owned();
let sort = SortType::from_str(&data.sort)?;
let listing_type = ListingType::from_str(&data.listing_type)?;
communities = blocking(context.pool(), move |conn| {
CommunityQueryBuilder::create(conn)
.sort(&sort)
.listing_type(&listing_type)
.search_term(q)
.my_person_id(person_id)
.page(page)
@ -286,6 +296,8 @@ impl Perform for Search {
.sort(&sort)
.show_nsfw(show_nsfw)
.show_bot_accounts(show_bot_accounts)
.listing_type(&listing_type)
.show_nsfw(true)
.my_person_id(person_id)
.community_id(community_id)
.community_name(community_name)

View File

@ -27,6 +27,7 @@ pub struct Search {
pub community_name: Option<String>,
pub creator_id: Option<PersonId>,
pub sort: String,
pub listing_type: String,
pub page: Option<i64>,
pub limit: Option<i64>,
pub auth: Option<String>,

View File

@ -27,7 +27,7 @@ impl PerformCrud for GetComments {
let show_bot_accounts = user_show_bot_accounts(&local_user_view);
let person_id = local_user_view.map(|u| u.person.id);
let type_ = ListingType::from_str(&data.type_)?;
let listing_type = ListingType::from_str(&data.type_)?;
let sort = SortType::from_str(&data.sort)?;
let community_id = data.community_id;
@ -37,7 +37,7 @@ impl PerformCrud for GetComments {
let limit = data.limit;
let comments = blocking(context.pool(), move |conn| {
CommentQueryBuilder::create(conn)
.listing_type(type_)
.listing_type(&listing_type)
.sort(&sort)
.saved_only(saved_only)
.community_id(community_id)

View File

@ -172,7 +172,7 @@ impl CommentView {
pub struct CommentQueryBuilder<'a> {
conn: &'a PgConnection,
listing_type: ListingType,
listing_type: &'a ListingType,
sort: &'a SortType,
community_id: Option<CommunityId>,
community_name: Option<String>,
@ -192,7 +192,7 @@ impl<'a> CommentQueryBuilder<'a> {
pub fn create(conn: &'a PgConnection) -> Self {
CommentQueryBuilder {
conn,
listing_type: ListingType::All,
listing_type: &ListingType::All,
sort: &SortType::New,
community_id: None,
community_name: None,
@ -209,7 +209,7 @@ impl<'a> CommentQueryBuilder<'a> {
}
}
pub fn listing_type(mut self, listing_type: ListingType) -> Self {
pub fn listing_type(mut self, listing_type: &'a ListingType) -> Self {
self.listing_type = listing_type;
self
}