Skip to content

Commit

Permalink
admin user table api
Browse files Browse the repository at this point in the history
  • Loading branch information
indpurvesh committed Dec 26, 2023
1 parent ab36f19 commit 421cdc0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use std::sync::Arc;
use axum::extract::{Query, State};
use axum::Json;
use serde::Serialize;
use crate::api::rest_api::handlers::page::request::page_table_request::PageTableRequest;
use crate::avored_state::AvoRedState;
use crate::error::Result;
use crate::models::admin_user_model::AdminUserPagination;
pub async fn admin_user_table_api_handler(
state: State<Arc<AvoRedState>>,
Query(query_param): Query<PageTableRequest>,
) -> Result<Json<AdminUserPagination>> {
println!("->> {:<12} - admin_user_table_api_handler", "HANDLER");

let current_page = query_param.page.unwrap_or(1);
let admin_user_pagination = state.admin_user_service.paginate(&state.db, current_page).await?;

Ok(Json(admin_user_pagination))
}


#[derive(Serialize, Debug)]
pub struct FetchPageResponse {
pub status: bool,
pub page_model: AdminUserPagination
}
3 changes: 2 additions & 1 deletion src/api/rest_api/handlers/admin_user/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod admin_user_login_api_handler;
pub mod admin_user_login_api_handler;
pub mod admin_user_table_api_handler;
5 changes: 4 additions & 1 deletion src/api/rest_api/rest_api_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use crate::api::rest_api::handlers::{
health_check_api_handler::health_check_api_handler,
page::store_page_api_handler::store_page_api_handler,
page::update_page_api_handler::update_page_api_handler,
page::fetch_page_api_handler::fetch_page_api_handler
page::fetch_page_api_handler::fetch_page_api_handler,
admin_user::admin_user_table_api_handler::admin_user_table_api_handler
};

pub fn rest_api_routes(state: Arc<AvoRedState>) -> Router {
Expand All @@ -35,6 +36,8 @@ pub fn rest_api_routes(state: Arc<AvoRedState>) -> Router {
]);

Router::new()

.route("/api/admin-user", get(admin_user_table_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 421cdc0

Please sign in to comment.