mirror of
https://github.com/perstarkse/minne.git
synced 2026-03-20 16:44:12 +01:00
feat: categories list api router
This commit is contained in:
@@ -6,6 +6,7 @@ edition = "2021"
|
||||
[dependencies]
|
||||
tokio = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
axum = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
anyhow = { workspace = true }
|
||||
|
||||
@@ -2,11 +2,11 @@ use api_state::ApiState;
|
||||
use axum::{
|
||||
extract::{DefaultBodyLimit, FromRef},
|
||||
middleware::from_fn_with_state,
|
||||
routing::post,
|
||||
routing::{get, post},
|
||||
Router,
|
||||
};
|
||||
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 error;
|
||||
@@ -21,6 +21,7 @@ where
|
||||
{
|
||||
Router::new()
|
||||
.route("/ingress", post(ingest_data))
|
||||
.route("/categories", get(get_categories))
|
||||
.layer(DefaultBodyLimit::max(1024 * 1024 * 1024))
|
||||
.route_layer(from_fn_with_state(app_state.clone(), api_auth))
|
||||
}
|
||||
|
||||
13
api-router/src/routes/categories.rs
Normal file
13
api-router/src/routes/categories.rs
Normal 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))
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
pub mod categories;
|
||||
pub mod ingress;
|
||||
|
||||
Reference in New Issue
Block a user