]> Untitled Git - lemmy.git/blobdiff - crates/api_crud/src/custom_emoji/create.rs
Make functions work with both connection and pool (#3420)
[lemmy.git] / crates / api_crud / src / custom_emoji / create.rs
index 42b6c5d916dd67f35c595b818b4b67f4c76b8896..dcf4fe7f9321101e24b74c185e8df89317c73ab6 100644 (file)
@@ -3,7 +3,7 @@ use actix_web::web::Data;
 use lemmy_api_common::{
   context::LemmyContext,
   custom_emoji::{CreateCustomEmoji, CustomEmojiResponse},
-  utils::{get_local_user_view_from_jwt, is_admin},
+  utils::{is_admin, local_user_view_from_jwt},
 };
 use lemmy_db_schema::source::{
   custom_emoji::{CustomEmoji, CustomEmojiInsertForm},
@@ -11,23 +11,18 @@ use lemmy_db_schema::source::{
   local_site::LocalSite,
 };
 use lemmy_db_views::structs::CustomEmojiView;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for CreateCustomEmoji {
   type Response = CustomEmojiResponse;
 
-  #[tracing::instrument(skip(self, context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<CustomEmojiResponse, LemmyError> {
+  #[tracing::instrument(skip(self, context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<CustomEmojiResponse, LemmyError> {
     let data: &CreateCustomEmoji = self;
-    let local_user_view =
-      get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
+    let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
-    let local_site = LocalSite::read(context.pool()).await?;
+    let local_site = LocalSite::read(&mut context.pool()).await?;
     // Make sure user is an admin
     is_admin(&local_user_view)?;
 
@@ -38,7 +33,7 @@ impl PerformCrud for CreateCustomEmoji {
       .category(data.category.to_string())
       .image_url(data.clone().image_url.into())
       .build();
-    let emoji = CustomEmoji::create(context.pool(), &emoji_form).await?;
+    let emoji = CustomEmoji::create(&mut context.pool(), &emoji_form).await?;
     let mut keywords = vec![];
     for keyword in &data.keywords {
       let keyword_form = CustomEmojiKeywordInsertForm::builder()
@@ -47,8 +42,8 @@ impl PerformCrud for CreateCustomEmoji {
         .build();
       keywords.push(keyword_form);
     }
-    CustomEmojiKeyword::create(context.pool(), keywords).await?;
-    let view = CustomEmojiView::get(context.pool(), emoji.id).await?;
+    CustomEmojiKeyword::create(&mut context.pool(), keywords).await?;
+    let view = CustomEmojiView::get(&mut context.pool(), emoji.id).await?;
     Ok(CustomEmojiResponse { custom_emoji: view })
   }
 }