- Ok(PostView {
- post,
- creator,
- community,
- creator_banned_from_community: creator_banned_from_community.is_some(),
- counts,
- subscribed: follower.is_some(),
- saved: saved.is_some(),
- read: read.is_some(),
- my_vote,
- })
- }
-}
-
-pub struct PostQueryBuilder<'a> {
- conn: &'a PgConnection,
- listing_type: &'a ListingType,
- sort: &'a SortType,
- creator_id: Option<PersonId>,
- community_id: Option<CommunityId>,
- community_name: Option<String>,
- my_person_id: Option<PersonId>,
- search_term: Option<String>,
- url_search: Option<String>,
- show_nsfw: bool,
- show_bot_accounts: bool,
- show_read_posts: bool,
- saved_only: bool,
- page: Option<i64>,
- limit: Option<i64>,
-}
-
-impl<'a> PostQueryBuilder<'a> {
- pub fn create(conn: &'a PgConnection) -> Self {
- PostQueryBuilder {
- conn,
- listing_type: &ListingType::All,
- sort: &SortType::Hot,
- creator_id: None,
- community_id: None,
- community_name: None,
- my_person_id: None,
- search_term: None,
- url_search: None,
- show_nsfw: true,
- show_bot_accounts: true,
- show_read_posts: true,
- saved_only: false,
- page: None,
- limit: None,
- }
- }
-
- pub fn listing_type(mut self, listing_type: &'a ListingType) -> Self {
- self.listing_type = listing_type;
- self
- }
-
- pub fn sort(mut self, sort: &'a SortType) -> Self {
- self.sort = sort;
- self
- }
-
- pub fn community_id<T: MaybeOptional<CommunityId>>(mut self, community_id: T) -> Self {
- self.community_id = community_id.get_optional();
- self
- }
-
- pub fn my_person_id<T: MaybeOptional<PersonId>>(mut self, my_person_id: T) -> Self {
- self.my_person_id = my_person_id.get_optional();
- self
- }
-
- pub fn community_name<T: MaybeOptional<String>>(mut self, community_name: T) -> Self {
- self.community_name = community_name.get_optional();
- self
- }
-
- pub fn creator_id<T: MaybeOptional<PersonId>>(mut self, creator_id: T) -> Self {
- self.creator_id = creator_id.get_optional();
- self
- }
-
- pub fn search_term<T: MaybeOptional<String>>(mut self, search_term: T) -> Self {
- self.search_term = search_term.get_optional();
- self
- }
-
- pub fn url_search<T: MaybeOptional<String>>(mut self, url_search: T) -> Self {
- self.url_search = url_search.get_optional();
- self
- }
-
- pub fn show_nsfw(mut self, show_nsfw: bool) -> Self {
- self.show_nsfw = show_nsfw;
- self
- }
-
- pub fn show_bot_accounts(mut self, show_bot_accounts: bool) -> Self {
- self.show_bot_accounts = show_bot_accounts;
- self
- }
-
- pub fn show_read_posts(mut self, show_read_posts: bool) -> Self {
- self.show_read_posts = show_read_posts;
- self
- }
-
- pub fn saved_only(mut self, saved_only: bool) -> Self {
- self.saved_only = saved_only;
- self
- }
-
- pub fn page<T: MaybeOptional<i64>>(mut self, page: T) -> Self {
- self.page = page.get_optional();
- self
- }
-
- pub fn limit<T: MaybeOptional<i64>>(mut self, limit: T) -> Self {
- self.limit = limit.get_optional();
- self
- }
-
- pub fn list(self) -> Result<Vec<PostView>, Error> {
- use diesel::dsl::*;