Repo/db fn name refactor.
This commit is contained in:
@@ -21,7 +21,7 @@ impl Default for Query {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn query<'e, E>(executor: E, query: Query) -> Result<Vec<AccountRow>, DatabaseError>
|
||||
pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<AccountRow>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
|
||||
@@ -19,7 +19,7 @@ impl Default for Query {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn query<'e, E>(
|
||||
pub async fn list<'e, E>(
|
||||
executor: E,
|
||||
query: Query,
|
||||
) -> Result<Vec<RecurringTransactionRow>, DatabaseError>
|
||||
|
||||
@@ -19,7 +19,7 @@ impl Default for Query {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn query<'e, E>(executor: E, query: Query) -> Result<Vec<TransactionRow>, DatabaseError>
|
||||
pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<TransactionRow>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
|
||||
@@ -21,7 +21,7 @@ impl Default for Query {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn query<'e, E>(executor: E, query: Query) -> Result<Vec<UserAppSecretRow>, DatabaseError>
|
||||
pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<UserAppSecretRow>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
|
||||
@@ -21,7 +21,7 @@ impl Default for Query {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn query<'e, E>(executor: E, query: Query) -> Result<Vec<UserAppRow>, DatabaseError>
|
||||
pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<UserAppRow>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
|
||||
@@ -19,7 +19,7 @@ impl Default for Query {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn query<'e, E>(executor: E, query: Query) -> Result<Vec<UserRow>, DatabaseError>
|
||||
pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<UserRow>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
|
||||
@@ -50,7 +50,7 @@ pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<Account>, Repo
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
let accounts = db::query(executor, query.try_into()?)
|
||||
let accounts = db::list(executor, query.try_into()?)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(decode)
|
||||
@@ -59,7 +59,7 @@ where
|
||||
Ok(accounts)
|
||||
}
|
||||
|
||||
pub async fn get<'e, E>(executor: E, id: Uuid) -> Result<Option<Account>, RepositoryError>
|
||||
pub async fn get_by_id<'e, E>(executor: E, id: Uuid) -> Result<Option<Account>, RepositoryError>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -105,7 +105,7 @@ where
|
||||
Ok(account.into())
|
||||
}
|
||||
|
||||
pub async fn delete<'e, E>(executor: E, id: Uuid) -> Result<Delete, RepositoryError>
|
||||
pub async fn delete_by_id<'e, E>(executor: E, id: Uuid) -> Result<Delete, RepositoryError>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
|
||||
@@ -47,14 +47,14 @@ impl TryFrom<Query> for db::Query {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn query<'e, E>(
|
||||
pub async fn list<'e, E>(
|
||||
executor: E,
|
||||
query: Query,
|
||||
) -> Result<Vec<RecurringTransaction>, RepositoryError>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
let transactions = db::query(executor, query.try_into()?)
|
||||
let transactions = db::list(executor, query.try_into()?)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(decode)
|
||||
@@ -63,7 +63,7 @@ where
|
||||
Ok(transactions)
|
||||
}
|
||||
|
||||
pub async fn get<'e, E>(
|
||||
pub async fn get_by_id<'e, E>(
|
||||
executor: E,
|
||||
id: Uuid,
|
||||
) -> Result<Option<RecurringTransaction>, RepositoryError>
|
||||
@@ -109,7 +109,7 @@ fn classify_upsert_error(error: DatabaseError) -> RepositoryError {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn delete<'e, E>(executor: E, id: Uuid) -> Result<Delete, RepositoryError>
|
||||
pub async fn delete_by_id<'e, E>(executor: E, id: Uuid) -> Result<Delete, RepositoryError>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
|
||||
@@ -46,7 +46,7 @@ pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<Transaction>,
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
let transactions = db::query(executor, query.try_into()?)
|
||||
let transactions = db::list(executor, query.try_into()?)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(decode)
|
||||
@@ -55,7 +55,7 @@ where
|
||||
Ok(transactions)
|
||||
}
|
||||
|
||||
pub async fn get<'e, E>(executor: E, id: Uuid) -> Result<Option<Transaction>, RepositoryError>
|
||||
pub async fn get_by_id<'e, E>(executor: E, id: Uuid) -> Result<Option<Transaction>, RepositoryError>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -93,7 +93,7 @@ fn classify_upsert_error(error: DatabaseError) -> RepositoryError {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn delete<'e, E>(executor: E, id: Uuid) -> Result<Delete, RepositoryError>
|
||||
pub async fn delete_by_id<'e, E>(executor: E, id: Uuid) -> Result<Delete, RepositoryError>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
|
||||
@@ -48,14 +48,14 @@ pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<UserAppSecret>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
Ok(db::query(executor, query.try_into()?)
|
||||
Ok(db::list(executor, query.try_into()?)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(decode)
|
||||
.collect())
|
||||
}
|
||||
|
||||
pub async fn get<'e, E>(
|
||||
pub async fn get_by_id<'e, E>(
|
||||
executor: E,
|
||||
app_id: Uuid,
|
||||
id: Uuid,
|
||||
@@ -108,7 +108,7 @@ where
|
||||
Ok(db::verify(executor, app_id, secret_hash).await?)
|
||||
}
|
||||
|
||||
pub async fn delete<'e, E>(
|
||||
pub async fn delete_by_id<'e, E>(
|
||||
executor: E,
|
||||
app_id: Uuid,
|
||||
id: Uuid,
|
||||
|
||||
@@ -46,14 +46,14 @@ pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<UserApp>, Repo
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
Ok(db::query(executor, query.try_into()?)
|
||||
Ok(db::list(executor, query.try_into()?)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(decode)
|
||||
.collect())
|
||||
}
|
||||
|
||||
pub async fn get<'e, E>(
|
||||
pub async fn get_by_id<'e, E>(
|
||||
executor: E,
|
||||
user_id: Uuid,
|
||||
id: Uuid,
|
||||
@@ -92,7 +92,7 @@ fn classify_upsert_error(error: DatabaseError) -> RepositoryError {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn delete<'e, E>(
|
||||
pub async fn delete_by_id<'e, E>(
|
||||
executor: E,
|
||||
user_id: Uuid,
|
||||
id: Uuid,
|
||||
|
||||
@@ -45,7 +45,7 @@ pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<User>, Reposit
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
let users = db::query(executor, query.try_into()?)
|
||||
let users = db::list(executor, query.try_into()?)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(decode)
|
||||
@@ -54,7 +54,7 @@ where
|
||||
Ok(users)
|
||||
}
|
||||
|
||||
pub async fn get<'e, E>(executor: E, id: Uuid) -> Result<Option<User>, RepositoryError>
|
||||
pub async fn get_by_id<'e, E>(executor: E, id: Uuid) -> Result<Option<User>, RepositoryError>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -72,7 +72,7 @@ where
|
||||
Ok(user.into())
|
||||
}
|
||||
|
||||
pub async fn delete<'e, E>(executor: E, id: Uuid) -> Result<Delete, RepositoryError>
|
||||
pub async fn delete_by_id<'e, E>(executor: E, id: Uuid) -> Result<Delete, RepositoryError>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
|
||||
@@ -61,7 +61,7 @@ async fn get_account(
|
||||
State(pool): State<PgPool>,
|
||||
Path(id): Path<Uuid>,
|
||||
) -> Result<Json<AccountResponse>, AppError> {
|
||||
let account = repository::accounts::get(&pool, id)
|
||||
let account = repository::accounts::get_by_id(&pool, id)
|
||||
.await?
|
||||
.ok_or(AppError::NotFound)?;
|
||||
|
||||
@@ -91,7 +91,7 @@ async fn delete_account(
|
||||
Path(id): Path<Uuid>,
|
||||
State(pool): State<PgPool>,
|
||||
) -> Result<StatusCode, AppError> {
|
||||
match repository::accounts::delete(&pool, id).await? {
|
||||
match repository::accounts::delete_by_id(&pool, id).await? {
|
||||
Delete::Deleted => Ok(StatusCode::NO_CONTENT),
|
||||
Delete::NotFound => Err(AppError::NotFound),
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ async fn list_scheduled_transactions(
|
||||
};
|
||||
|
||||
let mut tx = pool.begin().await.map_err(RepositoryError::from)?;
|
||||
let transactions = repository::recurring_transactions::query(&mut *tx, query).await?;
|
||||
let transactions = repository::recurring_transactions::list(&mut *tx, query).await?;
|
||||
let accounts = get_accounts_for_transactions(&mut tx, &transactions).await?;
|
||||
tx.commit().await.map_err(RepositoryError::from)?;
|
||||
|
||||
@@ -70,7 +70,7 @@ async fn get_scheduled_transaction(
|
||||
Path(id): Path<Uuid>,
|
||||
) -> Result<Json<ScheduledTransactionResponse>, AppError> {
|
||||
let mut tx = pool.begin().await.map_err(RepositoryError::from)?;
|
||||
let transaction = repository::recurring_transactions::get(&mut *tx, id)
|
||||
let transaction = repository::recurring_transactions::get_by_id(&mut *tx, id)
|
||||
.await?
|
||||
.ok_or(AppError::NotFound)?;
|
||||
let accounts =
|
||||
@@ -112,7 +112,7 @@ async fn delete_scheduled_transaction(
|
||||
State(pool): State<PgPool>,
|
||||
Path(id): Path<Uuid>,
|
||||
) -> Result<StatusCode, AppError> {
|
||||
match repository::recurring_transactions::delete(&pool, id).await? {
|
||||
match repository::recurring_transactions::delete_by_id(&pool, id).await? {
|
||||
Delete::Deleted => Ok(StatusCode::NO_CONTENT),
|
||||
Delete::NotFound => Err(AppError::NotFound),
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ async fn get_transaction(
|
||||
Path(id): Path<Uuid>,
|
||||
) -> Result<Json<TransactionResponse>, AppError> {
|
||||
let mut tx = pool.begin().await.map_err(RepositoryError::from)?;
|
||||
let transaction = repository::transactions::get(&mut *tx, id)
|
||||
let transaction = repository::transactions::get_by_id(&mut *tx, id)
|
||||
.await?
|
||||
.ok_or(AppError::NotFound)?;
|
||||
let accounts =
|
||||
@@ -104,7 +104,7 @@ async fn delete_transaction(
|
||||
Path(id): Path<Uuid>,
|
||||
State(pool): State<PgPool>,
|
||||
) -> Result<StatusCode, AppError> {
|
||||
match repository::transactions::delete(&pool, id).await? {
|
||||
match repository::transactions::delete_by_id(&pool, id).await? {
|
||||
Delete::Deleted => Ok(StatusCode::NO_CONTENT),
|
||||
Delete::NotFound => Err(AppError::NotFound),
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ async fn get_user_app_secret(
|
||||
State(pool): State<PgPool>,
|
||||
Path((user_id, app_id, secret_id)): Path<(Uuid, Uuid, Uuid)>,
|
||||
) -> Result<Json<UserAppSecretResponse>, AppError> {
|
||||
let secret = repository::user_app_secrets::get(&pool, app_id, secret_id)
|
||||
let secret = repository::user_app_secrets::get_by_id(&pool, app_id, secret_id)
|
||||
.await?
|
||||
.ok_or(AppError::NotFound)?;
|
||||
|
||||
@@ -116,7 +116,7 @@ async fn delete_user_app_secret(
|
||||
State(pool): State<PgPool>,
|
||||
Path((user_id, app_id, secret_id)): Path<(Uuid, Uuid, Uuid)>,
|
||||
) -> Result<StatusCode, AppError> {
|
||||
match repository::user_app_secrets::delete(&pool, app_id, secret_id).await? {
|
||||
match repository::user_app_secrets::delete_by_id(&pool, app_id, secret_id).await? {
|
||||
Delete::Deleted => Ok(StatusCode::NO_CONTENT),
|
||||
Delete::NotFound => Err(AppError::NotFound),
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ async fn get_user_app(
|
||||
State(pool): State<PgPool>,
|
||||
Path((user_id, app_id)): Path<(Uuid, Uuid)>,
|
||||
) -> Result<Json<UserAppResponse>, AppError> {
|
||||
let app = repository::user_apps::get(&pool, user_id, app_id)
|
||||
let app = repository::user_apps::get_by_id(&pool, user_id, app_id)
|
||||
.await?
|
||||
.ok_or(AppError::NotFound)?;
|
||||
|
||||
@@ -92,7 +92,7 @@ async fn delete_user_app(
|
||||
State(pool): State<PgPool>,
|
||||
Path((user_id, app_id)): Path<(Uuid, Uuid)>,
|
||||
) -> Result<StatusCode, AppError> {
|
||||
match repository::user_apps::delete(&pool, user_id, app_id).await? {
|
||||
match repository::user_apps::delete_by_id(&pool, user_id, app_id).await? {
|
||||
Delete::Deleted => Ok(StatusCode::NO_CONTENT),
|
||||
Delete::NotFound => Err(AppError::NotFound),
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ async fn get_user(
|
||||
State(pool): State<PgPool>,
|
||||
Path(id): Path<Uuid>,
|
||||
) -> Result<Json<UserResponse>, AppError> {
|
||||
let user = repository::users::get(&pool, id)
|
||||
let user = repository::users::get_by_id(&pool, id)
|
||||
.await?
|
||||
.ok_or(AppError::NotFound)?;
|
||||
|
||||
@@ -89,7 +89,7 @@ async fn delete_user(
|
||||
Path(id): Path<Uuid>,
|
||||
State(pool): State<PgPool>,
|
||||
) -> Result<StatusCode, AppError> {
|
||||
match repository::users::delete(&pool, id).await? {
|
||||
match repository::users::delete_by_id(&pool, id).await? {
|
||||
Delete::Deleted => Ok(StatusCode::NO_CONTENT),
|
||||
Delete::NotFound => Err(AppError::NotFound),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user