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,73 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::error::AppError;
|
||||
use crate::models::channels::ChannelRepoLink;
|
||||
use crate::service::ImService;
|
||||
|
||||
use super::session::ImSession;
|
||||
|
||||
#[derive(Deserialize, Serialize, Clone, Debug, utoipa::ToSchema)]
|
||||
pub struct CreateRepoLinkParams {
|
||||
pub repo_id: Uuid,
|
||||
pub link_type: String,
|
||||
pub notify_events: Vec<String>,
|
||||
}
|
||||
|
||||
impl ImService {
|
||||
pub async fn repo_link_list(
|
||||
&self,
|
||||
_ctx: &ImSession,
|
||||
channel_id: Uuid,
|
||||
) -> Result<Vec<ChannelRepoLink>, AppError> {
|
||||
sqlx::query_as::<_, ChannelRepoLink>(
|
||||
"SELECT id, channel_id, repo_id, link_type, notify_events, active, \
|
||||
created_by, created_at, updated_at \
|
||||
FROM channel_repo_link WHERE channel_id = $1 ORDER BY created_at",
|
||||
)
|
||||
.bind(channel_id)
|
||||
.fetch_all(self.ctx.db.reader())
|
||||
.await
|
||||
.map_err(AppError::Database)
|
||||
}
|
||||
|
||||
pub async fn repo_link_create(
|
||||
&self,
|
||||
ctx: &ImSession,
|
||||
channel_id: Uuid,
|
||||
params: CreateRepoLinkParams,
|
||||
) -> Result<ChannelRepoLink, AppError> {
|
||||
let now = chrono::Utc::now();
|
||||
sqlx::query_as::<_, ChannelRepoLink>(
|
||||
"INSERT INTO channel_repo_link \
|
||||
(id, channel_id, repo_id, link_type, notify_events, active, \
|
||||
created_by, created_at, updated_at) \
|
||||
VALUES ($1, $2, $3, $4::link_type, $5, true, $6, $7, $7) \
|
||||
RETURNING id, channel_id, repo_id, link_type, notify_events, active, \
|
||||
created_by, created_at, updated_at",
|
||||
)
|
||||
.bind(Uuid::now_v7())
|
||||
.bind(channel_id)
|
||||
.bind(params.repo_id)
|
||||
.bind(¶ms.link_type)
|
||||
.bind(¶ms.notify_events)
|
||||
.bind(ctx.user)
|
||||
.bind(now)
|
||||
.fetch_one(self.ctx.db.writer())
|
||||
.await
|
||||
.map_err(AppError::Database)
|
||||
}
|
||||
|
||||
pub async fn repo_link_delete(
|
||||
&self,
|
||||
_ctx: &ImSession,
|
||||
link_id: Uuid,
|
||||
) -> Result<(), AppError> {
|
||||
sqlx::query("DELETE FROM channel_repo_link WHERE id = $1")
|
||||
.bind(link_id)
|
||||
.execute(self.ctx.db.writer())
|
||||
.await
|
||||
.map_err(AppError::Database)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user