Working state
This commit is contained in:
@@ -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))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user