feat: enhance database configuration and media handling with PostgreSQL integration and storage quota management
This commit is contained in:
@@ -7,6 +7,8 @@ use libertas_core::{
|
||||
use sqlx::PgPool;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::db_models::PostgresAlbum;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct PostgresAlbumRepository {
|
||||
pool: PgPool,
|
||||
@@ -42,8 +44,8 @@ impl AlbumRepository for PostgresAlbumRepository {
|
||||
}
|
||||
|
||||
async fn find_by_id(&self, id: Uuid) -> CoreResult<Option<Album>> {
|
||||
sqlx::query_as!(
|
||||
Album,
|
||||
let pg_album = sqlx::query_as!(
|
||||
PostgresAlbum,
|
||||
r#"
|
||||
SELECT id, owner_id, name, description, is_public, created_at, updated_at
|
||||
FROM albums
|
||||
@@ -53,12 +55,13 @@ impl AlbumRepository for PostgresAlbumRepository {
|
||||
)
|
||||
.fetch_optional(&self.pool)
|
||||
.await
|
||||
.map_err(|e| CoreError::Database(e.to_string()))
|
||||
.map_err(|e| CoreError::Database(e.to_string()))?;
|
||||
Ok(pg_album.map(|a| a.into()))
|
||||
}
|
||||
|
||||
async fn list_by_user(&self, user_id: Uuid) -> CoreResult<Vec<Album>> {
|
||||
sqlx::query_as!(
|
||||
Album,
|
||||
let pg_albums = sqlx::query_as!(
|
||||
PostgresAlbum,
|
||||
r#"
|
||||
SELECT id, owner_id, name, description, is_public, created_at, updated_at
|
||||
FROM albums
|
||||
@@ -68,7 +71,9 @@ impl AlbumRepository for PostgresAlbumRepository {
|
||||
)
|
||||
.fetch_all(&self.pool)
|
||||
.await
|
||||
.map_err(|e| CoreError::Database(e.to_string()))
|
||||
.map_err(|e| CoreError::Database(e.to_string()))?;
|
||||
|
||||
Ok(pg_albums.into_iter().map(|a| a.into()).collect())
|
||||
}
|
||||
|
||||
async fn add_media_to_album(&self, album_id: Uuid, media_ids: &[Uuid]) -> CoreResult<()> {
|
||||
|
||||
Reference in New Issue
Block a user