9eb77ab98b
- Update channel, notification, PR, repo, user, workspace models - Remove deleted IM models: articles, channel follows, message attachments/bookmarks/drafts/edit history/embeds/mentions/pins/ polls/reactions/threads, saved messages, thread read states - Add new PR models: review requests, templates - Add repo release assets model - Add base_info module for API detail responses
95 lines
3.2 KiB
Rust
95 lines
3.2 KiB
Rust
use crate::models::base_info::{RepoBaseInfo, UserBaseInfo, WorkspaceBaseInfo};
|
|
use crate::models::common::{NotificationType, Priority, TargetType};
|
|
use crate::models::json_types::{NotificationMetadata, TypedJson};
|
|
use chrono::{DateTime, Utc};
|
|
use serde::{Deserialize, Serialize};
|
|
use uuid::Uuid;
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow, utoipa::ToSchema)]
|
|
pub struct Notification {
|
|
pub id: Uuid,
|
|
pub user_id: Uuid,
|
|
pub actor_id: Option<Uuid>,
|
|
pub workspace_id: Option<Uuid>,
|
|
pub repo_id: Option<Uuid>,
|
|
pub issue_id: Option<Uuid>,
|
|
pub pull_request_id: Option<Uuid>,
|
|
pub channel_id: Option<Uuid>,
|
|
pub message_id: Option<Uuid>,
|
|
pub notification_type: NotificationType,
|
|
pub title: String,
|
|
pub body: Option<String>,
|
|
pub target_type: Option<TargetType>,
|
|
pub target_id: Option<Uuid>,
|
|
pub action_url: Option<String>,
|
|
pub priority: Priority,
|
|
pub read_at: Option<DateTime<Utc>>,
|
|
pub dismissed_at: Option<DateTime<Utc>>,
|
|
#[schema(value_type = serde_json::Value)]
|
|
pub metadata: Option<TypedJson<NotificationMetadata>>,
|
|
pub created_at: DateTime<Utc>,
|
|
pub updated_at: DateTime<Utc>,
|
|
pub deleted_at: Option<DateTime<Utc>>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
|
|
pub struct NotificationDetail {
|
|
pub id: Uuid,
|
|
pub user_id: Uuid,
|
|
pub actor: Option<UserBaseInfo>,
|
|
pub workspace: Option<WorkspaceBaseInfo>,
|
|
pub repo: Option<RepoBaseInfo>,
|
|
pub issue_id: Option<Uuid>,
|
|
pub pull_request_id: Option<Uuid>,
|
|
pub channel_id: Option<Uuid>,
|
|
pub message_id: Option<Uuid>,
|
|
pub notification_type: NotificationType,
|
|
pub title: String,
|
|
pub body: Option<String>,
|
|
pub target_type: Option<TargetType>,
|
|
pub target_id: Option<Uuid>,
|
|
pub action_url: Option<String>,
|
|
pub priority: Priority,
|
|
pub read_at: Option<DateTime<Utc>>,
|
|
pub dismissed_at: Option<DateTime<Utc>>,
|
|
#[schema(value_type = serde_json::Value)]
|
|
pub metadata: Option<TypedJson<NotificationMetadata>>,
|
|
pub created_at: DateTime<Utc>,
|
|
pub updated_at: DateTime<Utc>,
|
|
pub deleted_at: Option<DateTime<Utc>>,
|
|
}
|
|
|
|
impl Notification {
|
|
pub fn into_detail(
|
|
self,
|
|
actor: Option<UserBaseInfo>,
|
|
workspace: Option<WorkspaceBaseInfo>,
|
|
repo: Option<RepoBaseInfo>,
|
|
) -> NotificationDetail {
|
|
NotificationDetail {
|
|
id: self.id,
|
|
user_id: self.user_id,
|
|
actor,
|
|
workspace,
|
|
repo,
|
|
issue_id: self.issue_id,
|
|
pull_request_id: self.pull_request_id,
|
|
channel_id: self.channel_id,
|
|
message_id: self.message_id,
|
|
notification_type: self.notification_type,
|
|
title: self.title,
|
|
body: self.body,
|
|
target_type: self.target_type,
|
|
target_id: self.target_id,
|
|
action_url: self.action_url,
|
|
priority: self.priority,
|
|
read_at: self.read_at,
|
|
dismissed_at: self.dismissed_at,
|
|
metadata: self.metadata,
|
|
created_at: self.created_at,
|
|
updated_at: self.updated_at,
|
|
deleted_at: self.deleted_at,
|
|
}
|
|
}
|
|
}
|