structural refactor and codebase improvements
This commit is contained in:
@@ -1,17 +1,14 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use chrono::Utc;
|
||||
use domain::errors::DomainError;
|
||||
use domain::events::DomainEvent;
|
||||
use domain::models::wrapup::{DateRange, WrapUpStatus};
|
||||
use domain::ports::{EventPublisher, WrapUpRepository};
|
||||
use domain::value_objects::{UserId, WrapUpId};
|
||||
|
||||
use crate::wrapup::commands::RequestWrapUpCommand;
|
||||
use crate::wrapup::deps::GenerateWrapUpDeps;
|
||||
|
||||
pub async fn execute(
|
||||
wrapup_repo: Arc<dyn WrapUpRepository>,
|
||||
event_publisher: Arc<dyn EventPublisher>,
|
||||
deps: &GenerateWrapUpDeps,
|
||||
cmd: RequestWrapUpCommand,
|
||||
) -> Result<WrapUpId, DomainError> {
|
||||
let date_range = DateRange::new(cmd.start_date, cmd.end_date)?;
|
||||
@@ -22,7 +19,8 @@ pub async fn execute(
|
||||
));
|
||||
}
|
||||
|
||||
let existing = wrapup_repo
|
||||
let existing = deps
|
||||
.wrapup_repo
|
||||
.find_existing(cmd.user_id, date_range.start(), date_range.end())
|
||||
.await?;
|
||||
|
||||
@@ -30,7 +28,7 @@ pub async fn execute(
|
||||
match rec.status {
|
||||
WrapUpStatus::Ready | WrapUpStatus::Generating => return Ok(rec.id.clone()),
|
||||
WrapUpStatus::Failed => {
|
||||
wrapup_repo.delete(&rec.id).await?;
|
||||
deps.wrapup_repo.delete(&rec.id).await?;
|
||||
}
|
||||
WrapUpStatus::Pending => return Ok(rec.id.clone()),
|
||||
}
|
||||
@@ -48,9 +46,9 @@ pub async fn execute(
|
||||
created_at: Utc::now().naive_utc(),
|
||||
completed_at: None,
|
||||
};
|
||||
wrapup_repo.create(&record).await?;
|
||||
deps.wrapup_repo.create(&record).await?;
|
||||
|
||||
event_publisher
|
||||
deps.event_publisher
|
||||
.publish(&DomainEvent::WrapUpRequested {
|
||||
wrapup_id: id.clone(),
|
||||
user_id: cmd.user_id.map(UserId::from_uuid),
|
||||
|
||||
Reference in New Issue
Block a user