feat: implement session-based authentication and core API handlers for user management
This commit is contained in:
36
backend/src/handlers/categories.rs
Normal file
36
backend/src/handlers/categories.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
//! Biomarker category API handlers.
|
||||
|
||||
use axum::{extract::State, http::StatusCode, Json};
|
||||
use sea_orm::{DatabaseConnection, EntityTrait};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::models::bio::biomarker_category;
|
||||
|
||||
/// Response for a biomarker category.
|
||||
#[derive(Serialize)]
|
||||
pub struct CategoryResponse {
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
pub description: Option<String>,
|
||||
}
|
||||
|
||||
/// GET /api/categories - List all biomarker categories.
|
||||
pub async fn list_categories(
|
||||
State(db): State<DatabaseConnection>,
|
||||
) -> Result<Json<Vec<CategoryResponse>>, StatusCode> {
|
||||
let categories = biomarker_category::Entity::find()
|
||||
.all(&db)
|
||||
.await
|
||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||
|
||||
let items: Vec<CategoryResponse> = categories
|
||||
.into_iter()
|
||||
.map(|c| CategoryResponse {
|
||||
id: c.id,
|
||||
name: c.name,
|
||||
description: c.description,
|
||||
})
|
||||
.collect();
|
||||
|
||||
Ok(Json(items))
|
||||
}
|
||||
Reference in New Issue
Block a user