(article_id: &str)
| 3421 | } |
| 3422 | |
| 3423 | pub async fn fetch_article_comment_stats(article_id: &str) -> Result<CommentStatsResponse, String> { |
| 3424 | if article_id.trim().is_empty() { |
| 3425 | return Err("article_id is empty".to_string()); |
| 3426 | } |
| 3427 | |
| 3428 | #[cfg(feature = "mock")] |
| 3429 | { |
| 3430 | Ok(CommentStatsResponse { |
| 3431 | article_id: article_id.to_string(), |
| 3432 | total: 0, |
| 3433 | }) |
| 3434 | } |
| 3435 | |
| 3436 | #[cfg(not(feature = "mock"))] |
| 3437 | { |
| 3438 | let url = |
| 3439 | format!("{}/comments/stats?article_id={}", API_BASE, urlencoding::encode(article_id),); |
| 3440 | let response = api_get(&url) |
| 3441 | .send() |
| 3442 | .await |
| 3443 | .map_err(|e| format!("Network error: {:?}", e))?; |
| 3444 | if !response.ok() { |
| 3445 | return Err(format!("HTTP error: {}", response.status())); |
| 3446 | } |
| 3447 | |
| 3448 | response |
| 3449 | .json() |
| 3450 | .await |
| 3451 | .map_err(|e| format!("Parse error: {:?}", e)) |
| 3452 | } |
| 3453 | } |
| 3454 | |
| 3455 | pub async fn fetch_admin_view_analytics_config() -> Result<ViewAnalyticsConfig, String> { |
| 3456 | #[cfg(feature = "mock")] |
no test coverage detected