]> Untitled Git - lemmy.git/commitdiff
Remove TypedBuilder from db_views and db_views_actor (#3637)
authordullbananas <dull.bananas0@gmail.com>
Mon, 17 Jul 2023 10:20:25 +0000 (03:20 -0700)
committerGitHub <noreply@github.com>
Mon, 17 Jul 2023 10:20:25 +0000 (12:20 +0200)
* change pool fields to parameters for list

* remove my_person_id and admin fields

* Change recipient id to list param

* Remove TypedBuilder from db_views and db_views_actor

29 files changed:
Cargo.lock
crates/api/src/comment_report/list.rs
crates/api/src/local_user/notifications/list_mentions.rs
crates/api/src/local_user/notifications/list_replies.rs
crates/api/src/post_report/list.rs
crates/api/src/private_message_report/list.rs
crates/api/src/site/registration_applications/list.rs
crates/api_common/src/utils.rs
crates/api_crud/src/community/list.rs
crates/api_crud/src/post/read.rs
crates/api_crud/src/private_message/read.rs
crates/apub/src/api/list_comments.rs
crates/apub/src/api/list_posts.rs
crates/apub/src/api/read_person.rs
crates/apub/src/api/search.rs
crates/db_views/Cargo.toml
crates/db_views/src/comment_report_view.rs
crates/db_views/src/comment_view.rs
crates/db_views/src/post_report_view.rs
crates/db_views/src/post_view.rs
crates/db_views/src/private_message_report_view.rs
crates/db_views/src/private_message_view.rs
crates/db_views/src/registration_application_view.rs
crates/db_views_actor/Cargo.toml
crates/db_views_actor/src/comment_reply_view.rs
crates/db_views_actor/src/community_view.rs
crates/db_views_actor/src/person_mention_view.rs
crates/db_views_actor/src/person_view.rs
crates/routes/src/feeds.rs

index 3396e1e5fe7552c7e0bc2c79e9ee6687639429f1..407cb9aae2a99a86061b4936598c04aedc664a88 100644 (file)
@@ -2769,7 +2769,6 @@ dependencies = [
  "tokio",
  "tracing",
  "ts-rs",
- "typed-builder",
 ]
 
 [[package]]
@@ -2782,7 +2781,6 @@ dependencies = [
  "serde",
  "serde_with",
  "ts-rs",
- "typed-builder",
 ]
 
 [[package]]
index baa1bf45fee3112de801814c1ba6ebec6562c348..b67ec333cac33e662653e09132c13eea78017a21 100644 (file)
@@ -22,24 +22,19 @@ impl Perform for ListCommentReports {
     let data: &ListCommentReports = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
-    let person_id = local_user_view.person.id;
-    let admin = local_user_view.person.admin;
     let community_id = data.community_id;
     let unresolved_only = data.unresolved_only;
 
     let page = data.page;
     let limit = data.limit;
-    let comment_reports = CommentReportQuery::builder()
-      .pool(&mut context.pool())
-      .my_person_id(person_id)
-      .admin(admin)
-      .community_id(community_id)
-      .unresolved_only(unresolved_only)
-      .page(page)
-      .limit(limit)
-      .build()
-      .list()
-      .await?;
+    let comment_reports = CommentReportQuery {
+      community_id,
+      unresolved_only,
+      page,
+      limit,
+    }
+    .list(&mut context.pool(), &local_user_view.person)
+    .await?;
 
     Ok(ListCommentReportsResponse { comment_reports })
   }
index 1b2d3c7b646f946ab92c67a57bd084b82eb031e5..10d24ff8f108c60e4861e4df6778800c874cb638 100644 (file)
@@ -27,18 +27,17 @@ impl Perform for GetPersonMentions {
     let person_id = Some(local_user_view.person.id);
     let show_bot_accounts = Some(local_user_view.local_user.show_bot_accounts);
 
-    let mentions = PersonMentionQuery::builder()
-      .pool(&mut context.pool())
-      .recipient_id(person_id)
-      .my_person_id(person_id)
-      .sort(sort)
-      .unread_only(unread_only)
-      .show_bot_accounts(show_bot_accounts)
-      .page(page)
-      .limit(limit)
-      .build()
-      .list()
-      .await?;
+    let mentions = PersonMentionQuery {
+      recipient_id: person_id,
+      my_person_id: person_id,
+      sort,
+      unread_only,
+      show_bot_accounts,
+      page,
+      limit,
+    }
+    .list(&mut context.pool())
+    .await?;
 
     Ok(GetPersonMentionsResponse { mentions })
   }
index 79b0fe223b6ca467b153d3f5a21a2814fd7187ff..8c7f3059bbf5860cb90550a6dbb000a36e60bee0 100644 (file)
@@ -24,18 +24,17 @@ impl Perform for GetReplies {
     let person_id = Some(local_user_view.person.id);
     let show_bot_accounts = Some(local_user_view.local_user.show_bot_accounts);
 
-    let replies = CommentReplyQuery::builder()
-      .pool(&mut context.pool())
-      .recipient_id(person_id)
-      .my_person_id(person_id)
-      .sort(sort)
-      .unread_only(unread_only)
-      .show_bot_accounts(show_bot_accounts)
-      .page(page)
-      .limit(limit)
-      .build()
-      .list()
-      .await?;
+    let replies = CommentReplyQuery {
+      recipient_id: person_id,
+      my_person_id: person_id,
+      sort,
+      unread_only,
+      show_bot_accounts,
+      page,
+      limit,
+    }
+    .list(&mut context.pool())
+    .await?;
 
     Ok(GetRepliesResponse { replies })
   }
index f7496e1a316f3f5975e444a4cb20725313bb6a2b..a0d909681de0abaa8545db08f8675e0f60c7b92a 100644 (file)
@@ -22,24 +22,19 @@ impl Perform for ListPostReports {
     let data: &ListPostReports = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
-    let person_id = local_user_view.person.id;
-    let admin = local_user_view.person.admin;
     let community_id = data.community_id;
     let unresolved_only = data.unresolved_only;
 
     let page = data.page;
     let limit = data.limit;
-    let post_reports = PostReportQuery::builder()
-      .pool(&mut context.pool())
-      .my_person_id(person_id)
-      .admin(admin)
-      .community_id(community_id)
-      .unresolved_only(unresolved_only)
-      .page(page)
-      .limit(limit)
-      .build()
-      .list()
-      .await?;
+    let post_reports = PostReportQuery {
+      community_id,
+      unresolved_only,
+      page,
+      limit,
+    }
+    .list(&mut context.pool(), &local_user_view.person)
+    .await?;
 
     Ok(ListPostReportsResponse { post_reports })
   }
index 72d182d4582aaf88829afb50bc64349c8162d463..8b4e50767fcb87b7f74d5e3dc289145bbe4d8684 100644 (file)
@@ -21,14 +21,13 @@ impl Perform for ListPrivateMessageReports {
     let unresolved_only = self.unresolved_only;
     let page = self.page;
     let limit = self.limit;
-    let private_message_reports = PrivateMessageReportQuery::builder()
-      .pool(&mut context.pool())
-      .unresolved_only(unresolved_only)
-      .page(page)
-      .limit(limit)
-      .build()
-      .list()
-      .await?;
+    let private_message_reports = PrivateMessageReportQuery {
+      unresolved_only,
+      page,
+      limit,
+    }
+    .list(&mut context.pool())
+    .await?;
 
     Ok(ListPrivateMessageReportsResponse {
       private_message_reports,
index 2389ad403d8ff62f58ecf2a5da4b31a58df36500..433cee425098cb3ed6b128b885f83d1a81de60bc 100644 (file)
@@ -23,19 +23,18 @@ impl Perform for ListRegistrationApplications {
     is_admin(&local_user_view)?;
 
     let unread_only = data.unread_only;
-    let verified_email_only = local_site.require_email_verification;
+    let verified_email_only = Some(local_site.require_email_verification);
 
     let page = data.page;
     let limit = data.limit;
-    let registration_applications = RegistrationApplicationQuery::builder()
-      .pool(&mut context.pool())
-      .unread_only(unread_only)
-      .verified_email_only(Some(verified_email_only))
-      .page(page)
-      .limit(limit)
-      .build()
-      .list()
-      .await?;
+    let registration_applications = RegistrationApplicationQuery {
+      unread_only,
+      verified_email_only,
+      page,
+      limit,
+    }
+    .list(&mut context.pool())
+    .await?;
 
     Ok(Self::Response {
       registration_applications,
index bd194c0f90f025eecca955a8277298894aee8f64..97afeaf0c61dc20420f575b4a05cefb3c24f8e7e 100644 (file)
@@ -667,13 +667,13 @@ pub async fn remove_user_data_in_community(
 
   // Comments
   // TODO Diesel doesn't allow updates with joins, so this has to be a loop
-  let comments = CommentQuery::builder()
-    .pool(pool)
-    .creator_id(Some(banned_person_id))
-    .community_id(Some(community_id))
-    .build()
-    .list()
-    .await?;
+  let comments = CommentQuery {
+    creator_id: Some(banned_person_id),
+    community_id: Some(community_id),
+    ..Default::default()
+  }
+  .list(pool)
+  .await?;
 
   for comment_view in &comments {
     let comment_id = comment_view.comment.id;
index 80ad6129cc1f2a0122dc30aaea1c10b6ad14b2d2..bd8189951528f80f992b04180015fa7372b6b1a6 100644 (file)
@@ -31,18 +31,18 @@ impl PerformCrud for ListCommunities {
     let page = data.page;
     let limit = data.limit;
     let local_user = local_user_view.map(|l| l.local_user);
-    let communities = CommunityQuery::builder()
-      .pool(&mut context.pool())
-      .listing_type(listing_type)
-      .show_nsfw(show_nsfw)
-      .sort(sort)
-      .local_user(local_user.as_ref())
-      .page(page)
-      .limit(limit)
-      .is_mod_or_admin(is_admin)
-      .build()
-      .list()
-      .await?;
+    let communities = CommunityQuery {
+      listing_type,
+      show_nsfw,
+      sort,
+      local_user: local_user.as_ref(),
+      page,
+      limit,
+      is_mod_or_admin: is_admin,
+      ..Default::default()
+    }
+    .list(&mut context.pool())
+    .await?;
 
     // Return the jwt
     Ok(ListCommunitiesResponse { communities })
index af19402ee3e0c82bbb18daeab573237d214f401d..e668517d3cb9e6908e17fc4dc621c87133db1b7c 100644 (file)
@@ -100,12 +100,12 @@ impl PerformCrud for GetPost {
 
     // Fetch the cross_posts
     let cross_posts = if let Some(url) = &post_view.post.url {
-      let mut x_posts = PostQuery::builder()
-        .pool(&mut context.pool())
-        .url_search(Some(url.inner().as_str().into()))
-        .build()
-        .list()
-        .await?;
+      let mut x_posts = PostQuery {
+        url_search: Some(url.inner().as_str().into()),
+        ..Default::default()
+      }
+      .list(&mut context.pool())
+      .await?;
 
       // Don't return this post as one of the cross_posts
       x_posts.retain(|x| x.post.id != post_id);
index 73ce034e96449bb7036c9ce19204711e5b515a1f..87d8ee66e28f537975dcb70a7a026dcc2f0f8578 100644 (file)
@@ -24,15 +24,13 @@ impl PerformCrud for GetPrivateMessages {
     let page = data.page;
     let limit = data.limit;
     let unread_only = data.unread_only;
-    let mut messages = PrivateMessageQuery::builder()
-      .pool(&mut context.pool())
-      .recipient_id(person_id)
-      .page(page)
-      .limit(limit)
-      .unread_only(unread_only)
-      .build()
-      .list()
-      .await?;
+    let mut messages = PrivateMessageQuery {
+      page,
+      limit,
+      unread_only,
+    }
+    .list(&mut context.pool(), person_id)
+    .await?;
 
     // Messages sent by ourselves should be marked as read. The `read` column in database is only
     // for the recipient, and shouldnt be exposed to sender.
index e3b7d065923e4180b606332a45d651e3fc0c5967..b64871221d67b57c15774f5f053b760d41500b78 100644 (file)
@@ -39,7 +39,11 @@ pub async fn list_comments(
   let limit = data.limit;
   let parent_id = data.parent_id;
 
-  let listing_type = listing_type_with_default(data.type_, &local_site, community_id)?;
+  let listing_type = Some(listing_type_with_default(
+    data.type_,
+    &local_site,
+    community_id,
+  )?);
 
   // If a parent_id is given, fetch the comment to get the path
   let parent_path = if let Some(parent_id) = parent_id {
@@ -51,22 +55,22 @@ pub async fn list_comments(
   let parent_path_cloned = parent_path.clone();
   let post_id = data.post_id;
   let local_user = local_user_view.map(|l| l.local_user);
-  let comments = CommentQuery::builder()
-    .pool(&mut context.pool())
-    .listing_type(Some(listing_type))
-    .sort(sort)
-    .max_depth(max_depth)
-    .saved_only(saved_only)
-    .community_id(community_id)
-    .parent_path(parent_path_cloned)
-    .post_id(post_id)
-    .local_user(local_user.as_ref())
-    .page(page)
-    .limit(limit)
-    .build()
-    .list()
-    .await
-    .with_lemmy_type(LemmyErrorType::CouldntGetComments)?;
+  let comments = CommentQuery {
+    listing_type,
+    sort,
+    max_depth,
+    saved_only,
+    community_id,
+    parent_path: parent_path_cloned,
+    post_id,
+    local_user: local_user.as_ref(),
+    page,
+    limit,
+    ..Default::default()
+  }
+  .list(&mut context.pool())
+  .await
+  .with_lemmy_type(LemmyErrorType::CouldntGetComments)?;
 
   Ok(Json(GetCommentsResponse { comments }))
 }
index 63d6800e8703af84fe517857739b69e2343802a6..c60abc966017b5bb6ade4fc39fe322d7e0c78c82 100644 (file)
@@ -36,27 +36,32 @@ pub async fn list_posts(
   };
   let saved_only = data.saved_only;
 
-  let listing_type = listing_type_with_default(data.type_, &local_site, community_id)?;
+  let listing_type = Some(listing_type_with_default(
+    data.type_,
+    &local_site,
+    community_id,
+  )?);
 
-  let is_mod_or_admin =
+  let is_mod_or_admin = Some(
     is_mod_or_admin_opt(&mut context.pool(), local_user_view.as_ref(), community_id)
       .await
-      .is_ok();
-
-  let posts = PostQuery::builder()
-    .pool(&mut context.pool())
-    .local_user(local_user_view.map(|l| l.local_user).as_ref())
-    .listing_type(Some(listing_type))
-    .sort(sort)
-    .community_id(community_id)
-    .saved_only(saved_only)
-    .page(page)
-    .limit(limit)
-    .is_mod_or_admin(Some(is_mod_or_admin))
-    .build()
-    .list()
-    .await
-    .with_lemmy_type(LemmyErrorType::CouldntGetPosts)?;
+      .is_ok(),
+  );
+
+  let posts = PostQuery {
+    local_user: local_user_view.map(|l| l.local_user).as_ref(),
+    listing_type,
+    sort,
+    community_id,
+    saved_only,
+    page,
+    limit,
+    is_mod_or_admin,
+    ..Default::default()
+  }
+  .list(&mut context.pool())
+  .await
+  .with_lemmy_type(LemmyErrorType::CouldntGetPosts)?;
 
   Ok(Json(GetPostsResponse { posts }))
 }
index 71f4abd519a90293ceea0b462f31f1bf6399a964..60cea766348af1acf47d905a2f19fd033b66ce58 100644 (file)
@@ -56,49 +56,49 @@ pub async fn read_person(
   let local_user = local_user_view.map(|l| l.local_user);
   let local_user_clone = local_user.clone();
 
-  let posts = PostQuery::builder()
-    .pool(&mut context.pool())
-    .sort(sort)
-    .saved_only(saved_only)
-    .local_user(local_user.as_ref())
-    .community_id(community_id)
-    .is_mod_or_admin(is_admin)
-    .page(page)
-    .limit(limit)
-    .creator_id(
+  let posts = PostQuery {
+    sort,
+    saved_only,
+    local_user:local_user.as_ref(),
+    community_id,
+    is_mod_or_admin: is_admin,
+    page,
+    limit,
+    creator_id:
       // If its saved only, you don't care what creator it was
       // Or, if its not saved, then you only want it for that specific creator
       if !saved_only.unwrap_or(false) {
         Some(person_details_id)
       } else {
         None
-      },
-    )
-    .build()
-    .list()
-    .await?;
+      }
+    ,
+    ..Default::default()
+  }
+  .list(&mut context.pool())
+  .await?;
 
-  let comments = CommentQuery::builder()
-    .pool(&mut context.pool())
-    .local_user(local_user_clone.as_ref())
-    .sort(sort.map(post_to_comment_sort_type))
-    .saved_only(saved_only)
-    .show_deleted_and_removed(Some(false))
-    .community_id(community_id)
-    .page(page)
-    .limit(limit)
-    .creator_id(
+  let comments = CommentQuery {
+    local_user: (local_user_clone.as_ref()),
+    sort: (sort.map(post_to_comment_sort_type)),
+    saved_only: (saved_only),
+    show_deleted_and_removed: (Some(false)),
+    community_id: (community_id),
+    page: (page),
+    limit: (limit),
+    creator_id: (
       // If its saved only, you don't care what creator it was
       // Or, if its not saved, then you only want it for that specific creator
       if !saved_only.unwrap_or(false) {
         Some(person_details_id)
       } else {
         None
-      },
-    )
-    .build()
-    .list()
-    .await?;
+      }
+    ),
+    ..Default::default()
+  }
+  .list(&mut context.pool())
+  .await?;
 
   let moderates =
     CommunityModeratorView::for_person(&mut context.pool(), person_details_id).await?;
index b7723a6f42fd51c21d0b7a0df5bf85ac6f72112e..2c65f302d51e9c67947d43cef183ceaf403c9b1f 100644 (file)
@@ -53,60 +53,59 @@ pub async fn search(
   let local_user = local_user_view.map(|l| l.local_user);
   match search_type {
     SearchType::Posts => {
-      posts = PostQuery::builder()
-        .pool(&mut context.pool())
-        .sort(sort)
-        .listing_type(listing_type)
-        .community_id(community_id)
-        .creator_id(creator_id)
-        .local_user(local_user.as_ref())
-        .search_term(Some(q))
-        .is_mod_or_admin(is_admin)
-        .page(page)
-        .limit(limit)
-        .build()
-        .list()
-        .await?;
+      posts = PostQuery {
+        sort: (sort),
+        listing_type: (listing_type),
+        community_id: (community_id),
+        creator_id: (creator_id),
+        local_user: (local_user.as_ref()),
+        search_term: (Some(q)),
+        is_mod_or_admin: (is_admin),
+        page: (page),
+        limit: (limit),
+        ..Default::default()
+      }
+      .list(&mut context.pool())
+      .await?;
     }
     SearchType::Comments => {
-      comments = CommentQuery::builder()
-        .pool(&mut context.pool())
-        .sort(sort.map(post_to_comment_sort_type))
-        .listing_type(listing_type)
-        .search_term(Some(q))
-        .community_id(community_id)
-        .creator_id(creator_id)
-        .local_user(local_user.as_ref())
-        .page(page)
-        .limit(limit)
-        .build()
-        .list()
-        .await?;
+      comments = CommentQuery {
+        sort: (sort.map(post_to_comment_sort_type)),
+        listing_type: (listing_type),
+        search_term: (Some(q)),
+        community_id: (community_id),
+        creator_id: (creator_id),
+        local_user: (local_user.as_ref()),
+        page: (page),
+        limit: (limit),
+        ..Default::default()
+      }
+      .list(&mut context.pool())
+      .await?;
     }
     SearchType::Communities => {
-      communities = CommunityQuery::builder()
-        .pool(&mut context.pool())
-        .sort(sort)
-        .listing_type(listing_type)
-        .search_term(Some(q))
-        .local_user(local_user.as_ref())
-        .is_mod_or_admin(is_admin)
-        .page(page)
-        .limit(limit)
-        .build()
-        .list()
-        .await?;
+      communities = CommunityQuery {
+        sort: (sort),
+        listing_type: (listing_type),
+        search_term: (Some(q)),
+        local_user: (local_user.as_ref()),
+        is_mod_or_admin: (is_admin),
+        page: (page),
+        limit: (limit),
+        ..Default::default()
+      }
+      .list(&mut context.pool())
+      .await?;
     }
     SearchType::Users => {
-      users = PersonQuery::builder()
-        .pool(&mut context.pool())
-        .sort(sort)
-        .search_term(Some(q))
-        .page(page)
-        .limit(limit)
-        .build()
-        .list()
-        .await?;
+      users = PersonQuery {
+        sort: (sort),
+        search_term: (Some(q)),
+        page: (page),
+        limit: (limit),
+      }
+      .list(&mut context.pool())
+      .await?;
     }
     SearchType::All => {
       // If the community or creator is included, dont search communities or users
@@ -114,55 +113,55 @@ pub async fn search(
         data.community_id.is_some() || data.community_name.is_some() || data.creator_id.is_some();
 
       let local_user_ = local_user.clone();
-      posts = PostQuery::builder()
-        .pool(&mut context.pool())
-        .sort(sort)
-        .listing_type(listing_type)
-        .community_id(community_id)
-        .creator_id(creator_id)
-        .local_user(local_user_.as_ref())
-        .search_term(Some(q))
-        .is_mod_or_admin(is_admin)
-        .page(page)
-        .limit(limit)
-        .build()
-        .list()
-        .await?;
+      posts = PostQuery {
+        sort: (sort),
+        listing_type: (listing_type),
+        community_id: (community_id),
+        creator_id: (creator_id),
+        local_user: (local_user_.as_ref()),
+        search_term: (Some(q)),
+        is_mod_or_admin: (is_admin),
+        page: (page),
+        limit: (limit),
+        ..Default::default()
+      }
+      .list(&mut context.pool())
+      .await?;
 
       let q = data.q.clone();
 
       let local_user_ = local_user.clone();
-      comments = CommentQuery::builder()
-        .pool(&mut context.pool())
-        .sort(sort.map(post_to_comment_sort_type))
-        .listing_type(listing_type)
-        .search_term(Some(q))
-        .community_id(community_id)
-        .creator_id(creator_id)
-        .local_user(local_user_.as_ref())
-        .page(page)
-        .limit(limit)
-        .build()
-        .list()
-        .await?;
+      comments = CommentQuery {
+        sort: (sort.map(post_to_comment_sort_type)),
+        listing_type: (listing_type),
+        search_term: (Some(q)),
+        community_id: (community_id),
+        creator_id: (creator_id),
+        local_user: (local_user_.as_ref()),
+        page: (page),
+        limit: (limit),
+        ..Default::default()
+      }
+      .list(&mut context.pool())
+      .await?;
 
       let q = data.q.clone();
 
       communities = if community_or_creator_included {
         vec![]
       } else {
-        CommunityQuery::builder()
-          .pool(&mut context.pool())
-          .sort(sort)
-          .listing_type(listing_type)
-          .search_term(Some(q))
-          .local_user(local_user.as_ref())
-          .is_mod_or_admin(is_admin)
-          .page(page)
-          .limit(limit)
-          .build()
-          .list()
-          .await?
+        CommunityQuery {
+          sort: (sort),
+          listing_type: (listing_type),
+          search_term: (Some(q)),
+          local_user: (local_user.as_ref()),
+          is_mod_or_admin: (is_admin),
+          page: (page),
+          limit: (limit),
+          ..Default::default()
+        }
+        .list(&mut context.pool())
+        .await?
       };
 
       let q = data.q.clone();
@@ -170,31 +169,30 @@ pub async fn search(
       users = if community_or_creator_included {
         vec![]
       } else {
-        PersonQuery::builder()
-          .pool(&mut context.pool())
-          .sort(sort)
-          .search_term(Some(q))
-          .page(page)
-          .limit(limit)
-          .build()
-          .list()
-          .await?
+        PersonQuery {
+          sort: (sort),
+          search_term: (Some(q)),
+          page: (page),
+          limit: (limit),
+        }
+        .list(&mut context.pool())
+        .await?
       };
     }
     SearchType::Url => {
-      posts = PostQuery::builder()
-        .pool(&mut context.pool())
-        .sort(sort)
-        .listing_type(listing_type)
-        .community_id(community_id)
-        .creator_id(creator_id)
-        .url_search(Some(q))
-        .is_mod_or_admin(is_admin)
-        .page(page)
-        .limit(limit)
-        .build()
-        .list()
-        .await?;
+      posts = PostQuery {
+        sort: (sort),
+        listing_type: (listing_type),
+        community_id: (community_id),
+        creator_id: (creator_id),
+        url_search: (Some(q)),
+        is_mod_or_admin: (is_admin),
+        page: (page),
+        limit: (limit),
+        ..Default::default()
+      }
+      .list(&mut context.pool())
+      .await?;
     }
   };
 
index 69dc1533dad15fb91674b50a97d2ee5c03b75c92..54a3aab6c4ab334b04c0372cda29b2dd030735fe 100644 (file)
@@ -29,7 +29,6 @@ diesel_ltree = { workspace = true, optional = true }
 serde = { workspace = true }
 serde_with = { workspace = true }
 tracing = { workspace = true, optional = true }
-typed-builder = { workspace = true }
 ts-rs = { workspace = true, optional = true }
 
 [dev-dependencies]
index 9c50eb67fa18002ecdeb16f9145d48de4ab1ad06..c28c7d673168b3ef4088da160143a7f8b321850f 100644 (file)
@@ -33,7 +33,6 @@ use lemmy_db_schema::{
   traits::JoinView,
   utils::{get_conn, limit_and_offset, DbPool},
 };
-use typed_builder::TypedBuilder;
 
 impl CommentReportView {
   /// returns the CommentReportView for the provided report_id
@@ -137,24 +136,21 @@ impl CommentReportView {
   }
 }
 
-#[derive(TypedBuilder)]
-#[builder(field_defaults(default))]
-pub struct CommentReportQuery<'a, 'b: 'a> {
-  #[builder(!default)]
-  pool: &'a mut DbPool<'b>,
-  #[builder(!default)]
-  my_person_id: PersonId,
-  #[builder(!default)]
-  admin: bool,
-  community_id: Option<CommunityId>,
-  page: Option<i64>,
-  limit: Option<i64>,
-  unresolved_only: Option<bool>,
+#[derive(Default)]
+pub struct CommentReportQuery {
+  pub community_id: Option<CommunityId>,
+  pub page: Option<i64>,
+  pub limit: Option<i64>,
+  pub unresolved_only: Option<bool>,
 }
 
-impl<'a, 'b: 'a> CommentReportQuery<'a, 'b> {
-  pub async fn list(self) -> Result<Vec<CommentReportView>, Error> {
-    let conn = &mut get_conn(self.pool).await?;
+impl CommentReportQuery {
+  pub async fn list(
+    self,
+    pool: &mut DbPool<'_>,
+    my_person: &Person,
+  ) -> Result<Vec<CommentReportView>, Error> {
+    let conn = &mut get_conn(pool).await?;
 
     let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2);
 
@@ -183,7 +179,7 @@ impl<'a, 'b: 'a> CommentReportQuery<'a, 'b> {
         comment_like::table.on(
           comment::id
             .eq(comment_like::comment_id)
-            .and(comment_like::person_id.eq(self.my_person_id)),
+            .and(comment_like::person_id.eq(my_person.id)),
         ),
       )
       .left_join(
@@ -220,13 +216,13 @@ impl<'a, 'b: 'a> CommentReportQuery<'a, 'b> {
       .offset(offset);
 
     // If its not an admin, get only the ones you mod
-    let res = if !self.admin {
+    let res = if !my_person.admin {
       query
         .inner_join(
           community_moderator::table.on(
             community_moderator::community_id
               .eq(post::community_id)
-              .and(community_moderator::person_id.eq(self.my_person_id)),
+              .and(community_moderator::person_id.eq(my_person.id)),
           ),
         )
         .load::<<CommentReportView as JoinView>::JoinTuple>(conn)
@@ -514,12 +510,8 @@ mod tests {
     };
 
     // Do a batch read of timmys reports
-    let reports = CommentReportQuery::builder()
-      .pool(pool)
-      .my_person_id(inserted_timmy.id)
-      .admin(false)
-      .build()
-      .list()
+    let reports = CommentReportQuery::default()
+      .list(pool, &inserted_timmy)
       .await
       .unwrap();
 
@@ -590,15 +582,13 @@ mod tests {
 
     // Do a batch read of timmys reports
     // It should only show saras, which is unresolved
-    let reports_after_resolve = CommentReportQuery::builder()
-      .pool(pool)
-      .my_person_id(inserted_timmy.id)
-      .admin(false)
-      .unresolved_only(Some(true))
-      .build()
-      .list()
-      .await
-      .unwrap();
+    let reports_after_resolve = CommentReportQuery {
+      unresolved_only: (Some(true)),
+      ..Default::default()
+    }
+    .list(pool, &inserted_timmy)
+    .await
+    .unwrap();
     assert_eq!(reports_after_resolve[0], expected_sara_report_view);
     assert_eq!(reports_after_resolve.len(), 1);
 
index 3556f85011d51da23c5d2cd439db77718db87790..435a3d8240213ecf0c79f148b831fe906e7bcd1a 100644 (file)
@@ -40,7 +40,6 @@ use lemmy_db_schema::{
   CommentSortType,
   ListingType,
 };
-use typed_builder::TypedBuilder;
 
 type CommentViewTuple = (
   Comment,
@@ -156,29 +155,26 @@ impl CommentView {
   }
 }
 
-#[derive(TypedBuilder)]
-#[builder(field_defaults(default))]
-pub struct CommentQuery<'a, 'b: 'a> {
-  #[builder(!default)]
-  pool: &'a mut DbPool<'b>,
-  listing_type: Option<ListingType>,
-  sort: Option<CommentSortType>,
-  community_id: Option<CommunityId>,
-  post_id: Option<PostId>,
-  parent_path: Option<Ltree>,
-  creator_id: Option<PersonId>,
-  local_user: Option<&'a LocalUser>,
-  search_term: Option<String>,
-  saved_only: Option<bool>,
-  show_deleted_and_removed: Option<bool>,
-  page: Option<i64>,
-  limit: Option<i64>,
-  max_depth: Option<i32>,
+#[derive(Default)]
+pub struct CommentQuery<'a> {
+  pub listing_type: Option<ListingType>,
+  pub sort: Option<CommentSortType>,
+  pub community_id: Option<CommunityId>,
+  pub post_id: Option<PostId>,
+  pub parent_path: Option<Ltree>,
+  pub creator_id: Option<PersonId>,
+  pub local_user: Option<&'a LocalUser>,
+  pub search_term: Option<String>,
+  pub saved_only: Option<bool>,
+  pub show_deleted_and_removed: Option<bool>,
+  pub page: Option<i64>,
+  pub limit: Option<i64>,
+  pub max_depth: Option<i32>,
 }
 
-impl<'a, 'b: 'a> CommentQuery<'a, 'b> {
-  pub async fn list(self) -> Result<Vec<CommentView>, Error> {
-    let conn = &mut get_conn(self.pool).await?;
+impl<'a> CommentQuery<'a> {
+  pub async fn list(self, pool: &mut DbPool<'_>) -> Result<Vec<CommentView>, Error> {
+    let conn = &mut get_conn(pool).await?;
 
     // The left join below will return None in this case
     let person_id_join = self.local_user.map(|l| l.person_id).unwrap_or(PersonId(-1));
@@ -602,29 +598,29 @@ mod tests {
     let mut expected_comment_view_with_person = expected_comment_view_no_person.clone();
     expected_comment_view_with_person.my_vote = Some(1);
 
-    let read_comment_views_no_person = CommentQuery::builder()
-      .pool(pool)
-      .sort(Some(CommentSortType::Old))
-      .post_id(Some(data.inserted_post.id))
-      .build()
-      .list()
-      .await
-      .unwrap();
+    let read_comment_views_no_person = CommentQuery {
+      sort: (Some(CommentSortType::Old)),
+      post_id: (Some(data.inserted_post.id)),
+      ..Default::default()
+    }
+    .list(pool)
+    .await
+    .unwrap();
 
     assert_eq!(
       expected_comment_view_no_person,
       read_comment_views_no_person[0]
     );
 
-    let read_comment_views_with_person = CommentQuery::builder()
-      .pool(pool)
-      .sort(Some(CommentSortType::Old))
-      .post_id(Some(data.inserted_post.id))
-      .local_user(Some(&data.inserted_local_user))
-      .build()
-      .list()
-      .await
-      .unwrap();
+    let read_comment_views_with_person = CommentQuery {
+      sort: (Some(CommentSortType::Old)),
+      post_id: (Some(data.inserted_post.id)),
+      local_user: (Some(&data.inserted_local_user)),
+      ..Default::default()
+    }
+    .list(pool)
+    .await
+    .unwrap();
 
     assert_eq!(
       expected_comment_view_with_person,
@@ -656,24 +652,24 @@ mod tests {
     let data = init_data(pool).await;
 
     let top_path = data.inserted_comment_0.path.clone();
-    let read_comment_views_top_path = CommentQuery::builder()
-      .pool(pool)
-      .post_id(Some(data.inserted_post.id))
-      .parent_path(Some(top_path))
-      .build()
-      .list()
-      .await
-      .unwrap();
+    let read_comment_views_top_path = CommentQuery {
+      post_id: (Some(data.inserted_post.id)),
+      parent_path: (Some(top_path)),
+      ..Default::default()
+    }
+    .list(pool)
+    .await
+    .unwrap();
 
     let child_path = data.inserted_comment_1.path.clone();
-    let read_comment_views_child_path = CommentQuery::builder()
-      .pool(pool)
-      .post_id(Some(data.inserted_post.id))
-      .parent_path(Some(child_path))
-      .build()
-      .list()
-      .await
-      .unwrap();
+    let read_comment_views_child_path = CommentQuery {
+      post_id: (Some(data.inserted_post.id)),
+      parent_path: (Some(child_path)),
+      ..Default::default()
+    }
+    .list(pool)
+    .await
+    .unwrap();
 
     // Make sure the comment parent-limited fetch is correct
     assert_eq!(6, read_comment_views_top_path.len());
@@ -687,14 +683,14 @@ mod tests {
     assert!(child_comments.contains(&data.inserted_comment_1));
     assert!(!child_comments.contains(&data.inserted_comment_2));
 
-    let read_comment_views_top_max_depth = CommentQuery::builder()
-      .pool(pool)
-      .post_id(Some(data.inserted_post.id))
-      .max_depth(Some(1))
-      .build()
-      .list()
-      .await
-      .unwrap();
+    let read_comment_views_top_max_depth = CommentQuery {
+      post_id: (Some(data.inserted_post.id)),
+      max_depth: (Some(1)),
+      ..Default::default()
+    }
+    .list(pool)
+    .await
+    .unwrap();
 
     // Make sure a depth limited one only has the top comment
     assert_eq!(
@@ -704,16 +700,16 @@ mod tests {
     assert_eq!(1, read_comment_views_top_max_depth.len());
 
     let child_path = data.inserted_comment_1.path.clone();
-    let read_comment_views_parent_max_depth = CommentQuery::builder()
-      .pool(pool)
-      .post_id(Some(data.inserted_post.id))
-      .parent_path(Some(child_path))
-      .max_depth(Some(1))
-      .sort(Some(CommentSortType::New))
-      .build()
-      .list()
-      .await
-      .unwrap();
+    let read_comment_views_parent_max_depth = CommentQuery {
+      post_id: (Some(data.inserted_post.id)),
+      parent_path: (Some(child_path)),
+      max_depth: (Some(1)),
+      sort: (Some(CommentSortType::New)),
+      ..Default::default()
+    }
+    .list(pool)
+    .await
+    .unwrap();
 
     // Make sure a depth limited one, and given child comment 1, has 3
     assert!(read_comment_views_parent_max_depth[2]
@@ -734,13 +730,13 @@ mod tests {
 
     // by default, user has all languages enabled and should see all comments
     // (except from blocked user)
-    let all_languages = CommentQuery::builder()
-      .pool(pool)
-      .local_user(Some(&data.inserted_local_user))
-      .build()
-      .list()
-      .await
-      .unwrap();
+    let all_languages = CommentQuery {
+      local_user: (Some(&data.inserted_local_user)),
+      ..Default::default()
+    }
+    .list(pool)
+    .await
+    .unwrap();
     assert_eq!(5, all_languages.len());
 
     // change user lang to finnish, should only show one post in finnish and one undetermined
@@ -751,13 +747,13 @@ mod tests {
     LocalUserLanguage::update(pool, vec![finnish_id], data.inserted_local_user.id)
       .await
       .unwrap();
-    let finnish_comments = CommentQuery::builder()
-      .pool(pool)
-      .local_user(Some(&data.inserted_local_user))
-      .build()
-      .list()
-      .await
-      .unwrap();
+    let finnish_comments = CommentQuery {
+      local_user: (Some(&data.inserted_local_user)),
+      ..Default::default()
+    }
+    .list(pool)
+    .await
+    .unwrap();
     assert_eq!(2, finnish_comments.len());
     let finnish_comment = finnish_comments
       .iter()
@@ -772,13 +768,13 @@ mod tests {
     LocalUserLanguage::update(pool, vec![UNDETERMINED_ID], data.inserted_local_user.id)
       .await
       .unwrap();
-    let undetermined_comment = CommentQuery::builder()
-      .pool(pool)
-      .local_user(Some(&data.inserted_local_user))
-      .build()
-      .list()
-      .await
-      .unwrap();
+    let undetermined_comment = CommentQuery {
+      local_user: (Some(&data.inserted_local_user)),
+      ..Default::default()
+    }
+    .list(pool)
+    .await
+    .unwrap();
     assert_eq!(1, undetermined_comment.len());
 
     cleanup(data, pool).await;
index 1219e0db514acc0cf6fffdfacc05c72efd9834c1..fff2a2bcc974b6fbf6d09c6425a7e39c881d5fde 100644 (file)
@@ -30,7 +30,6 @@ use lemmy_db_schema::{
   traits::JoinView,
   utils::{get_conn, limit_and_offset, DbPool},
 };
-use typed_builder::TypedBuilder;
 
 type PostReportViewTuple = (
   PostReport,
@@ -159,24 +158,21 @@ impl PostReportView {
   }
 }
 
-#[derive(TypedBuilder)]
-#[builder(field_defaults(default))]
-pub struct PostReportQuery<'a, 'b: 'a> {
-  #[builder(!default)]
-  pool: &'a mut DbPool<'b>,
-  #[builder(!default)]
-  my_person_id: PersonId,
-  #[builder(!default)]
-  admin: bool,
-  community_id: Option<CommunityId>,
-  page: Option<i64>,
-  limit: Option<i64>,
-  unresolved_only: Option<bool>,
+#[derive(Default)]
+pub struct PostReportQuery {
+  pub community_id: Option<CommunityId>,
+  pub page: Option<i64>,
+  pub limit: Option<i64>,
+  pub unresolved_only: Option<bool>,
 }
 
-impl<'a, 'b: 'a> PostReportQuery<'a, 'b> {
-  pub async fn list(self) -> Result<Vec<PostReportView>, Error> {
-    let conn = &mut get_conn(self.pool).await?;
+impl PostReportQuery {
+  pub async fn list(
+    self,
+    pool: &mut DbPool<'_>,
+    my_person: &Person,
+  ) -> Result<Vec<PostReportView>, Error> {
+    let conn = &mut get_conn(pool).await?;
     let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2);
 
     let mut query = post_report::table
@@ -195,7 +191,7 @@ impl<'a, 'b: 'a> PostReportQuery<'a, 'b> {
         post_like::table.on(
           post::id
             .eq(post_like::post_id)
-            .and(post_like::person_id.eq(self.my_person_id)),
+            .and(post_like::person_id.eq(my_person.id)),
         ),
       )
       .inner_join(post_aggregates::table.on(post_report::post_id.eq(post_aggregates::post_id)))
@@ -231,13 +227,13 @@ impl<'a, 'b: 'a> PostReportQuery<'a, 'b> {
       .offset(offset);
 
     // If its not an admin, get only the ones you mod
-    let res = if !self.admin {
+    let res = if !my_person.admin {
       query
         .inner_join(
           community_moderator::table.on(
             community_moderator::community_id
               .eq(post::community_id)
-              .and(community_moderator::person_id.eq(self.my_person_id)),
+              .and(community_moderator::person_id.eq(my_person.id)),
           ),
         )
         .load::<PostReportViewTuple>(conn)
@@ -506,12 +502,8 @@ mod tests {
     };
 
     // Do a batch read of timmys reports
-    let reports = PostReportQuery::builder()
-      .pool(pool)
-      .my_person_id(inserted_timmy.id)
-      .admin(false)
-      .build()
-      .list()
+    let reports = PostReportQuery::default()
+      .list(pool, &inserted_timmy)
       .await
       .unwrap();
 
@@ -580,15 +572,13 @@ mod tests {
 
     // Do a batch read of timmys reports
     // It should only show saras, which is unresolved
-    let reports_after_resolve = PostReportQuery::builder()
-      .pool(pool)
-      .my_person_id(inserted_timmy.id)
-      .admin(false)
-      .unresolved_only(Some(true))
-      .build()
-      .list()
-      .await
-      .unwrap();
+    let reports_after_resolve = PostReportQuery {
+      unresolved_only: (Some(true)),
+      ..Default::default()
+    }
+    .list(pool, &inserted_timmy)
+    .await
+    .unwrap();
     assert_eq!(reports_after_resolve[0], expected_sara_report_view);
 
     // Make sure the counts are correct
index 07433667a72ba1fb78be14a8eaf7db27cb464ba9..466713e1d3eb3db9f60146cf98f4a4e96feaf555 100644 (file)
@@ -45,7 +45,6 @@ use lemmy_db_schema::{
   SortType,
 };
 use tracing::debug;
-use typed_builder::TypedBuilder;
 
 type PostViewTuple = (
   Post,
@@ -193,28 +192,25 @@ impl PostView {
   }
 }
 
-#[derive(TypedBuilder)]
-#[builder(field_defaults(default))]
-pub struct PostQuery<'a, 'b: 'a> {
-  #[builder(!default)]
-  pool: &'a mut DbPool<'b>,
-  listing_type: Option<ListingType>,
-  sort: Option<SortType>,
-  creator_id: Option<PersonId>,
-  community_id: Option<CommunityId>,
-  local_user: Option<&'a LocalUser>,
-  search_term: Option<String>,
-  url_search: Option<String>,
-  saved_only: Option<bool>,
+#[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 LocalUser>,
+  pub search_term: Option<String>,
+  pub url_search: Option<String>,
+  pub saved_only: Option<bool>,
   /// Used to show deleted or removed posts for admins
-  is_mod_or_admin: Option<bool>,
-  page: Option<i64>,
-  limit: Option<i64>,
+  pub is_mod_or_admin: Option<bool>,
+  pub page: Option<i64>,
+  pub limit: Option<i64>,
 }
 
-impl<'a, 'b: 'a> PostQuery<'a, 'b> {
-  pub async fn list(self) -> Result<Vec<PostView>, Error> {
-    let conn = &mut get_conn(self.pool).await?;
+impl<'a> PostQuery<'a> {
+  pub async fn list(self, pool: &mut DbPool<'_>) -> Result<Vec<PostView>, Error> {
+    let conn = &mut get_conn(pool).await?;
 
     // The left join below will return None in this case
     let person_id_join = self.local_user.map(|l| l.person_id).unwrap_or(PersonId(-1));
@@ -619,15 +615,15 @@ mod tests {
         .await
         .unwrap();
 
-    let read_post_listing = PostQuery::builder()
-      .pool(pool)
-      .sort(Some(SortType::New))
-      .community_id(Some(data.inserted_community.id))
-      .local_user(Some(&inserted_local_user))
-      .build()
-      .list()
-      .await
-      .unwrap();
+    let read_post_listing = PostQuery {
+      sort: (Some(SortType::New)),
+      community_id: (Some(data.inserted_community.id)),
+      local_user: (Some(&inserted_local_user)),
+      ..Default::default()
+    }
+    .list(pool)
+    .await
+    .unwrap();
 
     let post_listing_single_with_person = PostView::read(
       pool,
@@ -658,15 +654,15 @@ mod tests {
         .await
         .unwrap();
 
-    let post_listings_with_bots = PostQuery::builder()
-      .pool(pool)
-      .sort(Some(SortType::New))
-      .community_id(Some(data.inserted_community.id))
-      .local_user(Some(&inserted_local_user))
-      .build()
-      .list()
-      .await
-      .unwrap();
+    let post_listings_with_bots = PostQuery {
+      sort: (Some(SortType::New)),
+      community_id: (Some(data.inserted_community.id)),
+      local_user: (Some(&inserted_local_user)),
+      ..Default::default()
+    }
+    .list(pool)
+    .await
+    .unwrap();
     // should include bot post which has "undetermined" language
     assert_eq!(2, post_listings_with_bots.len());
 
@@ -680,14 +676,14 @@ mod tests {
     let pool = &mut pool.into();
     let data = init_data(pool).await;
 
-    let read_post_listing_multiple_no_person = PostQuery::builder()
-      .pool(pool)
-      .sort(Some(SortType::New))
-      .community_id(Some(data.inserted_community.id))
-      .build()
-      .list()
-      .await
-      .unwrap();
+    let read_post_listing_multiple_no_person = PostQuery {
+      sort: (Some(SortType::New)),
+      community_id: (Some(data.inserted_community.id)),
+      ..Default::default()
+    }
+    .list(pool)
+    .await
+    .unwrap();
 
     let read_post_listing_single_no_person =
       PostView::read(pool, data.inserted_post.id, None, None)
@@ -724,15 +720,15 @@ mod tests {
     };
     CommunityBlock::block(pool, &community_block).await.unwrap();
 
-    let read_post_listings_with_person_after_block = PostQuery::builder()
-      .pool(pool)
-      .sort(Some(SortType::New))
-      .community_id(Some(data.inserted_community.id))
-      .local_user(Some(&data.inserted_local_user))
-      .build()
-      .list()
-      .await
-      .unwrap();
+    let read_post_listings_with_person_after_block = PostQuery {
+      sort: (Some(SortType::New)),
+      community_id: (Some(data.inserted_community.id)),
+      local_user: (Some(&data.inserted_local_user)),
+      ..Default::default()
+    }
+    .list(pool)
+    .await
+    .unwrap();
     // Should be 0 posts after the community block
     assert_eq!(0, read_post_listings_with_person_after_block.len());
 
@@ -789,15 +785,15 @@ mod tests {
         .await
         .unwrap();
 
-    let read_post_listing = PostQuery::builder()
-      .pool(pool)
-      .sort(Some(SortType::New))
-      .community_id(Some(data.inserted_community.id))
-      .local_user(Some(&inserted_local_user))
-      .build()
-      .list()
-      .await
-      .unwrap();
+    let read_post_listing = PostQuery {
+      sort: (Some(SortType::New)),
+      community_id: (Some(data.inserted_community.id)),
+      local_user: (Some(&inserted_local_user)),
+      ..Default::default()
+    }
+    .list(pool)
+    .await
+    .unwrap();
     assert_eq!(1, read_post_listing.len());
 
     assert_eq!(expected_post_with_upvote, read_post_listing[0]);
@@ -829,14 +825,14 @@ mod tests {
 
     Post::create(pool, &post_spanish).await.unwrap();
 
-    let post_listings_all = PostQuery::builder()
-      .pool(pool)
-      .sort(Some(SortType::New))
-      .local_user(Some(&data.inserted_local_user))
-      .build()
-      .list()
-      .await
-      .unwrap();
+    let post_listings_all = PostQuery {
+      sort: (Some(SortType::New)),
+      local_user: (Some(&data.inserted_local_user)),
+      ..Default::default()
+    }
+    .list(pool)
+    .await
+    .unwrap();
 
     // no language filters specified, all posts should be returned
     assert_eq!(3, post_listings_all.len());
@@ -849,14 +845,14 @@ mod tests {
       .await
       .unwrap();
 
-    let post_listing_french = PostQuery::builder()
-      .pool(pool)
-      .sort(Some(SortType::New))
-      .local_user(Some(&data.inserted_local_user))
-      .build()
-      .list()
-      .await
-      .unwrap();
+    let post_listing_french = PostQuery {
+      sort: (Some(SortType::New)),
+      local_user: (Some(&data.inserted_local_user)),
+      ..Default::default()
+    }
+    .list(pool)
+    .await
+    .unwrap();
 
     // only one post in french and one undetermined should be returned
     assert_eq!(2, post_listing_french.len());
@@ -871,14 +867,14 @@ mod tests {
     )
     .await
     .unwrap();
-    let post_listings_french_und = PostQuery::builder()
-      .pool(pool)
-      .sort(Some(SortType::New))
-      .local_user(Some(&data.inserted_local_user))
-      .build()
-      .list()
-      .await
-      .unwrap();
+    let post_listings_french_und = PostQuery {
+      sort: (Some(SortType::New)),
+      local_user: (Some(&data.inserted_local_user)),
+      ..Default::default()
+    }
+    .list(pool)
+    .await
+    .unwrap();
 
     // french post and undetermined language post should be returned
     assert_eq!(2, post_listings_french_und.len());
@@ -908,28 +904,28 @@ mod tests {
     .unwrap();
 
     // Make sure you don't see the deleted post in the results
-    let post_listings_no_admin = PostQuery::builder()
-      .pool(pool)
-      .sort(Some(SortType::New))
-      .local_user(Some(&data.inserted_local_user))
-      .is_mod_or_admin(Some(false))
-      .build()
-      .list()
-      .await
-      .unwrap();
+    let post_listings_no_admin = PostQuery {
+      sort: (Some(SortType::New)),
+      local_user: (Some(&data.inserted_local_user)),
+      is_mod_or_admin: (Some(false)),
+      ..Default::default()
+    }
+    .list(pool)
+    .await
+    .unwrap();
 
     assert_eq!(1, post_listings_no_admin.len());
 
     // Make sure they see both
-    let post_listings_is_admin = PostQuery::builder()
-      .pool(pool)
-      .sort(Some(SortType::New))
-      .local_user(Some(&data.inserted_local_user))
-      .is_mod_or_admin(Some(true))
-      .build()
-      .list()
-      .await
-      .unwrap();
+    let post_listings_is_admin = PostQuery {
+      sort: (Some(SortType::New)),
+      local_user: (Some(&data.inserted_local_user)),
+      is_mod_or_admin: (Some(true)),
+      ..Default::default()
+    }
+    .list(pool)
+    .await
+    .unwrap();
 
     assert_eq!(2, post_listings_is_admin.len());
 
index 74209f33aebb16a57d063905a94e9094d4c982ae..bdffa42e0bb458dd48c2d07291f9b928671eac92 100644 (file)
@@ -12,7 +12,6 @@ use lemmy_db_schema::{
   traits::JoinView,
   utils::{get_conn, limit_and_offset, DbPool},
 };
-use typed_builder::TypedBuilder;
 
 type PrivateMessageReportViewTuple = (
   PrivateMessageReport,
@@ -81,19 +80,16 @@ impl PrivateMessageReportView {
   }
 }
 
-#[derive(TypedBuilder)]
-#[builder(field_defaults(default))]
-pub struct PrivateMessageReportQuery<'a, 'b: 'a> {
-  #[builder(!default)]
-  pool: &'a mut DbPool<'b>,
-  page: Option<i64>,
-  limit: Option<i64>,
-  unresolved_only: Option<bool>,
+#[derive(Default)]
+pub struct PrivateMessageReportQuery {
+  pub page: Option<i64>,
+  pub limit: Option<i64>,
+  pub unresolved_only: Option<bool>,
 }
 
-impl<'a, 'b: 'a> PrivateMessageReportQuery<'a, 'b> {
-  pub async fn list(self) -> Result<Vec<PrivateMessageReportView>, Error> {
-    let conn = &mut get_conn(self.pool).await?;
+impl PrivateMessageReportQuery {
+  pub async fn list(self, pool: &mut DbPool<'_>) -> Result<Vec<PrivateMessageReportView>, Error> {
+    let conn = &mut get_conn(pool).await?;
     let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2);
 
     let mut query = private_message_report::table
@@ -208,10 +204,8 @@ mod tests {
       .await
       .unwrap();
 
-    let reports = PrivateMessageReportQuery::builder()
-      .pool(pool)
-      .build()
-      .list()
+    let reports = PrivateMessageReportQuery::default()
+      .list(pool)
       .await
       .unwrap();
     assert_eq!(1, reports.len());
@@ -233,13 +227,13 @@ mod tests {
       .await
       .unwrap();
 
-    let reports = PrivateMessageReportQuery::builder()
-      .pool(pool)
-      .unresolved_only(Some(false))
-      .build()
-      .list()
-      .await
-      .unwrap();
+    let reports = PrivateMessageReportQuery {
+      unresolved_only: (Some(false)),
+      ..Default::default()
+    }
+    .list(pool)
+    .await
+    .unwrap();
     assert_eq!(1, reports.len());
     assert!(reports[0].private_message_report.resolved);
     assert!(reports[0].resolver.is_some());
index 3d8fd42d0305028e2632fab65fe677e2fe5077d3..863db8125e2e63e1a0cdb9d9da52080f24fcb3ea 100644 (file)
@@ -17,7 +17,6 @@ use lemmy_db_schema::{
   utils::{get_conn, limit_and_offset, DbPool},
 };
 use tracing::debug;
-use typed_builder::TypedBuilder;
 
 type PrivateMessageViewTuple = (PrivateMessage, Person, Person);
 
@@ -68,21 +67,20 @@ impl PrivateMessageView {
   }
 }
 
-#[derive(TypedBuilder)]
-#[builder(field_defaults(default))]
-pub struct PrivateMessageQuery<'a, 'b: 'a> {
-  #[builder(!default)]
-  pool: &'a mut DbPool<'b>,
-  #[builder(!default)]
-  recipient_id: PersonId,
-  unread_only: Option<bool>,
-  page: Option<i64>,
-  limit: Option<i64>,
+#[derive(Default)]
+pub struct PrivateMessageQuery {
+  pub unread_only: Option<bool>,
+  pub page: Option<i64>,
+  pub limit: Option<i64>,
 }
 
-impl<'a, 'b: 'a> PrivateMessageQuery<'a, 'b> {
-  pub async fn list(self) -> Result<Vec<PrivateMessageView>, Error> {
-    let conn = &mut get_conn(self.pool).await?;
+impl PrivateMessageQuery {
+  pub async fn list(
+    self,
+    pool: &mut DbPool<'_>,
+    recipient_id: PersonId,
+  ) -> Result<Vec<PrivateMessageView>, Error> {
+    let conn = &mut get_conn(pool).await?;
     let person_alias_1 = diesel::alias!(person as person1);
 
     let mut query = private_message::table
@@ -101,14 +99,14 @@ impl<'a, 'b: 'a> PrivateMessageQuery<'a, 'b> {
     if self.unread_only.unwrap_or(false) {
       query = query
         .filter(private_message::read.eq(false))
-        .filter(private_message::recipient_id.eq(self.recipient_id));
+        .filter(private_message::recipient_id.eq(recipient_id));
     }
     // Otherwise, I want the ALL view to show both sent and received
     else {
       query = query.filter(
         private_message::recipient_id
-          .eq(self.recipient_id)
-          .or(private_message::creator_id.eq(self.recipient_id)),
+          .eq(recipient_id)
+          .or(private_message::creator_id.eq(recipient_id)),
       )
     }
 
index a2fdcba60973a68ade1acd6b78214ec9953b6b50..1ee820445201861aace6fc03869f0cee93713169 100644 (file)
@@ -18,7 +18,6 @@ use lemmy_db_schema::{
   traits::JoinView,
   utils::{get_conn, limit_and_offset, DbPool},
 };
-use typed_builder::TypedBuilder;
 
 type RegistrationApplicationViewTuple =
   (RegistrationApplication, LocalUser, Person, Option<Person>);
@@ -89,20 +88,20 @@ impl RegistrationApplicationView {
   }
 }
 
-#[derive(TypedBuilder)]
-#[builder(field_defaults(default))]
-pub struct RegistrationApplicationQuery<'a, 'b: 'a> {
-  #[builder(!default)]
-  pool: &'a mut DbPool<'b>,
-  unread_only: Option<bool>,
-  verified_email_only: Option<bool>,
-  page: Option<i64>,
-  limit: Option<i64>,
+#[derive(Default)]
+pub struct RegistrationApplicationQuery {
+  pub unread_only: Option<bool>,
+  pub verified_email_only: Option<bool>,
+  pub page: Option<i64>,
+  pub limit: Option<i64>,
 }
 
-impl<'a, 'b: 'a> RegistrationApplicationQuery<'a, 'b> {
-  pub async fn list(self) -> Result<Vec<RegistrationApplicationView>, Error> {
-    let conn = &mut get_conn(self.pool).await?;
+impl RegistrationApplicationQuery {
+  pub async fn list(
+    self,
+    pool: &mut DbPool<'_>,
+  ) -> Result<Vec<RegistrationApplicationView>, Error> {
+    let conn = &mut get_conn(pool).await?;
     let person_alias_1 = diesel::alias!(person as person1);
 
     let mut query = registration_application::table
@@ -327,13 +326,13 @@ mod tests {
     assert_eq!(read_sara_app_view, expected_sara_app_view);
 
     // Do a batch read of the applications
-    let apps = RegistrationApplicationQuery::builder()
-      .pool(pool)
-      .unread_only(Some(true))
-      .build()
-      .list()
-      .await
-      .unwrap();
+    let apps = RegistrationApplicationQuery {
+      unread_only: (Some(true)),
+      ..Default::default()
+    }
+    .list(pool)
+    .await
+    .unwrap();
 
     assert_eq!(
       apps,
@@ -403,13 +402,13 @@ mod tests {
 
     // Do a batch read of apps again
     // It should show only jessicas which is unresolved
-    let apps_after_resolve = RegistrationApplicationQuery::builder()
-      .pool(pool)
-      .unread_only(Some(true))
-      .build()
-      .list()
-      .await
-      .unwrap();
+    let apps_after_resolve = RegistrationApplicationQuery {
+      unread_only: (Some(true)),
+      ..Default::default()
+    }
+    .list(pool)
+    .await
+    .unwrap();
     assert_eq!(apps_after_resolve, vec![read_jess_app_view]);
 
     // Make sure the counts are correct
@@ -419,10 +418,8 @@ mod tests {
     assert_eq!(unread_count_after_approve, 1);
 
     // Make sure the not undenied_only has all the apps
-    let all_apps = RegistrationApplicationQuery::builder()
-      .pool(pool)
-      .build()
-      .list()
+    let all_apps = RegistrationApplicationQuery::default()
+      .list(pool)
       .await
       .unwrap();
     assert_eq!(all_apps.len(), 2);
index da84412450990c20f3e6d08f4f97825bcdeaa101..069013d7192ddd7e0a2e4c0902ab7ffcd501fec1 100644 (file)
@@ -27,5 +27,4 @@ diesel-async = { workspace = true, features = [
 ], optional = true }
 serde = { workspace = true }
 serde_with = { workspace = true }
-typed-builder = { workspace = true }
 ts-rs = { workspace = true, optional = true }
index 08cc5a45118a2278cd4b8a33bb7ef6cce9271ca8..4d7a8eac40c25ab247831b31a37d759af82c442f 100644 (file)
@@ -36,7 +36,6 @@ use lemmy_db_schema::{
   utils::{get_conn, limit_and_offset, DbPool},
   CommentSortType,
 };
-use typed_builder::TypedBuilder;
 
 type CommentReplyViewTuple = (
   CommentReply,
@@ -175,23 +174,20 @@ impl CommentReplyView {
   }
 }
 
-#[derive(TypedBuilder)]
-#[builder(field_defaults(default))]
-pub struct CommentReplyQuery<'a, 'b: 'a> {
-  #[builder(!default)]
-  pool: &'a mut DbPool<'b>,
-  my_person_id: Option<PersonId>,
-  recipient_id: Option<PersonId>,
-  sort: Option<CommentSortType>,
-  unread_only: Option<bool>,
-  show_bot_accounts: Option<bool>,
-  page: Option<i64>,
-  limit: Option<i64>,
+#[derive(Default)]
+pub struct CommentReplyQuery {
+  pub my_person_id: Option<PersonId>,
+  pub recipient_id: Option<PersonId>,
+  pub sort: Option<CommentSortType>,
+  pub unread_only: Option<bool>,
+  pub show_bot_accounts: Option<bool>,
+  pub page: Option<i64>,
+  pub limit: Option<i64>,
 }
 
-impl<'a, 'b: 'a> CommentReplyQuery<'a, 'b> {
-  pub async fn list(self) -> Result<Vec<CommentReplyView>, Error> {
-    let conn = &mut get_conn(self.pool).await?;
+impl CommentReplyQuery {
+  pub async fn list(self, pool: &mut DbPool<'_>) -> Result<Vec<CommentReplyView>, Error> {
+    let conn = &mut get_conn(pool).await?;
 
     let person_alias_1 = diesel::alias!(person as person1);
 
index 74aba52f2267d7ec93da7c56e633f3342bd34525..64dc090903004cbeddd1dc715f9479578261fddb 100644 (file)
@@ -23,7 +23,6 @@ use lemmy_db_schema::{
   ListingType,
   SortType,
 };
-use typed_builder::TypedBuilder;
 
 type CommunityViewTuple = (
   Community,
@@ -100,26 +99,23 @@ impl CommunityView {
   }
 }
 
-#[derive(TypedBuilder)]
-#[builder(field_defaults(default))]
-pub struct CommunityQuery<'a, 'b: 'a> {
-  #[builder(!default)]
-  pool: &'a mut DbPool<'b>,
-  listing_type: Option<ListingType>,
-  sort: Option<SortType>,
-  local_user: Option<&'a LocalUser>,
-  search_term: Option<String>,
-  is_mod_or_admin: Option<bool>,
-  show_nsfw: Option<bool>,
-  page: Option<i64>,
-  limit: Option<i64>,
+#[derive(Default)]
+pub struct CommunityQuery<'a> {
+  pub listing_type: Option<ListingType>,
+  pub sort: Option<SortType>,
+  pub local_user: Option<&'a LocalUser>,
+  pub search_term: Option<String>,
+  pub is_mod_or_admin: Option<bool>,
+  pub show_nsfw: Option<bool>,
+  pub page: Option<i64>,
+  pub limit: Option<i64>,
 }
 
-impl<'a, 'b: 'a> CommunityQuery<'a, 'b> {
-  pub async fn list(self) -> Result<Vec<CommunityView>, Error> {
+impl<'a> CommunityQuery<'a> {
+  pub async fn list(self, pool: &mut DbPool<'_>) -> Result<Vec<CommunityView>, Error> {
     use SortType::*;
 
-    let conn = &mut get_conn(self.pool).await?;
+    let conn = &mut get_conn(pool).await?;
 
     // The left join below will return None in this case
     let person_id_join = self.local_user.map(|l| l.person_id).unwrap_or(PersonId(-1));
index caa9116082c7dddcc4f65a1203bb75615d00474f..3e142254ab937e8bbc1c36130ca28e4e2357056e 100644 (file)
@@ -37,7 +37,6 @@ use lemmy_db_schema::{
   utils::{get_conn, limit_and_offset, DbPool},
   CommentSortType,
 };
-use typed_builder::TypedBuilder;
 
 type PersonMentionViewTuple = (
   PersonMention,
@@ -175,23 +174,20 @@ impl PersonMentionView {
   }
 }
 
-#[derive(TypedBuilder)]
-#[builder(field_defaults(default))]
-pub struct PersonMentionQuery<'a, 'b: 'a> {
-  #[builder(!default)]
-  pool: &'a mut DbPool<'b>,
-  my_person_id: Option<PersonId>,
-  recipient_id: Option<PersonId>,
-  sort: Option<CommentSortType>,
-  unread_only: Option<bool>,
-  show_bot_accounts: Option<bool>,
-  page: Option<i64>,
-  limit: Option<i64>,
+#[derive(Default)]
+pub struct PersonMentionQuery {
+  pub my_person_id: Option<PersonId>,
+  pub recipient_id: Option<PersonId>,
+  pub sort: Option<CommentSortType>,
+  pub unread_only: Option<bool>,
+  pub show_bot_accounts: Option<bool>,
+  pub page: Option<i64>,
+  pub limit: Option<i64>,
 }
 
-impl<'a, 'b: 'a> PersonMentionQuery<'a, 'b> {
-  pub async fn list(self) -> Result<Vec<PersonMentionView>, Error> {
-    let conn = &mut get_conn(self.pool).await?;
+impl PersonMentionQuery {
+  pub async fn list(self, pool: &mut DbPool<'_>) -> Result<Vec<PersonMentionView>, Error> {
+    let conn = &mut get_conn(pool).await?;
 
     let person_alias_1 = diesel::alias!(person as person1);
 
index 3aee145c9dada5ed84cece62b6e1d7c83c40afa7..e6baa1fc6ba2b12682fa70e34e0a74aae681da58 100644 (file)
@@ -19,7 +19,6 @@ use lemmy_db_schema::{
   SortType,
 };
 use std::iter::Iterator;
-use typed_builder::TypedBuilder;
 
 type PersonViewTuple = (Person, PersonAggregates);
 
@@ -79,20 +78,17 @@ impl PersonView {
   }
 }
 
-#[derive(TypedBuilder)]
-#[builder(field_defaults(default))]
-pub struct PersonQuery<'a, 'b: 'a> {
-  #[builder(!default)]
-  pool: &'a mut DbPool<'b>,
-  sort: Option<SortType>,
-  search_term: Option<String>,
-  page: Option<i64>,
-  limit: Option<i64>,
+#[derive(Default)]
+pub struct PersonQuery {
+  pub sort: Option<SortType>,
+  pub search_term: Option<String>,
+  pub page: Option<i64>,
+  pub limit: Option<i64>,
 }
 
-impl<'a, 'b: 'a> PersonQuery<'a, 'b> {
-  pub async fn list(self) -> Result<Vec<PersonView>, Error> {
-    let conn = &mut get_conn(self.pool).await?;
+impl PersonQuery {
+  pub async fn list(self, pool: &mut DbPool<'_>) -> Result<Vec<PersonView>, Error> {
+    let conn = &mut get_conn(pool).await?;
     let mut query = person::table
       .inner_join(person_aggregates::table)
       .select((person::all_columns, person_aggregates::all_columns))
index 8429f86061d32d75d59f6facfaa5b0579ad962e2..a71871abcd0a75e1570cae65d5679bfb0d210292 100644 (file)
@@ -124,15 +124,15 @@ async fn get_feed_data(
 ) -> Result<HttpResponse, LemmyError> {
   let site_view = SiteView::read_local(&mut context.pool()).await?;
 
-  let posts = PostQuery::builder()
-    .pool(&mut context.pool())
-    .listing_type(Some(listing_type))
-    .sort(Some(sort_type))
-    .limit(Some(limit))
-    .page(Some(page))
-    .build()
-    .list()
-    .await?;
+  let posts = PostQuery {
+    listing_type: (Some(listing_type)),
+    sort: (Some(sort_type)),
+    limit: (Some(limit)),
+    page: (Some(page)),
+    ..Default::default()
+  }
+  .list(&mut context.pool())
+  .await?;
 
   let items = create_post_items(posts, &context.settings().get_protocol_and_hostname())?;
 
@@ -243,16 +243,16 @@ async fn get_feed_user(
   let site_view = SiteView::read_local(pool).await?;
   let person = Person::read_from_name(pool, user_name, false).await?;
 
-  let posts = PostQuery::builder()
-    .pool(pool)
-    .listing_type(Some(ListingType::All))
-    .sort(Some(*sort_type))
-    .creator_id(Some(person.id))
-    .limit(Some(*limit))
-    .page(Some(*page))
-    .build()
-    .list()
-    .await?;
+  let posts = PostQuery {
+    listing_type: (Some(ListingType::All)),
+    sort: (Some(*sort_type)),
+    creator_id: (Some(person.id)),
+    limit: (Some(*limit)),
+    page: (Some(*page)),
+    ..Default::default()
+  }
+  .list(pool)
+  .await?;
 
   let items = create_post_items(posts, protocol_and_hostname)?;
 
@@ -278,15 +278,15 @@ async fn get_feed_community(
   let site_view = SiteView::read_local(pool).await?;
   let community = Community::read_from_name(pool, community_name, false).await?;
 
-  let posts = PostQuery::builder()
-    .pool(pool)
-    .sort(Some(*sort_type))
-    .community_id(Some(community.id))
-    .limit(Some(*limit))
-    .page(Some(*page))
-    .build()
-    .list()
-    .await?;
+  let posts = PostQuery {
+    sort: (Some(*sort_type)),
+    community_id: (Some(community.id)),
+    limit: (Some(*limit)),
+    page: (Some(*page)),
+    ..Default::default()
+  }
+  .list(pool)
+  .await?;
 
   let items = create_post_items(posts, protocol_and_hostname)?;
 
@@ -318,16 +318,16 @@ async fn get_feed_front(
   let local_user_id = LocalUserId(Claims::decode(jwt, jwt_secret)?.claims.sub);
   let local_user = LocalUser::read(pool, local_user_id).await?;
 
-  let posts = PostQuery::builder()
-    .pool(pool)
-    .listing_type(Some(ListingType::Subscribed))
-    .local_user(Some(&local_user))
-    .sort(Some(*sort_type))
-    .limit(Some(*limit))
-    .page(Some(*page))
-    .build()
-    .list()
-    .await?;
+  let posts = PostQuery {
+    listing_type: (Some(ListingType::Subscribed)),
+    local_user: (Some(&local_user)),
+    sort: (Some(*sort_type)),
+    limit: (Some(*limit)),
+    page: (Some(*page)),
+    ..Default::default()
+  }
+  .list(pool)
+  .await?;
 
   let items = create_post_items(posts, protocol_and_hostname)?;
 
@@ -360,27 +360,27 @@ async fn get_feed_inbox(
 
   let sort = CommentSortType::New;
 
-  let replies = CommentReplyQuery::builder()
-    .pool(pool)
-    .recipient_id(Some(person_id))
-    .my_person_id(Some(person_id))
-    .show_bot_accounts(Some(show_bot_accounts))
-    .sort(Some(sort))
-    .limit(Some(RSS_FETCH_LIMIT))
-    .build()
-    .list()
-    .await?;
-
-  let mentions = PersonMentionQuery::builder()
-    .pool(pool)
-    .recipient_id(Some(person_id))
-    .my_person_id(Some(person_id))
-    .show_bot_accounts(Some(show_bot_accounts))
-    .sort(Some(sort))
-    .limit(Some(RSS_FETCH_LIMIT))
-    .build()
-    .list()
-    .await?;
+  let replies = CommentReplyQuery {
+    recipient_id: (Some(person_id)),
+    my_person_id: (Some(person_id)),
+    show_bot_accounts: (Some(show_bot_accounts)),
+    sort: (Some(sort)),
+    limit: (Some(RSS_FETCH_LIMIT)),
+    ..Default::default()
+  }
+  .list(pool)
+  .await?;
+
+  let mentions = PersonMentionQuery {
+    recipient_id: (Some(person_id)),
+    my_person_id: (Some(person_id)),
+    show_bot_accounts: (Some(show_bot_accounts)),
+    sort: (Some(sort)),
+    limit: (Some(RSS_FETCH_LIMIT)),
+    ..Default::default()
+  }
+  .list(pool)
+  .await?;
 
   let items = create_reply_and_mention_items(replies, mentions, protocol_and_hostname)?;