Files
movies-diary/crates/application/src/watchlist/add.rs
Gabriel Kaszewski 6c295866a0 feat: atomic wrapup, movie, integration writes
Ride writes: WrapUpRequested/Completed (wrapup create/set_complete),
MovieDiscovered (resolve upsert, new+ext id only), PosterSynced (poster
handler upsert), MovieDeleted (delete_movie), WatchEventIngested (save).
Deps drop event_publisher: wrapup, ingest, delete_review, watchlist add,
review logger.

Remaining .publish( sites:
announce-only: users/delete_account UserDeleted, person/get +
get_credits PersonEnrichmentRequested, jobs/enrichment_staleness,
http-axum search, movies/sync_poster + poster_sync_handler +
image-converter backfill + users/update_profile ImageStored (object
storage), activitypub federation_event_bridge (reacting to events).
rides write, deferred: social/execute (see report),
activitypub review_handler MovieEnrichmentRequested (after
save_remote_review).
2026-10-26 01:02:34 +01:00

37 lines
1.1 KiB
Rust

use domain::{
errors::DomainError, events::DomainEvent, models::WatchlistEntry, value_objects::UserId,
};
use crate::{
movies::resolve::resolve_and_persist_movie,
watchlist::{commands::AddToWatchlistCommand, deps::WatchlistAddDeps},
};
pub async fn execute(
deps: &WatchlistAddDeps,
cmd: AddToWatchlistCommand,
) -> Result<(), DomainError> {
let user_id = UserId::from_uuid(cmd.user_id);
let (movie, _is_new) = resolve_and_persist_movie(
&cmd.input,
deps.movie_command.as_ref(),
deps.movie_query.as_ref(),
deps.metadata.as_ref(),
)
.await?;
let entry = WatchlistEntry::new(user_id.clone(), movie.id().clone());
let event = DomainEvent::WatchlistEntryAdded {
user_id,
movie_id: movie.id().clone(),
movie_title: movie.title().value().to_string(),
release_year: movie.release_year().value(),
external_metadata_id: movie.external_metadata_id().map(|e| e.value().to_string()),
added_at: entry.added_at,
};
deps.watchlist.add(&entry, &[event]).await?;
Ok(())
}