use serde::Deserialize; #[derive(Debug, Clone, PartialEq, Eq)] pub enum Role { User, Admin, } impl Role { pub fn as_str(&self) -> &'static str { match self { Role::User => "user", Role::Admin => "admin", } } } impl From<&str> for Role { fn from(s: &str) -> Self { match s { "admin" => Role::Admin, _ => Role::User, } } } #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum MediaMetadataSource { Exif, TrackInfo, } impl MediaMetadataSource { pub fn as_str(&self) -> &'static str { match self { MediaMetadataSource::Exif => "exif", MediaMetadataSource::TrackInfo => "track_info", } } } impl From<&str> for MediaMetadataSource { fn from(s: &str) -> Self { match s { "track_info" => MediaMetadataSource::TrackInfo, _ => MediaMetadataSource::Exif, } } } pub struct Media { pub id: uuid::Uuid, pub owner_id: uuid::Uuid, pub storage_path: String, pub original_filename: String, pub mime_type: String, pub hash: String, pub created_at: chrono::DateTime, pub thumbnail_path: Option, } pub struct MediaMetadata { pub id: uuid::Uuid, pub media_id: uuid::Uuid, pub source: MediaMetadataSource, pub tag_name: String, pub tag_value: String, } #[derive(Clone)] pub struct User { pub id: uuid::Uuid, pub username: String, pub email: String, pub hashed_password: String, pub created_at: chrono::DateTime, pub updated_at: chrono::DateTime, pub role: Role, pub storage_quota: i64, // in bytes pub storage_used: i64, // in bytes } #[derive(Clone)] pub struct Album { pub id: uuid::Uuid, pub owner_id: uuid::Uuid, pub name: String, pub description: Option, pub is_public: bool, pub created_at: chrono::DateTime, pub updated_at: chrono::DateTime, } #[derive(Clone, Debug)] pub struct Person { pub id: uuid::Uuid, pub owner_id: uuid::Uuid, pub name: String, pub thumbnail_media_id: Option, } #[derive(Clone, Debug)] pub struct FaceRegion { pub id: uuid::Uuid, pub media_id: uuid::Uuid, pub person_id: Option, pub x_min: f32, pub y_min: f32, pub x_max: f32, pub y_max: f32, } pub struct AlbumMedia { pub album_id: uuid::Uuid, pub media_id: uuid::Uuid, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)] pub enum AlbumPermission { View, Contribute, } impl AlbumPermission { pub fn as_str(&self) -> &'static str { match self { AlbumPermission::View => "view", AlbumPermission::Contribute => "contribute", } } } impl From<&str> for AlbumPermission { fn from(s: &str) -> Self { match s { "contribute" => AlbumPermission::Contribute, _ => AlbumPermission::View, } } } pub struct AlbumShare { pub album_id: uuid::Uuid, pub user_id: uuid::Uuid, pub permission: AlbumPermission, } pub struct MediaBundle { pub media: Media, pub metadata: Vec, } #[derive(Clone, Debug)] pub struct Tag { pub id: uuid::Uuid, pub name: String, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)] pub enum PersonPermission { View, CanUse, } impl PersonPermission { pub fn as_str(&self) -> &'static str { match self { PersonPermission::View => "view", PersonPermission::CanUse => "can_use", } } } impl From<&str> for PersonPermission { fn from(s: &str) -> Self { match s { "can_use" => PersonPermission::CanUse, _ => PersonPermission::View, } } } pub struct PersonShare { pub person_id: uuid::Uuid, pub user_id: uuid::Uuid, pub permission: PersonPermission, }