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

@@ -5,7 +5,7 @@ use domain::{
events::DomainEvent,
models::notification::{Notification, NotificationType},
ports::{NotificationRepository, ThoughtRepository},
value_objects::NotificationId,
value_objects::{NotificationId, UserId},
};
pub struct NotificationEventService {
@@ -13,6 +13,10 @@ pub struct NotificationEventService {
pub notifications: Arc<dyn NotificationRepository>,
}
fn is_self_action(thought_author: &UserId, actor: &UserId) -> bool {
thought_author == actor
}
impl NotificationEventService {
pub async fn process(&self, event: &DomainEvent) -> Result<(), DomainError> {
match event {
@@ -21,7 +25,7 @@ impl NotificationEventService {
Some(t) => t,
None => return Ok(()),
};
if thought.user_id == *user_id { return Ok(()); }
if is_self_action(&thought.user_id, user_id) { return Ok(()); }
self.notifications.save(&Notification {
id: NotificationId::new(),
user_id: thought.user_id,
@@ -37,7 +41,7 @@ impl NotificationEventService {
Some(t) => t,
None => return Ok(()),
};
if thought.user_id == *user_id { return Ok(()); }
if is_self_action(&thought.user_id, user_id) { return Ok(()); }
self.notifications.save(&Notification {
id: NotificationId::new(),
user_id: thought.user_id,
@@ -68,7 +72,7 @@ impl NotificationEventService {
Some(t) => t,
None => return Ok(()),
};
if original.user_id == *user_id { return Ok(()); }
if is_self_action(&original.user_id, user_id) { return Ok(()); }
self.notifications.save(&Notification {
id: NotificationId::new(),
user_id: original.user_id,