feat: GET /tags/popular — top tags by usage count
This commit is contained in:
@@ -133,6 +133,20 @@ pub async fn user_thoughts_handler(
|
||||
})))
|
||||
}
|
||||
|
||||
pub async fn get_popular_tags(
|
||||
State(s): State<AppState>,
|
||||
Query(params): Query<std::collections::HashMap<String, String>>,
|
||||
) -> Result<Json<serde_json::Value>, ApiError> {
|
||||
let limit: usize = params.get("limit").and_then(|v| v.parse().ok()).unwrap_or(20);
|
||||
let tags = s.tags.popular_tags(limit.min(100)).await?;
|
||||
Ok(Json(serde_json::json!({
|
||||
"tags": tags.iter().map(|(name, count)| serde_json::json!({
|
||||
"name": name,
|
||||
"thought_count": count,
|
||||
})).collect::<Vec<_>>()
|
||||
})))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get, path = "/tags/{name}",
|
||||
params(
|
||||
|
||||
Reference in New Issue
Block a user