2025-03-27 01:13:34 +01:00
|
|
|
use serde::{Serialize, Deserialize};
|
2025-03-17 21:28:08 +01:00
|
|
|
use crate::domain::entities::file::File;
|
|
|
|
|
|
|
|
|
|
/// DTO for file responses
|
2025-03-27 01:13:34 +01:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
2025-03-17 21:28:08 +01:00
|
|
|
pub struct FileDto {
|
|
|
|
|
/// File ID
|
|
|
|
|
pub id: String,
|
|
|
|
|
|
|
|
|
|
/// File name
|
|
|
|
|
pub name: String,
|
|
|
|
|
|
|
|
|
|
/// Path to the file (relative)
|
|
|
|
|
pub path: String,
|
|
|
|
|
|
|
|
|
|
/// Size in bytes
|
|
|
|
|
pub size: u64,
|
|
|
|
|
|
|
|
|
|
/// MIME type
|
|
|
|
|
pub mime_type: String,
|
|
|
|
|
|
|
|
|
|
/// Parent folder ID
|
|
|
|
|
pub folder_id: Option<String>,
|
|
|
|
|
|
|
|
|
|
/// Creation timestamp
|
|
|
|
|
pub created_at: u64,
|
|
|
|
|
|
|
|
|
|
/// Last modification timestamp
|
|
|
|
|
pub modified_at: u64,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<File> for FileDto {
|
|
|
|
|
fn from(file: File) -> Self {
|
|
|
|
|
Self {
|
2025-03-19 00:44:27 +01:00
|
|
|
id: file.id().to_string(),
|
|
|
|
|
name: file.name().to_string(),
|
|
|
|
|
path: file.path_string().to_string(),
|
|
|
|
|
size: file.size(),
|
|
|
|
|
mime_type: file.mime_type().to_string(),
|
|
|
|
|
folder_id: file.folder_id().map(String::from),
|
|
|
|
|
created_at: file.created_at(),
|
|
|
|
|
modified_at: file.modified_at(),
|
2025-03-17 21:28:08 +01:00
|
|
|
}
|
|
|
|
|
}
|
2025-03-19 00:44:27 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-12 09:41:25 +01:00
|
|
|
// To convert from FileDto to File for batch handlers
|
2025-03-19 00:44:27 +01:00
|
|
|
impl From<FileDto> for File {
|
|
|
|
|
fn from(dto: FileDto) -> Self {
|
2026-02-12 09:41:25 +01:00
|
|
|
// Use constructor to create an entity from DTO
|
|
|
|
|
// Note: this should be simplified if File has a proper constructor
|
|
|
|
|
// If not, make the conversion as best as possible
|
2025-03-19 00:44:27 +01:00
|
|
|
File::from_dto(
|
|
|
|
|
dto.id,
|
|
|
|
|
dto.name,
|
|
|
|
|
dto.path,
|
|
|
|
|
dto.size,
|
|
|
|
|
dto.mime_type,
|
|
|
|
|
dto.folder_id,
|
|
|
|
|
dto.created_at,
|
|
|
|
|
dto.modified_at
|
|
|
|
|
)
|
|
|
|
|
}
|
2025-03-20 09:22:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl FileDto {
|
|
|
|
|
/// Creates an empty file DTO for stub implementations
|
|
|
|
|
pub fn empty() -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
id: "stub-id".to_string(),
|
|
|
|
|
name: "stub-file".to_string(),
|
|
|
|
|
path: "/stub/path".to_string(),
|
|
|
|
|
size: 0,
|
|
|
|
|
mime_type: "application/octet-stream".to_string(),
|
|
|
|
|
folder_id: None,
|
|
|
|
|
created_at: 0,
|
|
|
|
|
modified_at: 0,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for FileDto {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Self::empty()
|
|
|
|
|
}
|
2025-03-17 21:28:08 +01:00
|
|
|
}
|