refactor: wrap direct port calls behind use cases — notifications, search, popular_tags
Some checks failed
lint / lint (push) Has been cancelled
test / unit (push) Has been cancelled
test / integration (push) Has been cancelled
lint / lint (pull_request) Failing after 5m7s
test / unit (pull_request) Successful in 15m51s
test / integration (pull_request) Failing after 17m3s

This commit is contained in:
2026-05-14 16:13:34 +02:00
parent 004f3cd4d2
commit d50c13a2db
7 changed files with 82 additions and 10 deletions

View File

@@ -1,7 +1,8 @@
use axum::{extract::{Path, Query, State}, Json};
use api_types::requests::{PaginationQuery, SearchQuery};
use api_types::responses::ThoughtResponse;
use application::use_cases::feed::{get_home_feed, get_public_feed, get_followers, get_following, get_user_feed, get_by_tag};
use application::use_cases::feed::{get_home_feed, get_public_feed, get_followers, get_following, get_user_feed, get_by_tag, get_popular_tags as uc_get_popular_tags};
use application::use_cases::search::{search_thoughts, search_users};
use domain::models::feed::PageParams;
use crate::{errors::ApiError, extractors::{AuthUser, OptionalAuthUser}, handlers::auth::to_user_response, state::AppState};
use application::use_cases::profile::get_user_by_username;
@@ -72,8 +73,8 @@ pub async fn search_handler(
let query = q.q.trim().to_string();
let (thoughts_result, users_result) = tokio::join!(
s.search.search_thoughts(&query, &page, viewer.as_ref()),
s.search.search_users(&query, &page),
search_thoughts(&*s.search, &query, PageParams { page: page.page, per_page: page.per_page }, viewer.as_ref()),
search_users(&*s.search, &query, PageParams { page: page.page, per_page: page.per_page }),
);
let thoughts = thoughts_result?.items.into_iter().map(|e| serde_json::json!({
@@ -139,7 +140,7 @@ pub async fn get_popular_tags(
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?;
let tags = uc_get_popular_tags(&*s.tags, limit.min(100)).await?;
Ok(Json(serde_json::json!({
"tags": tags.iter().map(|(name, count)| serde_json::json!({
"name": name,