feat(service): expand service layer with new domain operations
- Add IM service modules: audit, channel roles, custom emojis, forum tags, integrations, invitations, repo links, slash commands, stages, voice, webhooks - Add PR service modules: review requests, templates - Add repo service modules: contributors, release assets, git extras (archive, branch rename, commit extras, diff/merge, tag, tree) - Add user service: social (follow/block) - Add internal auth service - Update existing service modules with expanded functionality - Remove deleted IM modules: articles, delivery trace, drafts, follows, messages, polls, presence, reactions, threads
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
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<bool>,
|
||||
}
|
||||
|
||||
impl ImService {
|
||||
pub async fn custom_emoji_list(
|
||||
&self,
|
||||
_ctx: &ImSession,
|
||||
workspace_id: Uuid,
|
||||
) -> Result<Vec<CustomEmoji>, 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<CustomEmoji, AppError> {
|
||||
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(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user