1use candid::CandidType;
2use serde::{Deserialize, Serialize};
3use std::collections::BTreeSet;
4
5use crate::file::valid_file_name;
6
7#[derive(CandidType, Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
8pub struct FolderInfo {
9 pub id: u32,
10 pub parent: u32, pub name: String,
12 pub created_at: u64, pub updated_at: u64, pub status: i8, pub files: BTreeSet<u32>, pub folders: BTreeSet<u32>, }
18
19#[derive(CandidType, Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
20pub struct FolderName {
21 pub id: u32,
22 pub name: String,
23}
24
25#[derive(CandidType, Clone, Debug, Default, Deserialize, Serialize)]
26pub struct CreateFolderInput {
27 pub parent: u32,
28 pub name: String,
29}
30
31impl CreateFolderInput {
32 pub fn validate(&self) -> Result<(), String> {
33 if !valid_file_name(&self.name) {
34 return Err("invalid folder name".to_string());
35 }
36
37 Ok(())
38 }
39}
40
41#[derive(CandidType, Clone, Debug, Default, Deserialize, Serialize)]
42pub struct CreateFolderOutput {
43 pub id: u32,
44 pub created_at: u64,
45}
46
47#[derive(CandidType, Clone, Debug, Default, Deserialize, Serialize)]
48pub struct UpdateFolderInput {
49 pub id: u32,
50 pub name: Option<String>,
51 pub status: Option<i8>, }
53
54impl UpdateFolderInput {
55 pub fn validate(&self) -> Result<(), String> {
56 if let Some(name) = &self.name {
57 if !valid_file_name(name) {
58 return Err("invalid folder name".to_string());
59 }
60 }
61
62 if let Some(status) = self.status {
63 if !(-1i8..=1i8).contains(&status) {
64 return Err("status should be -1, 0 or 1".to_string());
65 }
66 }
67 Ok(())
68 }
69}
70
71#[derive(CandidType, Clone, Debug, Default, Deserialize, Serialize)]
72pub struct UpdateFolderOutput {
73 pub updated_at: u64,
74}