feat(health): 新增公开文章列表端点 /public/articles 供小程序访客首页使用
访客首页文章列表调用 /health/articles 需要 JWT 认证导致 401。 新增 GET /public/articles?tenant_id=xxx 端点,强制只返回已发布文章, 无需认证。小程序访客首页改用此公开端点。
This commit is contained in:
@@ -60,8 +60,8 @@ function GuestHome({ modeClass }: { modeClass: string }) {
|
||||
try {
|
||||
const [bannerData, articleData] = await Promise.allSettled([
|
||||
api.get<PublicBanner[]>('/public/banners', { tenant_id: tenantId }, 300_000),
|
||||
api.get<{ data: Article[]; total: number }>('/health/articles', {
|
||||
status: 'published',
|
||||
api.get<{ data: Article[]; total: number }>('/public/articles', {
|
||||
tenant_id: tenantId,
|
||||
page_size: 4,
|
||||
}, 300_000),
|
||||
]);
|
||||
|
||||
@@ -55,6 +55,8 @@ pub struct ArticleListItem {
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, IntoParams)]
|
||||
pub struct ArticleListParams {
|
||||
/// 公开端点必需:租户 ID
|
||||
pub tenant_id: Option<Uuid>,
|
||||
pub page: Option<u64>,
|
||||
pub page_size: Option<u64>,
|
||||
pub category: Option<String>,
|
||||
|
||||
@@ -48,6 +48,30 @@ where
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
pub async fn list_public_articles(
|
||||
State(state): State<HealthState>,
|
||||
Query(params): Query<ArticleListParams>,
|
||||
) -> Result<Json<ApiResponse<PaginatedResponse<ArticleListItem>>>, AppError> {
|
||||
let tenant_id = params
|
||||
.tenant_id
|
||||
.ok_or_else(|| AppError::Validation("tenant_id is required".into()))?;
|
||||
let page = params.page.unwrap_or(1);
|
||||
let page_size = params.page_size.unwrap_or(20);
|
||||
let result = article_service::list_articles(
|
||||
&state,
|
||||
tenant_id,
|
||||
page,
|
||||
page_size,
|
||||
params.category,
|
||||
Some("published".to_string()),
|
||||
params.category_id,
|
||||
params.tag_id,
|
||||
params.keyword,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
pub async fn get_article<S>(
|
||||
State(state): State<HealthState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
|
||||
@@ -157,6 +157,10 @@ impl HealthModule {
|
||||
"/public/banners",
|
||||
axum::routing::get(banner_handler::list_public_banners),
|
||||
)
|
||||
.route(
|
||||
"/public/articles",
|
||||
axum::routing::get(article_handler::list_public_articles),
|
||||
)
|
||||
}
|
||||
|
||||
/// FHIR R4 只读路由(使用 OAuth client_credentials 认证)
|
||||
|
||||
Reference in New Issue
Block a user