lb_rs/model/
file.rs

1use super::account::Username;
2use super::file_metadata::FileType;
3use serde::{Deserialize, Serialize};
4use std::fmt;
5use std::str::FromStr;
6use uuid::Uuid;
7
8#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Hash, Clone, Copy)]
9#[repr(C)]
10pub enum ShareMode {
11    Write,
12    Read,
13}
14
15impl FromStr for ShareMode {
16    type Err = ();
17
18    fn from_str(s: &str) -> Result<Self, Self::Err> {
19        match s {
20            "Write" => Ok(ShareMode::Write),
21            "Read" => Ok(ShareMode::Read),
22            _ => Err(()),
23        }
24    }
25}
26
27impl fmt::Display for ShareMode {
28    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
29        write!(f, "{self:?}")
30    }
31}
32
33#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Hash, Clone)]
34pub struct Share {
35    pub mode: ShareMode,
36    pub shared_by: Username,
37    pub shared_with: Username,
38}
39
40#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash)]
41pub struct File {
42    pub id: Uuid,
43    pub parent: Uuid,
44    pub name: String,
45    pub file_type: FileType,
46    pub last_modified: u64,
47    /// Note: not yet populated
48    pub last_modified_by: Username,
49    pub shares: Vec<Share>,
50}
51
52impl File {
53    pub fn is_document(&self) -> bool {
54        self.file_type == FileType::Document
55    }
56
57    pub fn is_folder(&self) -> bool {
58        self.file_type == FileType::Folder
59    }
60
61    pub fn is_root(&self) -> bool {
62        self.id == self.parent
63    }
64}