feat(config): ThemeResp 增加品牌字段 + 公开品牌信息端点
- ThemeResp 新增 brand_name/brand_slogan/brand_features/brand_copyright 字段 - default_theme 提供品牌默认值 - 新增 PublicBrandResp 和 GET /api/v1/public/brand 公开端点(无需认证) - ConfigModule 增加 public_routes 方法 - 更新测试覆盖品牌字段
This commit is contained in:
@@ -224,6 +224,23 @@ pub struct ThemeResp {
|
|||||||
pub logo_url: Option<String>,
|
pub logo_url: Option<String>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub sidebar_style: Option<String>,
|
pub sidebar_style: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub brand_name: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub brand_slogan: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub brand_features: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub brand_copyright: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 品牌信息公开响应(不含内部配置)
|
||||||
|
#[derive(Debug, Serialize, Deserialize, ToSchema, Clone)]
|
||||||
|
pub struct PublicBrandResp {
|
||||||
|
pub brand_name: String,
|
||||||
|
pub brand_slogan: String,
|
||||||
|
pub brand_features: String,
|
||||||
|
pub brand_copyright: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Language DTOs (stored via settings) ---
|
// --- Language DTOs (stored via settings) ---
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use erp_core::rbac::require_permission;
|
|||||||
use erp_core::types::{ApiResponse, TenantContext};
|
use erp_core::types::{ApiResponse, TenantContext};
|
||||||
|
|
||||||
use crate::config_state::ConfigState;
|
use crate::config_state::ConfigState;
|
||||||
use crate::dto::{SetSettingParams, ThemeResp};
|
use crate::dto::{PublicBrandResp, SetSettingParams, ThemeResp};
|
||||||
use crate::error::ConfigError;
|
use crate::error::ConfigError;
|
||||||
use crate::service::setting_service::SettingService;
|
use crate::service::setting_service::SettingService;
|
||||||
|
|
||||||
@@ -17,6 +17,10 @@ fn default_theme() -> ThemeResp {
|
|||||||
primary_color: None,
|
primary_color: None,
|
||||||
logo_url: None,
|
logo_url: None,
|
||||||
sidebar_style: None,
|
sidebar_style: None,
|
||||||
|
brand_name: Some("HMS 健康管理平台".into()),
|
||||||
|
brand_slogan: Some("新一代健康管理平台".into()),
|
||||||
|
brand_features: Some("患者管理 · 健康监测 · 随访管理 · AI 智能分析".into()),
|
||||||
|
brand_copyright: Some("HMS 健康管理平台 · ©汕头市智界科技有限公司".into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,16 +111,45 @@ where
|
|||||||
Ok(JsonResponse(ApiResponse::ok(req)))
|
Ok(JsonResponse(ApiResponse::ok(req)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[utoipa::path(
|
||||||
|
get,
|
||||||
|
path = "/api/v1/public/brand",
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "成功", body = ApiResponse<PublicBrandResp>),
|
||||||
|
),
|
||||||
|
tag = "主题设置"
|
||||||
|
)]
|
||||||
|
/// GET /api/v1/public/brand
|
||||||
|
///
|
||||||
|
/// 获取公开品牌信息(无需认证)。
|
||||||
|
pub async fn get_public_brand() -> JsonResponse<ApiResponse<PublicBrandResp>> {
|
||||||
|
let defaults = default_theme();
|
||||||
|
JsonResponse(ApiResponse::ok(PublicBrandResp {
|
||||||
|
brand_name: defaults.brand_name.unwrap_or_else(|| "HMS 健康管理平台".into()),
|
||||||
|
brand_slogan: defaults.brand_slogan.unwrap_or_else(|| "新一代健康管理平台".into()),
|
||||||
|
brand_features: defaults
|
||||||
|
.brand_features
|
||||||
|
.unwrap_or_else(|| "患者管理 · 健康监测 · 随访管理 · AI 智能分析".into()),
|
||||||
|
brand_copyright: defaults
|
||||||
|
.brand_copyright
|
||||||
|
.unwrap_or_else(|| "HMS 健康管理平台 · ©汕头市智界科技有限公司".into()),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn default_theme_all_fields_none() {
|
fn default_theme_has_brand_defaults() {
|
||||||
let theme = default_theme();
|
let theme = default_theme();
|
||||||
assert!(theme.primary_color.is_none());
|
assert!(theme.primary_color.is_none());
|
||||||
assert!(theme.logo_url.is_none());
|
assert!(theme.logo_url.is_none());
|
||||||
assert!(theme.sidebar_style.is_none());
|
assert!(theme.sidebar_style.is_none());
|
||||||
|
assert_eq!(theme.brand_name, Some("HMS 健康管理平台".to_string()));
|
||||||
|
assert_eq!(theme.brand_slogan, Some("新一代健康管理平台".to_string()));
|
||||||
|
assert!(theme.brand_features.is_some());
|
||||||
|
assert!(theme.brand_copyright.is_some());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -125,11 +158,15 @@ mod tests {
|
|||||||
primary_color: Some("#1890ff".to_string()),
|
primary_color: Some("#1890ff".to_string()),
|
||||||
logo_url: None,
|
logo_url: None,
|
||||||
sidebar_style: Some("dark".to_string()),
|
sidebar_style: Some("dark".to_string()),
|
||||||
|
brand_name: Some("测试平台".to_string()),
|
||||||
|
brand_slogan: None,
|
||||||
|
brand_features: None,
|
||||||
|
brand_copyright: None,
|
||||||
};
|
};
|
||||||
let json = serde_json::to_string(&theme).unwrap();
|
let json = serde_json::to_string(&theme).unwrap();
|
||||||
let back: ThemeResp = serde_json::from_str(&json).unwrap();
|
let back: ThemeResp = serde_json::from_str(&json).unwrap();
|
||||||
assert_eq!(back.primary_color, Some("#1890ff".to_string()));
|
assert_eq!(back.primary_color, Some("#1890ff".to_string()));
|
||||||
assert_eq!(back.logo_url, None);
|
assert_eq!(back.brand_name, Some("测试平台".to_string()));
|
||||||
assert_eq!(back.sidebar_style, Some("dark".to_string()));
|
assert!(back.brand_slogan.is_none());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,6 +102,14 @@ impl ConfigModule {
|
|||||||
put(language_handler::update_language),
|
put(language_handler::update_language),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Build public (unauthenticated) routes for the config module.
|
||||||
|
pub fn public_routes<S>() -> Router<S>
|
||||||
|
where
|
||||||
|
S: Clone + Send + Sync + 'static,
|
||||||
|
{
|
||||||
|
Router::new().route("/public/brand", get(theme_handler::get_public_brand))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ConfigModule {
|
impl Default for ConfigModule {
|
||||||
|
|||||||
@@ -535,13 +535,14 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
))
|
))
|
||||||
.with_state(state.clone());
|
.with_state(state.clone());
|
||||||
|
|
||||||
// Unthrottled public routes (health, docs) — no rate limiting
|
// Unthrottled public routes (health, docs, brand) — no rate limiting
|
||||||
let unthrottled_routes = Router::new()
|
let unthrottled_routes = Router::new()
|
||||||
.merge(handlers::health::health_check_router())
|
.merge(handlers::health::health_check_router())
|
||||||
.route(
|
.route(
|
||||||
"/docs/openapi.json",
|
"/docs/openapi.json",
|
||||||
axum::routing::get(handlers::openapi::openapi_spec),
|
axum::routing::get(handlers::openapi::openapi_spec),
|
||||||
)
|
)
|
||||||
|
.merge(erp_config::ConfigModule::public_routes())
|
||||||
.with_state(state.clone());
|
.with_state(state.clone());
|
||||||
|
|
||||||
// Clone jwt_secret for upload auth before protected_routes closure moves it
|
// Clone jwt_secret for upload auth before protected_routes closure moves it
|
||||||
|
|||||||
Reference in New Issue
Block a user