Made accounts and their transaction accessible to account members only.

This commit is contained in:
2026-10-11 13:28:16 +02:00
parent 21f0c17af9
commit 3faea141dd
34 changed files with 462 additions and 295 deletions
@@ -22,6 +22,7 @@ pub struct Query {
pub async fn list<'e, E>(
executor: E,
user_id: Uuid,
query: Query,
) -> Result<Vec<RecurringTransaction>, RepositoryError>
where
@@ -38,7 +39,7 @@ where
.transpose()?,
};
let transactions = db::list(executor, query)
let transactions = db::list(executor, user_id, query)
.await?
.into_iter()
.map(decode)
@@ -49,30 +50,36 @@ where
pub async fn get_by_id<'e, E>(
executor: E,
user_id: Uuid,
id: Uuid,
) -> Result<Option<RecurringTransaction>, RepositoryError>
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let transaction = db::get_by_id(executor, id).await?.map(decode).transpose()?;
let transaction = db::get_by_id(executor, user_id, id)
.await?
.map(decode)
.transpose()?;
Ok(transaction)
}
pub async fn upsert<'e, E>(
executor: E,
user_id: Uuid,
transaction: RecurringTransaction,
) -> Result<Upsert<RecurringTransaction>, RepositoryError>
) -> Result<Option<Upsert<RecurringTransaction>>, RepositoryError>
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let transaction = db::upsert(executor, encode(transaction))
let upserted = db::upsert(executor, user_id, encode(transaction))
.await
.map_err(classify_upsert_error)?
.try_map(decode)?
.into();
.map(|upserted| upserted.try_map(decode))
.transpose()?
.map(Into::into);
Ok(transaction)
Ok(upserted)
}
fn classify_upsert_error(error: DatabaseError) -> RepositoryError {
@@ -96,12 +103,13 @@ fn classify_upsert_error(error: DatabaseError) -> RepositoryError {
pub async fn delete_by_id<'e, E>(
executor: E,
user_id: Uuid,
id: Uuid,
) -> Result<Option<RecurringTransaction>, RepositoryError>
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let transaction = db::delete_by_id(executor, id)
let transaction = db::delete_by_id(executor, user_id, id)
.await?
.map(decode)
.transpose()?;