Made accounts and their transaction accessible to account members only.
This commit is contained in:
@@ -15,7 +15,11 @@ pub struct Query {
|
||||
pub offset: Option<u64>,
|
||||
}
|
||||
|
||||
pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<Transaction>, RepositoryError>
|
||||
pub async fn list<'e, E>(
|
||||
executor: E,
|
||||
user_id: Uuid,
|
||||
query: Query,
|
||||
) -> Result<Vec<Transaction>, RepositoryError>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -30,7 +34,7 @@ where
|
||||
.transpose()?,
|
||||
};
|
||||
|
||||
let transactions = db::list(executor, query)
|
||||
let transactions = db::list(executor, user_id, query)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(decode)
|
||||
@@ -39,29 +43,38 @@ where
|
||||
Ok(transactions)
|
||||
}
|
||||
|
||||
pub async fn get_by_id<'e, E>(executor: E, id: Uuid) -> Result<Option<Transaction>, RepositoryError>
|
||||
pub async fn get_by_id<'e, E>(
|
||||
executor: E,
|
||||
user_id: Uuid,
|
||||
id: Uuid,
|
||||
) -> Result<Option<Transaction>, 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: Transaction,
|
||||
) -> Result<Upsert<Transaction>, RepositoryError>
|
||||
) -> Result<Option<Upsert<Transaction>>, 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 {
|
||||
@@ -80,12 +93,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<Transaction>, 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()?;
|
||||
|
||||
Reference in New Issue
Block a user