feat: Implement media import functionality with repository and bundle support
This commit is contained in:
@@ -4,7 +4,7 @@ use libertas_core::{
|
||||
models::User,
|
||||
repositories::UserRepository,
|
||||
};
|
||||
use sqlx::{PgPool, SqlitePool, types::Uuid};
|
||||
use sqlx::{Executor, PgPool, Postgres, SqlitePool, types::Uuid};
|
||||
|
||||
use crate::db_models::PostgresUser;
|
||||
|
||||
@@ -17,6 +17,27 @@ impl PostgresUserRepository {
|
||||
pub fn new(pool: PgPool) -> Self {
|
||||
Self { pool }
|
||||
}
|
||||
|
||||
pub(crate) async fn update_storage_used_internal<'a>(
|
||||
exec: impl Executor<'a, Database = Postgres>,
|
||||
user_id: Uuid,
|
||||
bytes: i64,
|
||||
) -> CoreResult<()> {
|
||||
sqlx::query!(
|
||||
r#"
|
||||
UPDATE users
|
||||
SET storage_used = storage_used + $1, updated_at = NOW()
|
||||
WHERE id = $2
|
||||
"#,
|
||||
bytes,
|
||||
user_id
|
||||
)
|
||||
.execute(exec)
|
||||
.await
|
||||
.map_err(|e| CoreError::Database(e.to_string()))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -114,20 +135,7 @@ impl UserRepository for PostgresUserRepository {
|
||||
}
|
||||
|
||||
async fn update_storage_used(&self, user_id: Uuid, bytes: i64) -> CoreResult<()> {
|
||||
sqlx::query!(
|
||||
r#"
|
||||
UPDATE users
|
||||
SET storage_used = storage_used + $1, updated_at = NOW()
|
||||
WHERE id = $2
|
||||
"#,
|
||||
bytes,
|
||||
user_id
|
||||
)
|
||||
.execute(&self.pool)
|
||||
.await
|
||||
.map_err(|e| CoreError::Database(e.to_string()))?;
|
||||
|
||||
Ok(())
|
||||
Self::update_storage_used_internal(&self.pool, user_id, bytes).await
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user