Skip to content

Commit

Permalink
in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
RWDai committed Nov 26, 2023
1 parent c72a11e commit f6c0a09
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
14 changes: 14 additions & 0 deletions admin/src/api/auth_api.rs
Original file line number Diff line number Diff line change
@@ -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<Void> {
TardisResp::ok(Void {})
}
}
71 changes: 71 additions & 0 deletions admin/src/api/dashboard_api.rs
Original file line number Diff line number Diff line change
@@ -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<Statistics> {
//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,
}

0 comments on commit f6c0a09

Please sign in to comment.