- Added `Person` and `Tag` models to the core library. - Created `PersonService` and `TagService` traits with implementations for managing persons and tags. - Introduced repositories for `Person`, `Tag`, `FaceRegion`, and `PersonShare` with PostgreSQL support. - Updated authorization logic to include permissions for accessing and editing persons. - Enhanced the schema to support new models and relationships. - Implemented database migrations for new tables related to persons and tags. - Added request and response structures for API interactions with persons and tags.
191 lines
3.9 KiB
Rust
191 lines
3.9 KiB
Rust
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<chrono::Utc>,
|
|
pub thumbnail_path: Option<String>,
|
|
}
|
|
|
|
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<chrono::Utc>,
|
|
pub updated_at: chrono::DateTime<chrono::Utc>,
|
|
|
|
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<String>,
|
|
pub is_public: bool,
|
|
pub created_at: chrono::DateTime<chrono::Utc>,
|
|
pub updated_at: chrono::DateTime<chrono::Utc>,
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct Person {
|
|
pub id: uuid::Uuid,
|
|
pub owner_id: uuid::Uuid,
|
|
pub name: String,
|
|
pub thumbnail_media_id: Option<uuid::Uuid>,
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct FaceRegion {
|
|
pub id: uuid::Uuid,
|
|
pub media_id: uuid::Uuid,
|
|
pub person_id: Option<uuid::Uuid>,
|
|
|
|
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<MediaMetadata>,
|
|
}
|
|
|
|
#[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,
|
|
} |