use serde::{Deserialize, Serialize}; use uuid::Uuid; use crate::error::AppError; use crate::models::channels::CustomEmoji; use crate::service::ImService; use super::session::ImSession; #[derive(Deserialize, Serialize, Clone, Debug, utoipa::ToSchema)] pub struct CreateCustomEmojiParams { pub name: String, pub url: String, pub animated: Option, } impl ImService { pub async fn custom_emoji_list( &self, _ctx: &ImSession, workspace_id: Uuid, ) -> Result, AppError> { sqlx::query_as::<_, CustomEmoji>( "SELECT id, workspace_id, name, url, animated, managed, \ created_by, created_at, updated_at \ FROM custom_emoji WHERE workspace_id = $1 ORDER BY name", ) .bind(workspace_id) .fetch_all(self.ctx.db.reader()) .await .map_err(AppError::Database) } pub async fn custom_emoji_create( &self, ctx: &ImSession, workspace_id: Uuid, params: CreateCustomEmojiParams, ) -> Result { let now = chrono::Utc::now(); sqlx::query_as::<_, CustomEmoji>( "INSERT INTO custom_emoji \ (id, workspace_id, name, url, animated, managed, created_by, created_at, updated_at) \ VALUES ($1, $2, $3, $4, $5, false, $6, $7, $7) \ RETURNING id, workspace_id, name, url, animated, managed, \ created_by, created_at, updated_at", ) .bind(Uuid::now_v7()) .bind(workspace_id) .bind(¶ms.name) .bind(¶ms.url) .bind(params.animated.unwrap_or(false)) .bind(ctx.user) .bind(now) .fetch_one(self.ctx.db.writer()) .await .map_err(AppError::Database) } pub async fn custom_emoji_delete( &self, _ctx: &ImSession, emoji_id: Uuid, ) -> Result<(), AppError> { sqlx::query("DELETE FROM custom_emoji WHERE id = $1") .bind(emoji_id) .execute(self.ctx.db.writer()) .await .map_err(AppError::Database)?; Ok(()) } }