refactor(wrapup): scoped deps — HandleWrapUpRequestedDeps, flat-Arc jobs
This commit is contained in:
@@ -1,18 +1,30 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use chrono::Datelike;
|
use chrono::Datelike;
|
||||||
use domain::{errors::DomainError, ports::PeriodicJob};
|
use domain::{
|
||||||
|
errors::DomainError,
|
||||||
use crate::context::AppContext;
|
ports::{EventPublisher, PeriodicJob, UserRepository, WrapUpRepository},
|
||||||
|
};
|
||||||
|
|
||||||
pub struct WrapUpAutoGenerateJob {
|
pub struct WrapUpAutoGenerateJob {
|
||||||
ctx: AppContext,
|
user: Arc<dyn UserRepository>,
|
||||||
|
wrapup_repo: Arc<dyn WrapUpRepository>,
|
||||||
|
event_publisher: Arc<dyn EventPublisher>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WrapUpAutoGenerateJob {
|
impl WrapUpAutoGenerateJob {
|
||||||
pub fn new(ctx: AppContext) -> Self {
|
pub fn new(
|
||||||
Self { ctx }
|
user: Arc<dyn UserRepository>,
|
||||||
|
wrapup_repo: Arc<dyn WrapUpRepository>,
|
||||||
|
event_publisher: Arc<dyn EventPublisher>,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
user,
|
||||||
|
wrapup_repo,
|
||||||
|
event_publisher,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,12 +45,10 @@ impl PeriodicJob for WrapUpAutoGenerateJob {
|
|||||||
let end = chrono::NaiveDate::from_ymd_opt(year + 1, 1, 1)
|
let end = chrono::NaiveDate::from_ymd_opt(year + 1, 1, 1)
|
||||||
.ok_or_else(|| DomainError::ValidationError("invalid date".into()))?;
|
.ok_or_else(|| DomainError::ValidationError("invalid date".into()))?;
|
||||||
|
|
||||||
let users = self.ctx.repos.user.list_with_stats().await?;
|
let users = self.user.list_with_stats().await?;
|
||||||
for user in &users {
|
for user in &users {
|
||||||
if user.total_movies > 0 {
|
if user.total_movies > 0 {
|
||||||
let existing = self
|
let existing = self
|
||||||
.ctx
|
|
||||||
.repos
|
|
||||||
.wrapup_repo
|
.wrapup_repo
|
||||||
.find_existing(Some(user.user_id.value()), start, end)
|
.find_existing(Some(user.user_id.value()), start, end)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -48,7 +58,13 @@ impl PeriodicJob for WrapUpAutoGenerateJob {
|
|||||||
start_date: start,
|
start_date: start,
|
||||||
end_date: end,
|
end_date: end,
|
||||||
};
|
};
|
||||||
if let Err(e) = crate::wrapup::generate::execute(&self.ctx, cmd).await {
|
if let Err(e) = crate::wrapup::generate::execute(
|
||||||
|
self.wrapup_repo.clone(),
|
||||||
|
self.event_publisher.clone(),
|
||||||
|
cmd,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
tracing::warn!(
|
tracing::warn!(
|
||||||
"auto-generate wrapup for user {} failed: {e}",
|
"auto-generate wrapup for user {} failed: {e}",
|
||||||
user.user_id.value()
|
user.user_id.value()
|
||||||
@@ -58,19 +74,20 @@ impl PeriodicJob for WrapUpAutoGenerateJob {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let existing = self
|
let existing = self.wrapup_repo.find_existing(None, start, end).await?;
|
||||||
.ctx
|
|
||||||
.repos
|
|
||||||
.wrapup_repo
|
|
||||||
.find_existing(None, start, end)
|
|
||||||
.await?;
|
|
||||||
if existing.is_none() {
|
if existing.is_none() {
|
||||||
let cmd = crate::wrapup::commands::RequestWrapUpCommand {
|
let cmd = crate::wrapup::commands::RequestWrapUpCommand {
|
||||||
user_id: None,
|
user_id: None,
|
||||||
start_date: start,
|
start_date: start,
|
||||||
end_date: end,
|
end_date: end,
|
||||||
};
|
};
|
||||||
if let Err(e) = crate::wrapup::generate::execute(&self.ctx, cmd).await {
|
if let Err(e) = crate::wrapup::generate::execute(
|
||||||
|
self.wrapup_repo.clone(),
|
||||||
|
self.event_publisher.clone(),
|
||||||
|
cmd,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
tracing::warn!("auto-generate global wrapup failed: {e}");
|
tracing::warn!("auto-generate global wrapup failed: {e}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -80,12 +97,12 @@ impl PeriodicJob for WrapUpAutoGenerateJob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct WrapUpCleanupJob {
|
pub struct WrapUpCleanupJob {
|
||||||
ctx: AppContext,
|
wrapup_repo: Arc<dyn WrapUpRepository>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WrapUpCleanupJob {
|
impl WrapUpCleanupJob {
|
||||||
pub fn new(ctx: AppContext) -> Self {
|
pub fn new(wrapup_repo: Arc<dyn WrapUpRepository>) -> Self {
|
||||||
Self { ctx }
|
Self { wrapup_repo }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,8 +115,6 @@ impl PeriodicJob for WrapUpCleanupJob {
|
|||||||
async fn run(&self) -> Result<(), DomainError> {
|
async fn run(&self) -> Result<(), DomainError> {
|
||||||
let cutoff = chrono::Utc::now().naive_utc() - chrono::Duration::days(7);
|
let cutoff = chrono::Utc::now().naive_utc() - chrono::Duration::days(7);
|
||||||
let n = self
|
let n = self
|
||||||
.ctx
|
|
||||||
.repos
|
|
||||||
.wrapup_repo
|
.wrapup_repo
|
||||||
.delete_failed_older_than(cutoff)
|
.delete_failed_older_than(cutoff)
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
use crate::context::AppContext;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::wrapup::queries::ComputeWrapUpQuery;
|
use crate::wrapup::queries::ComputeWrapUpQuery;
|
||||||
use domain::errors::DomainError;
|
use domain::errors::DomainError;
|
||||||
use domain::models::wrapup::WrapUpReport;
|
use domain::models::wrapup::WrapUpReport;
|
||||||
|
use domain::ports::WrapUpStatsQuery;
|
||||||
use domain::services::wrapup_analyzer;
|
use domain::services::wrapup_analyzer;
|
||||||
|
|
||||||
pub async fn execute(
|
pub async fn execute(
|
||||||
ctx: &AppContext,
|
wrapup_stats: Arc<dyn WrapUpStatsQuery>,
|
||||||
query: ComputeWrapUpQuery,
|
query: ComputeWrapUpQuery,
|
||||||
) -> Result<WrapUpReport, DomainError> {
|
) -> Result<WrapUpReport, DomainError> {
|
||||||
let rows = ctx
|
let rows = wrapup_stats
|
||||||
.repos
|
|
||||||
.wrapup_stats
|
|
||||||
.get_reviews_with_profiles(&query.scope, &query.date_range)
|
.get_reviews_with_profiles(&query.scope, &query.date_range)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(wrapup_analyzer::build_report(
|
Ok(wrapup_analyzer::build_report(
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use domain::errors::DomainError;
|
use domain::errors::DomainError;
|
||||||
|
use domain::ports::WrapUpRepository;
|
||||||
use domain::value_objects::WrapUpId;
|
use domain::value_objects::WrapUpId;
|
||||||
|
|
||||||
use crate::context::AppContext;
|
pub async fn execute(
|
||||||
|
wrapup_repo: Arc<dyn WrapUpRepository>,
|
||||||
pub async fn execute(ctx: &AppContext, id: WrapUpId) -> Result<(), DomainError> {
|
id: WrapUpId,
|
||||||
ctx.repos
|
) -> Result<(), DomainError> {
|
||||||
.wrapup_repo
|
wrapup_repo
|
||||||
.get_by_id(&id)
|
.get_by_id(&id)
|
||||||
.await?
|
.await?
|
||||||
.ok_or_else(|| DomainError::NotFound("wrap-up not found".into()))?;
|
.ok_or_else(|| DomainError::NotFound("wrap-up not found".into()))?;
|
||||||
|
|
||||||
ctx.repos.wrapup_repo.delete(&id).await
|
wrapup_repo.delete(&id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
9
crates/application/src/wrapup/deps.rs
Normal file
9
crates/application/src/wrapup/deps.rs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use domain::ports::{EventPublisher, WrapUpRepository, WrapUpStatsQuery};
|
||||||
|
|
||||||
|
pub struct HandleWrapUpRequestedDeps {
|
||||||
|
pub wrapup_repo: Arc<dyn WrapUpRepository>,
|
||||||
|
pub event_publisher: Arc<dyn EventPublisher>,
|
||||||
|
pub wrapup_stats: Arc<dyn WrapUpStatsQuery>,
|
||||||
|
}
|
||||||
@@ -3,20 +3,28 @@ use std::sync::Arc;
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use domain::errors::DomainError;
|
use domain::errors::DomainError;
|
||||||
use domain::events::DomainEvent;
|
use domain::events::DomainEvent;
|
||||||
use domain::ports::EventHandler;
|
use domain::ports::{EventHandler, EventPublisher, WrapUpRepository, WrapUpStatsQuery};
|
||||||
use tokio::sync::Semaphore;
|
use tokio::sync::Semaphore;
|
||||||
|
|
||||||
use crate::context::AppContext;
|
use super::deps::HandleWrapUpRequestedDeps;
|
||||||
|
|
||||||
pub struct WrapUpEventHandler {
|
pub struct WrapUpEventHandler {
|
||||||
ctx: AppContext,
|
deps: HandleWrapUpRequestedDeps,
|
||||||
semaphore: Arc<Semaphore>,
|
semaphore: Arc<Semaphore>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WrapUpEventHandler {
|
impl WrapUpEventHandler {
|
||||||
pub fn new(ctx: AppContext) -> Self {
|
pub fn new(
|
||||||
|
wrapup_repo: Arc<dyn WrapUpRepository>,
|
||||||
|
event_publisher: Arc<dyn EventPublisher>,
|
||||||
|
wrapup_stats: Arc<dyn WrapUpStatsQuery>,
|
||||||
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
ctx,
|
deps: HandleWrapUpRequestedDeps {
|
||||||
|
wrapup_repo,
|
||||||
|
event_publisher,
|
||||||
|
wrapup_stats,
|
||||||
|
},
|
||||||
semaphore: Arc::new(Semaphore::new(2)),
|
semaphore: Arc::new(Semaphore::new(2)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,7 +44,7 @@ impl EventHandler for WrapUpEventHandler {
|
|||||||
DomainError::InfrastructureError("render semaphore closed".into())
|
DomainError::InfrastructureError("render semaphore closed".into())
|
||||||
})?;
|
})?;
|
||||||
super::handle_requested::execute(
|
super::handle_requested::execute(
|
||||||
&self.ctx,
|
&self.deps,
|
||||||
wrapup_id.clone(),
|
wrapup_id.clone(),
|
||||||
user_id.as_ref().map(|u| u.value()),
|
user_id.as_ref().map(|u| u.value()),
|
||||||
*start_date,
|
*start_date,
|
||||||
|
|||||||
@@ -1,13 +1,19 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use domain::errors::DomainError;
|
use domain::errors::DomainError;
|
||||||
use domain::events::DomainEvent;
|
use domain::events::DomainEvent;
|
||||||
use domain::models::wrapup::{DateRange, WrapUpStatus};
|
use domain::models::wrapup::{DateRange, WrapUpStatus};
|
||||||
|
use domain::ports::{EventPublisher, WrapUpRepository};
|
||||||
use domain::value_objects::{UserId, WrapUpId};
|
use domain::value_objects::{UserId, WrapUpId};
|
||||||
|
|
||||||
use crate::context::AppContext;
|
|
||||||
use crate::wrapup::commands::RequestWrapUpCommand;
|
use crate::wrapup::commands::RequestWrapUpCommand;
|
||||||
|
|
||||||
pub async fn execute(ctx: &AppContext, cmd: RequestWrapUpCommand) -> Result<WrapUpId, DomainError> {
|
pub async fn execute(
|
||||||
|
wrapup_repo: Arc<dyn WrapUpRepository>,
|
||||||
|
event_publisher: Arc<dyn EventPublisher>,
|
||||||
|
cmd: RequestWrapUpCommand,
|
||||||
|
) -> Result<WrapUpId, DomainError> {
|
||||||
let date_range = DateRange::new(cmd.start_date, cmd.end_date)?;
|
let date_range = DateRange::new(cmd.start_date, cmd.end_date)?;
|
||||||
|
|
||||||
if cmd.end_date > Utc::now().date_naive() {
|
if cmd.end_date > Utc::now().date_naive() {
|
||||||
@@ -16,9 +22,7 @@ pub async fn execute(ctx: &AppContext, cmd: RequestWrapUpCommand) -> Result<Wrap
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let existing = ctx
|
let existing = wrapup_repo
|
||||||
.repos
|
|
||||||
.wrapup_repo
|
|
||||||
.find_existing(cmd.user_id, date_range.start(), date_range.end())
|
.find_existing(cmd.user_id, date_range.start(), date_range.end())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -26,7 +30,7 @@ pub async fn execute(ctx: &AppContext, cmd: RequestWrapUpCommand) -> Result<Wrap
|
|||||||
match rec.status {
|
match rec.status {
|
||||||
WrapUpStatus::Ready | WrapUpStatus::Generating => return Ok(rec.id.clone()),
|
WrapUpStatus::Ready | WrapUpStatus::Generating => return Ok(rec.id.clone()),
|
||||||
WrapUpStatus::Failed => {
|
WrapUpStatus::Failed => {
|
||||||
ctx.repos.wrapup_repo.delete(&rec.id).await?;
|
wrapup_repo.delete(&rec.id).await?;
|
||||||
}
|
}
|
||||||
WrapUpStatus::Pending => return Ok(rec.id.clone()),
|
WrapUpStatus::Pending => return Ok(rec.id.clone()),
|
||||||
}
|
}
|
||||||
@@ -44,10 +48,9 @@ pub async fn execute(ctx: &AppContext, cmd: RequestWrapUpCommand) -> Result<Wrap
|
|||||||
created_at: Utc::now().naive_utc(),
|
created_at: Utc::now().naive_utc(),
|
||||||
completed_at: None,
|
completed_at: None,
|
||||||
};
|
};
|
||||||
ctx.repos.wrapup_repo.create(&record).await?;
|
wrapup_repo.create(&record).await?;
|
||||||
|
|
||||||
ctx.services
|
event_publisher
|
||||||
.event_publisher
|
|
||||||
.publish(&DomainEvent::WrapUpRequested {
|
.publish(&DomainEvent::WrapUpRequested {
|
||||||
wrapup_id: id.clone(),
|
wrapup_id: id.clone(),
|
||||||
user_id: cmd.user_id.map(UserId::from_uuid),
|
user_id: cmd.user_id.map(UserId::from_uuid),
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use domain::errors::DomainError;
|
use domain::errors::DomainError;
|
||||||
use domain::models::wrapup::WrapUpRecord;
|
use domain::models::wrapup::WrapUpRecord;
|
||||||
|
use domain::ports::WrapUpRepository;
|
||||||
use domain::value_objects::WrapUpId;
|
use domain::value_objects::WrapUpId;
|
||||||
|
|
||||||
use crate::context::AppContext;
|
pub async fn execute(
|
||||||
|
wrapup_repo: Arc<dyn WrapUpRepository>,
|
||||||
pub async fn execute(ctx: &AppContext, id: WrapUpId) -> Result<Option<WrapUpRecord>, DomainError> {
|
id: WrapUpId,
|
||||||
ctx.repos.wrapup_repo.get_by_id(&id).await
|
) -> Result<Option<WrapUpRecord>, DomainError> {
|
||||||
|
wrapup_repo.get_by_id(&id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
use crate::context::AppContext;
|
use crate::wrapup::{compute, deps::HandleWrapUpRequestedDeps, queries::ComputeWrapUpQuery};
|
||||||
use crate::wrapup::{compute, queries::ComputeWrapUpQuery};
|
|
||||||
use domain::errors::DomainError;
|
use domain::errors::DomainError;
|
||||||
use domain::events::DomainEvent;
|
use domain::events::DomainEvent;
|
||||||
use domain::models::wrapup::{DateRange, WrapUpScope, WrapUpStatus};
|
use domain::models::wrapup::{DateRange, WrapUpScope, WrapUpStatus};
|
||||||
use domain::value_objects::WrapUpId;
|
use domain::value_objects::WrapUpId;
|
||||||
|
|
||||||
pub async fn execute(
|
pub async fn execute(
|
||||||
ctx: &AppContext,
|
deps: &HandleWrapUpRequestedDeps,
|
||||||
wrapup_id: WrapUpId,
|
wrapup_id: WrapUpId,
|
||||||
user_id: Option<uuid::Uuid>,
|
user_id: Option<uuid::Uuid>,
|
||||||
start_date: chrono::NaiveDate,
|
start_date: chrono::NaiveDate,
|
||||||
end_date: chrono::NaiveDate,
|
end_date: chrono::NaiveDate,
|
||||||
) -> Result<(), DomainError> {
|
) -> Result<(), DomainError> {
|
||||||
if let Ok(Some(rec)) = ctx.repos.wrapup_repo.get_by_id(&wrapup_id).await
|
if let Ok(Some(rec)) = deps.wrapup_repo.get_by_id(&wrapup_id).await
|
||||||
&& (rec.status == WrapUpStatus::Ready || rec.status == WrapUpStatus::Generating)
|
&& (rec.status == WrapUpStatus::Ready || rec.status == WrapUpStatus::Generating)
|
||||||
{
|
{
|
||||||
tracing::debug!(
|
tracing::debug!(
|
||||||
@@ -23,8 +22,7 @@ pub async fn execute(
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.repos
|
deps.wrapup_repo
|
||||||
.wrapup_repo
|
|
||||||
.update_status(&wrapup_id, &WrapUpStatus::Generating, None)
|
.update_status(&wrapup_id, &WrapUpStatus::Generating, None)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -37,22 +35,19 @@ pub async fn execute(
|
|||||||
date_range: DateRange::new(start_date, end_date)?,
|
date_range: DateRange::new(start_date, end_date)?,
|
||||||
};
|
};
|
||||||
|
|
||||||
match compute::execute(ctx, query).await {
|
match compute::execute(deps.wrapup_stats.clone(), query).await {
|
||||||
Ok(report) => {
|
Ok(report) => {
|
||||||
ctx.repos
|
deps.wrapup_repo
|
||||||
.wrapup_repo
|
|
||||||
.set_complete(&wrapup_id, &report)
|
.set_complete(&wrapup_id, &report)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
ctx.services
|
deps.event_publisher
|
||||||
.event_publisher
|
|
||||||
.publish(&DomainEvent::WrapUpCompleted { wrapup_id })
|
.publish(&DomainEvent::WrapUpCompleted { wrapup_id })
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
ctx.repos
|
deps.wrapup_repo
|
||||||
.wrapup_repo
|
|
||||||
.update_status(&wrapup_id, &WrapUpStatus::Failed, Some(&e.to_string()))
|
.update_status(&wrapup_id, &WrapUpStatus::Failed, Some(&e.to_string()))
|
||||||
.await?;
|
.await?;
|
||||||
Err(e)
|
Err(e)
|
||||||
|
|||||||
@@ -1,21 +1,22 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use domain::errors::DomainError;
|
use domain::errors::DomainError;
|
||||||
use domain::models::wrapup::WrapUpRecord;
|
use domain::models::wrapup::WrapUpRecord;
|
||||||
|
use domain::ports::WrapUpRepository;
|
||||||
use crate::context::AppContext;
|
|
||||||
|
|
||||||
pub struct ListWrapUpsQuery {
|
pub struct ListWrapUpsQuery {
|
||||||
pub user_id: Option<Uuid>,
|
pub user_id: Option<Uuid>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute(
|
pub async fn execute(
|
||||||
ctx: &AppContext,
|
wrapup_repo: Arc<dyn WrapUpRepository>,
|
||||||
query: ListWrapUpsQuery,
|
query: ListWrapUpsQuery,
|
||||||
) -> Result<Vec<WrapUpRecord>, DomainError> {
|
) -> Result<Vec<WrapUpRecord>, DomainError> {
|
||||||
match query.user_id {
|
match query.user_id {
|
||||||
Some(uid) => ctx.repos.wrapup_repo.list_for_user(uid).await,
|
Some(uid) => wrapup_repo.list_for_user(uid).await,
|
||||||
None => ctx.repos.wrapup_repo.list_global().await,
|
None => wrapup_repo.list_global().await,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
pub mod commands;
|
pub mod commands;
|
||||||
pub mod compute;
|
pub mod compute;
|
||||||
pub mod delete;
|
pub mod delete;
|
||||||
|
pub mod deps;
|
||||||
pub mod event_handler;
|
pub mod event_handler;
|
||||||
pub mod generate;
|
pub mod generate;
|
||||||
pub mod get_wrapup;
|
pub mod get_wrapup;
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ use domain::ports::WrapUpMovieRow;
|
|||||||
use domain::testing::InMemoryWrapUpStatsQuery;
|
use domain::testing::InMemoryWrapUpStatsQuery;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::test_helpers::TestContextBuilder;
|
|
||||||
use crate::wrapup::queries::ComputeWrapUpQuery;
|
use crate::wrapup::queries::ComputeWrapUpQuery;
|
||||||
|
|
||||||
fn make_row(title: &str, rating: u8, watched_at: &str) -> WrapUpMovieRow {
|
fn make_row(title: &str, rating: u8, watched_at: &str) -> WrapUpMovieRow {
|
||||||
@@ -42,11 +41,10 @@ fn year_2024_range() -> DateRange {
|
|||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn empty_report() {
|
async fn empty_report() {
|
||||||
let stats = InMemoryWrapUpStatsQuery::new();
|
let stats = InMemoryWrapUpStatsQuery::new();
|
||||||
let ctx = TestContextBuilder::new().wrapup_stats(stats).build();
|
|
||||||
let user_id = Uuid::new_v4();
|
let user_id = Uuid::new_v4();
|
||||||
|
|
||||||
let report = super::execute(
|
let report = super::execute(
|
||||||
&ctx,
|
stats,
|
||||||
ComputeWrapUpQuery {
|
ComputeWrapUpQuery {
|
||||||
scope: WrapUpScope::User(user_id),
|
scope: WrapUpScope::User(user_id),
|
||||||
date_range: year_2024_range(),
|
date_range: year_2024_range(),
|
||||||
@@ -74,10 +72,9 @@ async fn basic_stats() {
|
|||||||
r2.genres = vec!["Comedy".to_string()];
|
r2.genres = vec!["Comedy".to_string()];
|
||||||
|
|
||||||
let stats = InMemoryWrapUpStatsQuery::with_rows(vec![r1, r2]);
|
let stats = InMemoryWrapUpStatsQuery::with_rows(vec![r1, r2]);
|
||||||
let ctx = TestContextBuilder::new().wrapup_stats(stats).build();
|
|
||||||
|
|
||||||
let report = super::execute(
|
let report = super::execute(
|
||||||
&ctx,
|
stats,
|
||||||
ComputeWrapUpQuery {
|
ComputeWrapUpQuery {
|
||||||
scope: WrapUpScope::User(user_id),
|
scope: WrapUpScope::User(user_id),
|
||||||
date_range: year_2024_range(),
|
date_range: year_2024_range(),
|
||||||
@@ -109,10 +106,9 @@ async fn rewatch_detection() {
|
|||||||
r2.movie_id = movie_id;
|
r2.movie_id = movie_id;
|
||||||
|
|
||||||
let stats = InMemoryWrapUpStatsQuery::with_rows(vec![r1, r2]);
|
let stats = InMemoryWrapUpStatsQuery::with_rows(vec![r1, r2]);
|
||||||
let ctx = TestContextBuilder::new().wrapup_stats(stats).build();
|
|
||||||
|
|
||||||
let report = super::execute(
|
let report = super::execute(
|
||||||
&ctx,
|
stats,
|
||||||
ComputeWrapUpQuery {
|
ComputeWrapUpQuery {
|
||||||
scope: WrapUpScope::User(user_id),
|
scope: WrapUpScope::User(user_id),
|
||||||
date_range: year_2024_range(),
|
date_range: year_2024_range(),
|
||||||
@@ -141,10 +137,9 @@ async fn global_scope() {
|
|||||||
r2.user_id = user_b;
|
r2.user_id = user_b;
|
||||||
|
|
||||||
let stats = InMemoryWrapUpStatsQuery::with_rows(vec![r1, r2]);
|
let stats = InMemoryWrapUpStatsQuery::with_rows(vec![r1, r2]);
|
||||||
let ctx = TestContextBuilder::new().wrapup_stats(stats).build();
|
|
||||||
|
|
||||||
let report = super::execute(
|
let report = super::execute(
|
||||||
&ctx,
|
stats,
|
||||||
ComputeWrapUpQuery {
|
ComputeWrapUpQuery {
|
||||||
scope: WrapUpScope::Global,
|
scope: WrapUpScope::Global,
|
||||||
date_range: year_2024_range(),
|
date_range: year_2024_range(),
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
use domain::models::wrapup::{WrapUpRecord, WrapUpStatus};
|
use domain::models::wrapup::{WrapUpRecord, WrapUpStatus};
|
||||||
use domain::testing::InMemoryWrapUpRepository;
|
use domain::testing::InMemoryWrapUpRepository;
|
||||||
use domain::value_objects::WrapUpId;
|
use domain::value_objects::WrapUpId;
|
||||||
|
|
||||||
use crate::test_helpers::TestContextBuilder;
|
|
||||||
use crate::wrapup::delete;
|
use crate::wrapup::delete;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -24,22 +21,13 @@ async fn deletes_existing_wrapup() {
|
|||||||
completed_at: None,
|
completed_at: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
let ctx = TestContextBuilder::new().build();
|
delete::execute(repo.clone(), id).await.unwrap();
|
||||||
let ctx = crate::context::AppContext {
|
|
||||||
repos: crate::context::Repositories {
|
|
||||||
wrapup_repo: Arc::clone(&repo) as _,
|
|
||||||
..ctx.repos
|
|
||||||
},
|
|
||||||
..ctx
|
|
||||||
};
|
|
||||||
|
|
||||||
delete::execute(&ctx, id).await.unwrap();
|
|
||||||
assert_eq!(repo.store.lock().unwrap().len(), 0);
|
assert_eq!(repo.store.lock().unwrap().len(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn fails_when_not_found() {
|
async fn fails_when_not_found() {
|
||||||
let ctx = TestContextBuilder::new().build();
|
let repo = InMemoryWrapUpRepository::new();
|
||||||
let result = delete::execute(&ctx, WrapUpId::generate()).await;
|
let result = delete::execute(repo.clone(), WrapUpId::generate()).await;
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
use domain::events::DomainEvent;
|
use domain::events::DomainEvent;
|
||||||
use domain::models::wrapup::{WrapUpRecord, WrapUpStatus};
|
use domain::models::wrapup::{WrapUpRecord, WrapUpStatus};
|
||||||
@@ -7,7 +5,6 @@ use domain::testing::{InMemoryWrapUpRepository, NoopEventPublisher};
|
|||||||
use domain::value_objects::WrapUpId;
|
use domain::value_objects::WrapUpId;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::test_helpers::TestContextBuilder;
|
|
||||||
use crate::wrapup::{commands::RequestWrapUpCommand, generate};
|
use crate::wrapup::{commands::RequestWrapUpCommand, generate};
|
||||||
|
|
||||||
fn past_cmd() -> RequestWrapUpCommand {
|
fn past_cmd() -> RequestWrapUpCommand {
|
||||||
@@ -22,22 +19,10 @@ fn past_cmd() -> RequestWrapUpCommand {
|
|||||||
async fn creates_pending_record_and_emits_event() {
|
async fn creates_pending_record_and_emits_event() {
|
||||||
let repo = InMemoryWrapUpRepository::new();
|
let repo = InMemoryWrapUpRepository::new();
|
||||||
let events = NoopEventPublisher::new();
|
let events = NoopEventPublisher::new();
|
||||||
let ctx = TestContextBuilder::new()
|
|
||||||
.wrapup_stats(domain::testing::InMemoryWrapUpStatsQuery::new())
|
|
||||||
.build();
|
|
||||||
let ctx = crate::context::AppContext {
|
|
||||||
repos: crate::context::Repositories {
|
|
||||||
wrapup_repo: Arc::clone(&repo) as _,
|
|
||||||
..ctx.repos
|
|
||||||
},
|
|
||||||
services: crate::context::Services {
|
|
||||||
event_publisher: Arc::clone(&events) as _,
|
|
||||||
..ctx.services
|
|
||||||
},
|
|
||||||
config: ctx.config,
|
|
||||||
};
|
|
||||||
|
|
||||||
let id = generate::execute(&ctx, past_cmd()).await.unwrap();
|
let id = generate::execute(repo.clone(), events.clone(), past_cmd())
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let stored = repo.store.lock().unwrap();
|
let stored = repo.store.lock().unwrap();
|
||||||
assert_eq!(stored.len(), 1);
|
assert_eq!(stored.len(), 1);
|
||||||
@@ -67,17 +52,11 @@ async fn reuses_existing_ready_wrapup() {
|
|||||||
created_at: chrono::Utc::now().naive_utc(),
|
created_at: chrono::Utc::now().naive_utc(),
|
||||||
completed_at: None,
|
completed_at: None,
|
||||||
});
|
});
|
||||||
|
let events = NoopEventPublisher::new();
|
||||||
|
|
||||||
let ctx = TestContextBuilder::new().build();
|
let id = generate::execute(repo.clone(), events.clone(), past_cmd())
|
||||||
let ctx = crate::context::AppContext {
|
.await
|
||||||
repos: crate::context::Repositories {
|
.unwrap();
|
||||||
wrapup_repo: Arc::clone(&repo) as _,
|
|
||||||
..ctx.repos
|
|
||||||
},
|
|
||||||
..ctx
|
|
||||||
};
|
|
||||||
|
|
||||||
let id = generate::execute(&ctx, past_cmd()).await.unwrap();
|
|
||||||
assert_eq!(id, existing_id);
|
assert_eq!(id, existing_id);
|
||||||
assert_eq!(repo.store.lock().unwrap().len(), 1);
|
assert_eq!(repo.store.lock().unwrap().len(), 1);
|
||||||
}
|
}
|
||||||
@@ -98,20 +77,10 @@ async fn replaces_failed_wrapup() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let events = NoopEventPublisher::new();
|
let events = NoopEventPublisher::new();
|
||||||
let ctx = TestContextBuilder::new().build();
|
|
||||||
let ctx = crate::context::AppContext {
|
|
||||||
repos: crate::context::Repositories {
|
|
||||||
wrapup_repo: Arc::clone(&repo) as _,
|
|
||||||
..ctx.repos
|
|
||||||
},
|
|
||||||
services: crate::context::Services {
|
|
||||||
event_publisher: Arc::clone(&events) as _,
|
|
||||||
..ctx.services
|
|
||||||
},
|
|
||||||
config: ctx.config,
|
|
||||||
};
|
|
||||||
|
|
||||||
let id = generate::execute(&ctx, past_cmd()).await.unwrap();
|
let id = generate::execute(repo.clone(), events.clone(), past_cmd())
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let stored = repo.store.lock().unwrap();
|
let stored = repo.store.lock().unwrap();
|
||||||
assert_eq!(stored.len(), 1);
|
assert_eq!(stored.len(), 1);
|
||||||
@@ -121,9 +90,11 @@ async fn replaces_failed_wrapup() {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn rejects_future_end_date() {
|
async fn rejects_future_end_date() {
|
||||||
let ctx = TestContextBuilder::new().build();
|
let repo = InMemoryWrapUpRepository::new();
|
||||||
|
let events = NoopEventPublisher::new();
|
||||||
let err = generate::execute(
|
let err = generate::execute(
|
||||||
&ctx,
|
repo.clone(),
|
||||||
|
events.clone(),
|
||||||
RequestWrapUpCommand {
|
RequestWrapUpCommand {
|
||||||
user_id: None,
|
user_id: None,
|
||||||
start_date: NaiveDate::from_ymd_opt(2030, 1, 1).unwrap(),
|
start_date: NaiveDate::from_ymd_opt(2030, 1, 1).unwrap(),
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
use domain::models::wrapup::{WrapUpRecord, WrapUpStatus};
|
use domain::models::wrapup::{WrapUpRecord, WrapUpStatus};
|
||||||
use domain::testing::InMemoryWrapUpRepository;
|
use domain::testing::InMemoryWrapUpRepository;
|
||||||
use domain::value_objects::WrapUpId;
|
use domain::value_objects::WrapUpId;
|
||||||
|
|
||||||
use crate::test_helpers::TestContextBuilder;
|
|
||||||
use crate::wrapup::get_wrapup;
|
use crate::wrapup::get_wrapup;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -24,24 +21,15 @@ async fn returns_record_when_exists() {
|
|||||||
completed_at: None,
|
completed_at: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
let ctx = TestContextBuilder::new().build();
|
let result = get_wrapup::execute(repo.clone(), id).await.unwrap();
|
||||||
let ctx = crate::context::AppContext {
|
|
||||||
repos: crate::context::Repositories {
|
|
||||||
wrapup_repo: Arc::clone(&repo) as _,
|
|
||||||
..ctx.repos
|
|
||||||
},
|
|
||||||
..ctx
|
|
||||||
};
|
|
||||||
|
|
||||||
let result = get_wrapup::execute(&ctx, id).await.unwrap();
|
|
||||||
assert!(result.is_some());
|
assert!(result.is_some());
|
||||||
assert_eq!(result.unwrap().status, WrapUpStatus::Pending);
|
assert_eq!(result.unwrap().status, WrapUpStatus::Pending);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn returns_none_when_missing() {
|
async fn returns_none_when_missing() {
|
||||||
let ctx = TestContextBuilder::new().build();
|
let repo = InMemoryWrapUpRepository::new();
|
||||||
let result = get_wrapup::execute(&ctx, WrapUpId::generate())
|
let result = get_wrapup::execute(repo.clone(), WrapUpId::generate())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(result.is_none());
|
assert!(result.is_none());
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use chrono::{NaiveDate, Utc};
|
use chrono::{NaiveDate, Utc};
|
||||||
use domain::models::wrapup::{WrapUpRecord, WrapUpStatus};
|
use domain::models::wrapup::{WrapUpRecord, WrapUpStatus};
|
||||||
use domain::ports::WrapUpRepository;
|
use domain::ports::WrapUpRepository;
|
||||||
use domain::testing::InMemoryWrapUpRepository;
|
use domain::testing::{InMemoryWrapUpRepository, InMemoryWrapUpStatsQuery, NoopEventPublisher};
|
||||||
use domain::value_objects::WrapUpId;
|
use domain::value_objects::WrapUpId;
|
||||||
|
|
||||||
use crate::test_helpers::TestContextBuilder;
|
use crate::wrapup::{deps::HandleWrapUpRequestedDeps, handle_requested};
|
||||||
use crate::wrapup::handle_requested;
|
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn skips_if_already_ready() {
|
async fn skips_if_already_ready() {
|
||||||
@@ -27,12 +24,14 @@ async fn skips_if_already_ready() {
|
|||||||
};
|
};
|
||||||
repo.create(&record).await.unwrap();
|
repo.create(&record).await.unwrap();
|
||||||
|
|
||||||
let ctx = TestContextBuilder::new()
|
let deps = HandleWrapUpRequestedDeps {
|
||||||
.with_wrapup_repo(Arc::clone(&repo) as _)
|
wrapup_repo: repo.clone(),
|
||||||
.build();
|
event_publisher: NoopEventPublisher::new(),
|
||||||
|
wrapup_stats: InMemoryWrapUpStatsQuery::new(),
|
||||||
|
};
|
||||||
|
|
||||||
let result = handle_requested::execute(
|
let result = handle_requested::execute(
|
||||||
&ctx,
|
&deps,
|
||||||
wrapup_id,
|
wrapup_id,
|
||||||
None,
|
None,
|
||||||
NaiveDate::from_ymd_opt(2024, 1, 1).unwrap(),
|
NaiveDate::from_ymd_opt(2024, 1, 1).unwrap(),
|
||||||
@@ -46,8 +45,8 @@ async fn skips_if_already_ready() {
|
|||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn generates_wrapup_and_marks_complete() {
|
async fn generates_wrapup_and_marks_complete() {
|
||||||
let repo = InMemoryWrapUpRepository::new();
|
let repo = InMemoryWrapUpRepository::new();
|
||||||
let stats = domain::testing::InMemoryWrapUpStatsQuery::new();
|
let stats = InMemoryWrapUpStatsQuery::new();
|
||||||
let events = domain::testing::NoopEventPublisher::new();
|
let events = NoopEventPublisher::new();
|
||||||
let wrapup_id = WrapUpId::generate();
|
let wrapup_id = WrapUpId::generate();
|
||||||
let uid = uuid::Uuid::new_v4();
|
let uid = uuid::Uuid::new_v4();
|
||||||
|
|
||||||
@@ -64,14 +63,14 @@ async fn generates_wrapup_and_marks_complete() {
|
|||||||
};
|
};
|
||||||
repo.create(&record).await.unwrap();
|
repo.create(&record).await.unwrap();
|
||||||
|
|
||||||
let ctx = TestContextBuilder::new()
|
let deps = HandleWrapUpRequestedDeps {
|
||||||
.with_wrapup_repo(Arc::clone(&repo) as _)
|
wrapup_repo: repo.clone(),
|
||||||
.wrapup_stats(Arc::clone(&stats) as _)
|
event_publisher: events.clone(),
|
||||||
.with_event_publisher(Arc::clone(&events) as _)
|
wrapup_stats: stats.clone(),
|
||||||
.build();
|
};
|
||||||
|
|
||||||
let result = handle_requested::execute(
|
let result = handle_requested::execute(
|
||||||
&ctx,
|
&deps,
|
||||||
wrapup_id.clone(),
|
wrapup_id.clone(),
|
||||||
Some(uid),
|
Some(uid),
|
||||||
NaiveDate::from_ymd_opt(2024, 1, 1).unwrap(),
|
NaiveDate::from_ymd_opt(2024, 1, 1).unwrap(),
|
||||||
@@ -113,12 +112,14 @@ async fn skips_if_already_generating() {
|
|||||||
};
|
};
|
||||||
repo.create(&record).await.unwrap();
|
repo.create(&record).await.unwrap();
|
||||||
|
|
||||||
let ctx = TestContextBuilder::new()
|
let deps = HandleWrapUpRequestedDeps {
|
||||||
.with_wrapup_repo(Arc::clone(&repo) as _)
|
wrapup_repo: repo.clone(),
|
||||||
.build();
|
event_publisher: NoopEventPublisher::new(),
|
||||||
|
wrapup_stats: InMemoryWrapUpStatsQuery::new(),
|
||||||
|
};
|
||||||
|
|
||||||
let result = handle_requested::execute(
|
let result = handle_requested::execute(
|
||||||
&ctx,
|
&deps,
|
||||||
wrapup_id.clone(),
|
wrapup_id.clone(),
|
||||||
None,
|
None,
|
||||||
NaiveDate::from_ymd_opt(2024, 1, 1).unwrap(),
|
NaiveDate::from_ymd_opt(2024, 1, 1).unwrap(),
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
use domain::models::wrapup::{WrapUpRecord, WrapUpStatus};
|
use domain::models::wrapup::{WrapUpRecord, WrapUpStatus};
|
||||||
use domain::testing::InMemoryWrapUpRepository;
|
use domain::testing::InMemoryWrapUpRepository;
|
||||||
use domain::value_objects::WrapUpId;
|
use domain::value_objects::WrapUpId;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::test_helpers::TestContextBuilder;
|
|
||||||
use crate::wrapup::list_wrapups::{self, ListWrapUpsQuery};
|
use crate::wrapup::list_wrapups::{self, ListWrapUpsQuery};
|
||||||
|
|
||||||
fn make_record(user_id: Option<Uuid>) -> WrapUpRecord {
|
fn make_record(user_id: Option<Uuid>) -> WrapUpRecord {
|
||||||
@@ -34,16 +31,7 @@ async fn filters_by_user() {
|
|||||||
store.push(make_record(None));
|
store.push(make_record(None));
|
||||||
}
|
}
|
||||||
|
|
||||||
let ctx = TestContextBuilder::new().build();
|
let result = list_wrapups::execute(repo.clone(), ListWrapUpsQuery { user_id: Some(uid) })
|
||||||
let ctx = crate::context::AppContext {
|
|
||||||
repos: crate::context::Repositories {
|
|
||||||
wrapup_repo: Arc::clone(&repo) as _,
|
|
||||||
..ctx.repos
|
|
||||||
},
|
|
||||||
..ctx
|
|
||||||
};
|
|
||||||
|
|
||||||
let result = list_wrapups::execute(&ctx, ListWrapUpsQuery { user_id: Some(uid) })
|
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(result.len(), 1);
|
assert_eq!(result.len(), 1);
|
||||||
@@ -60,16 +48,7 @@ async fn returns_global_when_no_user() {
|
|||||||
store.push(make_record(Some(Uuid::new_v4())));
|
store.push(make_record(Some(Uuid::new_v4())));
|
||||||
}
|
}
|
||||||
|
|
||||||
let ctx = TestContextBuilder::new().build();
|
let result = list_wrapups::execute(repo.clone(), ListWrapUpsQuery { user_id: None })
|
||||||
let ctx = crate::context::AppContext {
|
|
||||||
repos: crate::context::Repositories {
|
|
||||||
wrapup_repo: Arc::clone(&repo) as _,
|
|
||||||
..ctx.repos
|
|
||||||
},
|
|
||||||
..ctx
|
|
||||||
};
|
|
||||||
|
|
||||||
let result = list_wrapups::execute(&ctx, ListWrapUpsQuery { user_id: None })
|
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(result.len(), 2);
|
assert_eq!(result.len(), 2);
|
||||||
|
|||||||
@@ -66,7 +66,12 @@ pub async fn post_generate(
|
|||||||
start_date: start,
|
start_date: start,
|
||||||
end_date: end,
|
end_date: end,
|
||||||
};
|
};
|
||||||
let id = generate::execute(&state.app_ctx, cmd).await?;
|
let id = generate::execute(
|
||||||
|
state.app_ctx.repos.wrapup_repo.clone(),
|
||||||
|
state.app_ctx.services.event_publisher.clone(),
|
||||||
|
cmd,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
Ok(Json(WrapUpGeneratedResponse {
|
Ok(Json(WrapUpGeneratedResponse {
|
||||||
id: id.value().to_string(),
|
id: id.value().to_string(),
|
||||||
}))
|
}))
|
||||||
@@ -85,7 +90,7 @@ pub async fn get_list(
|
|||||||
user: AuthenticatedUser,
|
user: AuthenticatedUser,
|
||||||
) -> Result<Json<WrapUpListResponse>, ApiError> {
|
) -> Result<Json<WrapUpListResponse>, ApiError> {
|
||||||
let records = list_wrapups::execute(
|
let records = list_wrapups::execute(
|
||||||
&state.app_ctx,
|
state.app_ctx.repos.wrapup_repo.clone(),
|
||||||
ListWrapUpsQuery {
|
ListWrapUpsQuery {
|
||||||
user_id: Some(user.0.value()),
|
user_id: Some(user.0.value()),
|
||||||
},
|
},
|
||||||
@@ -111,7 +116,7 @@ pub async fn get_status(
|
|||||||
_user: AuthenticatedUser,
|
_user: AuthenticatedUser,
|
||||||
Path(id): Path<Uuid>,
|
Path(id): Path<Uuid>,
|
||||||
) -> Result<Json<WrapUpStatusResponse>, ApiError> {
|
) -> Result<Json<WrapUpStatusResponse>, ApiError> {
|
||||||
let record = get_wrapup::execute(&state.app_ctx, WrapUpId::from_uuid(id))
|
let record = get_wrapup::execute(state.app_ctx.repos.wrapup_repo.clone(), WrapUpId::from_uuid(id))
|
||||||
.await?
|
.await?
|
||||||
.ok_or_else(|| DomainError::NotFound("wrap-up not found".into()))?;
|
.ok_or_else(|| DomainError::NotFound("wrap-up not found".into()))?;
|
||||||
Ok(Json(record_to_dto(&record)))
|
Ok(Json(record_to_dto(&record)))
|
||||||
@@ -133,7 +138,7 @@ pub async fn get_report(
|
|||||||
_user: AuthenticatedUser,
|
_user: AuthenticatedUser,
|
||||||
Path(id): Path<Uuid>,
|
Path(id): Path<Uuid>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
match get_wrapup::execute(&state.app_ctx, WrapUpId::from_uuid(id)).await {
|
match get_wrapup::execute(state.app_ctx.repos.wrapup_repo.clone(), WrapUpId::from_uuid(id)).await {
|
||||||
Ok(Some(record)) if record.status == WrapUpStatus::Ready => match record.report {
|
Ok(Some(record)) if record.status == WrapUpStatus::Ready => match record.report {
|
||||||
Some(ref report) => {
|
Some(ref report) => {
|
||||||
let json = serde_json::to_string(report).unwrap_or_default();
|
let json = serde_json::to_string(report).unwrap_or_default();
|
||||||
@@ -163,7 +168,7 @@ pub async fn delete_wrapup_handler(
|
|||||||
_admin: AdminApiUser,
|
_admin: AdminApiUser,
|
||||||
Path(id): Path<Uuid>,
|
Path(id): Path<Uuid>,
|
||||||
) -> Result<StatusCode, ApiError> {
|
) -> Result<StatusCode, ApiError> {
|
||||||
delete_wrapup::execute(&state.app_ctx, WrapUpId::from_uuid(id)).await?;
|
delete_wrapup::execute(state.app_ctx.repos.wrapup_repo.clone(), WrapUpId::from_uuid(id)).await?;
|
||||||
Ok(StatusCode::NO_CONTENT)
|
Ok(StatusCode::NO_CONTENT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -182,8 +182,14 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
let mut periodic_jobs: Vec<Arc<dyn PeriodicJob>> = vec![
|
let mut periodic_jobs: Vec<Arc<dyn PeriodicJob>> = vec![
|
||||||
Arc::new(application::jobs::ImportSessionCleanupJob::new(ctx.repos.import_session.clone())),
|
Arc::new(application::jobs::ImportSessionCleanupJob::new(ctx.repos.import_session.clone())),
|
||||||
Arc::new(application::jobs::WatchEventCleanupJob::new(ctx.repos.watch_event.clone())),
|
Arc::new(application::jobs::WatchEventCleanupJob::new(ctx.repos.watch_event.clone())),
|
||||||
Arc::new(application::jobs::WrapUpAutoGenerateJob::new(ctx.clone())),
|
Arc::new(application::jobs::WrapUpAutoGenerateJob::new(
|
||||||
Arc::new(application::jobs::WrapUpCleanupJob::new(ctx.clone())),
|
Arc::clone(&ctx.repos.user),
|
||||||
|
Arc::clone(&ctx.repos.wrapup_repo),
|
||||||
|
Arc::clone(&ctx.services.event_publisher),
|
||||||
|
)),
|
||||||
|
Arc::new(application::jobs::WrapUpCleanupJob::new(
|
||||||
|
Arc::clone(&ctx.repos.wrapup_repo),
|
||||||
|
)),
|
||||||
Arc::new(application::jobs::RefreshSessionCleanupJob::new(
|
Arc::new(application::jobs::RefreshSessionCleanupJob::new(
|
||||||
ctx.clone(),
|
ctx.clone(),
|
||||||
)),
|
)),
|
||||||
@@ -234,7 +240,11 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
Arc::clone(&ctx.repos.search_command),
|
Arc::clone(&ctx.repos.search_command),
|
||||||
)) as Arc<dyn EventHandler>;
|
)) as Arc<dyn EventHandler>;
|
||||||
let wrapup_handler = Arc::new(
|
let wrapup_handler = Arc::new(
|
||||||
application::wrapup::event_handler::WrapUpEventHandler::new(ctx.clone()),
|
application::wrapup::event_handler::WrapUpEventHandler::new(
|
||||||
|
Arc::clone(&ctx.repos.wrapup_repo),
|
||||||
|
Arc::clone(&ctx.services.event_publisher),
|
||||||
|
Arc::clone(&ctx.repos.wrapup_stats),
|
||||||
|
),
|
||||||
) as Arc<dyn EventHandler>;
|
) as Arc<dyn EventHandler>;
|
||||||
let reindex_handler =
|
let reindex_handler =
|
||||||
Arc::new(SearchReindexHandler::new(ReindexSearchDeps {
|
Arc::new(SearchReindexHandler::new(ReindexSearchDeps {
|
||||||
@@ -297,7 +307,11 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
)) as Arc<dyn EventHandler>;
|
)) as Arc<dyn EventHandler>;
|
||||||
tracing::info!("federation event handler registered");
|
tracing::info!("federation event handler registered");
|
||||||
let wrapup_handler = Arc::new(
|
let wrapup_handler = Arc::new(
|
||||||
application::wrapup::event_handler::WrapUpEventHandler::new(ctx.clone()),
|
application::wrapup::event_handler::WrapUpEventHandler::new(
|
||||||
|
Arc::clone(&ctx.repos.wrapup_repo),
|
||||||
|
Arc::clone(&ctx.services.event_publisher),
|
||||||
|
Arc::clone(&ctx.repos.wrapup_stats),
|
||||||
|
),
|
||||||
) as Arc<dyn EventHandler>;
|
) as Arc<dyn EventHandler>;
|
||||||
let reindex_handler =
|
let reindex_handler =
|
||||||
Arc::new(SearchReindexHandler::new(ReindexSearchDeps {
|
Arc::new(SearchReindexHandler::new(ReindexSearchDeps {
|
||||||
|
|||||||
Reference in New Issue
Block a user