Added initial authorization layer.
This commit is contained in:
@@ -5,12 +5,9 @@ use uuid::Uuid;
|
||||
|
||||
use super::{
|
||||
dtos::user::{UserRequest, UserResponse},
|
||||
extractors::{json::Json, path::Path, query::Query},
|
||||
};
|
||||
use crate::{
|
||||
error::AppError,
|
||||
repository::{self},
|
||||
extractors::{auth::Auth, json::Json, path::Path, query::Query},
|
||||
};
|
||||
use crate::{error::AppError, repository};
|
||||
|
||||
pub fn create_router() -> axum::Router<PgPool> {
|
||||
axum::Router::new()
|
||||
@@ -32,6 +29,7 @@ pub struct QueryParams {
|
||||
#[axum::debug_handler]
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn list_users(
|
||||
Auth(auth): Auth,
|
||||
State(pool): State<PgPool>,
|
||||
Query(query): Query<QueryParams>,
|
||||
) -> Result<Json<Vec<UserResponse>>, AppError> {
|
||||
@@ -52,6 +50,7 @@ async fn list_users(
|
||||
#[axum::debug_handler]
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn get_user(
|
||||
Auth(auth): Auth,
|
||||
State(pool): State<PgPool>,
|
||||
Path(id): Path<Uuid>,
|
||||
) -> Result<Json<UserResponse>, AppError> {
|
||||
@@ -65,6 +64,7 @@ async fn get_user(
|
||||
#[axum::debug_handler]
|
||||
#[tracing::instrument(skip(pool, user))]
|
||||
async fn upsert_user(
|
||||
Auth(auth): Auth,
|
||||
State(pool): State<PgPool>,
|
||||
Path(id): Path<Uuid>,
|
||||
Json(user): Json<UserRequest>,
|
||||
@@ -84,6 +84,7 @@ async fn upsert_user(
|
||||
#[axum::debug_handler]
|
||||
#[tracing::instrument(skip(pool))]
|
||||
async fn delete_user(
|
||||
Auth(auth): Auth,
|
||||
Path(id): Path<Uuid>,
|
||||
State(pool): State<PgPool>,
|
||||
) -> Result<StatusCode, AppError> {
|
||||
|
||||
Reference in New Issue
Block a user