mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-05-20 02:38:05 +00:00
Impl Crud for CustomEmoji
This commit is contained in:
parent
5342a22765
commit
bab417a73e
|
@ -5,10 +5,13 @@ use lemmy_api_common::{
|
|||
custom_emoji::{CreateCustomEmoji, CustomEmojiResponse},
|
||||
utils::is_admin,
|
||||
};
|
||||
use lemmy_db_schema::source::{
|
||||
custom_emoji::{CustomEmoji, CustomEmojiInsertForm},
|
||||
custom_emoji_keyword::{CustomEmojiKeyword, CustomEmojiKeywordInsertForm},
|
||||
local_site::LocalSite,
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
custom_emoji::{CustomEmoji, CustomEmojiInsertForm},
|
||||
custom_emoji_keyword::{CustomEmojiKeyword, CustomEmojiKeywordInsertForm},
|
||||
local_site::LocalSite,
|
||||
},
|
||||
traits::Crud,
|
||||
};
|
||||
use lemmy_db_views::structs::{CustomEmojiView, LocalUserView};
|
||||
use lemmy_utils::error::LemmyError;
|
||||
|
|
|
@ -6,7 +6,7 @@ use lemmy_api_common::{
|
|||
utils::is_admin,
|
||||
SuccessResponse,
|
||||
};
|
||||
use lemmy_db_schema::source::custom_emoji::CustomEmoji;
|
||||
use lemmy_db_schema::{source::custom_emoji::CustomEmoji, traits::Crud};
|
||||
use lemmy_db_views::structs::LocalUserView;
|
||||
use lemmy_utils::error::LemmyError;
|
||||
|
||||
|
|
|
@ -5,10 +5,13 @@ use lemmy_api_common::{
|
|||
custom_emoji::{CustomEmojiResponse, EditCustomEmoji},
|
||||
utils::is_admin,
|
||||
};
|
||||
use lemmy_db_schema::source::{
|
||||
custom_emoji::{CustomEmoji, CustomEmojiUpdateForm},
|
||||
custom_emoji_keyword::{CustomEmojiKeyword, CustomEmojiKeywordInsertForm},
|
||||
local_site::LocalSite,
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
custom_emoji::{CustomEmoji, CustomEmojiUpdateForm},
|
||||
custom_emoji_keyword::{CustomEmojiKeyword, CustomEmojiKeywordInsertForm},
|
||||
local_site::LocalSite,
|
||||
},
|
||||
traits::Crud,
|
||||
};
|
||||
use lemmy_db_views::structs::{CustomEmojiView, LocalUserView};
|
||||
use lemmy_utils::error::LemmyError;
|
||||
|
|
|
@ -8,35 +8,41 @@ use crate::{
|
|||
custom_emoji::{CustomEmoji, CustomEmojiInsertForm, CustomEmojiUpdateForm},
|
||||
custom_emoji_keyword::{CustomEmojiKeyword, CustomEmojiKeywordInsertForm},
|
||||
},
|
||||
traits::Crud,
|
||||
utils::{get_conn, DbPool},
|
||||
};
|
||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||
use diesel_async::RunQueryDsl;
|
||||
|
||||
impl CustomEmoji {
|
||||
pub async fn create(pool: &mut DbPool<'_>, form: &CustomEmojiInsertForm) -> Result<Self, Error> {
|
||||
#[async_trait]
|
||||
impl Crud for CustomEmoji {
|
||||
type InsertForm = CustomEmojiInsertForm;
|
||||
type UpdateForm = CustomEmojiUpdateForm;
|
||||
type IdType = CustomEmojiId;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(custom_emoji)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
}
|
||||
pub async fn update(
|
||||
|
||||
async fn update(
|
||||
pool: &mut DbPool<'_>,
|
||||
emoji_id: CustomEmojiId,
|
||||
form: &CustomEmojiUpdateForm,
|
||||
emoji_id: Self::IdType,
|
||||
new_custom_emoji: &Self::UpdateForm,
|
||||
) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(custom_emoji.find(emoji_id))
|
||||
.set(form)
|
||||
.set(new_custom_emoji)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
}
|
||||
pub async fn delete(pool: &mut DbPool<'_>, emoji_id: CustomEmojiId) -> Result<usize, Error> {
|
||||
|
||||
async fn delete(pool: &mut DbPool<'_>, id: Self::IdType) -> Result<usize, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::delete(custom_emoji.find(emoji_id))
|
||||
.execute(conn)
|
||||
.await
|
||||
diesel::delete(custom_emoji.find(id)).execute(conn).await
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue