Working state
This commit is contained in:
parent
2da103d5b5
commit
466f8dd992
@ -2,6 +2,7 @@ use std::sync::Arc;
|
||||
|
||||
use axum::{serve, Router};
|
||||
use config::db::init_db;
|
||||
use dotenvy::dotenv;
|
||||
use tokio::net::TcpListener;
|
||||
use crate::routes::user::controller::UserController;
|
||||
use crate::routes::user::service::UserService;
|
||||
@ -12,6 +13,7 @@ mod routes;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
dotenv().ok();
|
||||
let pool = init_db();
|
||||
|
||||
let user_service = UserService::new(pool);
|
||||
|
@ -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))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user