]> Untitled Git - lemmy.git/blobdiff - crates/db_schema/src/impls/comment_reply.rs
Cache & Optimize Woodpecker CI (#3450)
[lemmy.git] / crates / db_schema / src / impls / comment_reply.rs
index 4c7a38d7ae2b494ce6816409fac6ea50fec59f29..eeb171f58e657276297e183005ca4524a4f36176 100644 (file)
@@ -1,11 +1,11 @@
 use crate::{
   newtypes::{CommentId, CommentReplyId, PersonId},
-  schema::comment_reply::dsl::*,
-  source::comment_reply::*,
+  schema::comment_reply::dsl::{comment_id, comment_reply, read, recipient_id},
+  source::comment_reply::{CommentReply, CommentReplyInsertForm, CommentReplyUpdateForm},
   traits::Crud,
   utils::{get_conn, DbPool},
 };
-use diesel::{dsl::*, result::Error, ExpressionMethods, QueryDsl};
+use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
 use diesel_async::RunQueryDsl;
 
 #[async_trait]
@@ -13,7 +13,7 @@ impl Crud for CommentReply {
   type InsertForm = CommentReplyInsertForm;
   type UpdateForm = CommentReplyUpdateForm;
   type IdType = CommentReplyId;
-  async fn read(pool: &DbPool, comment_reply_id: CommentReplyId) -> Result<Self, Error> {
+  async fn read(pool: &mut DbPool<'_>, comment_reply_id: CommentReplyId) -> Result<Self, Error> {
     let conn = &mut get_conn(pool).await?;
     comment_reply
       .find(comment_reply_id)
@@ -21,7 +21,10 @@ impl Crud for CommentReply {
       .await
   }
 
-  async fn create(pool: &DbPool, comment_reply_form: &Self::InsertForm) -> Result<Self, Error> {
+  async fn create(
+    pool: &mut DbPool<'_>,
+    comment_reply_form: &Self::InsertForm,
+  ) -> Result<Self, Error> {
     let conn = &mut get_conn(pool).await?;
 
     // since the return here isnt utilized, we dont need to do an update
@@ -36,7 +39,7 @@ impl Crud for CommentReply {
   }
 
   async fn update(
-    pool: &DbPool,
+    pool: &mut DbPool<'_>,
     comment_reply_id: CommentReplyId,
     comment_reply_form: &Self::UpdateForm,
   ) -> Result<Self, Error> {
@@ -50,7 +53,7 @@ impl Crud for CommentReply {
 
 impl CommentReply {
   pub async fn mark_all_as_read(
-    pool: &DbPool,
+    pool: &mut DbPool<'_>,
     for_recipient_id: PersonId,
   ) -> Result<Vec<CommentReply>, Error> {
     let conn = &mut get_conn(pool).await?;
@@ -64,7 +67,10 @@ impl CommentReply {
     .await
   }
 
-  pub async fn read_by_comment(pool: &DbPool, for_comment_id: CommentId) -> Result<Self, Error> {
+  pub async fn read_by_comment(
+    pool: &mut DbPool<'_>,
+    for_comment_id: CommentId,
+  ) -> Result<Self, Error> {
     let conn = &mut get_conn(pool).await?;
     comment_reply
       .filter(comment_id.eq(for_comment_id))
@@ -75,14 +81,17 @@ impl CommentReply {
 
 #[cfg(test)]
 mod tests {
+  #![allow(clippy::unwrap_used)]
+  #![allow(clippy::indexing_slicing)]
+
   use crate::{
     source::{
-      comment::*,
-      comment_reply::*,
+      comment::{Comment, CommentInsertForm},
+      comment_reply::{CommentReply, CommentReplyInsertForm, CommentReplyUpdateForm},
       community::{Community, CommunityInsertForm},
       instance::Instance,
-      person::*,
-      post::*,
+      person::{Person, PersonInsertForm},
+      post::{Post, PostInsertForm},
     },
     traits::Crud,
     utils::build_db_pool_for_tests,
@@ -93,8 +102,11 @@ mod tests {
   #[serial]
   async fn test_crud() {
     let pool = &build_db_pool_for_tests().await;
+    let pool = &mut pool.into();
 
-    let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap();
+    let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
+      .await
+      .unwrap();
 
     let new_person = PersonInsertForm::builder()
       .name("terrylake".into())