refactor(ports): CQRS split — UserRepository = UserReader + UserWriter supertrait
This commit is contained in:
@@ -2,14 +2,14 @@ use domain::{
|
||||
errors::DomainError,
|
||||
events::DomainEvent,
|
||||
models::thought::Visibility,
|
||||
ports::{ActivityPubRepository, OutboundFederationPort, ThoughtRepository, UserRepository},
|
||||
ports::{ActivityPubRepository, OutboundFederationPort, ThoughtRepository, UserReader},
|
||||
value_objects::ThoughtId,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct FederationEventService {
|
||||
pub thoughts: Arc<dyn ThoughtRepository>,
|
||||
pub users: Arc<dyn UserRepository>,
|
||||
pub users: Arc<dyn UserReader>,
|
||||
pub ap: Arc<dyn OutboundFederationPort>,
|
||||
pub base_url: String,
|
||||
pub ap_repo: Arc<dyn ActivityPubRepository>,
|
||||
|
||||
@@ -2,7 +2,7 @@ use domain::{
|
||||
errors::DomainError,
|
||||
events::DomainEvent,
|
||||
models::user::User,
|
||||
ports::{AuthService, EventPublisher, PasswordHasher, UserRepository},
|
||||
ports::{AuthService, EventPublisher, PasswordHasher, UserReader, UserRepository},
|
||||
value_objects::{Email, UserId, Username},
|
||||
};
|
||||
|
||||
@@ -58,7 +58,7 @@ pub struct LoginOutput {
|
||||
}
|
||||
|
||||
pub async fn login(
|
||||
users: &dyn UserRepository,
|
||||
users: &dyn UserReader,
|
||||
hasher: &dyn PasswordHasher,
|
||||
auth: &dyn AuthService,
|
||||
input: LoginInput,
|
||||
|
||||
@@ -7,7 +7,7 @@ use domain::{
|
||||
},
|
||||
ports::{
|
||||
ActivityPubRepository, EventPublisher, FederationActionPort, FederationSchedulerPort,
|
||||
FeedRepository, FollowRepository, RemoteActorConnectionRepository, UserRepository,
|
||||
FeedRepository, FollowRepository, RemoteActorConnectionRepository, UserReader,
|
||||
},
|
||||
value_objects::UserId,
|
||||
};
|
||||
@@ -61,7 +61,7 @@ pub async fn list_remote_following(
|
||||
|
||||
pub async fn remove_remote_following(
|
||||
follows: &dyn FollowRepository,
|
||||
users: &dyn UserRepository,
|
||||
users: &dyn UserReader,
|
||||
federation: &dyn FederationActionPort,
|
||||
events: &dyn EventPublisher,
|
||||
user_id: &UserId,
|
||||
|
||||
@@ -4,7 +4,7 @@ use domain::{
|
||||
feed::{FeedEntry, PageParams, Paginated, UserSummary},
|
||||
user::User,
|
||||
},
|
||||
ports::{FeedRepository, FollowRepository, TagRepository, UserRepository},
|
||||
ports::{FeedRepository, FollowRepository, TagRepository, UserReader},
|
||||
value_objects::UserId,
|
||||
};
|
||||
|
||||
@@ -70,12 +70,12 @@ pub async fn search(
|
||||
feed.search(query, &page, viewer_id).await
|
||||
}
|
||||
|
||||
pub async fn list_users(users: &dyn UserRepository) -> Result<Vec<UserSummary>, DomainError> {
|
||||
pub async fn list_users(users: &dyn UserReader) -> Result<Vec<UserSummary>, DomainError> {
|
||||
users.list_with_stats().await
|
||||
}
|
||||
|
||||
pub async fn list_users_paginated(
|
||||
users: &dyn UserRepository,
|
||||
users: &dyn UserReader,
|
||||
page: PageParams,
|
||||
) -> Result<Paginated<UserSummary>, DomainError> {
|
||||
let all = users.list_with_stats().await?;
|
||||
|
||||
@@ -4,11 +4,11 @@ use domain::{
|
||||
errors::DomainError,
|
||||
events::DomainEvent,
|
||||
models::{top_friend::TopFriend, user::User},
|
||||
ports::{EventPublisher, TopFriendRepository, UserRepository},
|
||||
ports::{EventPublisher, TopFriendRepository, UserReader, UserWriter},
|
||||
value_objects::{UserId, Username},
|
||||
};
|
||||
|
||||
pub async fn get_user(users: &dyn UserRepository, user_id: &UserId) -> Result<User, DomainError> {
|
||||
pub async fn get_user(users: &dyn UserReader, user_id: &UserId) -> Result<User, DomainError> {
|
||||
users
|
||||
.find_by_id(user_id)
|
||||
.await?
|
||||
@@ -16,7 +16,7 @@ pub async fn get_user(users: &dyn UserRepository, user_id: &UserId) -> Result<Us
|
||||
}
|
||||
|
||||
pub async fn get_user_by_username(
|
||||
users: &dyn UserRepository,
|
||||
users: &dyn UserReader,
|
||||
username: &str,
|
||||
) -> Result<User, DomainError> {
|
||||
let username = Username::new(username).map_err(|_| DomainError::NotFound)?;
|
||||
@@ -28,7 +28,7 @@ pub async fn get_user_by_username(
|
||||
|
||||
/// Resolve a path segment that is either a UUID (AP actor URL) or a username.
|
||||
pub async fn get_user_by_id_or_username(
|
||||
users: &dyn UserRepository,
|
||||
users: &dyn UserReader,
|
||||
id_or_username: &str,
|
||||
) -> Result<User, DomainError> {
|
||||
if let Ok(uuid) = uuid::Uuid::parse_str(id_or_username) {
|
||||
@@ -43,7 +43,7 @@ pub async fn get_user_by_id_or_username(
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub async fn update_profile(
|
||||
users: &dyn UserRepository,
|
||||
users: &dyn UserWriter,
|
||||
events: &dyn EventPublisher,
|
||||
user_id: &UserId,
|
||||
display_name: Option<String>,
|
||||
|
||||
@@ -5,7 +5,7 @@ use domain::{
|
||||
models::social::{Block, Boost, Follow, FollowState, Like},
|
||||
ports::{
|
||||
BlockRepository, BoostRepository, EventPublisher, FederationActionPort, FollowRepository,
|
||||
LikeRepository, UserRepository,
|
||||
LikeRepository, UserReader,
|
||||
},
|
||||
value_objects::{BoostId, LikeId, ThoughtId, UserId, Username},
|
||||
};
|
||||
@@ -92,7 +92,7 @@ pub async fn unboost_thought(
|
||||
|
||||
pub async fn follow_actor(
|
||||
follows: &dyn FollowRepository,
|
||||
users: &dyn UserRepository,
|
||||
users: &dyn UserReader,
|
||||
federation: &dyn FederationActionPort,
|
||||
events: &dyn EventPublisher,
|
||||
follower_id: &UserId,
|
||||
@@ -139,7 +139,7 @@ pub async fn follow_user(
|
||||
|
||||
pub async fn unfollow_actor(
|
||||
follows: &dyn FollowRepository,
|
||||
users: &dyn UserRepository,
|
||||
users: &dyn UserReader,
|
||||
federation: &dyn FederationActionPort,
|
||||
events: &dyn EventPublisher,
|
||||
follower_id: &UserId,
|
||||
@@ -212,7 +212,7 @@ pub async fn reject_follow(
|
||||
|
||||
pub async fn block_by_username(
|
||||
blocks: &dyn BlockRepository,
|
||||
users: &dyn UserRepository,
|
||||
users: &dyn UserReader,
|
||||
events: &dyn EventPublisher,
|
||||
blocker_id: &UserId,
|
||||
username: &str,
|
||||
@@ -227,7 +227,7 @@ pub async fn block_by_username(
|
||||
|
||||
pub async fn unblock_by_username(
|
||||
blocks: &dyn BlockRepository,
|
||||
users: &dyn UserRepository,
|
||||
users: &dyn UserReader,
|
||||
events: &dyn EventPublisher,
|
||||
blocker_id: &UserId,
|
||||
username: &str,
|
||||
|
||||
@@ -2,7 +2,7 @@ use domain::{
|
||||
errors::DomainError,
|
||||
events::DomainEvent,
|
||||
models::thought::{Thought, Visibility},
|
||||
ports::{EventPublisher, TagRepository, ThoughtRepository, UserRepository},
|
||||
ports::{EventPublisher, TagRepository, ThoughtRepository, UserReader},
|
||||
value_objects::{Content, ThoughtId, UserId},
|
||||
};
|
||||
|
||||
@@ -51,7 +51,7 @@ pub struct CreateThoughtOutput {
|
||||
|
||||
pub async fn create_thought(
|
||||
thoughts: &dyn ThoughtRepository,
|
||||
_users: &dyn UserRepository,
|
||||
_users: &dyn UserReader,
|
||||
tags: &dyn TagRepository,
|
||||
events: &dyn EventPublisher,
|
||||
input: CreateThoughtInput,
|
||||
|
||||
Reference in New Issue
Block a user