62 lines
2.1 KiB
Rust
62 lines
2.1 KiB
Rust
use async_trait::async_trait;
|
|
use uuid::Uuid;
|
|
|
|
use crate::{
|
|
error::CoreResult,
|
|
models::{Album, AlbumPermission, Media, User},
|
|
};
|
|
|
|
#[async_trait]
|
|
pub trait MediaRepository: Send + Sync {
|
|
async fn find_by_hash(&self, hash: &str) -> CoreResult<Option<Media>>;
|
|
async fn create(&self, media: &Media) -> CoreResult<()>;
|
|
async fn find_by_id(&self, id: Uuid) -> CoreResult<Option<Media>>;
|
|
async fn list_by_user(&self, user_id: Uuid) -> CoreResult<Vec<Media>>;
|
|
async fn update_metadata(
|
|
&self,
|
|
id: Uuid,
|
|
width: Option<i32>,
|
|
height: Option<i32>,
|
|
location: Option<String>,
|
|
date_taken: Option<chrono::DateTime<chrono::Utc>>,
|
|
) -> CoreResult<()>;
|
|
async fn delete(&self, id: Uuid) -> CoreResult<()>;
|
|
}
|
|
|
|
#[async_trait]
|
|
pub trait UserRepository: Send + Sync {
|
|
async fn create(&self, user: User) -> CoreResult<()>;
|
|
async fn find_by_email(&self, email: &str) -> CoreResult<Option<User>>;
|
|
async fn find_by_username(&self, username: &str) -> CoreResult<Option<User>>;
|
|
async fn find_by_id(&self, id: Uuid) -> CoreResult<Option<User>>;
|
|
async fn update_storage_used(&self, user_id: Uuid, bytes: i64) -> CoreResult<()>;
|
|
}
|
|
|
|
#[async_trait]
|
|
pub trait AlbumRepository: Send + Sync {
|
|
async fn create(&self, album: Album) -> CoreResult<()>;
|
|
async fn find_by_id(&self, id: Uuid) -> CoreResult<Option<Album>>;
|
|
async fn list_by_user(&self, user_id: Uuid) -> CoreResult<Vec<Album>>;
|
|
async fn add_media_to_album(&self, album_id: Uuid, media_ids: &[Uuid]) -> CoreResult<()>;
|
|
async fn update(&self, album: Album) -> CoreResult<()>;
|
|
async fn delete(&self, id: Uuid) -> CoreResult<()>;
|
|
}
|
|
|
|
#[async_trait]
|
|
pub trait AlbumShareRepository: Send + Sync {
|
|
async fn create_or_update_share(
|
|
&self,
|
|
album_id: Uuid,
|
|
user_id: Uuid,
|
|
permission: AlbumPermission,
|
|
) -> CoreResult<()>;
|
|
|
|
async fn get_user_permission(
|
|
&self,
|
|
album_id: Uuid,
|
|
user_id: Uuid,
|
|
) -> CoreResult<Option<AlbumPermission>>;
|
|
|
|
async fn is_media_in_shared_album(&self, media_id: Uuid, user_id: Uuid) -> CoreResult<bool>;
|
|
}
|