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:
zhenyi
2026-06-10 18:49:32 +08:00
parent cec6dce955
commit 420dedbc1e
100 changed files with 3797 additions and 3839 deletions
+24 -11
View File
@@ -6,7 +6,7 @@ use crate::models::wiki::WikiPage;
use crate::service::RepoService;
use crate::session::Session;
use super::util::{clamp_limit_offset, ensure_affected, required_text};
use super::util::{clamp_limit_offset, ensure_affected, required_text, set_local_user_id};
#[derive(serde::Deserialize, serde::Serialize, Clone, Debug, utoipa::ToSchema)]
pub struct CreateWikiPageParams {
@@ -120,8 +120,7 @@ impl RepoService {
.begin()
.await
.map_err(|_| AppError::TxnError)?;
sqlx::query("SET LOCAL app.current_user_id = $1")
.bind(user_uid)
sqlx::query(set_local_user_id(user_uid))
.execute(&mut *txn)
.await
.map_err(AppError::Database)?;
@@ -190,15 +189,14 @@ impl RepoService {
.begin()
.await
.map_err(|_| AppError::TxnError)?;
sqlx::query("SET LOCAL app.current_user_id = $1")
.bind(user_uid)
sqlx::query(set_local_user_id(user_uid))
.execute(&mut *txn)
.await
.map_err(AppError::Database)?;
let updated = sqlx::query_as::<_, WikiPage>(
"UPDATE wiki_page SET title = $1, content = $2, last_editor_id = $3, version = $4, updated_at = $5 \
WHERE id = $6 AND deleted_at IS NULL \
WHERE id = $6 AND deleted_at IS NULL AND version = $7 \
RETURNING id, repo_id, slug, title, content, author_id, last_editor_id, version, created_at, updated_at, deleted_at",
)
.bind(&new_title)
@@ -207,9 +205,11 @@ impl RepoService {
.bind(new_version)
.bind(now)
.bind(page.id)
.fetch_one(&mut *txn)
.bind(page.version)
.fetch_optional(&mut *txn)
.await
.map_err(AppError::Database)?;
.map_err(AppError::Database)?
.ok_or(AppError::Conflict("page was modified concurrently; please refresh and try again".into()))?;
sqlx::query(
"INSERT INTO wiki_page_revision (id, page_id, version, title, content, editor_id, commit_message, created_at) \
@@ -305,15 +305,28 @@ impl RepoService {
}
fn generate_slug(title: &str) -> String {
title
let slug: String = title
.to_lowercase()
.chars()
.map(|c| if c.is_alphanumeric() { c } else { '-' })
.map(|c| {
if c.is_alphanumeric() || c.is_ascii_alphanumeric() {
c
} else {
'-'
}
})
.collect::<String>()
.split('-')
.filter(|s| !s.is_empty())
.collect::<Vec<_>>()
.join("-")
.join("-");
// If slug is empty (e.g., all non-ASCII characters), generate a fallback
if slug.is_empty() {
format!("page-{}", uuid::Uuid::now_v7().as_simple())
} else {
slug
}
}
async fn generate_wiki_slug(&self, repo_id: Uuid, title: &str) -> Result<String, AppError> {