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
|
|
|
|
2026-02-15 23:45:11 +01:00
|
|
|
/// Owner user ID (scopes visibility per user)
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
|
pub owner_id: Option<String>,
|
|
|
|
|
|
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,
|
2026-02-16 01:09:28 +01:00
|
|
|
|
|
|
|
|
// ── Pre-computed display fields ──
|
|
|
|
|
/// FontAwesome icon CSS class (always "fas fa-folder")
|
|
|
|
|
pub icon_class: String,
|
|
|
|
|
|
|
|
|
|
/// Extra CSS class for icon styling (always "folder-icon")
|
|
|
|
|
pub icon_special_class: String,
|
|
|
|
|
|
|
|
|
|
/// Human-readable category (always "Folder")
|
|
|
|
|
pub category: String,
|
2025-03-17 21:28:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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),
|
2026-02-15 23:45:11 +01:00
|
|
|
owner_id: folder.owner_id().map(String::from),
|
2025-03-19 00:44:27 +01:00
|
|
|
created_at: folder.created_at(),
|
|
|
|
|
modified_at: folder.modified_at(),
|
2025-03-17 21:28:08 +01:00
|
|
|
is_root,
|
2026-02-16 01:09:28 +01:00
|
|
|
icon_class: "fas fa-folder".to_string(),
|
|
|
|
|
icon_special_class: "folder-icon".to_string(),
|
|
|
|
|
category: "Folder".to_string(),
|
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 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-16 01:09:28 +01:00
|
|
|
// Display fields (icon_class, icon_special_class, category)
|
|
|
|
|
// are not part of the domain entity and are ignored.
|
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,
|
2026-02-15 23:45:11 +01:00
|
|
|
owner_id: None,
|
2025-03-20 09:22:31 +01:00
|
|
|
created_at: 0,
|
|
|
|
|
modified_at: 0,
|
|
|
|
|
is_root: true,
|
2026-02-16 01:09:28 +01:00
|
|
|
icon_class: "fas fa-folder".to_string(),
|
|
|
|
|
icon_special_class: "folder-icon".to_string(),
|
|
|
|
|
category: "Folder".to_string(),
|
2025-03-20 09:22:31 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for FolderDto {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Self::empty()
|
|
|
|
|
}
|
2026-02-14 01:29:34 +01:00
|
|
|
}
|