From f6c0a092e9fee3a2188a341a527defc50ef56230 Mon Sep 17 00:00:00 2001 From: RWDai <27391645+RWDai@users.noreply.github.com> Date: Sun, 26 Nov 2023 11:17:09 +0800 Subject: [PATCH] in progress --- admin/src/api/auth_api.rs | 14 +++++++ admin/src/api/dashboard_api.rs | 71 ++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 admin/src/api/auth_api.rs create mode 100644 admin/src/api/dashboard_api.rs diff --git a/admin/src/api/auth_api.rs b/admin/src/api/auth_api.rs new file mode 100644 index 00000000..ccc44995 --- /dev/null +++ b/admin/src/api/auth_api.rs @@ -0,0 +1,14 @@ +use tardis::web::poem_openapi; +use tardis::web::web_resp::{TardisApiResult, TardisResp, Void}; + +#[derive(Clone, Default)] +pub struct AuthApi; + +/// Auth API +#[poem_openapi::OpenApi(prefix_path = "/")] +impl AuthApi { + #[oai(path = "/login", method = "post")] + async fn login(&self) -> TardisApiResult { + TardisResp::ok(Void {}) + } +} diff --git a/admin/src/api/dashboard_api.rs b/admin/src/api/dashboard_api.rs new file mode 100644 index 00000000..e180290e --- /dev/null +++ b/admin/src/api/dashboard_api.rs @@ -0,0 +1,71 @@ +use serde::{Deserialize, Serialize}; +use tardis::web::poem_openapi; +use tardis::web::web_resp::{TardisApiResult, TardisResp}; + +use crate::model::query_dto::{GatewayQueryInst, HttpRouteQueryInst, PluginQueryInst}; +use crate::service::gateway_service::GatewayVoService; +use crate::{ + model::query_dto::{SgTlsQueryInst, SpacegateInstQueryInst}, + service::{plugin_service::PluginVoService, route_service::HttpRouteVoService, secret_service::TlsVoService, spacegate_manage_service::SpacegateManageService}, +}; + +#[derive(Clone, Default)] +pub struct DashboardApi; + +/// Dashboard API +#[poem_openapi::OpenApi(prefix_path = "/")] +impl DashboardApi { + async fn statistics(&self) -> TardisApiResult { + //todo client_name + let client_name = ""; + TardisResp::ok(Statistics { + gateway_count: GatewayVoService::list( + client_name, + GatewayQueryInst { + names: None, + port: None, + hostname: None, + tls_ids: None, + }, + ) + .await? + .len() as i64, + route_count: HttpRouteVoService::list( + client_name, + HttpRouteQueryInst { + names: None, + gateway_name: None, + hostnames: None, + filter_ids: None, + }, + ) + .await? + .len() as i64, + plugin_count: PluginVoService::list( + client_name, + PluginQueryInst { + ids: None, + name: None, + code: None, + namespace: None, + target_name: None, + target_kind: None, + target_namespace: None, + }, + ) + .await? + .len() as i64, + tls_count: TlsVoService::list(client_name, SgTlsQueryInst { names: None }).await?.len() as i64, + instance_count: SpacegateManageService::list(SpacegateInstQueryInst { names: None }).await?.len() as i64, + }) + } +} + +#[derive(Default, Debug, Serialize, Deserialize, Clone, poem_openapi::Object)] +struct Statistics { + pub gateway_count: i64, + pub route_count: i64, + pub plugin_count: i64, + pub tls_count: i64, + pub instance_count: i64, +}