Reordered state extractors.

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