- 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: Option<ListingType>,
- sort: Option<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: Option<bool>,
- show_bot_accounts: Option<bool>,
- show_read_posts: Option<bool>,
- saved_only: Option<bool>,
- page: Option<i64>,
- limit: Option<i64>,
-}
-
-impl<'a> PostQueryBuilder<'a> {
- pub fn create(conn: &'a PgConnection) -> Self {
- PostQueryBuilder {
- conn,
- listing_type: None,
- sort: None,
- creator_id: None,
- community_id: None,
- community_name: None,
- my_person_id: None,
- search_term: None,
- url_search: None,
- show_nsfw: None,
- show_bot_accounts: None,
- show_read_posts: None,
- saved_only: None,
- page: None,
- limit: None,
- }
- }
-
- pub fn listing_type<T: MaybeOptional<ListingType>>(mut self, listing_type: T) -> Self {
- self.listing_type = listing_type.get_optional();
- self
- }
-
- pub fn sort<T: MaybeOptional<SortType>>(mut self, sort: T) -> Self {
- self.sort = sort.get_optional();
- 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<T: MaybeOptional<bool>>(mut self, show_nsfw: T) -> Self {
- self.show_nsfw = show_nsfw.get_optional();
- self
- }
-
- pub fn show_bot_accounts<T: MaybeOptional<bool>>(mut self, show_bot_accounts: T) -> Self {
- self.show_bot_accounts = show_bot_accounts.get_optional();
- self
- }
-
- pub fn show_read_posts<T: MaybeOptional<bool>>(mut self, show_read_posts: T) -> Self {
- self.show_read_posts = show_read_posts.get_optional();
- self
- }
-
- pub fn saved_only<T: MaybeOptional<bool>>(mut self, saved_only: T) -> Self {
- self.saved_only = saved_only.get_optional();
- 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::*;