2025-03-24 16:47:42 +01:00
|
|
|
use chrono::{DateTime, Utc};
|
|
|
|
|
use uuid::Uuid;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
|
|
|
pub enum TrashedItemType {
|
|
|
|
|
File,
|
|
|
|
|
Folder,
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-18 22:02:00 +00:00
|
|
|
/// Owned decomposition of a [`TrashedItem`] (see
|
|
|
|
|
/// [`TrashedItem::into_parts`]).
|
|
|
|
|
pub struct TrashedItemParts {
|
|
|
|
|
pub id: Uuid,
|
|
|
|
|
pub original_id: Uuid,
|
|
|
|
|
pub item_type: TrashedItemType,
|
|
|
|
|
pub name: String,
|
|
|
|
|
pub original_path: String,
|
|
|
|
|
pub trashed_at: DateTime<Utc>,
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-18 22:46:20 +00:00
|
|
|
#[derive(Debug, Clone)]
|
2025-03-24 16:47:42 +01:00
|
|
|
pub struct TrashedItem {
|
2026-02-08 13:40:23 +01:00
|
|
|
id: Uuid,
|
|
|
|
|
original_id: Uuid,
|
|
|
|
|
user_id: Uuid,
|
|
|
|
|
item_type: TrashedItemType,
|
|
|
|
|
name: String,
|
|
|
|
|
original_path: String,
|
|
|
|
|
trashed_at: DateTime<Utc>,
|
|
|
|
|
deletion_date: DateTime<Utc>,
|
2025-03-24 16:47:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl TrashedItem {
|
|
|
|
|
pub fn new(
|
|
|
|
|
original_id: Uuid,
|
|
|
|
|
user_id: Uuid,
|
|
|
|
|
item_type: TrashedItemType,
|
|
|
|
|
name: String,
|
|
|
|
|
original_path: String,
|
|
|
|
|
retention_days: u32,
|
|
|
|
|
) -> Self {
|
|
|
|
|
let now = Utc::now();
|
|
|
|
|
Self {
|
|
|
|
|
id: Uuid::new_v4(),
|
|
|
|
|
original_id,
|
|
|
|
|
user_id,
|
|
|
|
|
item_type,
|
|
|
|
|
name,
|
|
|
|
|
original_path,
|
|
|
|
|
trashed_at: now,
|
|
|
|
|
deletion_date: now + chrono::Duration::days(retention_days as i64),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-15 17:53:25 +01:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2026-02-08 13:40:23 +01:00
|
|
|
pub fn from_raw(
|
|
|
|
|
id: Uuid,
|
|
|
|
|
original_id: Uuid,
|
|
|
|
|
user_id: Uuid,
|
|
|
|
|
item_type: TrashedItemType,
|
|
|
|
|
name: String,
|
|
|
|
|
original_path: String,
|
|
|
|
|
trashed_at: DateTime<Utc>,
|
|
|
|
|
deletion_date: DateTime<Utc>,
|
|
|
|
|
) -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
id,
|
|
|
|
|
original_id,
|
|
|
|
|
user_id,
|
|
|
|
|
item_type,
|
|
|
|
|
name,
|
|
|
|
|
original_path,
|
|
|
|
|
trashed_at,
|
|
|
|
|
deletion_date,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── Getters ──
|
|
|
|
|
|
|
|
|
|
pub fn id(&self) -> Uuid {
|
|
|
|
|
self.id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn original_id(&self) -> Uuid {
|
|
|
|
|
self.original_id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn user_id(&self) -> Uuid {
|
|
|
|
|
self.user_id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn item_type(&self) -> &TrashedItemType {
|
|
|
|
|
&self.item_type
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn name(&self) -> &str {
|
|
|
|
|
&self.name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn original_path(&self) -> &str {
|
|
|
|
|
&self.original_path
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn trashed_at(&self) -> DateTime<Utc> {
|
|
|
|
|
self.trashed_at
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn deletion_date(&self) -> DateTime<Utc> {
|
|
|
|
|
self.deletion_date
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-18 22:02:00 +00:00
|
|
|
/// Decompose into owned parts for DTO conversion — moves `name` /
|
|
|
|
|
/// `original_path` instead of the getter clones `to_dto` used to make
|
|
|
|
|
/// per trash row (benches/ROUND11.md; the File/Folder/Contact pattern).
|
|
|
|
|
pub fn into_parts(self) -> TrashedItemParts {
|
|
|
|
|
TrashedItemParts {
|
|
|
|
|
id: self.id,
|
|
|
|
|
original_id: self.original_id,
|
|
|
|
|
item_type: self.item_type,
|
|
|
|
|
name: self.name,
|
|
|
|
|
original_path: self.original_path,
|
|
|
|
|
trashed_at: self.trashed_at,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-24 16:47:42 +01:00
|
|
|
pub fn days_until_deletion(&self) -> i64 {
|
|
|
|
|
let now = Utc::now();
|
|
|
|
|
(self.deletion_date - now).num_days().max(0)
|
|
|
|
|
}
|
2026-02-14 01:29:34 +01:00
|
|
|
}
|