+impl PostView {
+ pub async fn read(
+ pool: &mut DbPool<'_>,
+ post_id: PostId,
+ my_person_id: Option<PersonId>,
+ is_mod_or_admin: Option<bool>,
+ ) -> Result<Self, Error> {
+ let mut res = queries()
+ .read(pool, (post_id, my_person_id, is_mod_or_admin))
+ .await?;
+
+ // If a person is given, then my_vote, if None, should be 0, not null
+ // Necessary to differentiate between other person's votes
+ if my_person_id.is_some() && res.my_vote.is_none() {
+ res.my_vote = Some(0)
+ };
+
+ Ok(res)
+ }
+}
+
+#[derive(Default)]
+pub struct PostQuery<'a> {
+ pub listing_type: Option<ListingType>,
+ pub sort: Option<SortType>,
+ pub creator_id: Option<PersonId>,
+ pub community_id: Option<CommunityId>,
+ pub local_user: Option<&'a LocalUserView>,
+ pub search_term: Option<String>,
+ pub url_search: Option<String>,
+ pub saved_only: Option<bool>,
+ pub liked_only: Option<bool>,
+ pub disliked_only: Option<bool>,
+ pub moderator_view: Option<bool>,
+ pub is_profile_view: bool,
+ pub page: Option<i64>,
+ pub limit: Option<i64>,
+}
+
+impl<'a> PostQuery<'a> {
+ pub async fn list(self, pool: &mut DbPool<'_>) -> Result<Vec<PostView>, Error> {
+ queries().list(pool, self).await