use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use sqlx::FromRow;
use uuid::Uuid;
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct UploadSessionProjection {
pub id: Uuid,
pub bucket_id: Uuid,
pub user_id: Uuid,
pub path: String,
pub filename: String,
pub mime_type: Option<String>,
pub file_size: i64,
pub chunk_size: i32,
pub total_chunks: i32,
pub uploaded_chunks: i32,
pub status: UploadStatus,
pub storage_backend: StorageBackend,
pub completed_parts: Vec<i32>,
pub part_etags: Option<serde_json::Value>,
pub expires_at: DateTime<Utc>,
pub metadata: serde_json::Value,
pub projection_version: i64,
pub last_event_sequence: i64,
pub projection_updated_at: DateTime<Utc>,
}
impl UploadSessionProjection {
pub fn new(
id: Uuid,
bucket_id: Uuid,
user_id: Uuid,
path: String,
filename: String,
mime_type: Option<String>,
file_size: i64,
chunk_size: i32,
total_chunks: i32,
uploaded_chunks: i32,
status: UploadStatus,
storage_backend: StorageBackend,
completed_parts: Vec<i32>,
part_etags: Option<serde_json::Value>,
expires_at: DateTime<Utc>,
metadata: serde_json::Value
) -> Self {
Self {
id,
bucket_id,
user_id,
path,
filename,
mime_type,
file_size,
chunk_size,
total_chunks,
uploaded_chunks,
status,
storage_backend,
completed_parts,
part_etags,
expires_at,
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 UploadSessionSummary {
pub id: Uuid,
pub status: UploadStatus,
}