2025-03-17 21:28:08 +01:00
|
|
|
use crate::domain::entities::folder::Folder;
|
2026-02-14 01:29:34 +01:00
|
|
|
use serde::{Deserialize, Serialize};
|
2025-03-17 21:28:08 +01:00
|
|
|
|
|
|
|
|
/// DTO for folder creation requests
|
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
|
pub struct CreateFolderDto {
|
|
|
|
|
/// Name of the folder to create
|
|
|
|
|
pub name: String,
|
2026-02-14 01:29:34 +01:00
|
|
|
|
2025-03-17 21:28:08 +01:00
|
|
|
/// Parent folder ID (None for root level)
|
|
|
|
|
pub parent_id: Option<String>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// DTO for folder rename requests
|
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
|
pub struct RenameFolderDto {
|
|
|
|
|
/// New name for the folder
|
|
|
|
|
pub name: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// DTO for folder move requests
|
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
|
pub struct MoveFolderDto {
|
|
|
|
|
/// New parent folder ID (None for root level)
|
|
|
|
|
pub parent_id: Option<String>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// DTO for folder responses
|
2025-03-27 01:13:34 +01:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
2025-03-17 21:28:08 +01:00
|
|
|
pub struct FolderDto {
|
|
|
|
|
/// Folder ID
|
|
|
|
|
pub id: String,
|
2026-02-14 01:29:34 +01:00
|
|
|
|
2025-03-17 21:28:08 +01:00
|
|
|
/// Folder name
|
|
|
|
|
pub name: String,
|
2026-02-14 01:29:34 +01:00
|
|
|
|
2025-03-17 21:28:08 +01:00
|
|
|
/// Path to the folder (relative)
|
|
|
|
|
pub path: String,
|
2026-02-14 01:29:34 +01:00
|
|
|
|
2025-03-17 21:28:08 +01:00
|
|
|
/// Parent folder ID
|
|
|
|
|
pub parent_id: Option<String>,
|
2026-02-14 01:29:34 +01:00
|
|
|
|
2025-03-17 21:28:08 +01:00
|
|
|
/// Creation timestamp
|
|
|
|
|
pub created_at: u64,
|
2026-02-14 01:29:34 +01:00
|
|
|
|
2025-03-17 21:28:08 +01:00
|
|
|
/// Last modification timestamp
|
|
|
|
|
pub modified_at: u64,
|
2026-02-14 01:29:34 +01:00
|
|
|
|
2025-03-17 21:28:08 +01:00
|
|
|
/// Whether this is a root folder
|
|
|
|
|
pub is_root: bool,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<Folder> for FolderDto {
|
|
|
|
|
fn from(folder: Folder) -> Self {
|
2025-03-19 00:44:27 +01:00
|
|
|
let is_root = folder.parent_id().is_none();
|
2026-02-14 01:29:34 +01:00
|
|
|
|
2025-03-17 21:28:08 +01:00
|
|
|
Self {
|
2025-03-19 00:44:27 +01:00
|
|
|
id: folder.id().to_string(),
|
|
|
|
|
name: folder.name().to_string(),
|
|
|
|
|
path: folder.path_string().to_string(),
|
|
|
|
|
parent_id: folder.parent_id().map(String::from),
|
|
|
|
|
created_at: folder.created_at(),
|
|
|
|
|
modified_at: folder.modified_at(),
|
2025-03-17 21:28:08 +01:00
|
|
|
is_root,
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-19 00:44:27 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-12 09:41:25 +01:00
|
|
|
// To convert from FolderDto to Folder for batch handlers
|
2025-03-19 00:44:27 +01:00
|
|
|
impl From<FolderDto> for Folder {
|
|
|
|
|
fn from(dto: FolderDto) -> Self {
|
2026-02-12 09:41:25 +01:00
|
|
|
// Use constructor to create an entity from DTO
|
|
|
|
|
// Note: this should be simplified if Folder has a proper constructor
|
2025-03-19 00:44:27 +01:00
|
|
|
Folder::from_dto(
|
|
|
|
|
dto.id,
|
|
|
|
|
dto.name,
|
|
|
|
|
dto.path,
|
|
|
|
|
dto.parent_id,
|
|
|
|
|
dto.created_at,
|
2026-02-14 01:29:34 +01:00
|
|
|
dto.modified_at,
|
2025-03-19 00:44:27 +01:00
|
|
|
)
|
|
|
|
|
}
|
2025-03-20 09:22:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl FolderDto {
|
|
|
|
|
/// Creates an empty folder DTO for stub implementations
|
|
|
|
|
pub fn empty() -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
id: "stub-id".to_string(),
|
|
|
|
|
name: "stub-folder".to_string(),
|
|
|
|
|
path: "/stub/path".to_string(),
|
|
|
|
|
parent_id: None,
|
|
|
|
|
created_at: 0,
|
|
|
|
|
modified_at: 0,
|
|
|
|
|
is_root: true,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for FolderDto {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Self::empty()
|
|
|
|
|
}
|
2026-02-14 01:29:34 +01:00
|
|
|
}
|