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
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:
@@ -4,7 +4,7 @@ use domain::{
|
||||
feed::{FeedEntry, PageParams, Paginated, UserSummary},
|
||||
user::User,
|
||||
},
|
||||
ports::{FeedRepository, FollowRepository, UserRepository},
|
||||
ports::{FeedRepository, FollowRepository, TagRepository, UserRepository},
|
||||
value_objects::UserId,
|
||||
};
|
||||
|
||||
@@ -40,3 +40,7 @@ pub async fn search(feed: &dyn FeedRepository, query: &str, page: PageParams, vi
|
||||
pub async fn list_users(users: &dyn UserRepository) -> Result<Vec<UserSummary>, DomainError> {
|
||||
users.list_with_stats().await
|
||||
}
|
||||
|
||||
pub async fn get_popular_tags(tags: &dyn TagRepository, limit: usize) -> Result<Vec<(String, i64)>, DomainError> {
|
||||
tags.popular_tags(limit).await
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
pub mod api_keys;
|
||||
pub mod auth;
|
||||
pub mod feed;
|
||||
pub mod notifications;
|
||||
pub mod profile;
|
||||
pub mod search;
|
||||
pub mod social;
|
||||
pub mod thoughts;
|
||||
|
||||
30
crates/application/src/use_cases/notifications.rs
Normal file
30
crates/application/src/use_cases/notifications.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use domain::{
|
||||
errors::DomainError,
|
||||
models::feed::{PageParams, Paginated},
|
||||
models::notification::Notification,
|
||||
ports::NotificationRepository,
|
||||
value_objects::{NotificationId, UserId},
|
||||
};
|
||||
|
||||
pub async fn list_notifications(
|
||||
repo: &dyn NotificationRepository,
|
||||
user_id: &UserId,
|
||||
page: PageParams,
|
||||
) -> Result<Paginated<Notification>, DomainError> {
|
||||
repo.list_for_user(user_id, &page).await
|
||||
}
|
||||
|
||||
pub async fn mark_notification_read(
|
||||
repo: &dyn NotificationRepository,
|
||||
id: &NotificationId,
|
||||
user_id: &UserId,
|
||||
) -> Result<(), DomainError> {
|
||||
repo.mark_read(id, user_id).await
|
||||
}
|
||||
|
||||
pub async fn mark_all_notifications_read(
|
||||
repo: &dyn NotificationRepository,
|
||||
user_id: &UserId,
|
||||
) -> Result<(), DomainError> {
|
||||
repo.mark_all_read(user_id).await
|
||||
}
|
||||
26
crates/application/src/use_cases/search.rs
Normal file
26
crates/application/src/use_cases/search.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
use domain::{
|
||||
errors::DomainError,
|
||||
models::{
|
||||
feed::{FeedEntry, PageParams, Paginated},
|
||||
user::User,
|
||||
},
|
||||
ports::SearchPort,
|
||||
value_objects::UserId,
|
||||
};
|
||||
|
||||
pub async fn search_thoughts(
|
||||
search: &dyn SearchPort,
|
||||
query: &str,
|
||||
page: PageParams,
|
||||
viewer_id: Option<&UserId>,
|
||||
) -> Result<Paginated<FeedEntry>, DomainError> {
|
||||
search.search_thoughts(query, &page, viewer_id).await
|
||||
}
|
||||
|
||||
pub async fn search_users(
|
||||
search: &dyn SearchPort,
|
||||
query: &str,
|
||||
page: PageParams,
|
||||
) -> Result<Paginated<User>, DomainError> {
|
||||
search.search_users(query, &page).await
|
||||
}
|
||||
Reference in New Issue
Block a user