mirror of
https://github.com/perstarkse/minne.git
synced 2026-04-23 17:28:34 +02:00
feat: categories list api router
This commit is contained in:
@@ -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 }
|
||||||
|
|||||||
@@ -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))
|
||||||
}
|
}
|
||||||
|
|||||||
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;
|
pub mod ingress;
|
||||||
|
|||||||
Reference in New Issue
Block a user