diff --git a/src/api/rest_api/handlers/admin_user/fetch_admin_user_api_handler.rs b/src/api/rest_api/handlers/admin_user/fetch_admin_user_api_handler.rs new file mode 100644 index 00000000..c71cd579 --- /dev/null +++ b/src/api/rest_api/handlers/admin_user/fetch_admin_user_api_handler.rs @@ -0,0 +1,33 @@ +use std::sync::Arc; +use crate::{ + avored_state::AvoRedState, error::Result +}; + +use axum::{extract::{Path as AxumPath, State}, Json, response::IntoResponse}; +use serde::Serialize; +use crate::models::admin_user_model::AdminUserModel; + +pub async fn fetch_admin_user_api_handler( + AxumPath(admin_user_id): AxumPath, + state: State> +) -> Result { + println!("->> {:<12} - fetch_admin_user_api_handler", "HANDLER"); + + let admin_user_model = state + .admin_user_service + .find_by_id(&state.db, admin_user_id) + .await?; + let response = FetchAdminUserResponse { + status: true, + admin_user_model: admin_user_model + }; + + Ok(Json(response)) +} + + +#[derive(Serialize, Debug)] +pub struct FetchAdminUserResponse { + pub status: bool, + pub admin_user_model: AdminUserModel +} \ No newline at end of file diff --git a/src/api/rest_api/handlers/admin_user/mod.rs b/src/api/rest_api/handlers/admin_user/mod.rs index 4cdf002b..6b6ab808 100644 --- a/src/api/rest_api/handlers/admin_user/mod.rs +++ b/src/api/rest_api/handlers/admin_user/mod.rs @@ -2,4 +2,5 @@ pub mod admin_user_login_api_handler; pub mod admin_user_table_api_handler; pub mod store_admin_user_api_handler; pub mod update_admin_user_api_handler; +pub mod fetch_admin_user_api_handler; pub mod request; \ No newline at end of file diff --git a/src/api/rest_api/rest_api_routes.rs b/src/api/rest_api/rest_api_routes.rs index 450823de..57012086 100644 --- a/src/api/rest_api/rest_api_routes.rs +++ b/src/api/rest_api/rest_api_routes.rs @@ -17,7 +17,8 @@ use crate::api::rest_api::handlers::{ page::fetch_page_api_handler::fetch_page_api_handler, admin_user::admin_user_table_api_handler::admin_user_table_api_handler, admin_user::store_admin_user_api_handler::store_admin_user_api_handler, - admin_user::update_admin_user_api_handler::update_admin_user_api_handler + admin_user::update_admin_user_api_handler::update_admin_user_api_handler, + admin_user::fetch_admin_user_api_handler::fetch_admin_user_api_handler }; pub fn rest_api_routes(state: Arc) -> Router { @@ -42,6 +43,7 @@ pub fn rest_api_routes(state: Arc) -> Router { .route("/api/admin-user", get(admin_user_table_api_handler)) .route("/api/admin-user", post(store_admin_user_api_handler)) .route("/api/admin-user/:admin_user_id", put(update_admin_user_api_handler)) + .route("/api/admin-user/:admin_user_id", get(fetch_admin_user_api_handler)) .route("/api/page", get(page_table_api_handler)) .route("/api/page", post(store_page_api_handler)) .route("/api/page/:page_id", put(update_page_api_handler))