use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use sqlx::FromRow;
use uuid::Uuid;
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct FileCommentProjection {
pub id: Uuid,
pub file_id: Uuid,
pub user_id: Uuid,
pub parent_id: Option<Uuid>,
pub content: String,
pub annotation_region: Option<serde_json::Value>,
pub mentions: Vec<Uuid>,
pub resolved: bool,
pub resolved_by: Option<Uuid>,
pub resolved_at: Option<DateTime<Utc>>,
pub status: CommentStatus,
pub metadata: serde_json::Value,
pub projection_version: i64,
pub last_event_sequence: i64,
pub projection_updated_at: DateTime<Utc>,
}
impl FileCommentProjection {
pub fn new(
id: Uuid,
file_id: Uuid,
user_id: Uuid,
parent_id: Option<Uuid>,
content: String,
annotation_region: Option<serde_json::Value>,
mentions: Vec<Uuid>,
resolved: bool,
resolved_by: Option<Uuid>,
resolved_at: Option<DateTime<Utc>>,
status: CommentStatus,
metadata: serde_json::Value
) -> Self {
Self {
id,
file_id,
user_id,
parent_id,
content,
annotation_region,
mentions,
resolved,
resolved_by,
resolved_at,
status,
metadata,
projection_version: 1,
last_event_sequence: 0,
projection_updated_at: Utc::now(),
}
}
pub fn id(&self) -> &Uuid {
&self.id
}
pub fn apply_event(&mut self, event_sequence: i64) {
self.projection_version += 1;
self.last_event_sequence = event_sequence;
self.projection_updated_at = Utc::now();
}
}
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct FileCommentSummary {
pub id: Uuid,
pub status: CommentStatus,
}