Reordered state extractors.
This commit is contained in:
@@ -32,9 +32,9 @@ pub struct QueryParams {
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn list_account_members(
|
||||
Auth(auth): Auth,
|
||||
State(pool): State<PgPool>,
|
||||
Path(account_id): Path<Uuid>,
|
||||
Query(query): Query<QueryParams>,
|
||||
State(pool): State<PgPool>,
|
||||
) -> Result<Json<Vec<AccountMemberResponse>>, AppError> {
|
||||
let user_id = auth.user_id();
|
||||
|
||||
@@ -63,13 +63,14 @@ async fn list_account_members(
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn get_account_member(
|
||||
Auth(auth): Auth,
|
||||
State(pool): State<PgPool>,
|
||||
Path((account_id, member_id)): Path<(Uuid, Uuid)>,
|
||||
State(pool): State<PgPool>,
|
||||
) -> Result<Json<AccountMemberResponse>, AppError> {
|
||||
let member =
|
||||
repository::account_members::get_by_id(&pool, auth.user_id(), account_id, member_id)
|
||||
.await?
|
||||
.ok_or(AppError::NotFound)?;
|
||||
let user_id = auth.user_id();
|
||||
|
||||
let member = repository::account_members::get_by_id(&pool, user_id, account_id, member_id)
|
||||
.await?
|
||||
.ok_or(AppError::NotFound)?;
|
||||
let users = repository::users::get_by_id(&pool, member.user_id)
|
||||
.await?
|
||||
.map(|user| HashMap::from([(user.id, user)]))
|
||||
@@ -82,8 +83,8 @@ async fn get_account_member(
|
||||
#[tracing::instrument(skip(pool, member))]
|
||||
async fn upsert_account_member(
|
||||
Auth(auth): Auth,
|
||||
State(pool): State<PgPool>,
|
||||
Path((account_id, member_id)): Path<(Uuid, Uuid)>,
|
||||
State(pool): State<PgPool>,
|
||||
Json(member): Json<AccountMemberRequest>,
|
||||
) -> Result<(StatusCode, Json<AccountMemberResponse>), AppError> {
|
||||
let user_id = auth.user_id();
|
||||
@@ -115,8 +116,8 @@ async fn upsert_account_member(
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn delete_account_member(
|
||||
Auth(auth): Auth,
|
||||
State(pool): State<PgPool>,
|
||||
Path((account_id, member_id)): Path<(Uuid, Uuid)>,
|
||||
State(pool): State<PgPool>,
|
||||
) -> Result<StatusCode, AppError> {
|
||||
let user_id = auth.user_id();
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@ pub struct QueryParams {
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn list_accounts(
|
||||
Auth(auth): Auth,
|
||||
State(pool): State<PgPool>,
|
||||
Query(query): Query<QueryParams>,
|
||||
State(pool): State<PgPool>,
|
||||
) -> Result<Json<Vec<AccountResponse>>, AppError> {
|
||||
let query = repository::accounts::Query {
|
||||
name: query.name,
|
||||
@@ -53,8 +53,8 @@ async fn list_accounts(
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn get_account(
|
||||
Auth(auth): Auth,
|
||||
State(pool): State<PgPool>,
|
||||
Path(id): Path<Uuid>,
|
||||
State(pool): State<PgPool>,
|
||||
) -> Result<Json<AccountResponse>, AppError> {
|
||||
let account = repository::accounts::get_by_id(&pool, auth.user_id(), id)
|
||||
.await?
|
||||
@@ -67,8 +67,8 @@ async fn get_account(
|
||||
#[tracing::instrument(skip(pool, account))]
|
||||
async fn upsert_account(
|
||||
Auth(auth): Auth,
|
||||
State(pool): State<PgPool>,
|
||||
Path(id): Path<Uuid>,
|
||||
State(pool): State<PgPool>,
|
||||
Json(account): Json<AccountRequest>,
|
||||
) -> Result<(StatusCode, Json<AccountResponse>), AppError> {
|
||||
let user_id = auth.user_id();
|
||||
|
||||
@@ -35,8 +35,8 @@ pub struct QueryParams {
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn list_scheduled_transactions(
|
||||
Auth(auth): Auth,
|
||||
State(pool): State<PgPool>,
|
||||
Query(query): Query<QueryParams>,
|
||||
State(pool): State<PgPool>,
|
||||
) -> Result<Json<Vec<ScheduledTransactionResponse>>, AppError> {
|
||||
let user_id = auth.user_id();
|
||||
|
||||
@@ -60,8 +60,8 @@ async fn list_scheduled_transactions(
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn get_scheduled_transaction(
|
||||
Auth(auth): Auth,
|
||||
State(pool): State<PgPool>,
|
||||
Path(id): Path<Uuid>,
|
||||
State(pool): State<PgPool>,
|
||||
) -> Result<Json<ScheduledTransactionResponse>, AppError> {
|
||||
let user_id = auth.user_id();
|
||||
|
||||
@@ -83,8 +83,8 @@ async fn get_scheduled_transaction(
|
||||
#[tracing::instrument(skip(pool, transaction))]
|
||||
async fn upsert_scheduled_transaction(
|
||||
Auth(auth): Auth,
|
||||
State(pool): State<PgPool>,
|
||||
Path(id): Path<Uuid>,
|
||||
State(pool): State<PgPool>,
|
||||
Json(transaction): Json<ScheduledTransactionRequest>,
|
||||
) -> Result<(StatusCode, Json<ScheduledTransactionResponse>), AppError> {
|
||||
let user_id = auth.user_id();
|
||||
@@ -117,8 +117,8 @@ async fn upsert_scheduled_transaction(
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn delete_scheduled_transaction(
|
||||
Auth(auth): Auth,
|
||||
State(pool): State<PgPool>,
|
||||
Path(id): Path<Uuid>,
|
||||
State(pool): State<PgPool>,
|
||||
) -> Result<StatusCode, AppError> {
|
||||
repository::recurring_transactions::delete_by_id(&pool, auth.user_id(), id)
|
||||
.await?
|
||||
|
||||
@@ -32,8 +32,8 @@ pub struct QueryParams {
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn list_transactions(
|
||||
Auth(auth): Auth,
|
||||
State(pool): State<PgPool>,
|
||||
Query(query): Query<QueryParams>,
|
||||
State(pool): State<PgPool>,
|
||||
) -> Result<Json<Vec<TransactionResponse>>, AppError> {
|
||||
let user_id = auth.user_id();
|
||||
|
||||
@@ -57,8 +57,8 @@ async fn list_transactions(
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn get_transaction(
|
||||
Auth(auth): Auth,
|
||||
State(pool): State<PgPool>,
|
||||
Path(id): Path<Uuid>,
|
||||
State(pool): State<PgPool>,
|
||||
) -> Result<Json<TransactionResponse>, AppError> {
|
||||
let user_id = auth.user_id();
|
||||
|
||||
@@ -79,8 +79,8 @@ async fn get_transaction(
|
||||
#[tracing::instrument(skip(pool, transaction))]
|
||||
async fn upsert_transaction(
|
||||
Auth(auth): Auth,
|
||||
State(pool): State<PgPool>,
|
||||
Path(id): Path<Uuid>,
|
||||
State(pool): State<PgPool>,
|
||||
Json(transaction): Json<TransactionRequest>,
|
||||
) -> Result<(StatusCode, Json<TransactionResponse>), AppError> {
|
||||
let user_id = auth.user_id();
|
||||
|
||||
@@ -37,9 +37,9 @@ pub struct QueryParams {
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn list_user_app_secrets(
|
||||
Auth(auth): Auth,
|
||||
State(pool): State<PgPool>,
|
||||
Path((user_id, app_id)): Path<(Uuid, Uuid)>,
|
||||
Query(query): Query<QueryParams>,
|
||||
State(pool): State<PgPool>,
|
||||
) -> Result<Json<Vec<UserAppSecretResponse>>, AppError> {
|
||||
if auth.user_id() != user_id {
|
||||
return Err(AppError::NotFound);
|
||||
@@ -67,8 +67,8 @@ async fn list_user_app_secrets(
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn get_user_app_secret(
|
||||
Auth(auth): Auth,
|
||||
State(pool): State<PgPool>,
|
||||
Path((user_id, app_id, secret_id)): Path<(Uuid, Uuid, Uuid)>,
|
||||
State(pool): State<PgPool>,
|
||||
) -> Result<Json<UserAppSecretResponse>, AppError> {
|
||||
if auth.user_id() != user_id {
|
||||
return Err(AppError::NotFound);
|
||||
@@ -85,8 +85,8 @@ async fn get_user_app_secret(
|
||||
#[tracing::instrument(skip(pool, request))]
|
||||
async fn upsert_user_app_secret(
|
||||
Auth(auth): Auth,
|
||||
State(pool): State<PgPool>,
|
||||
Path((user_id, app_id, secret_id)): Path<(Uuid, Uuid, Uuid)>,
|
||||
State(pool): State<PgPool>,
|
||||
Json(request): Json<UserAppSecretRequest>,
|
||||
) -> Result<(StatusCode, Json<CreatedUserAppSecretResponse>), AppError> {
|
||||
if auth.user_id() != user_id {
|
||||
@@ -120,8 +120,8 @@ async fn upsert_user_app_secret(
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn delete_user_app_secret(
|
||||
Auth(auth): Auth,
|
||||
State(pool): State<PgPool>,
|
||||
Path((user_id, app_id, secret_id)): Path<(Uuid, Uuid, Uuid)>,
|
||||
State(pool): State<PgPool>,
|
||||
) -> Result<StatusCode, AppError> {
|
||||
if auth.user_id() != user_id {
|
||||
return Err(AppError::NotFound);
|
||||
|
||||
@@ -30,9 +30,9 @@ pub struct QueryParams {
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn list_user_apps(
|
||||
Auth(auth): Auth,
|
||||
State(pool): State<PgPool>,
|
||||
Path(user_id): Path<Uuid>,
|
||||
Query(query): Query<QueryParams>,
|
||||
State(pool): State<PgPool>,
|
||||
) -> Result<Json<Vec<UserAppResponse>>, AppError> {
|
||||
if auth.user_id() != user_id {
|
||||
return Err(AppError::NotFound);
|
||||
@@ -56,8 +56,8 @@ async fn list_user_apps(
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn get_user_app(
|
||||
Auth(auth): Auth,
|
||||
State(pool): State<PgPool>,
|
||||
Path((user_id, app_id)): Path<(Uuid, Uuid)>,
|
||||
State(pool): State<PgPool>,
|
||||
) -> Result<Json<UserAppResponse>, AppError> {
|
||||
if auth.user_id() != user_id {
|
||||
return Err(AppError::NotFound);
|
||||
@@ -74,8 +74,8 @@ async fn get_user_app(
|
||||
#[tracing::instrument(skip(pool, request))]
|
||||
async fn upsert_user_app(
|
||||
Auth(auth): Auth,
|
||||
State(pool): State<PgPool>,
|
||||
Path((user_id, app_id)): Path<(Uuid, Uuid)>,
|
||||
State(pool): State<PgPool>,
|
||||
Json(request): Json<UserAppRequest>,
|
||||
) -> Result<(StatusCode, Json<UserAppResponse>), AppError> {
|
||||
if auth.user_id() != user_id {
|
||||
@@ -100,8 +100,8 @@ async fn upsert_user_app(
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn delete_user_app(
|
||||
Auth(auth): Auth,
|
||||
State(pool): State<PgPool>,
|
||||
Path((user_id, app_id)): Path<(Uuid, Uuid)>,
|
||||
State(pool): State<PgPool>,
|
||||
) -> Result<StatusCode, AppError> {
|
||||
if auth.user_id() != user_id {
|
||||
return Err(AppError::NotFound);
|
||||
|
||||
@@ -30,8 +30,8 @@ pub struct QueryParams {
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn list_users(
|
||||
Auth(auth): Auth,
|
||||
State(pool): State<PgPool>,
|
||||
Query(query): Query<QueryParams>,
|
||||
State(pool): State<PgPool>,
|
||||
) -> Result<Json<Vec<UserResponse>>, AppError> {
|
||||
let query = repository::users::Query {
|
||||
limit: Some(query.limit.unwrap_or(20)),
|
||||
@@ -51,8 +51,8 @@ async fn list_users(
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn get_user(
|
||||
Auth(auth): Auth,
|
||||
State(pool): State<PgPool>,
|
||||
Path(id): Path<Uuid>,
|
||||
State(pool): State<PgPool>,
|
||||
) -> Result<Json<UserResponse>, AppError> {
|
||||
let user = repository::users::get_by_id(&pool, id)
|
||||
.await?
|
||||
@@ -65,8 +65,8 @@ async fn get_user(
|
||||
#[tracing::instrument(skip(pool, user))]
|
||||
async fn upsert_user(
|
||||
Auth(auth): Auth,
|
||||
State(pool): State<PgPool>,
|
||||
Path(id): Path<Uuid>,
|
||||
State(pool): State<PgPool>,
|
||||
Json(user): Json<UserRequest>,
|
||||
) -> Result<(StatusCode, Json<UserResponse>), AppError> {
|
||||
let user = user.into_domain(id)?;
|
||||
|
||||
Reference in New Issue
Block a user