Working state

This commit is contained in:
2025-02-18 16:35:17 +01:00
parent 2da103d5b5
commit 466f8dd992
2 changed files with 7 additions and 11 deletions

View File

@@ -2,6 +2,7 @@ use std::sync::Arc;
use axum::extract::State;
use axum::http::StatusCode;
use axum::response::IntoResponse;
use axum::{Json, Router};
use axum::routing::get;
use crate::base::controller::BaseController;
@@ -28,16 +29,9 @@ impl UserController {
async fn get_users(
State(controller): State<Arc<UserController>>,
) -> Result<Json<Vec<User>>, (StatusCode, Json<String>)> {
match controller.base_controller.get_all().await {
Ok(users) => {
// Wrap the users in Json, which implements IntoResponse
Ok(Json(users))
}
Err(err) => {
// In case of error, return StatusCode with Json error message
Err((StatusCode::INTERNAL_SERVER_ERROR, Json(err.to_string())))
}
}
) -> Result<impl IntoResponse, (StatusCode, Json<String>)> {
controller.base_controller.get_all().await.map_err(|err| {
(StatusCode::INTERNAL_SERVER_ERROR, Json(err))
})
}
}