refactor(application): fix 4 code smells — validate username input, extract ownership guard and dedup helpers
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 5m12s
test / unit (pull_request) Successful in 16m23s
test / integration (pull_request) Failing after 17m26s

This commit is contained in:
2026-05-14 16:27:03 +02:00
parent dd7beb7ab4
commit e6f4a6256f
4 changed files with 28 additions and 14 deletions

View File

@@ -2,8 +2,9 @@ use std::sync::Arc;
use domain::{
errors::DomainError,
events::DomainEvent,
models::thought::Visibility,
models::thought::{Thought, Visibility},
ports::{OutboundFederationPort, ThoughtRepository, UserRepository},
value_objects::ThoughtId,
};
pub struct FederationEventService {
@@ -14,6 +15,12 @@ pub struct FederationEventService {
}
impl FederationEventService {
fn object_ap_id(&self, thought: &Thought, thought_id: &ThoughtId) -> String {
thought.ap_id.clone().unwrap_or_else(|| {
format!("{}/thoughts/{}", self.base_url, thought_id)
})
}
pub async fn process(&self, event: &DomainEvent) -> Result<(), DomainError> {
match event {
DomainEvent::ThoughtCreated { thought_id, user_id, .. } => {
@@ -52,9 +59,7 @@ impl FederationEventService {
Some(t) => t,
None => return Ok(()),
};
let object_ap_id = thought.ap_id.clone().unwrap_or_else(|| {
format!("{}/thoughts/{}", self.base_url, thought_id)
});
let object_ap_id = self.object_ap_id(&thought, thought_id);
self.ap.broadcast_announce(user_id, &object_ap_id).await
}
@@ -63,9 +68,7 @@ impl FederationEventService {
Some(t) => t,
None => return Ok(()),
};
let object_ap_id = thought.ap_id.clone().unwrap_or_else(|| {
format!("{}/thoughts/{}", self.base_url, thought_id)
});
let object_ap_id = self.object_ap_id(&thought, thought_id);
self.ap.broadcast_undo_announce(user_id, &object_ap_id).await
}