]> Untitled Git - lemmy.git/blobdiff - crates/api/src/comment/save.rs
Make functions work with both connection and pool (#3420)
[lemmy.git] / crates / api / src / comment / save.rs
index 70c9745f8b884bb42af1bbe4c18ec9e4f5d7b205..7161c8e9cdea8c3bca9f34653a62017a15e104a7 100644 (file)
@@ -10,7 +10,7 @@ use lemmy_db_schema::{
   traits::Saveable,
 };
 use lemmy_db_views::structs::CommentView;
-use lemmy_utils::error::LemmyError;
+use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
 
 #[async_trait::async_trait(?Send)]
 impl Perform for SaveComment {
@@ -27,18 +27,18 @@ impl Perform for SaveComment {
     };
 
     if data.save {
-      CommentSaved::save(context.pool(), &comment_saved_form)
+      CommentSaved::save(&mut context.pool(), &comment_saved_form)
         .await
-        .map_err(|e| LemmyError::from_error_message(e, "couldnt_save_comment"))?;
+        .with_lemmy_type(LemmyErrorType::CouldntSaveComment)?;
     } else {
-      CommentSaved::unsave(context.pool(), &comment_saved_form)
+      CommentSaved::unsave(&mut context.pool(), &comment_saved_form)
         .await
-        .map_err(|e| LemmyError::from_error_message(e, "couldnt_save_comment"))?;
+        .with_lemmy_type(LemmyErrorType::CouldntSaveComment)?;
     }
 
     let comment_id = data.comment_id;
     let person_id = local_user_view.person.id;
-    let comment_view = CommentView::read(context.pool(), comment_id, Some(person_id)).await?;
+    let comment_view = CommentView::read(&mut context.pool(), comment_id, Some(person_id)).await?;
 
     Ok(CommentResponse {
       comment_view,