Files
libertas/libertas_core/src/repositories.rs

40 lines
1.4 KiB
Rust

use async_trait::async_trait;
use uuid::Uuid;
use crate::{
error::CoreResult,
models::{Album, 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>,
) -> 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<()>;
}