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:
@@ -9,7 +9,7 @@ use uuid::Uuid;
|
||||
|
||||
use super::util::clamp_limit_offset;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[derive(Debug, Deserialize, Serialize, utoipa::ToSchema)]
|
||||
pub struct CreateBlockParams {
|
||||
pub workspace_id: Option<Uuid>,
|
||||
pub repo_id: Option<Uuid>,
|
||||
@@ -81,10 +81,12 @@ impl NotificationService {
|
||||
let id = Uuid::now_v7();
|
||||
let now = Utc::now();
|
||||
|
||||
sqlx::query(
|
||||
sqlx::query_as::<_, NotificationBlock>(
|
||||
"INSERT INTO notification_block \
|
||||
(id, user_id, workspace_id, repo_id, target_type, target_id, notification_type, channel, reason, expires_at, created_at, updated_at) \
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $11)",
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $11) \
|
||||
RETURNING id, user_id, workspace_id, repo_id, target_type, target_id, notification_type, \
|
||||
channel, reason, expires_at, created_at, updated_at",
|
||||
)
|
||||
.bind(id)
|
||||
.bind(user_id)
|
||||
@@ -97,15 +99,9 @@ impl NotificationService {
|
||||
.bind(params.reason)
|
||||
.bind(params.expires_at)
|
||||
.bind(now)
|
||||
.execute(self.ctx.db.writer())
|
||||
.fetch_one(self.ctx.db.writer())
|
||||
.await
|
||||
.map_err(AppError::Database)?;
|
||||
|
||||
NotificationBlock::find_by_id(self.ctx.db.reader(), id, user_id)
|
||||
.await?
|
||||
.ok_or(AppError::InternalServerError(
|
||||
"failed to fetch created block".into(),
|
||||
))
|
||||
.map_err(AppError::Database)
|
||||
}
|
||||
|
||||
pub async fn delete_block(&self, session: &Session, block_id: Uuid) -> Result<(), AppError> {
|
||||
|
||||
+14
-16
@@ -34,21 +34,20 @@ impl NotificationService {
|
||||
let user_id = session.user().ok_or(AppError::Unauthorized)?;
|
||||
let now = Utc::now();
|
||||
|
||||
sqlx::query(
|
||||
sqlx::query_as::<_, Notification>(
|
||||
"UPDATE notification SET read_at = $1, updated_at = $2 \
|
||||
WHERE id = $3 AND user_id = $4 AND deleted_at IS NULL",
|
||||
WHERE id = $3 AND user_id = $4 AND deleted_at IS NULL \
|
||||
RETURNING id, user_id, notification_type, target_type, target_id, title, body, \
|
||||
action_url, action_text, read_at, dismissed_at, created_at, updated_at, deleted_at",
|
||||
)
|
||||
.bind(now)
|
||||
.bind(now)
|
||||
.bind(notification_id)
|
||||
.bind(user_id)
|
||||
.execute(self.ctx.db.writer())
|
||||
.fetch_optional(self.ctx.db.writer())
|
||||
.await
|
||||
.map_err(AppError::Database)?;
|
||||
|
||||
Notification::find_by_id(self.ctx.db.reader(), notification_id, user_id)
|
||||
.await?
|
||||
.ok_or(AppError::NotFound("notification not found".into()))
|
||||
.map_err(AppError::Database)?
|
||||
.ok_or(AppError::NotFound("notification not found".into()))
|
||||
}
|
||||
|
||||
pub async fn mark_all_as_read(&self, session: &Session) -> Result<i64, AppError> {
|
||||
@@ -77,21 +76,20 @@ impl NotificationService {
|
||||
let user_id = session.user().ok_or(AppError::Unauthorized)?;
|
||||
let now = Utc::now();
|
||||
|
||||
sqlx::query(
|
||||
sqlx::query_as::<_, Notification>(
|
||||
"UPDATE notification SET dismissed_at = $1, updated_at = $2 \
|
||||
WHERE id = $3 AND user_id = $4 AND deleted_at IS NULL",
|
||||
WHERE id = $3 AND user_id = $4 AND deleted_at IS NULL \
|
||||
RETURNING id, user_id, notification_type, target_type, target_id, title, body, \
|
||||
action_url, action_text, read_at, dismissed_at, created_at, updated_at, deleted_at",
|
||||
)
|
||||
.bind(now)
|
||||
.bind(now)
|
||||
.bind(notification_id)
|
||||
.bind(user_id)
|
||||
.execute(self.ctx.db.writer())
|
||||
.fetch_optional(self.ctx.db.writer())
|
||||
.await
|
||||
.map_err(AppError::Database)?;
|
||||
|
||||
Notification::find_by_id(self.ctx.db.reader(), notification_id, user_id)
|
||||
.await?
|
||||
.ok_or(AppError::NotFound("notification not found".into()))
|
||||
.map_err(AppError::Database)?
|
||||
.ok_or(AppError::NotFound("notification not found".into()))
|
||||
}
|
||||
|
||||
pub async fn delete_notification(
|
||||
|
||||
@@ -9,7 +9,7 @@ use uuid::Uuid;
|
||||
|
||||
use super::util::clamp_limit_offset;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[derive(Debug, Deserialize, Serialize, utoipa::ToSchema)]
|
||||
pub struct CreateSubscriptionParams {
|
||||
pub workspace_id: Option<Uuid>,
|
||||
pub repo_id: Option<Uuid>,
|
||||
@@ -20,7 +20,7 @@ pub struct CreateSubscriptionParams {
|
||||
pub level: SubscriptionLevel,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[derive(Debug, Deserialize, Serialize, utoipa::ToSchema)]
|
||||
pub struct UpdateSubscriptionParams {
|
||||
pub event_types: Option<Vec<EventType>>,
|
||||
pub channels: Option<Vec<String>>,
|
||||
@@ -89,10 +89,12 @@ impl NotificationService {
|
||||
let id = Uuid::now_v7();
|
||||
let now = Utc::now();
|
||||
|
||||
sqlx::query(
|
||||
sqlx::query_as::<_, NotificationSubscription>(
|
||||
"INSERT INTO notification_subscription \
|
||||
(id, user_id, workspace_id, repo_id, target_type, target_id, event_types, channels, level, muted, muted_until, created_at, updated_at) \
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, false, NULL, $10, $10)",
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, false, NULL, $10, $10) \
|
||||
RETURNING id, user_id, workspace_id, repo_id, target_type, target_id, event_types, \
|
||||
channels, level, muted, muted_until, created_at, updated_at",
|
||||
)
|
||||
.bind(id)
|
||||
.bind(user_id)
|
||||
@@ -104,15 +106,9 @@ impl NotificationService {
|
||||
.bind(¶ms.channels)
|
||||
.bind(params.level.as_str())
|
||||
.bind(now)
|
||||
.execute(self.ctx.db.writer())
|
||||
.fetch_one(self.ctx.db.writer())
|
||||
.await
|
||||
.map_err(AppError::Database)?;
|
||||
|
||||
NotificationSubscription::find_by_id(self.ctx.db.reader(), id, user_id)
|
||||
.await?
|
||||
.ok_or(AppError::InternalServerError(
|
||||
"failed to fetch created subscription".into(),
|
||||
))
|
||||
.map_err(AppError::Database)
|
||||
}
|
||||
|
||||
pub async fn update_subscription(
|
||||
|
||||
@@ -9,7 +9,7 @@ use uuid::Uuid;
|
||||
|
||||
use super::util::clamp_limit_offset;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[derive(Debug, Deserialize, Serialize, utoipa::ToSchema)]
|
||||
pub struct CreateTemplateParams {
|
||||
pub key: String,
|
||||
pub notification_type: NotificationType,
|
||||
@@ -22,7 +22,7 @@ pub struct CreateTemplateParams {
|
||||
pub enabled: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[derive(Debug, Deserialize, Serialize, utoipa::ToSchema)]
|
||||
pub struct UpdateTemplateParams {
|
||||
pub subject_template: Option<String>,
|
||||
pub title_template: Option<String>,
|
||||
@@ -115,11 +115,13 @@ impl NotificationService {
|
||||
let id = Uuid::now_v7();
|
||||
let now = chrono::Utc::now();
|
||||
|
||||
sqlx::query(
|
||||
sqlx::query_as::<_, NotificationTemplate>(
|
||||
"INSERT INTO notification_template \
|
||||
(id, key, notification_type, channel, locale, subject_template, title_template, \
|
||||
body_template, action_text_template, enabled, created_by, created_at, updated_at) \
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $12)",
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $12) \
|
||||
RETURNING id, key, notification_type, channel, locale, subject_template, title_template, \
|
||||
body_template, action_text_template, enabled, created_by, created_at, updated_at",
|
||||
)
|
||||
.bind(id)
|
||||
.bind(¶ms.key)
|
||||
@@ -133,15 +135,9 @@ impl NotificationService {
|
||||
.bind(params.enabled)
|
||||
.bind(user_id)
|
||||
.bind(now)
|
||||
.execute(self.ctx.db.writer())
|
||||
.fetch_one(self.ctx.db.writer())
|
||||
.await
|
||||
.map_err(AppError::Database)?;
|
||||
|
||||
NotificationTemplate::find_by_id(self.ctx.db.reader(), id)
|
||||
.await?
|
||||
.ok_or(AppError::InternalServerError(
|
||||
"failed to fetch created template".into(),
|
||||
))
|
||||
.map_err(AppError::Database)
|
||||
}
|
||||
|
||||
pub async fn update_template(
|
||||
|
||||
Reference in New Issue
Block a user