129 lines
4.6 KiB
Rust
129 lines
4.6 KiB
Rust
use async_trait::async_trait;
|
|
use uuid::Uuid;
|
|
|
|
use crate::{
|
|
error::CoreResult,
|
|
models::{
|
|
Album, AlbumPermission, FaceRegion, Media, MediaMetadata, Person, PersonPermission, Tag,
|
|
User,
|
|
},
|
|
schema::{ListMediaOptions, MediaImportBundle},
|
|
};
|
|
|
|
#[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,
|
|
options: &ListMediaOptions,
|
|
) -> CoreResult<Vec<Media>>;
|
|
async fn update_thumbnail_path(&self, id: Uuid, thumbnail_path: String) -> 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>;
|
|
async fn is_media_in_contributable_album(
|
|
&self,
|
|
media_id: Uuid,
|
|
user_id: Uuid,
|
|
) -> CoreResult<bool>;
|
|
}
|
|
|
|
#[async_trait]
|
|
pub trait MediaMetadataRepository: Send + Sync {
|
|
async fn create_batch(&self, metadata: &[MediaMetadata]) -> CoreResult<()>;
|
|
async fn find_by_media_id(&self, media_id: Uuid) -> CoreResult<Vec<MediaMetadata>>;
|
|
}
|
|
|
|
#[async_trait]
|
|
pub trait TagRepository: Send + Sync {
|
|
async fn find_or_create_tags(&self, tag_names: &[String]) -> CoreResult<Vec<Tag>>;
|
|
async fn add_tags_to_media(&self, media_id: Uuid, tag_ids: &[Uuid]) -> CoreResult<()>;
|
|
async fn remove_tags_from_media(&self, media_id: Uuid, tag_ids: &[Uuid]) -> CoreResult<()>;
|
|
async fn list_tags_for_media(&self, media_id: Uuid) -> CoreResult<Vec<Tag>>;
|
|
async fn find_tag_by_name(&self, name: &str) -> CoreResult<Option<Tag>>;
|
|
}
|
|
|
|
#[async_trait]
|
|
pub trait PersonRepository: Send + Sync {
|
|
async fn create(&self, person: Person) -> CoreResult<()>;
|
|
async fn find_by_id(&self, id: Uuid) -> CoreResult<Option<Person>>;
|
|
async fn list_by_user(&self, user_id: Uuid) -> CoreResult<Vec<Person>>;
|
|
async fn update(&self, person: Person) -> CoreResult<()>;
|
|
async fn delete(&self, id: Uuid) -> CoreResult<()>;
|
|
}
|
|
|
|
#[async_trait]
|
|
pub trait FaceRegionRepository: Send + Sync {
|
|
async fn create_batch(&self, face_regions: &[FaceRegion]) -> CoreResult<()>;
|
|
async fn find_by_media_id(&self, media_id: Uuid) -> CoreResult<Vec<FaceRegion>>;
|
|
async fn find_by_id(&self, face_region_id: Uuid) -> CoreResult<Option<FaceRegion>>;
|
|
async fn update_person_id(&self, face_region_id: Uuid, person_id: Uuid) -> CoreResult<()>;
|
|
async fn delete(&self, face_region_id: Uuid) -> CoreResult<()>;
|
|
}
|
|
|
|
#[async_trait]
|
|
pub trait PersonShareRepository: Send + Sync {
|
|
async fn create_or_update_share(
|
|
&self,
|
|
person_id: Uuid,
|
|
user_id: Uuid,
|
|
permission: PersonPermission,
|
|
) -> CoreResult<()>;
|
|
|
|
async fn remove_share(&self, person_id: Uuid, user_id: Uuid) -> CoreResult<()>;
|
|
|
|
async fn get_user_permission(
|
|
&self,
|
|
person_id: Uuid,
|
|
user_id: Uuid,
|
|
) -> CoreResult<Option<PersonPermission>>;
|
|
|
|
async fn list_people_shared_with_user(
|
|
&self,
|
|
user_id: Uuid,
|
|
) -> CoreResult<Vec<(Person, PersonPermission)>>;
|
|
}
|
|
|
|
#[async_trait]
|
|
pub trait MediaImportRepository: Send + Sync {
|
|
async fn create_media_bundle(&self, bundle: MediaImportBundle) -> CoreResult<()>;
|
|
}
|