refactor: extract handler business logic into application use cases
11 handlers were calling repos/ports directly, bypassing the
application layer. Extracted into proper use cases:
feed: get_public_feed, get_user_feed, get_tag_feed, get_popular_tags
profile: get_user_profile (with follow check), list_users,
count_local_users, list_local_followers, list_local_following
federation_management: set_also_known_as
Also registers 9 previously undocumented handlers in OpenAPI modules.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use domain::{
|
||||
errors::DomainError,
|
||||
models::feed::{FeedEntry, PageParams, Paginated},
|
||||
ports::{FeedOptions, FeedQuery, FeedRepository, FeedRequest, FollowRepository},
|
||||
ports::{FeedOptions, FeedQuery, FeedRepository, FeedRequest, FollowRepository, TagRepository},
|
||||
value_objects::UserId,
|
||||
};
|
||||
|
||||
@@ -20,3 +20,51 @@ pub async fn get_home_feed(
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_public_feed(
|
||||
feed: &dyn FeedRepository,
|
||||
viewer: Option<UserId>,
|
||||
page: PageParams,
|
||||
opts: FeedOptions,
|
||||
) -> Result<Paginated<FeedEntry>, DomainError> {
|
||||
feed.query(&FeedRequest {
|
||||
query: FeedQuery::public(page, viewer),
|
||||
options: opts,
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_user_feed(
|
||||
feed: &dyn FeedRepository,
|
||||
user_id: UserId,
|
||||
page: PageParams,
|
||||
opts: FeedOptions,
|
||||
viewer: Option<UserId>,
|
||||
) -> Result<Paginated<FeedEntry>, DomainError> {
|
||||
feed.query(&FeedRequest {
|
||||
query: FeedQuery::user(user_id, page, viewer),
|
||||
options: opts,
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_tag_feed(
|
||||
feed: &dyn FeedRepository,
|
||||
tag: &str,
|
||||
page: PageParams,
|
||||
opts: FeedOptions,
|
||||
viewer: Option<UserId>,
|
||||
) -> Result<Paginated<FeedEntry>, DomainError> {
|
||||
feed.query(&FeedRequest {
|
||||
query: FeedQuery::tag(tag, page, viewer),
|
||||
options: opts,
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_popular_tags(
|
||||
tags: &dyn TagRepository,
|
||||
limit: usize,
|
||||
) -> Result<Vec<(String, i64)>, DomainError> {
|
||||
tags.popular_tags(limit).await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user