Skip to content

Commit

Permalink
Fetch admin user api
Browse files Browse the repository at this point in the history
  • Loading branch information
indpurvesh committed Dec 27, 2023
1 parent edfaa6c commit 787b4bc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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<String>,
state: State<Arc<AvoRedState>>
) -> Result<impl IntoResponse> {
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
}
1 change: 1 addition & 0 deletions src/api/rest_api/handlers/admin_user/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
4 changes: 3 additions & 1 deletion src/api/rest_api/rest_api_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AvoRedState>) -> Router {
Expand All @@ -42,6 +43,7 @@ pub fn rest_api_routes(state: Arc<AvoRedState>) -> 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))
Expand Down

0 comments on commit 787b4bc

Please sign in to comment.