refactor (v2): better arch

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-06-07 21:19:54 +02:00
parent 0753f3d256
commit 839308ec19
166 changed files with 8553 additions and 884 deletions

View File

@@ -0,0 +1,46 @@
use domain::{
errors::DomainResult,
events::DomainEvent,
note::{
entity::Note,
value_objects::{NoteColor, NoteTitle},
},
user::entity::UserId,
};
use super::commands::CreateNoteCommand;
use crate::context::AppContext;
pub async fn execute(ctx: &AppContext, cmd: CreateNoteCommand) -> DomainResult<Note> {
let user_id = UserId::from_uuid(cmd.user_id);
let title = NoteTitle::from_optional(cmd.title)?;
let mut note = Note::new(user_id, title, cmd.content);
if let Some(color) = cmd.color {
note.set_color(NoteColor::new(color));
}
if cmd.is_pinned {
note.set_pinned(true);
}
ctx.repos.note.save(&note).await?;
if let Err(e) = ctx
.services
.event_publisher
.publish(&DomainEvent::NoteCreated {
note_id: note.id,
user_id,
})
.await
{
tracing::warn!("failed to publish NoteCreated: {e}");
}
Ok(note)
}
#[cfg(test)]
#[path = "tests/create_note.rs"]
mod tests;