Unified repo references.
This commit is contained in:
@@ -10,7 +10,7 @@ use super::{
|
||||
use crate::{
|
||||
error::AppError,
|
||||
repository::{
|
||||
accounts as repository,
|
||||
self,
|
||||
dtos::{Delete, Upsert},
|
||||
},
|
||||
};
|
||||
@@ -33,11 +33,11 @@ pub struct QueryParams {
|
||||
pub offset: Option<u64>,
|
||||
}
|
||||
|
||||
impl TryFrom<QueryParams> for repository::Query {
|
||||
impl TryFrom<QueryParams> for repository::accounts::Query {
|
||||
type Error = AppError;
|
||||
|
||||
fn try_from(query: QueryParams) -> Result<Self, Self::Error> {
|
||||
Ok(repository::Query {
|
||||
Ok(repository::accounts::Query {
|
||||
name: query.name,
|
||||
limit: Some(query.limit.unwrap_or(20)),
|
||||
offset: query.offset,
|
||||
@@ -52,7 +52,7 @@ async fn list_accounts(
|
||||
State(pool): State<PgPool>,
|
||||
Query(query): Query<QueryParams>,
|
||||
) -> Result<Json<Vec<AccountResponse>>, AppError> {
|
||||
let accounts = repository::list(&pool, query.try_into()?)
|
||||
let accounts = repository::accounts::list(&pool, query.try_into()?)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(AccountResponse::from)
|
||||
@@ -67,7 +67,7 @@ async fn get_account(
|
||||
State(pool): State<PgPool>,
|
||||
Path(id): Path<Uuid>,
|
||||
) -> Result<Json<AccountResponse>, AppError> {
|
||||
let account = repository::get(&pool, id)
|
||||
let account = repository::accounts::get(&pool, id)
|
||||
.await?
|
||||
.ok_or(AppError::NotFound)?;
|
||||
|
||||
@@ -83,7 +83,7 @@ async fn upsert_account(
|
||||
) -> Result<(StatusCode, Json<AccountResponse>), AppError> {
|
||||
let account = account.into_domain(id)?;
|
||||
|
||||
let (status, account) = match repository::upsert(&pool, account).await? {
|
||||
let (status, account) = match repository::accounts::upsert(&pool, account).await? {
|
||||
Upsert::Created(account) => (StatusCode::CREATED, account),
|
||||
Upsert::Updated(account) => (StatusCode::OK, account),
|
||||
};
|
||||
@@ -97,7 +97,7 @@ async fn delete_account(
|
||||
Path(id): Path<Uuid>,
|
||||
State(pool): State<PgPool>,
|
||||
) -> Result<StatusCode, AppError> {
|
||||
match repository::delete(&pool, id).await? {
|
||||
match repository::accounts::delete(&pool, id).await? {
|
||||
Delete::Deleted => Ok(StatusCode::NO_CONTENT),
|
||||
Delete::NotFound => Err(AppError::NotFound),
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::{
|
||||
crypto::{generate_secret, hash_secret},
|
||||
domain::Token,
|
||||
error::AppError,
|
||||
repository::{self, user_app_secrets},
|
||||
repository,
|
||||
routes::{
|
||||
dtos::token::{TokenRequest, TokenResponse, TokenRevocationRequest, TokenType},
|
||||
extractors::{form::Form, json::Json},
|
||||
@@ -35,7 +35,7 @@ async fn issue_token(
|
||||
client_secret,
|
||||
} => {
|
||||
let secret_hash = hash_secret(&client_secret);
|
||||
if !user_app_secrets::verify(&pool, client_id, &secret_hash).await? {
|
||||
if !repository::user_app_secrets::verify(&pool, client_id, &secret_hash).await? {
|
||||
return Err(AppError::Unauthorized);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,8 @@ use crate::{
|
||||
domain,
|
||||
error::AppError,
|
||||
repository::{
|
||||
RepositoryError, accounts as account_repository,
|
||||
self, RepositoryError, accounts,
|
||||
dtos::{Delete, Upsert},
|
||||
recurring_transactions as repository,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -39,11 +38,11 @@ pub struct QueryParams {
|
||||
pub offset: Option<u64>,
|
||||
}
|
||||
|
||||
impl TryFrom<QueryParams> for repository::Query {
|
||||
impl TryFrom<QueryParams> for repository::recurring_transactions::Query {
|
||||
type Error = AppError;
|
||||
|
||||
fn try_from(query: QueryParams) -> Result<Self, Self::Error> {
|
||||
Ok(repository::Query {
|
||||
Ok(repository::recurring_transactions::Query {
|
||||
limit: Some(query.limit.unwrap_or(20)),
|
||||
offset: query.offset,
|
||||
..Default::default()
|
||||
@@ -61,7 +60,7 @@ async fn list_scheduled_transactions(
|
||||
let query = query.try_into()?;
|
||||
|
||||
let mut tx = pool.begin().await.map_err(RepositoryError::from)?;
|
||||
let transactions = repository::query(&mut *tx, query).await?;
|
||||
let transactions = repository::recurring_transactions::query(&mut *tx, query).await?;
|
||||
let accounts = get_accounts_for_transactions(&mut tx, &transactions).await?;
|
||||
tx.commit().await.map_err(RepositoryError::from)?;
|
||||
|
||||
@@ -80,7 +79,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::get(&mut *tx, id)
|
||||
let transaction = repository::recurring_transactions::get(&mut *tx, id)
|
||||
.await?
|
||||
.ok_or(AppError::NotFound)?;
|
||||
let accounts =
|
||||
@@ -101,7 +100,8 @@ async fn upsert_scheduled_transaction(
|
||||
let transaction = transaction.into_domain(id)?;
|
||||
|
||||
let mut tx = pool.begin().await.map_err(RepositoryError::from)?;
|
||||
let (status, transaction) = match repository::upsert(&mut *tx, transaction).await? {
|
||||
let (status, transaction) =
|
||||
match repository::recurring_transactions::upsert(&mut *tx, transaction).await? {
|
||||
Upsert::Created(transaction) => (StatusCode::CREATED, transaction),
|
||||
Upsert::Updated(transaction) => (StatusCode::OK, transaction),
|
||||
};
|
||||
@@ -121,7 +121,7 @@ async fn delete_scheduled_transaction(
|
||||
State(pool): State<PgPool>,
|
||||
Path(id): Path<Uuid>,
|
||||
) -> Result<StatusCode, AppError> {
|
||||
match repository::delete(&pool, id).await? {
|
||||
match repository::recurring_transactions::delete(&pool, id).await? {
|
||||
Delete::Deleted => Ok(StatusCode::NO_CONTENT),
|
||||
Delete::NotFound => Err(AppError::NotFound),
|
||||
}
|
||||
@@ -138,7 +138,7 @@ async fn get_accounts_for_transactions(
|
||||
.into_iter()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Ok(account_repository::get_by_ids(connection, &account_ids).await?)
|
||||
Ok(accounts::get_by_ids(connection, &account_ids).await?)
|
||||
}
|
||||
|
||||
fn create_response(
|
||||
|
||||
@@ -13,9 +13,8 @@ use crate::{
|
||||
domain,
|
||||
error::AppError,
|
||||
repository::{
|
||||
RepositoryError, accounts as account_repository,
|
||||
self, RepositoryError,
|
||||
dtos::{Delete, Upsert},
|
||||
transactions as repository,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -36,11 +35,11 @@ pub struct QueryParams {
|
||||
pub offset: Option<u64>,
|
||||
}
|
||||
|
||||
impl TryFrom<QueryParams> for repository::Query {
|
||||
impl TryFrom<QueryParams> for repository::transactions::Query {
|
||||
type Error = AppError;
|
||||
|
||||
fn try_from(query: QueryParams) -> Result<Self, Self::Error> {
|
||||
Ok(repository::Query {
|
||||
Ok(repository::transactions::Query {
|
||||
limit: Some(query.limit.unwrap_or(20)),
|
||||
offset: query.offset,
|
||||
..Default::default()
|
||||
@@ -55,7 +54,7 @@ async fn list_transactions(
|
||||
Query(query): Query<QueryParams>,
|
||||
) -> Result<Json<Vec<TransactionResponse>>, AppError> {
|
||||
let mut tx = pool.begin().await.map_err(RepositoryError::from)?;
|
||||
let transactions = repository::list(&mut *tx, query.try_into()?).await?;
|
||||
let transactions = repository::transactions::list(&mut *tx, query.try_into()?).await?;
|
||||
let accounts = get_accounts_for_transactions(&mut tx, &transactions).await?;
|
||||
tx.commit().await.map_err(RepositoryError::from)?;
|
||||
|
||||
@@ -74,7 +73,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::get(&mut *tx, id)
|
||||
let transaction = repository::transactions::get(&mut *tx, id)
|
||||
.await?
|
||||
.ok_or(AppError::NotFound)?;
|
||||
let accounts =
|
||||
@@ -94,7 +93,8 @@ async fn upsert_transaction(
|
||||
let transaction = transaction.into_domain(id)?;
|
||||
|
||||
let mut tx = pool.begin().await.map_err(RepositoryError::from)?;
|
||||
let (status, transaction) = match repository::upsert(&mut *tx, transaction).await? {
|
||||
let (status, transaction) =
|
||||
match repository::transactions::upsert(&mut *tx, transaction).await? {
|
||||
Upsert::Created(transaction) => (StatusCode::CREATED, transaction),
|
||||
Upsert::Updated(transaction) => (StatusCode::OK, transaction),
|
||||
};
|
||||
@@ -111,7 +111,7 @@ async fn delete_transaction(
|
||||
Path(id): Path<Uuid>,
|
||||
State(pool): State<PgPool>,
|
||||
) -> Result<StatusCode, AppError> {
|
||||
match repository::delete(&pool, id).await? {
|
||||
match repository::transactions::delete(&pool, id).await? {
|
||||
Delete::Deleted => Ok(StatusCode::NO_CONTENT),
|
||||
Delete::NotFound => Err(AppError::NotFound),
|
||||
}
|
||||
@@ -128,7 +128,7 @@ async fn get_accounts_for_transactions(
|
||||
.into_iter()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Ok(account_repository::get_by_ids(connection, &account_ids).await?)
|
||||
Ok(repository::accounts::get_by_ids(connection, &account_ids).await?)
|
||||
}
|
||||
|
||||
fn create_response(
|
||||
|
||||
@@ -14,8 +14,8 @@ use crate::{
|
||||
domain::UserAppSecret,
|
||||
error::AppError,
|
||||
repository::{
|
||||
self,
|
||||
dtos::{Delete, Upsert},
|
||||
user_app_secrets as repository,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -43,9 +43,9 @@ async fn list_user_app_secrets(
|
||||
Path((user_id, app_id)): Path<(Uuid, Uuid)>,
|
||||
Query(query): Query<QueryParams>,
|
||||
) -> Result<Json<Vec<UserAppSecretResponse>>, AppError> {
|
||||
let secrets = repository::list(
|
||||
let secrets = repository::user_app_secrets::list(
|
||||
&pool,
|
||||
repository::Query {
|
||||
repository::user_app_secrets::Query {
|
||||
app_id,
|
||||
limit: Some(query.limit.unwrap_or(20)),
|
||||
offset: query.offset,
|
||||
@@ -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::get(&pool, app_id, secret_id)
|
||||
let secret = repository::user_app_secrets::get(&pool, app_id, secret_id)
|
||||
.await?
|
||||
.ok_or(AppError::NotFound)?;
|
||||
|
||||
@@ -94,7 +94,7 @@ async fn upsert_user_app_secret(
|
||||
expires_at,
|
||||
created_at: chrono::Utc::now(),
|
||||
};
|
||||
let upsert = repository::upsert(&pool, secret).await?;
|
||||
let upsert = repository::user_app_secrets::upsert(&pool, secret).await?;
|
||||
|
||||
let (status, secret) = match upsert {
|
||||
Upsert::Created(secret) => (StatusCode::CREATED, secret),
|
||||
@@ -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::delete(&pool, app_id, secret_id).await? {
|
||||
match repository::user_app_secrets::delete(&pool, app_id, secret_id).await? {
|
||||
Delete::Deleted => Ok(StatusCode::NO_CONTENT),
|
||||
Delete::NotFound => Err(AppError::NotFound),
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ use super::{
|
||||
use crate::{
|
||||
error::AppError,
|
||||
repository::{
|
||||
self,
|
||||
dtos::{Delete, Upsert},
|
||||
user_apps as repository,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -39,9 +39,9 @@ async fn list_user_apps(
|
||||
Path(user_id): Path<Uuid>,
|
||||
Query(query): Query<QueryParams>,
|
||||
) -> Result<Json<Vec<UserAppResponse>>, AppError> {
|
||||
let apps = repository::list(
|
||||
let apps = repository::user_apps::list(
|
||||
&pool,
|
||||
repository::Query {
|
||||
repository::user_apps::Query {
|
||||
user_id,
|
||||
limit: Some(query.limit.unwrap_or(20)),
|
||||
offset: query.offset,
|
||||
@@ -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::get(&pool, user_id, app_id)
|
||||
let app = repository::user_apps::get(&pool, user_id, app_id)
|
||||
.await?
|
||||
.ok_or(AppError::NotFound)?;
|
||||
|
||||
@@ -76,7 +76,7 @@ async fn upsert_user_app(
|
||||
Json(request): Json<UserAppRequest>,
|
||||
) -> Result<(StatusCode, Json<UserAppResponse>), AppError> {
|
||||
let app = request.into_domain(user_id, app_id);
|
||||
let upsert = repository::upsert(&pool, app).await?;
|
||||
let upsert = repository::user_apps::upsert(&pool, app).await?;
|
||||
|
||||
let (status, app) = match upsert {
|
||||
Upsert::Created(app) => (StatusCode::CREATED, app),
|
||||
@@ -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::delete(&pool, user_id, app_id).await? {
|
||||
match repository::user_apps::delete(&pool, user_id, app_id).await? {
|
||||
Delete::Deleted => Ok(StatusCode::NO_CONTENT),
|
||||
Delete::NotFound => Err(AppError::NotFound),
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ use super::{
|
||||
use crate::{
|
||||
error::AppError,
|
||||
repository::{
|
||||
self,
|
||||
dtos::{Delete, Upsert},
|
||||
users as repository,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -32,11 +32,11 @@ pub struct QueryParams {
|
||||
pub offset: Option<u64>,
|
||||
}
|
||||
|
||||
impl TryFrom<QueryParams> for repository::Query {
|
||||
impl TryFrom<QueryParams> for repository::users::Query {
|
||||
type Error = AppError;
|
||||
|
||||
fn try_from(query: QueryParams) -> Result<Self, Self::Error> {
|
||||
Ok(repository::Query {
|
||||
Ok(repository::users::Query {
|
||||
limit: Some(query.limit.unwrap_or(20)),
|
||||
offset: query.offset,
|
||||
..Default::default()
|
||||
@@ -50,7 +50,7 @@ async fn list_users(
|
||||
State(pool): State<PgPool>,
|
||||
Query(query): Query<QueryParams>,
|
||||
) -> Result<Json<Vec<UserResponse>>, AppError> {
|
||||
let users = repository::list(&pool, query.try_into()?)
|
||||
let users = repository::users::list(&pool, query.try_into()?)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(UserResponse::from)
|
||||
@@ -65,7 +65,7 @@ async fn get_user(
|
||||
State(pool): State<PgPool>,
|
||||
Path(id): Path<Uuid>,
|
||||
) -> Result<Json<UserResponse>, AppError> {
|
||||
let user = repository::get(&pool, id)
|
||||
let user = repository::users::get(&pool, id)
|
||||
.await?
|
||||
.ok_or(AppError::NotFound)?;
|
||||
|
||||
@@ -81,7 +81,7 @@ async fn upsert_user(
|
||||
) -> Result<(StatusCode, Json<UserResponse>), AppError> {
|
||||
let user = user.into_domain(id)?;
|
||||
|
||||
let (status, user) = match repository::upsert(&pool, user).await? {
|
||||
let (status, user) = match repository::users::upsert(&pool, user).await? {
|
||||
Upsert::Created(user) => (StatusCode::CREATED, user),
|
||||
Upsert::Updated(user) => (StatusCode::OK, user),
|
||||
};
|
||||
@@ -95,7 +95,7 @@ async fn delete_user(
|
||||
Path(id): Path<Uuid>,
|
||||
State(pool): State<PgPool>,
|
||||
) -> Result<StatusCode, AppError> {
|
||||
match repository::delete(&pool, id).await? {
|
||||
match repository::users::delete(&pool, id).await? {
|
||||
Delete::Deleted => Ok(StatusCode::NO_CONTENT),
|
||||
Delete::NotFound => Err(AppError::NotFound),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user