feat: categories list api router

This commit is contained in:
Per Stark
2025-05-03 21:16:52 +02:00
parent 37f55b50f3
commit 48b83f3d73
4 changed files with 18 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ edition = "2021"
[dependencies] [dependencies]
tokio = { workspace = true } tokio = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
serde_json = { workspace = true }
axum = { workspace = true } axum = { workspace = true }
tracing = { workspace = true } tracing = { workspace = true }
anyhow = { workspace = true } anyhow = { workspace = true }

View File

@@ -2,11 +2,11 @@ use api_state::ApiState;
use axum::{ use axum::{
extract::{DefaultBodyLimit, FromRef}, extract::{DefaultBodyLimit, FromRef},
middleware::from_fn_with_state, middleware::from_fn_with_state,
routing::post, routing::{get, post},
Router, Router,
}; };
use middleware_api_auth::api_auth; use middleware_api_auth::api_auth;
use routes::ingress::ingest_data; use routes::{categories::get_categories, ingress::ingest_data};
pub mod api_state; pub mod api_state;
pub mod error; pub mod error;
@@ -21,6 +21,7 @@ where
{ {
Router::new() Router::new()
.route("/ingress", post(ingest_data)) .route("/ingress", post(ingest_data))
.route("/categories", get(get_categories))
.layer(DefaultBodyLimit::max(1024 * 1024 * 1024)) .layer(DefaultBodyLimit::max(1024 * 1024 * 1024))
.route_layer(from_fn_with_state(app_state.clone(), api_auth)) .route_layer(from_fn_with_state(app_state.clone(), api_auth))
} }

View File

@@ -0,0 +1,13 @@
use axum::{extract::State, response::IntoResponse, Extension, Json};
use common::storage::types::user::User;
use crate::{api_state::ApiState, error::ApiError};
pub async fn get_categories(
State(state): State<ApiState>,
Extension(user): Extension<User>,
) -> Result<impl IntoResponse, ApiError> {
let categories = User::get_user_categories(&user.id, &state.db).await?;
Ok(Json(categories))
}

View File

@@ -1 +1,2 @@
pub mod categories;
pub mod ingress; pub mod ingress;