Files
libertas/libertas_infra/src/db_models.rs

128 lines
2.9 KiB
Rust

use chrono::Utc;
use serde::Deserialize;
use uuid::Uuid;
#[derive(Debug, Clone, PartialEq, Eq, sqlx::Type)]
#[sqlx(rename_all = "lowercase")]
#[sqlx(type_name = "TEXT")]
pub enum PostgresRole {
User,
Admin,
}
#[derive(Debug, Clone, PartialEq, Eq, sqlx::Type)]
#[sqlx(rename_all = "lowercase")]
#[sqlx(type_name = "TEXT")]
pub enum PostgresMediaMetadataSource {
Exif,
TrackInfo,
}
#[derive(sqlx::FromRow)]
pub struct PostgresUser {
pub id: Uuid,
pub username: String,
pub email: String,
pub hashed_password: String,
pub created_at: chrono::DateTime<Utc>,
pub updated_at: chrono::DateTime<Utc>,
pub role: String,
pub storage_quota: i64,
pub storage_used: i64,
}
#[derive(sqlx::FromRow)]
pub struct PostgresAlbum {
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(sqlx::FromRow)]
pub struct PostgresMedia {
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 date_taken: Option<chrono::DateTime<chrono::Utc>>,
}
#[derive(sqlx::FromRow)]
pub struct PostgresMediaMetadata {
pub id: uuid::Uuid,
pub media_id: uuid::Uuid,
pub source: String,
pub tag_name: String,
pub tag_value: String,
}
#[derive(Debug, Clone, Copy, sqlx::Type, PartialEq, Eq, Deserialize)]
#[sqlx(rename_all = "lowercase")]
#[sqlx(type_name = "album_permission")]
pub enum PostgresAlbumPermission {
View,
Contribute,
}
pub struct PostgresAlbumShare {
pub album_id: uuid::Uuid,
pub user_id: uuid::Uuid,
pub permission: PostgresAlbumPermission,
}
#[derive(sqlx::FromRow)]
pub struct PostgresTag {
pub id: uuid::Uuid,
pub name: String,
}
#[derive(sqlx::FromRow)]
pub struct PostgresPerson {
pub id: uuid::Uuid,
pub owner_id: uuid::Uuid,
pub name: String,
}
#[derive(sqlx::FromRow)]
pub struct PostgresFaceRegion {
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,
}
#[derive(Debug, Clone, Copy, sqlx::Type, PartialEq, Eq, Deserialize)]
#[sqlx(rename_all = "lowercase")]
#[sqlx(type_name = "person_permission")]
pub enum PostgresPersonPermission {
View,
CanUse,
}
#[derive(sqlx::FromRow)]
pub struct PostgresPersonShared {
pub id: Uuid,
pub owner_id: Uuid,
pub name: String,
pub permission: PostgresPersonPermission,
}
#[derive(sqlx::FromRow)]
pub struct PostgresFaceEmbedding {
pub id: Uuid,
pub face_region_id: Uuid,
pub model_id: i16,
pub embedding: Vec<u8>,
}