This commit is contained in:
Andras Schmelczer 2024-12-08 14:25:12 +00:00
parent c576287eea
commit 3f5409da60
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
2 changed files with 97 additions and 0 deletions

View file

@ -0,0 +1,82 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use sync_lib::bytes_to_base64;
pub type VaultId = String;
pub type DocumentId = uuid::Uuid;
pub type DocumentVersionId = i64;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StoredDocumentVersion {
pub vault_id: VaultId,
pub document_id: DocumentId,
pub version_id: DocumentVersionId,
pub created_date: DateTime<Utc>,
pub updated_date: DateTime<Utc>,
pub relative_path: String,
pub content: Vec<u8>,
pub is_binary: bool,
pub is_deleted: bool,
}
impl StoredDocumentVersion {
pub fn content_as_string(&self) -> String {
String::from_utf8_lossy(&self.content).to_string()
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DocumentVersionWithoutContent {
pub vault_id: VaultId,
pub document_id: DocumentId,
pub version_id: DocumentVersionId,
pub created_date: DateTime<Utc>,
pub updated_date: DateTime<Utc>,
pub relative_path: String,
pub is_binary: bool,
pub is_deleted: bool,
}
impl From<StoredDocumentVersion> for DocumentVersionWithoutContent {
fn from(value: StoredDocumentVersion) -> Self {
Self {
vault_id: value.vault_id,
document_id: value.document_id,
version_id: value.version_id,
created_date: value.created_date,
updated_date: value.updated_date,
relative_path: value.relative_path,
is_binary: value.is_binary,
is_deleted: value.is_deleted,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DocumentVersion {
pub vault_id: VaultId,
pub document_id: DocumentId,
pub version_id: DocumentVersionId,
pub created_date: DateTime<Utc>,
pub updated_date: DateTime<Utc>,
pub relative_path: String,
pub content_base64: String,
pub is_binary: bool,
pub is_deleted: bool,
}
impl From<StoredDocumentVersion> for DocumentVersion {
fn from(value: StoredDocumentVersion) -> Self {
Self {
vault_id: value.vault_id,
document_id: value.document_id,
version_id: value.version_id,
created_date: value.created_date,
updated_date: value.updated_date,
relative_path: value.relative_path,
content_base64: bytes_to_base64(&value.content),
is_binary: value.is_binary,
is_deleted: value.is_deleted,
}
}
}

View file

@ -0,0 +1,15 @@
use chrono::{DateTime, Utc};
use serde::Deserialize;
#[derive(Debug, Deserialize)]
pub struct CreateDocumentVersion {
pub created_date: DateTime<Utc>,
pub relative_path: String,
pub content_base64: String,
pub is_binary: bool,
}
#[derive(Debug, Deserialize)]
pub struct DeleteDocumentVersion {
pub created_date: DateTime<Utc>,
}