feat: refactor and multiworkspace rows
This commit is contained in:
parent
13ce89d27e
commit
b68b897165
|
|
@ -1,5 +1,6 @@
|
||||||
use database_entity::dto::AFWorkspace;
|
use database_entity::dto::AFWorkspace;
|
||||||
use serde::Deserialize;
|
|
||||||
|
use super::entities::{JsonResponse, UserUsageLimit};
|
||||||
|
|
||||||
pub async fn get_user_workspace_count(
|
pub async fn get_user_workspace_count(
|
||||||
auth_header: &str,
|
auth_header: &str,
|
||||||
|
|
@ -36,13 +37,22 @@ pub async fn get_user_workspace_limit(
|
||||||
Ok(c as u32)
|
Ok(c as u32)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
pub async fn get_workspace_limit(
|
||||||
pub struct JsonResponse<T> {
|
auth_header: &str,
|
||||||
pub code: u16,
|
appflowy_cloud_base_url: &str,
|
||||||
pub data: T,
|
) -> Result<u32, reqwest::Error> {
|
||||||
}
|
let http_client = reqwest::Client::new();
|
||||||
|
let resp = http_client
|
||||||
|
.get(format!("{}/api/user/limit", appflowy_cloud_base_url))
|
||||||
|
.header("Authorization", format!("Bearer {}", auth_header))
|
||||||
|
.send()
|
||||||
|
.await?;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
let res = resp.json::<JsonResponse<UserUsageLimit>>().await?;
|
||||||
pub struct UserUsageLimit {
|
let b = res.data;
|
||||||
pub workspace_count: Option<i64>,
|
let c = b.workspace_count.unwrap_or({
|
||||||
|
tracing::warn!("workspace_count is None, returning 0");
|
||||||
|
0
|
||||||
|
});
|
||||||
|
Ok(c as u32)
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
pub struct JsonResponse<T> {
|
||||||
|
pub code: u16,
|
||||||
|
pub data: T,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct UserUsageLimit {
|
||||||
|
pub workspace_count: Option<i64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct WorkspaceUsage {
|
||||||
|
pub name: String,
|
||||||
|
pub member_count: i64,
|
||||||
|
pub member_limit: i64,
|
||||||
|
pub total_doc_size: String,
|
||||||
|
pub total_blob_size: String,
|
||||||
|
pub total_blob_limit: String,
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
pub mod api;
|
||||||
|
pub mod entities;
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
use gotrue_entity::{dto::User, sso::SSOProvider};
|
use gotrue_entity::{dto::User, sso::SSOProvider};
|
||||||
|
|
||||||
|
use crate::ext::entities::WorkspaceUsage;
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(path = "components/user_usage.html")]
|
#[template(path = "components/user_usage.html")]
|
||||||
pub struct UserUsage {
|
pub struct UserUsage {
|
||||||
|
|
@ -8,15 +10,11 @@ pub struct UserUsage {
|
||||||
pub workspace_limit: u32,
|
pub workspace_limit: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ./../templates/components/workspace_usage.html
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(path = "components/workspace_usage.html")]
|
#[template(path = "components/workspace_usage.html")]
|
||||||
pub struct WorkspaceUsage<'a> {
|
pub struct WorkspaceUsageList {
|
||||||
pub name: &'a str,
|
pub workspace_usages: Vec<WorkspaceUsage>,
|
||||||
pub member_count: u32,
|
|
||||||
pub member_limit: u32,
|
|
||||||
pub total_doc_size: &'a str,
|
|
||||||
pub total_blob_size: &'a str,
|
|
||||||
pub total_blob_limit: &'a str,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::error::WebAppError;
|
use crate::error::WebAppError;
|
||||||
use crate::ext::{get_user_workspace_count, get_user_workspace_limit};
|
use crate::ext::api::{get_user_workspace_count, get_user_workspace_limit};
|
||||||
|
use crate::ext::entities::WorkspaceUsage;
|
||||||
use crate::session::UserSession;
|
use crate::session::UserSession;
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
use axum::extract::{Path, State};
|
use axum::extract::{Path, State};
|
||||||
|
|
@ -122,15 +123,30 @@ pub async fn user_usage_handler(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn workspace_usage_handler(session: UserSession) -> Result<Html<String>, WebAppError> {
|
pub async fn workspace_usage_handler(
|
||||||
render_template(templates::WorkspaceUsage {
|
State(app_state): State<AppState>,
|
||||||
name: "test",
|
session: UserSession,
|
||||||
member_count: 6,
|
) -> Result<Html<String>, WebAppError> {
|
||||||
member_limit: 7,
|
let workspace_usages = vec![
|
||||||
total_doc_size: &human_bytes(987654),
|
WorkspaceUsage {
|
||||||
total_blob_size: &human_bytes(9876543),
|
name: "test".to_owned(),
|
||||||
total_blob_limit: &human_bytes(98765432),
|
member_count: 6,
|
||||||
})
|
member_limit: 7,
|
||||||
|
total_doc_size: human_bytes(987654),
|
||||||
|
total_blob_size: human_bytes(9876543),
|
||||||
|
total_blob_limit: human_bytes(98765432),
|
||||||
|
},
|
||||||
|
WorkspaceUsage {
|
||||||
|
name: "test".to_owned(),
|
||||||
|
member_count: 6,
|
||||||
|
member_limit: 7,
|
||||||
|
total_doc_size: human_bytes(987654),
|
||||||
|
total_blob_size: human_bytes(9876543),
|
||||||
|
total_blob_limit: human_bytes(98765432),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
render_template(templates::WorkspaceUsageList { workspace_usages })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn admin_users_create_handler() -> Result<Html<String>, WebAppError> {
|
pub async fn admin_users_create_handler() -> Result<Html<String>, WebAppError> {
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,17 @@
|
||||||
<th>Object Storage Limit</th>
|
<th>Object Storage Limit</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tr>
|
|
||||||
<td> {{ name|escape }} </td>
|
{% for workspace_usage in workspace_usages %}
|
||||||
<td> {{ member_count|escape }} </td>
|
<tr>
|
||||||
<td> {{ member_limit|escape }} </td>
|
<td> {{ workspace_usage.name|escape }} </td>
|
||||||
<td> {{ total_doc_size|escape }} </td>
|
<td> {{ workspace_usage.member_count|escape }} </td>
|
||||||
<td> {{ total_blob_size|escape }} </td>
|
<td> {{ workspace_usage.member_limit|escape }} </td>
|
||||||
<td> {{ total_blob_limit|escape }} </td>
|
<td> {{ workspace_usage.total_doc_size|escape }} </td>
|
||||||
</tr>
|
<td> {{ workspace_usage.total_blob_size|escape }} </td>
|
||||||
|
<td> {{ workspace_usage.total_blob_limit|escape }} </td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue