feat(application): wrapup generate/get/list use cases
This commit is contained in:
@@ -6,7 +6,7 @@ use domain::ports::{
|
|||||||
MovieRepository, PasswordHasher, PersonCommand, PersonQuery, PosterFetcherClient,
|
MovieRepository, PasswordHasher, PersonCommand, PersonQuery, PosterFetcherClient,
|
||||||
RemoteWatchlistRepository, ReviewRepository, SearchCommand, SearchPort, SocialQueryPort,
|
RemoteWatchlistRepository, ReviewRepository, SearchCommand, SearchPort, SocialQueryPort,
|
||||||
StatsRepository, UserProfileFieldsRepository, UserRepository, WatchEventRepository,
|
StatsRepository, UserProfileFieldsRepository, UserRepository, WatchEventRepository,
|
||||||
WatchlistRepository, WrapUpStatsQuery, WebhookTokenRepository,
|
WatchlistRepository, WrapUpRepository, WrapUpStatsQuery, WebhookTokenRepository,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::config::AppConfig;
|
use crate::config::AppConfig;
|
||||||
@@ -32,6 +32,7 @@ pub struct Repositories {
|
|||||||
pub remote_watchlist: Arc<dyn RemoteWatchlistRepository>,
|
pub remote_watchlist: Arc<dyn RemoteWatchlistRepository>,
|
||||||
pub social_query: Arc<dyn SocialQueryPort>,
|
pub social_query: Arc<dyn SocialQueryPort>,
|
||||||
pub wrapup_stats: Arc<dyn WrapUpStatsQuery>,
|
pub wrapup_stats: Arc<dyn WrapUpStatsQuery>,
|
||||||
|
pub wrapup_repo: Arc<dyn WrapUpRepository>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use domain::testing::{InMemoryWrapUpStatsQuery, NoopRemoteWatchlistRepository, NoopSocialQueryPort};
|
use domain::testing::{InMemoryWrapUpRepository, InMemoryWrapUpStatsQuery, NoopRemoteWatchlistRepository, NoopSocialQueryPort};
|
||||||
use domain::{
|
use domain::{
|
||||||
ports::{
|
ports::{
|
||||||
AuthService, DiaryExporter, DiaryRepository, DocumentParser, EventPublisher, ImageStorage,
|
AuthService, DiaryExporter, DiaryRepository, DocumentParser, EventPublisher, ImageStorage,
|
||||||
@@ -8,7 +8,7 @@ use domain::{
|
|||||||
MovieRepository, PasswordHasher, PersonCommand, PersonQuery, PosterFetcherClient,
|
MovieRepository, PasswordHasher, PersonCommand, PersonQuery, PosterFetcherClient,
|
||||||
ReviewRepository, SearchCommand, SearchPort, StatsRepository, UserProfileFieldsRepository,
|
ReviewRepository, SearchCommand, SearchPort, StatsRepository, UserProfileFieldsRepository,
|
||||||
UserRepository, WatchEventRepository, WatchlistRepository, WebhookTokenRepository,
|
UserRepository, WatchEventRepository, WatchlistRepository, WebhookTokenRepository,
|
||||||
WrapUpStatsQuery,
|
WrapUpRepository, WrapUpStatsQuery,
|
||||||
},
|
},
|
||||||
testing::{
|
testing::{
|
||||||
FakeAuthService, FakeMetadataClient, FakePasswordHasher, InMemoryMovieRepository,
|
FakeAuthService, FakeMetadataClient, FakePasswordHasher, InMemoryMovieRepository,
|
||||||
@@ -52,6 +52,7 @@ pub struct TestContextBuilder {
|
|||||||
pub search_port: Arc<dyn SearchPort>,
|
pub search_port: Arc<dyn SearchPort>,
|
||||||
pub search_command: Arc<dyn SearchCommand>,
|
pub search_command: Arc<dyn SearchCommand>,
|
||||||
pub wrapup_stats: Arc<dyn WrapUpStatsQuery>,
|
pub wrapup_stats: Arc<dyn WrapUpStatsQuery>,
|
||||||
|
pub wrapup_repo: Arc<dyn WrapUpRepository>,
|
||||||
pub config: AppConfig,
|
pub config: AppConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,6 +84,7 @@ impl TestContextBuilder {
|
|||||||
search_port: Arc::new(PanicSearchPort),
|
search_port: Arc::new(PanicSearchPort),
|
||||||
search_command: Arc::new(PanicSearchCommand),
|
search_command: Arc::new(PanicSearchCommand),
|
||||||
wrapup_stats: InMemoryWrapUpStatsQuery::new(),
|
wrapup_stats: InMemoryWrapUpStatsQuery::new(),
|
||||||
|
wrapup_repo: InMemoryWrapUpRepository::new(),
|
||||||
config: AppConfig {
|
config: AppConfig {
|
||||||
allow_registration: true,
|
allow_registration: true,
|
||||||
base_url: "http://localhost:3000".into(),
|
base_url: "http://localhost:3000".into(),
|
||||||
@@ -153,6 +155,7 @@ impl TestContextBuilder {
|
|||||||
remote_watchlist: Arc::new(NoopRemoteWatchlistRepository),
|
remote_watchlist: Arc::new(NoopRemoteWatchlistRepository),
|
||||||
social_query: Arc::new(NoopSocialQueryPort),
|
social_query: Arc::new(NoopSocialQueryPort),
|
||||||
wrapup_stats: self.wrapup_stats,
|
wrapup_stats: self.wrapup_stats,
|
||||||
|
wrapup_repo: self.wrapup_repo,
|
||||||
},
|
},
|
||||||
services: Services {
|
services: Services {
|
||||||
auth: self.auth_service,
|
auth: self.auth_service,
|
||||||
|
|||||||
8
crates/application/src/wrapup/commands.rs
Normal file
8
crates/application/src/wrapup/commands.rs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
use chrono::NaiveDate;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
pub struct RequestWrapUpCommand {
|
||||||
|
pub user_id: Option<Uuid>,
|
||||||
|
pub start_date: NaiveDate,
|
||||||
|
pub end_date: NaiveDate,
|
||||||
|
}
|
||||||
47
crates/application/src/wrapup/generate.rs
Normal file
47
crates/application/src/wrapup/generate.rs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
use domain::errors::DomainError;
|
||||||
|
use domain::events::DomainEvent;
|
||||||
|
use domain::models::wrapup::WrapUpStatus;
|
||||||
|
use domain::value_objects::{UserId, WrapUpId};
|
||||||
|
|
||||||
|
use crate::context::AppContext;
|
||||||
|
use crate::wrapup::commands::RequestWrapUpCommand;
|
||||||
|
|
||||||
|
pub async fn execute(ctx: &AppContext, cmd: RequestWrapUpCommand) -> Result<WrapUpId, DomainError> {
|
||||||
|
let existing = ctx
|
||||||
|
.repos
|
||||||
|
.wrapup_repo
|
||||||
|
.find_existing(cmd.user_id, cmd.start_date, cmd.end_date)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if let Some(ref rec) = existing {
|
||||||
|
if rec.status == WrapUpStatus::Ready || rec.status == WrapUpStatus::Generating {
|
||||||
|
return Ok(rec.id.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let id = WrapUpId::generate();
|
||||||
|
let record = domain::models::wrapup::WrapUpRecord {
|
||||||
|
id: id.clone(),
|
||||||
|
user_id: cmd.user_id,
|
||||||
|
start_date: cmd.start_date,
|
||||||
|
end_date: cmd.end_date,
|
||||||
|
status: WrapUpStatus::Pending,
|
||||||
|
report_json: None,
|
||||||
|
error_message: None,
|
||||||
|
created_at: chrono::Utc::now().naive_utc(),
|
||||||
|
completed_at: None,
|
||||||
|
};
|
||||||
|
ctx.repos.wrapup_repo.create(&record).await?;
|
||||||
|
|
||||||
|
ctx.services
|
||||||
|
.event_publisher
|
||||||
|
.publish(&DomainEvent::WrapUpRequested {
|
||||||
|
wrapup_id: id.clone(),
|
||||||
|
user_id: cmd.user_id.map(UserId::from_uuid),
|
||||||
|
start_date: cmd.start_date,
|
||||||
|
end_date: cmd.end_date,
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(id)
|
||||||
|
}
|
||||||
9
crates/application/src/wrapup/get_wrapup.rs
Normal file
9
crates/application/src/wrapup/get_wrapup.rs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
use domain::errors::DomainError;
|
||||||
|
use domain::models::wrapup::WrapUpRecord;
|
||||||
|
use domain::value_objects::WrapUpId;
|
||||||
|
|
||||||
|
use crate::context::AppContext;
|
||||||
|
|
||||||
|
pub async fn execute(ctx: &AppContext, id: WrapUpId) -> Result<Option<WrapUpRecord>, DomainError> {
|
||||||
|
ctx.repos.wrapup_repo.get_by_id(&id).await
|
||||||
|
}
|
||||||
20
crates/application/src/wrapup/list_wrapups.rs
Normal file
20
crates/application/src/wrapup/list_wrapups.rs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use domain::errors::DomainError;
|
||||||
|
use domain::models::wrapup::WrapUpRecord;
|
||||||
|
|
||||||
|
use crate::context::AppContext;
|
||||||
|
|
||||||
|
pub struct ListWrapUpsQuery {
|
||||||
|
pub user_id: Option<Uuid>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn execute(
|
||||||
|
ctx: &AppContext,
|
||||||
|
query: ListWrapUpsQuery,
|
||||||
|
) -> Result<Vec<WrapUpRecord>, DomainError> {
|
||||||
|
match query.user_id {
|
||||||
|
Some(uid) => ctx.repos.wrapup_repo.list_for_user(uid).await,
|
||||||
|
None => ctx.repos.wrapup_repo.list_global().await,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,2 +1,6 @@
|
|||||||
|
pub mod commands;
|
||||||
pub mod compute;
|
pub mod compute;
|
||||||
|
pub mod generate;
|
||||||
|
pub mod get_wrapup;
|
||||||
|
pub mod list_wrapups;
|
||||||
pub mod queries;
|
pub mod queries;
|
||||||
|
|||||||
@@ -194,6 +194,7 @@ async fn wire_dependencies() -> anyhow::Result<(AppState, axum::Router)> {
|
|||||||
#[cfg(not(feature = "federation"))]
|
#[cfg(not(feature = "federation"))]
|
||||||
social_query: Arc::new(domain::testing::NoopSocialQueryPort),
|
social_query: Arc::new(domain::testing::NoopSocialQueryPort),
|
||||||
wrapup_stats: Arc::new(domain::testing::PanicWrapUpStatsQuery) as Arc<dyn domain::ports::WrapUpStatsQuery>,
|
wrapup_stats: Arc::new(domain::testing::PanicWrapUpStatsQuery) as Arc<dyn domain::ports::WrapUpStatsQuery>,
|
||||||
|
wrapup_repo: Arc::new(domain::testing::PanicWrapUpRepository) as Arc<dyn domain::ports::WrapUpRepository>,
|
||||||
},
|
},
|
||||||
services: Services {
|
services: Services {
|
||||||
auth: auth_service,
|
auth: auth_service,
|
||||||
|
|||||||
@@ -568,6 +568,50 @@ impl domain::ports::WebhookTokenRepository for Panic {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl domain::ports::WrapUpStatsQuery for Panic {
|
||||||
|
async fn get_reviews_with_profiles(
|
||||||
|
&self,
|
||||||
|
_: &domain::models::wrapup::WrapUpScope,
|
||||||
|
_: &domain::models::wrapup::DateRange,
|
||||||
|
) -> Result<Vec<domain::ports::WrapUpMovieRow>, DomainError> {
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl domain::ports::WrapUpRepository for Panic {
|
||||||
|
async fn create(&self, _: &domain::models::wrapup::WrapUpRecord) -> Result<(), DomainError> {
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
|
async fn update_status(
|
||||||
|
&self,
|
||||||
|
_: &domain::value_objects::WrapUpId,
|
||||||
|
_: &domain::models::wrapup::WrapUpStatus,
|
||||||
|
_: Option<&str>,
|
||||||
|
) -> Result<(), DomainError> {
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
|
async fn set_complete(&self, _: &domain::value_objects::WrapUpId, _: &str) -> Result<(), DomainError> {
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
|
async fn get_by_id(&self, _: &domain::value_objects::WrapUpId) -> Result<Option<domain::models::wrapup::WrapUpRecord>, DomainError> {
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
|
async fn list_for_user(&self, _: uuid::Uuid) -> Result<Vec<domain::models::wrapup::WrapUpRecord>, DomainError> {
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
|
async fn list_global(&self) -> Result<Vec<domain::models::wrapup::WrapUpRecord>, DomainError> {
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
|
async fn find_existing(
|
||||||
|
&self,
|
||||||
|
_: Option<uuid::Uuid>,
|
||||||
|
_: chrono::NaiveDate,
|
||||||
|
_: chrono::NaiveDate,
|
||||||
|
) -> Result<Option<domain::models::wrapup::WrapUpRecord>, DomainError> {
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// --- Single state factory — only auth_service varies ---
|
// --- Single state factory — only auth_service varies ---
|
||||||
|
|
||||||
pub fn make_test_state(auth_service: Arc<dyn AuthService>) -> crate::state::AppState {
|
pub fn make_test_state(auth_service: Arc<dyn AuthService>) -> crate::state::AppState {
|
||||||
@@ -593,6 +637,8 @@ pub fn make_test_state(auth_service: Arc<dyn AuthService>) -> crate::state::AppS
|
|||||||
search_command: Arc::clone(&repo) as _,
|
search_command: Arc::clone(&repo) as _,
|
||||||
remote_watchlist: Arc::clone(&repo) as _,
|
remote_watchlist: Arc::clone(&repo) as _,
|
||||||
social_query: Arc::clone(&repo) as _,
|
social_query: Arc::clone(&repo) as _,
|
||||||
|
wrapup_stats: Arc::clone(&repo) as _,
|
||||||
|
wrapup_repo: Arc::clone(&repo) as _,
|
||||||
},
|
},
|
||||||
services: Services {
|
services: Services {
|
||||||
auth: auth_service,
|
auth: auth_service,
|
||||||
|
|||||||
@@ -415,6 +415,8 @@ async fn test_app() -> Router {
|
|||||||
search_command: Arc::new(PanicSearchCommand),
|
search_command: Arc::new(PanicSearchCommand),
|
||||||
remote_watchlist: Arc::new(PanicRemoteWatchlist),
|
remote_watchlist: Arc::new(PanicRemoteWatchlist),
|
||||||
social_query: Arc::new(PanicSocialQuery),
|
social_query: Arc::new(PanicSocialQuery),
|
||||||
|
wrapup_stats: Arc::new(domain::testing::PanicWrapUpStatsQuery) as _,
|
||||||
|
wrapup_repo: Arc::new(domain::testing::PanicWrapUpRepository) as _,
|
||||||
},
|
},
|
||||||
services: Services {
|
services: Services {
|
||||||
auth: Arc::new(PanicAuth),
|
auth: Arc::new(PanicAuth),
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
#[cfg(not(feature = "federation"))]
|
#[cfg(not(feature = "federation"))]
|
||||||
social_query: Arc::new(domain::testing::NoopSocialQueryPort),
|
social_query: Arc::new(domain::testing::NoopSocialQueryPort),
|
||||||
wrapup_stats: Arc::new(domain::testing::PanicWrapUpStatsQuery) as Arc<dyn domain::ports::WrapUpStatsQuery>,
|
wrapup_stats: Arc::new(domain::testing::PanicWrapUpStatsQuery) as Arc<dyn domain::ports::WrapUpStatsQuery>,
|
||||||
|
wrapup_repo: Arc::new(domain::testing::PanicWrapUpRepository) as Arc<dyn domain::ports::WrapUpRepository>,
|
||||||
},
|
},
|
||||||
services: Services {
|
services: Services {
|
||||||
auth: auth_service,
|
auth: auth_service,
|
||||||
|
|||||||
Reference in New Issue
Block a user