Added initial authorization layer.

This commit is contained in:
2026-10-09 17:22:46 +02:00
parent 7fb3abc93d
commit 1f6de34e5b
16 changed files with 184 additions and 64 deletions
+14 -5
View File
@@ -7,10 +7,7 @@ use super::{
dtos::account::{AccountRequest, AccountResponse},
extractors::{auth::Auth, json::Json, path::Path, query::Query},
};
use crate::{
error::AppError,
repository::{self},
};
use crate::{error::AppError, repository};
pub fn create_router() -> axum::Router<PgPool> {
axum::Router::new()
@@ -37,24 +34,34 @@ async fn list_accounts(
State(pool): State<PgPool>,
Query(query): Query<QueryParams>,
) -> Result<Json<Vec<AccountResponse>>, AppError> {
let mut tx = pool
.begin()
.await
.map_err(repository::RepositoryError::from)?;
let query = repository::accounts::Query {
name: query.name,
limit: Some(query.limit.unwrap_or(20)),
offset: query.offset,
};
let accounts = repository::accounts::list(&pool, query)
let accounts = repository::accounts::list(&mut *tx, query)
.await?
.into_iter()
.map(AccountResponse::from)
.collect();
tx.commit()
.await
.map_err(repository::RepositoryError::from)?;
Ok(Json(accounts))
}
#[axum::debug_handler]
#[tracing::instrument(skip(pool))]
async fn get_account(
Auth(auth): Auth,
State(pool): State<PgPool>,
Path(id): Path<Uuid>,
) -> Result<Json<AccountResponse>, AppError> {
@@ -68,6 +75,7 @@ async fn get_account(
#[axum::debug_handler]
#[tracing::instrument(skip(pool, account))]
async fn upsert_account(
Auth(auth): Auth,
State(pool): State<PgPool>,
Path(id): Path<Uuid>,
Json(account): Json<AccountRequest>,
@@ -87,6 +95,7 @@ async fn upsert_account(
#[axum::debug_handler]
#[tracing::instrument(skip(pool))]
async fn delete_account(
Auth(auth): Auth,
Path(id): Path<Uuid>,
State(pool): State<PgPool>,
) -> Result<StatusCode, AppError> {